Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 174 additions & 4 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,9 @@ type Migrations = (RemoveXTokensMigrationStatus<Runtime>);

#[cfg(feature = "runtime-benchmarks")]
mod benches {
use super::*;
use alloc::boxed::Box;

frame_benchmarking::define_benchmarks!(
[module_aggregated_dex, AggregatedDex]
[module_asset_registry, AssetRegistry]
Expand Down Expand Up @@ -2090,14 +2093,181 @@ mod benches {
// Acala Ecosystem Modules
[nutsfinance_stable_asset, StableAsset]
// XCM
// [pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
);

use crate::xcm_config::AssetHubLocation;
use cumulus_primitives_core::{Asset, Assets, Fungible, GeneralKey, Location, ParaId, Parachain, ParentThen};
use frame_benchmarking::BenchmarkError;

const DOT_UNITS: Balance = 10_000_000_000;
const DOT_CENTS: Balance = DOT_UNITS / 100;

parameter_types! {
pub AssetHubParaId: ParaId = ParaId::from(parachains::asset_hub_polkadot::ID);
pub FeeAssetId: AssetId = AssetId(Location::parent());
pub const ToSiblingBaseDeliveryFee: u128 = DOT_CENTS.saturating_mul(3);
}

pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
FeeAssetId,
ToSiblingBaseDeliveryFee,
TransactionByteFee,
XcmpQueue,
>;

parameter_types! {
pub ExistentialDepositAsset: Option<Asset> = Some((
Location::parent(),
NativeTokenExistentialDeposit::get()
).into());
pub const RandomParaId: ParaId = ParaId::new(43211234);
}

impl pallet_xcm::benchmarking::Config for Runtime {
type DeliveryHelper = (
polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
xcm_config::XcmConfig,
ExistentialDepositAsset,
PriceForSiblingParachainDelivery,
RandomParaId,
ParachainSystem,
>,
polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
xcm_config::XcmConfig,
ExistentialDepositAsset,
PriceForSiblingParachainDelivery,
AssetHubParaId,
ParachainSystem,
>,
);

fn reachable_dest() -> Option<Location> {
Some(AssetHubLocation::get())
}

fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
// XcmTeleportFilter is Nothing
None
}

fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(RandomParaId::get());

let encoded = ACA.encode();
let mut data = [0u8; 32];
let len = encoded.len().min(32);
data[..len].copy_from_slice(&encoded[..len]);

Some((
Asset {
id: AssetId(Location::new(
0,
GeneralKey {
data: data,
length: encoded.len() as u8,
},
)),
fun: Fungible(NativeTokenExistentialDeposit::get() * 100),
},
ParentThen(Parachain(RandomParaId::get().into()).into()).into(),
))
}

fn set_up_complex_asset_transfer() -> Option<(Assets, u32, Location, Box<dyn FnOnce()>)> {
// transfer AUSD from this parachain to RandomParaId parachain
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(RandomParaId::get());

let dest = Location::new(1, Parachain(RandomParaId::get().into()));

// fee asset
let fee_amount = NativeTokenExistentialDeposit::get();
let aca_encoded = ACA.encode();
let mut aca_data = [0u8; 32];
let len = aca_encoded.len().min(32);
aca_data[..len].copy_from_slice(&aca_encoded[..len]);
let fee_location = Location::new(
0,
GeneralKey {
data: aca_data,
length: aca_encoded.len() as u8,
},
);
let fee_asset: Asset = (fee_location, fee_amount).into();

// asset to transfer
let asset_amount = 1_000_000_000_000u128;
let asset_balance = asset_amount * 10;
let ausd_encoded = AUSD.encode();
let mut ausd_data = [0u8; 32];
let len = ausd_encoded.len().min(32);
ausd_data[..len].copy_from_slice(&ausd_encoded[..len]);
let asset_location = Location::new(
0,
GeneralKey {
data: ausd_data,
length: ausd_encoded.len() as u8,
},
);
let transfer_asset: Asset = (asset_location, asset_amount).into();

let assets: Assets = vec![fee_asset.clone(), transfer_asset].into();

let who = frame_benchmarking::whitelisted_caller();
// Give some multiple of the existential deposit
let native_balance = NativeTokenExistentialDeposit::get() * 1000;
let _ = <Balances as frame_support::traits::Currency<_>>::make_free_balance_be(&who, native_balance);
let _ = Tokens::deposit(AUSD, &who, asset_balance);
// verify initial balance
assert_eq!(Balances::free_balance(&who), native_balance);
assert_eq!(Tokens::free_balance(AUSD, &who), asset_balance);

let fee_index = if assets.get(0).unwrap().eq(&fee_asset) { 0 } else { 1 };

// verify transferred successfully
let verify = Box::new(move || {
// verify native balance after transfer, decreased by transferred fee amount
// (plus transport fees)
assert!(Balances::free_balance(&who) <= native_balance - fee_amount);
// verify asset balance after transfer, decreased by transferred asset amount
assert_eq!(Tokens::free_balance(AUSD, &who), asset_balance - asset_amount);
});
Some((assets, fee_index as u32, dest, verify))
}

fn get_asset() -> Asset {
Asset {
id: AssetId(Location::parent()),
fun: Fungible(DOT_UNITS),
}
}
}

impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = xcm_config::XcmConfig;
type AccountIdConverter = xcm_config::LocationToAccountId;
type DeliveryHelper = polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
xcm_config::XcmConfig,
ExistentialDepositAsset,
PriceForSiblingParachainDelivery,
AssetHubParaId,
ParachainSystem,
>;
fn valid_destination() -> Result<Location, BenchmarkError> {
Ok(AssetHubLocation::get())
}
fn worst_case_holding(_depositable_count: u32) -> Assets {
let assets: Vec<Asset> = vec![Asset {
id: AssetId(Location::parent()),
fun: Fungible(1_000 * DOT_UNITS),
}];
assets.into()
}
}

