From faaf9dcc9a80273e2cd3665f827cdca6f050b8be Mon Sep 17 00:00:00 2001 From: Jamie Date: Sat, 18 May 2024 12:56:43 +0800 Subject: [PATCH] Fix xcm benchmark tests (#1333) * update to v1.6.0 Signed-off-by: Charles Ferrell * update primitives Signed-off-by: Charles Ferrell * bump a few pallets Signed-off-by: Charles Ferrell * compile more pallets Signed-off-by: Charles Ferrell * [no-ci] finish compiling pallets Signed-off-by: Charles Ferrell * [no ci] update calamari Signed-off-by: Charles Ferrell * calamari xcmp module configuration Signed-off-by: Charles Ferrell * [no ci] compile calamari runtime Signed-off-by: Charles Ferrell * [no ci] get lottery test to compile Signed-off-by: Charles Ferrell * [no ci] manta runtime update Signed-off-by: Charles Ferrell * [no ci] update client Signed-off-by: Charles Ferrell * [no ci] some client fixes and add rust toolchain info Signed-off-by: Charles Ferrell * [no ci] compile node, a bit broken still Signed-off-by: Charles Ferrell * [no ci] wip integration test fix Signed-off-by: Charles Ferrell * [no ci] fix integration test Signed-off-by: Charles Ferrell * [no ci] update mocks to correctly process xcm Signed-off-by: Charles Ferrell * [no ci] compile calamari integration test Signed-off-by: Charles Ferrell * [no ci] runtime benchmarks fix Signed-off-by: Charles Ferrell * [no ci] runtime benchmarks now compiles Signed-off-by: Charles Ferrell * [no ci] Fix some warnings Signed-off-by: Charles Ferrell * fix some failed integration tests Signed-off-by: Charles Ferrell * [no ci] fix more integration test Signed-off-by: Charles Ferrell * [no ci] fix tx pause unit tests Signed-off-by: Charles Ferrell * [no ci] fix tx pause tests Signed-off-by: Charles Ferrell * [no ci] fix some client issue Signed-off-by: Charles Ferrell * [no ci] clean up chain specs Signed-off-by: Charles Ferrell * [no ci] try-runtime to work Signed-off-by: Charles Ferrell * [no ci] use nimbus consensus... uses deprecated function for now Signed-off-by: Charles Ferrell * [no ci] add concrete weight values Signed-off-by: Charles Ferrell * update ci Signed-off-by: Charles Ferrell * [no ci]Add comments for async backing Signed-off-by: Dengjianping * [no ci] compile with moonkit Signed-off-by: Charles Ferrell * [no ci] fix block import issue, now panics on execution Signed-off-by: Charles Ferrell * Use forked moonkit Signed-off-by: Dengjianping * [no ci] dont implement vrf, cleanup client code Signed-off-by: Charles Ferrell * [no ci] remove compilation warnings Signed-off-by: Charles Ferrell * [no ci] update runtimes Signed-off-by: Charles Ferrell * add logic to disallow blocks on consecutive relay slots Signed-off-by: Charles Ferrell * use clippy Signed-off-by: Charles Ferrell * get tests to compile Signed-off-by: Charles Ferrell * [no ci] bump workflows Signed-off-by: Charles Ferrell * fix all clippy lints and fix failing tests Signed-off-by: Charles Ferrell * Fix benchmarking for frame-system Signed-off-by: Dengjianping * fix compilation Signed-off-by: Charles Ferrell * fix runtime-bench compilation Signed-off-by: Charles Ferrell * remove sudo migration and update vesting pallet Cargo.toml Signed-off-by: Charles Ferrell * Fix benchmarking for vesting Signed-off-by: Dengjianping * add dev mode Signed-off-by: Charles Ferrell * fix manta integration tests Signed-off-by: Charles Ferrell * Fix aura block importing Signed-off-by: Dengjianping * fix block import to use delayed best block Signed-off-by: Charles Ferrell * fix benchmarking Signed-off-by: Charles Ferrell * fix benchmark Signed-off-by: Charles Ferrell * update treasury in manta to spend via root Signed-off-by: Charles Ferrell * Fix xcm benchmarking Signed-off-by: Jamie * Fix clippy Signed-off-by: Jamie * Fix tests Signed-off-by: Jamie * Fix fmt Signed-off-by: Jamie * Fix xcm benchmarking Signed-off-by: Jamie * Fix tests Signed-off-by: Jamie * Fix benchmarkng Signed-off-by: Jamie --------- Signed-off-by: Charles Ferrell Signed-off-by: Dengjianping Signed-off-by: Jamie Co-authored-by: Charles Ferrell --- pallets/asset-manager/src/benchmarking.rs | 13 +++--- runtime/calamari/src/lib.rs | 52 ++++++++++++++-------- runtime/manta/src/lib.rs | 42 ++++++++++++----- scripts/benchmarking/run_all_benchmarks.sh | 2 - tests/check_parachain_lease_expiration.ts | 2 +- 5 files changed, 74 insertions(+), 37 deletions(-) diff --git a/pallets/asset-manager/src/benchmarking.rs b/pallets/asset-manager/src/benchmarking.rs index d13a61f99..60af7770f 100644 --- a/pallets/asset-manager/src/benchmarking.rs +++ b/pallets/asset-manager/src/benchmarking.rs @@ -28,6 +28,7 @@ use manta_primitives::{ types::Balance, }; use scale_info::prelude::*; +use sp_runtime::traits::One; use sp_std::vec; use xcm::latest::prelude::*; @@ -39,6 +40,9 @@ fn assert_last_event(generic_event: ::RuntimeEvent) { } pub fn register_asset_helper(location: MultiLocation, i: u32) { + if crate::LocationAssetId::::contains_key(T::Location::from(location)) { + return; + } let metadata = AssetRegistryMetadata:: { metadata: AssetStorageMetadata { name: format!("{}-name", i).into(), @@ -51,12 +55,9 @@ pub fn register_asset_helper(location: MultiLocation, i: u32) { }; Pallet::::register_asset(RawOrigin::Root.into(), location.into(), metadata) .expect("Filed to register asset"); - Pallet::::set_units_per_second( - RawOrigin::Root.into(), - ::AssetId::from(i), - i.into(), - ) - .expect("Filed to set ups"); + let current_asset_id = crate::NextAssetId::::get() - One::one(); + Pallet::::set_units_per_second(RawOrigin::Root.into(), current_asset_id, i.into()) + .expect("Filed to set ups"); } benchmarks! { diff --git a/runtime/calamari/src/lib.rs b/runtime/calamari/src/lib.rs index 367731ebc..65ed96120 100644 --- a/runtime/calamari/src/lib.rs +++ b/runtime/calamari/src/lib.rs @@ -1162,9 +1162,8 @@ mod benches { // always get this error(Unimplemented) while benchmarking pallet_xcm_benchmarks::fungible::initiate_teleport // so this time we will use statemint's fungible weights // and actually we don't support teleport now - // [pallet_xcm_benchmarks::generic, XcmGeneric] // [pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::] - // [pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::] + [pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::] // Nimbus pallets // [pallet_author_inherent, AuthorInherent] ); @@ -1519,9 +1518,6 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; use frame_system_benchmarking::Pallet as SystemBench; - //type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; - //type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - let mut list = Vec::::new(); list_benchmarks!(list, extra); @@ -1551,7 +1547,6 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} - use pallet_xcm_benchmarks::asset_instance_from; use xcm_config::{LocationToAccountId, XcmExecutorConfig}; parameter_types! { @@ -1580,7 +1575,22 @@ impl_runtime_apis! { >; fn valid_destination() -> Result { - Ok(KsmLocation::get()) + let assets = vec![ + MultiAsset { + id: Concrete(KsmLocation::get()), + fun: Fungible(1_000_000 * KMA), + } + ]; + + for (i, asset) in assets.iter().enumerate() { + if let MultiAsset { + id: Concrete(location), + fun: Fungible(_) + } = asset { + pallet_asset_manager::benchmarking::register_asset_helper::(*location, i as u32); + } + } + Ok(KsmLocation::get()) } fn worst_case_holding(depositable_count: u32) -> MultiAssets { @@ -1596,16 +1606,25 @@ impl_runtime_apis! { } }) .chain(core::iter::once(MultiAsset { id: Concrete(Here.into()), fun: Fungible(u128::MAX) })) - .chain((0..holding_non_fungibles).map(|i| MultiAsset { - id: Concrete(GeneralIndex(i as u128).into()), - fun: NonFungible(asset_instance_from(i)), - })) .collect::>(); - assets.push(MultiAsset { - id: Concrete(KmaLocation::get()), - fun: Fungible(1_000_000 * KMA), - }); + assets.push(MultiAsset { + id: Concrete(KsmLocation::get()), + fun: Fungible(1_000_000 * KMA), + }); + assets.push(MultiAsset { + id: Concrete(KmaLocation::get()), + fun: Fungible(1_000_000 * KMA), + }); + + for (i, asset) in assets.iter().enumerate() { + if let MultiAsset { + id: Concrete(location), + fun: Fungible(_) + } = asset { + pallet_asset_manager::benchmarking::register_asset_helper::(*location, i as u32); + } + } assets.into() } } @@ -1670,9 +1689,6 @@ impl_runtime_apis! { } } - //type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; - //type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - let whitelist: Vec = vec![ // Block Number hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), diff --git a/runtime/manta/src/lib.rs b/runtime/manta/src/lib.rs index db2a0a597..d46c66bcf 100644 --- a/runtime/manta/src/lib.rs +++ b/runtime/manta/src/lib.rs @@ -1088,7 +1088,7 @@ mod benches { // always get this error(Unimplemented) while benchmarking pallet_xcm_benchmarks::fungible::initiate_teleport // so this time we will use statemint's fungible weights // [pallet_xcm_benchmarks::fungible, XcmBalances] - // [pallet_xcm_benchmarks::generic, XcmGeneric] + [pallet_xcm_benchmarks::generic, XcmGeneric] [pallet_session, SessionBench::] // Manta pallets [pallet_tx_pause, TransactionPause] @@ -1448,8 +1448,7 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; use frame_system_benchmarking::Pallet as SystemBench; - //type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; - //type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; let mut list = Vec::::new(); list_benchmarks!(list, extra); @@ -1479,7 +1478,6 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} - use pallet_xcm_benchmarks::asset_instance_from; use xcm_config::{LocationToAccountId, XcmExecutorConfig}; parameter_types! { @@ -1512,6 +1510,21 @@ impl_runtime_apis! { >; fn valid_destination() -> Result { + let assets = vec![ + MultiAsset { + id: Concrete(DotLocation::get()), + fun: Fungible(1_000_000 * MANTA), + } + ]; + + for (i, asset) in assets.iter().enumerate() { + if let MultiAsset { + id: Concrete(location), + fun: Fungible(_) + } = asset { + pallet_asset_manager::benchmarking::register_asset_helper::(*location, i as u32); + } + } Ok(DotLocation::get()) } @@ -1528,16 +1541,26 @@ impl_runtime_apis! { } }) .chain(core::iter::once(MultiAsset { id: Concrete(Here.into()), fun: Fungible(u128::MAX) })) - .chain((0..holding_non_fungibles).map(|i| MultiAsset { - id: Concrete(GeneralIndex(i as u128).into()), - fun: NonFungible(asset_instance_from(i)), - })) .collect::>(); assets.push(MultiAsset { id: Concrete(DotLocation::get()), fun: Fungible(1_000_000 * MANTA), }); + assets.push(MultiAsset { + id: Concrete(MantaLocation::get()), + fun: Fungible(1_000_000 * MANTA), + }); + + for (i, asset) in assets.iter().enumerate() { + if let MultiAsset { + id: Concrete(location), + fun: Fungible(_) + } = asset { + pallet_asset_manager::benchmarking::register_asset_helper::(*location, i as u32); + } + } + assets.into() } } @@ -1601,8 +1624,7 @@ impl_runtime_apis! { } } - //type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; - //type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; let whitelist: Vec = vec![ // Block Number diff --git a/scripts/benchmarking/run_all_benchmarks.sh b/scripts/benchmarking/run_all_benchmarks.sh index 9846eeaf9..60643c253 100755 --- a/scripts/benchmarking/run_all_benchmarks.sh +++ b/scripts/benchmarking/run_all_benchmarks.sh @@ -79,8 +79,6 @@ MANTA=./target/production/manta # Will fix it in next release # currently, both pallets have problems on benchmarking EXCLUDED_PALLETS=( - "frame_system" - "zenlink_protocol" ) # Load all pallet names in an array. diff --git a/tests/check_parachain_lease_expiration.ts b/tests/check_parachain_lease_expiration.ts index 55d379895..2396166e5 100644 --- a/tests/check_parachain_lease_expiration.ts +++ b/tests/check_parachain_lease_expiration.ts @@ -19,7 +19,7 @@ export async function createPromiseApi(nodeAddress: string) { describe('Check Parachain_Lease_Expiration', () => { it('Check Manta Parachain Lease', async () => { - const polkadotNode = 'wss://1rpc.io/dot'; + const polkadotNode = 'wss://polkadot.api.onfinality.io/public-ws'; const polkadotApi = await createPromiseApi(polkadotNode); const mantaParaId = 2104; const oneDay = 3600 * 24;