From ce2d3756c2fd428a5de172c8cd741a39a4ddc332 Mon Sep 17 00:00:00 2001 From: girazoki Date: Wed, 17 Jan 2024 12:28:51 +0100 Subject: [PATCH 1/3] Allow to set a worst case buy execution fee asset and weight --- .../src/generic/benchmarking.rs | 8 +++++--- .../xcm/pallet-xcm-benchmarks/src/generic/mod.rs | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs index 14d53c4ebf539..50877e69381c4 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs @@ -77,11 +77,13 @@ benchmarks! { let mut executor = new_executor::(Default::default()); executor.set_holding(holding); - let fee_asset = AssetId(Here.into()); + // The worst case we want for buy execution in terms of + // fee asset and weight + let (fee_asset, weight_limit) = T::worst_case_buy_execution()?; let instruction = Instruction::>::BuyExecution { - fees: (fee_asset, 100_000_000u128).into(), // should be something inside of holding - weight_limit: WeightLimit::Unlimited, + fees: fee_asset, + weight_limit: weight_limit.into(), }; let xcm = Xcm(vec![instruction]); diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs index 3728baea98331..5e9aa2b628cca 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs @@ -26,7 +26,13 @@ pub mod pallet { use frame_benchmarking::BenchmarkError; use frame_support::{dispatch::GetDispatchInfo, pallet_prelude::Encode}; use sp_runtime::traits::Dispatchable; - use xcm::latest::{Asset, Assets, InteriorLocation, Junction, Location, NetworkId, Response}; + use xcm::{ + latest::{ + Asset, AssetId, Assets, InteriorLocation, Junction, Junctions, Location, NetworkId, + Response, + }, + v2::WeightLimit, + }; #[pallet::config] pub trait Config: frame_system::Config + crate::Config { @@ -100,6 +106,13 @@ pub mod pallet { crate_version: as frame_support::traits::PalletInfoAccess>::crate_version(), } } + + /// The worst case buy execution weight limit and + /// asset to trigger the Trader::buy_execution in the XCM executor + /// By default returns ((AssetId(Here.into()), 100_000_000u128), Unlimited) + fn worst_case_buy_execution() -> Result<(Asset, WeightLimit), BenchmarkError> { + Ok(((AssetId(Junctions::Here.into()), 100_000_000u128).into(), WeightLimit::Unlimited)) + } } #[pallet::pallet] From 0b426c73c268ba35b772e10f02f3d739be52c05c Mon Sep 17 00:00:00 2001 From: girazoki Date: Mon, 19 Feb 2024 17:10:45 +0100 Subject: [PATCH 2/3] add prdoc --- prdoc/pr_2962.prdoc | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 prdoc/pr_2962.prdoc diff --git a/prdoc/pr_2962.prdoc b/prdoc/pr_2962.prdoc new file mode 100644 index 0000000000000..9798115708496 --- /dev/null +++ b/prdoc/pr_2962.prdoc @@ -0,0 +1,11 @@ +title: Allow to set a worst case buy execution fee asset and weight + +doc: + - audience: Runtime Dev + description: | + Allows to set a worst case for the `BuyExecution` XCM instruction + benchmark. Currently the benchmark assumes best case scenario (i.e.) + the case where does not even need to go into the Trader. This PR allows + developers to set the worst-case scenario as they wish. +crates: + - name: pallet-xcm-benchmarks From c982b26c1fae824084ac2eef9cc6e65e05e14d7e Mon Sep 17 00:00:00 2001 From: girazoki Date: Mon, 19 Feb 2024 17:12:44 +0100 Subject: [PATCH 3/3] remove default impl --- polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs index 9a9694b93d42d..02bab9193bada 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs @@ -114,9 +114,7 @@ pub mod pallet { /// The worst case buy execution weight limit and /// asset to trigger the Trader::buy_execution in the XCM executor /// By default returns ((AssetId(Here.into()), 100_000_000u128), Unlimited) - fn worst_case_buy_execution() -> Result<(Asset, WeightLimit), BenchmarkError> { - Ok(((AssetId(Junctions::Here.into()), 100_000_000u128).into(), WeightLimit::Unlimited)) - } + fn worst_case_buy_execution() -> Result<(Asset, WeightLimit), BenchmarkError>; } #[pallet::pallet]