From bbcff0bfdeac3014edbd44d48c37593272e24a8f Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Fri, 20 Oct 2023 14:24:06 +0530 Subject: [PATCH] clean up --- .../src/fungible/assets/benchmarking.rs | 17 ++++++++++++----- .../src/fungible/assets/mock.rs | 13 ------------- .../src/fungible/balances/mock.rs | 2 -- runtime/astar/src/xcm_config.rs | 4 ++-- runtime/shibuya/src/lib.rs | 14 +++++--------- .../weights/xcm_instruction_benchmarks/mod.rs | 3 --- runtime/shibuya/src/xcm_config.rs | 4 ---- runtime/shiden/src/xcm_config.rs | 4 ++-- 8 files changed, 21 insertions(+), 40 deletions(-) diff --git a/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs index 70a92e0a58..85c9182a2e 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs @@ -37,6 +37,12 @@ benchmarks_instance_pallet! { as TryInto >::Error: sp_std::fmt::Debug, + + < T::TransactAsset + as + Inspect + >::Balance : Into + } withdraw_asset { @@ -86,14 +92,12 @@ benchmarks_instance_pallet! { }, ).unwrap(); assert!(T::TransactAsset::balance(&dest_account).is_zero()); + // reducing some assets for Existential deposit if let Fungible(x) = asset.fun { asset.fun = Fungible(x/10) }; - log::trace!( - target: "xcm::process", - "asset is {:?}",asset.clone()); let assets: MultiAssets = vec![ asset.clone() ].into(); log::trace!( target: "xcm::process", @@ -116,13 +120,14 @@ benchmarks_instance_pallet! { target: "xcm::process", "destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + let previous_balance: u128 = T::TransactAsset::balance(&dest_account).into(); }: { executor.bench_process(xcm)?; } verify { log::trace!( target: "xcm::process", "destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); - assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + assert!(T::TransactAsset::balance(&dest_account).into() == 2 * previous_balance); } transfer_reserve_asset { @@ -165,10 +170,12 @@ benchmarks_instance_pallet! { xcm: Xcm::new() }; let xcm = Xcm(vec![instruction]); + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + let previous_balance: u128 = T::TransactAsset::balance(&dest_account).into(); }: { executor.bench_process(xcm)?; } verify { - assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + assert!(T::TransactAsset::balance(&dest_account).into() == 2 * previous_balance); } receive_teleported_asset { diff --git a/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs index 9de8238fb2..6a09dafc24 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs @@ -129,19 +129,6 @@ impl pallet_assets::Config for Test { #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = (); } -// pub struct MatchAnyFungible; -// impl xcm_executor::traits::MatchesFungible for MatchAnyFungible { -// fn matches_fungible(m: &MultiAsset) -> Option { -// use sp_runtime::traits::SaturatedConversion; -// match m { -// MultiAsset { -// fun: Fungible(amount), -// .. -// } => Some((*amount).saturated_into::()), -// _ => None, -// } -// } -// } // Use fungible transactor as the asset transactor. pub type AssetTransactor = xcm_builder::FungiblesAdapter< diff --git a/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs index 76f5f46a7e..0bd3e943b4 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs @@ -126,8 +126,6 @@ pub type AssetTransactor = xcm_builder::CurrencyAdapter< >; parameter_types! { - /// Maximum number of instructions in a single XCM fragment. A sanity check against weight - /// calculations getting too crazy. pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; } diff --git a/runtime/astar/src/xcm_config.rs b/runtime/astar/src/xcm_config.rs index f104062473..5f01ba0bbf 100644 --- a/runtime/astar/src/xcm_config.rs +++ b/runtime/astar/src/xcm_config.rs @@ -136,8 +136,8 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - // For the PoV size, we estimate 64 kB per instruction - which will is once again very conservative. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, astar_primitives::xcm::DEFAULT_PROOF_SIZE); + // For the PoV size, we estimate 4 kB per instruction. This will be changed when we benchmark the instructions. + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 4 * 1024); pub const MaxInstructions: u32 = 100; } diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index d374335d8b..063b96ed9a 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -1982,15 +1982,11 @@ impl_runtime_apis! { type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { - // not sure what will be the worst case for Response - // either `Assets(MultiAssets)` or `PalletsInfo(BoundedVec)` - // in either case, what will be the worst case? - // let assets: Vec = vec![MultiAsset { - // id: Concrete(MultiLocation::parent()), - // fun: Fungible(u128::MAX), - // }]; - // (0u64, Response::Assets(assets.into())) - (0u64, Response::Version(Default::default())) + let assets: Vec = vec![MultiAsset { + id: Concrete(MultiLocation::parent()), + fun: Fungible(u128::MAX), + }]; + (0u64, Response::Assets(assets.into())) } diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs index 9886207aec..7633bf4fb5 100644 --- a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs @@ -212,12 +212,9 @@ impl XcmWeightInfo for ShibuyaXcmWeight { XcmGeneric::::unsubscribe_version() } fn burn_asset(assets: &MultiAssets) -> Weight { - //TODO: This should not be multiploed by assets, we are already burning worse case - // assets assets.weigh_multi_assets(XcmGeneric::::burn_asset()) } fn expect_asset(assets: &MultiAssets) -> Weight { - // TODO same here assets.weigh_multi_assets(XcmGeneric::::expect_asset()) } fn expect_origin(_origin: &Option) -> Weight { diff --git a/runtime/shibuya/src/xcm_config.rs b/runtime/shibuya/src/xcm_config.rs index 4fe7017fd2..2d985fd13d 100644 --- a/runtime/shibuya/src/xcm_config.rs +++ b/runtime/shibuya/src/xcm_config.rs @@ -137,9 +137,6 @@ pub type XcmOriginToTransactDispatchOrigin = ( ); parameter_types! { - // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - // For the PoV size, we estimate 64 kB per instruction - which will is once again very conservative. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, astar_primitives::xcm::DEFAULT_PROOF_SIZE); pub const MaxInstructions: u32 = 100; } @@ -171,7 +168,6 @@ pub type ShibuyaXcmFungibleFeeHandler = XcmFungibleFeeHandler< TreasuryAccountId, >; -// pub type Weigher = FixedWeightBounds; pub type Weigher = WeightInfoBounds< crate::weights::xcm_instruction_benchmarks::ShibuyaXcmWeight, RuntimeCall, diff --git a/runtime/shiden/src/xcm_config.rs b/runtime/shiden/src/xcm_config.rs index 3521d637d7..a38ec8091d 100644 --- a/runtime/shiden/src/xcm_config.rs +++ b/runtime/shiden/src/xcm_config.rs @@ -138,8 +138,8 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - // For the PoV size, we estimate 64 kB per instruction - which will is once again very conservative. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, astar_primitives::xcm::DEFAULT_PROOF_SIZE); + // For the PoV size, we estimate 4 kB per instruction. This will be changed when we benchmark the instructions. + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 4 * 1024); pub const MaxInstructions: u32 = 100; }