pub use frame_benchmarking::{BenchmarkBatch, BenchmarkList};
pub use frame_support::traits::{StorageInfoTrait, WhitelistedStorageKeys};
// pub use frame_system_benchmarking::{
// extensions::Pallet as SystemExtensionsBench, Pallet as SystemBench,
// };
pub use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
pub use sp_storage::TrackedStorageKey;
}

Expand Down
66 changes: 34 additions & 32 deletions runtime/acala/src/weights/module_aggregated_dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@

//! Autogenerated weights for module_aggregated_dex
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 35.0.1
//! DATE: 2024-04-29, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `ip-172-31-41-141`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
//! WASM-EXECUTION: Compiled, CHAIN: Some("acala-dev"), DB CACHE: 1024
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 51.0.0
//! DATE: 2025-12-04, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `ip-172-31-17-239`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
//! WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024

// Executed Command:
// target/production/acala
// frame-omni-bencher
// v1
// benchmark
// pallet
// --chain=acala-dev
// --runtime
// target/release/wbuild/acala-runtime/acala_runtime.compact.compressed.wasm
// --steps=50
// --repeat=20
// --pallet=*
Expand All @@ -51,59 +53,59 @@ impl<T: frame_system::Config> module_aggregated_dex::WeightInfo for WeightInfo<T
// Proof: `Dex::TradingPairStatuses` (`max_values`: None, `max_size`: Some(195), added: 2670, mode: `MaxEncodedLen`)
// Storage: `Dex::LiquidityPool` (r:3 w:3)
// Proof: `Dex::LiquidityPool` (`max_values`: None, `max_size`: Some(126), added: 2601, mode: `MaxEncodedLen`)
// Storage: `System::Account` (r:1 w:1)
// Storage: `System::Account` (r:2 w:2)
// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
// Storage: `Tokens::Accounts` (r:2 w:2)
// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(147), added: 2622, mode: `MaxEncodedLen`)
/// The range of component `u` is `[2, 4]`.
fn swap_with_exact_supply(u: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1842 + u * (112 ±0)`
// Estimated: `6234 + u * (643 ±18)`
// Minimum execution time: 86_812 nanoseconds.
Weight::from_parts(66_480_055, 6234)
// Standard Error: 91_043
.saturating_add(Weight::from_parts(12_057_473, 0).saturating_mul(u.into()))
.saturating_add(T::DbWeight::get().reads(1))
// Measured: `475 + u * (112 ±0)`
// Estimated: `6234 + u * (643 ±19)`
// Minimum execution time: 121_994 nanoseconds.
Weight::from_parts(94_087_716, 6234)
// Standard Error: 94_446
.saturating_add(Weight::from_parts(15_905_369, 0).saturating_mul(u.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(u.into())))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(T::DbWeight::get().writes(3))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(u.into())))
.saturating_add(Weight::from_parts(0, 643).saturating_mul(u.into()))
}
// Storage: `Dex::TradingPairStatuses` (r:3 w:0)
// Proof: `Dex::TradingPairStatuses` (`max_values`: None, `max_size`: Some(195), added: 2670, mode: `MaxEncodedLen`)
// Storage: `Dex::LiquidityPool` (r:3 w:3)
// Proof: `Dex::LiquidityPool` (`max_values`: None, `max_size`: Some(126), added: 2601, mode: `MaxEncodedLen`)
// Storage: `System::Account` (r:1 w:1)
// Storage: `System::Account` (r:2 w:2)
// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
// Storage: `Tokens::Accounts` (r:2 w:2)
// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(147), added: 2622, mode: `MaxEncodedLen`)
/// The range of component `u` is `[2, 4]`.
fn swap_with_exact_target(u: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1842 + u * (112 ±0)`
// Estimated: `6234 + u * (643 ±18)`
// Minimum execution time: 93_849 nanoseconds.
Weight::from_parts(65_961_366, 6234)
// Standard Error: 152_574
.saturating_add(Weight::from_parts(17_376_660, 0).saturating_mul(u.into()))
.saturating_add(T::DbWeight::get().reads(1))
// Measured: `475 + u * (112 ±0)`
// Estimated: `6234 + u * (643 ±19)`
// Minimum execution time: 135_179 nanoseconds.
Weight::from_parts(88_922_478, 6234)
// Standard Error: 138_298
.saturating_add(Weight::from_parts(25_304_348, 0).saturating_mul(u.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(u.into())))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(T::DbWeight::get().writes(3))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(u.into())))
.saturating_add(Weight::from_parts(0, 643).saturating_mul(u.into()))
}
// Storage: `AggregatedDex::AggregatedSwapPaths` (r:0 w:5)
// Storage: `AggregatedDex::AggregatedSwapPaths` (r:0 w:3)
// Proof: `AggregatedDex::AggregatedSwapPaths` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `n` is `[0, 6]`.
/// The range of component `n` is `[0, 4]`.
fn update_aggregated_swap_paths(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `666`
// Estimated: `666`
// Minimum execution time: 3_971 nanoseconds.
Weight::from_parts(3_692_678, 666)
// Standard Error: 11_381
.saturating_add(Weight::from_parts(1_464_785, 0).saturating_mul(n.into()))
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_294 nanoseconds.
Weight::from_parts(2_583_870, 0)
// Standard Error: 36_646
.saturating_add(Weight::from_parts(2_590_708, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into())))
}
}
Loading