From 5f3497830afc69e756ffc2f8104a83494763079b Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 7 Mar 2022 21:09:44 -0800 Subject: [PATCH] Add missing XCM benchmarks for ReserveAssetDeposited (#4923) * Add missing XCM benchmarks for ReserveAssetDeposited * Check whether checking account is zero before minting * Try and prevent overflow * Remove minting currencies into the checking account * cargo run --quiet --profile=production --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=pallet_xcm_benchmarks::fungible --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --template=./xcm/pallet-xcm-benchmarks/template.hbs --output=./runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs * Use a smaller divisor * Mint a smaller amount still * cargo run --quiet --profile=production --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=pallet_xcm_benchmarks::fungible --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --template=./xcm/pallet-xcm-benchmarks/template.hbs --output=./runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs * Remove logic for minting assets to the checking account * Configure a smaller amount of reserve asset used for testing * Try unwrapping the result of an execution * Set the origin properly * Revert "Set the origin properly" This reverts commit c748a05733173fb7072878c19b10a583675a5f54. * Update license year * cargo run --quiet --profile=production --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=pallet_xcm_benchmarks::fungible --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --template=./xcm/pallet-xcm-benchmarks/template.hbs --output=./runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs * Update license year Co-authored-by: Parity Bot --- polkadot/file_header.txt | 2 +- polkadot/runtime/westend/src/lib.rs | 5 ++++ .../runtime/westend/src/weights/xcm/mod.rs | 5 ++-- .../xcm/pallet_xcm_benchmarks_fungible.rs | 27 ++++++++++--------- .../src/fungible/benchmarking.rs | 19 +++++++++++++ .../src/fungible/mock.rs | 10 ++++++- .../pallet-xcm-benchmarks/src/fungible/mod.rs | 4 +++ 7 files changed, 55 insertions(+), 17 deletions(-) diff --git a/polkadot/file_header.txt b/polkadot/file_header.txt index 6dbc98f18e..bae07bb7ec 100644 --- a/polkadot/file_header.txt +++ b/polkadot/file_header.txt @@ -1,4 +1,4 @@ -// Copyright 2017-2021 Parity Technologies (UK) Ltd. +// Copyright 2017-2022 Parity Technologies (UK) Ltd. // This file is part of Polkadot. // Polkadot is free software: you can redistribute it and/or modify diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index cc071c66b2..7d3416ed0a 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1556,6 +1556,10 @@ sp_api::impl_runtime_apis! { Westmint::get(), MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(WndLocation::get()) }, )); + pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some(( + Westmint::get(), + MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(WndLocation::get()) }, + )); } impl pallet_xcm_benchmarks::fungible::Config for Runtime { @@ -1563,6 +1567,7 @@ sp_api::impl_runtime_apis! { type CheckedAccount = xcm_config::CheckAccount; type TrustedTeleporter = TrustedTeleporter; + type TrustedReserve = TrustedReserve; fn get_multi_asset() -> MultiAsset { MultiAsset { diff --git a/polkadot/runtime/westend/src/weights/xcm/mod.rs b/polkadot/runtime/westend/src/weights/xcm/mod.rs index 78fb9b739e..a06120b7b0 100644 --- a/polkadot/runtime/westend/src/weights/xcm/mod.rs +++ b/polkadot/runtime/westend/src/weights/xcm/mod.rs @@ -69,9 +69,8 @@ impl XcmWeightInfo for WestendXcmWeight { fn withdraw_asset(assets: &MultiAssets) -> Weight { assets.weigh_multi_assets(XcmBalancesWeight::::withdraw_asset()) } - fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight { - // Westend does not support reserve asset deposits. - Weight::MAX + fn reserve_asset_deposited(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmBalancesWeight::::reserve_asset_deposited()) } fn receive_teleported_asset(assets: &MultiAssets) -> Weight { assets.weigh_multi_assets(XcmBalancesWeight::::receive_teleported_asset()) diff --git a/polkadot/runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/polkadot/runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs index 08b75be936..13a8514f6d 100644 --- a/polkadot/runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ b/polkadot/runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -1,4 +1,4 @@ -// Copyright 2017-2021 Parity Technologies (UK) Ltd. +// Copyright 2022 Parity Technologies (UK) Ltd. // This file is part of Polkadot. // Polkadot is free software: you can redistribute it and/or modify @@ -17,11 +17,11 @@ //! Autogenerated weights for `pallet_xcm_benchmarks::fungible` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-10-25, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 128 +//! DATE: 2022-03-08, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 1024 // Executed Command: -// target/release/polkadot +// target/production/polkadot // benchmark // --chain=westend-dev // --steps=50 @@ -35,7 +35,6 @@ // --template=./xcm/pallet-xcm-benchmarks/template.hbs // --output=./runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs - #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] @@ -48,13 +47,13 @@ pub struct WeightInfo(PhantomData); impl WeightInfo { // Storage: System Account (r:1 w:1) pub(crate) fn withdraw_asset() -> Weight { - (43_806_000 as Weight) + (20_308_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: System Account (r:2 w:2) pub(crate) fn transfer_asset() -> Weight { - (68_076_000 as Weight) + (32_193_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -65,19 +64,23 @@ impl WeightInfo { // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) pub(crate) fn transfer_reserve_asset() -> Weight { - (99_639_000 as Weight) + (50_731_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } + // Storage: Benchmark Override (r:0 w:0) + pub(crate) fn reserve_asset_deposited() -> Weight { + (2_000_000_000_000 as Weight) + } // Storage: System Account (r:1 w:1) pub(crate) fn receive_teleported_asset() -> Weight { - (38_670_000 as Weight) + (19_622_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: System Account (r:1 w:1) pub(crate) fn deposit_asset() -> Weight { - (51_793_000 as Weight) + (22_433_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -88,7 +91,7 @@ impl WeightInfo { // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) pub(crate) fn deposit_reserve_asset() -> Weight { - (85_782_000 as Weight) + (41_765_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -99,7 +102,7 @@ impl WeightInfo { // Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) // Storage: Dmp DownwardMessageQueues (r:1 w:1) pub(crate) fn initiate_teleport() -> Weight { - (84_873_000 as Weight) + (41_204_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs index 8a987cf84d..53ca6dd3a0 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs @@ -107,6 +107,25 @@ benchmarks_instance_pallet! { // TODO: Check sender queue is not empty. #4426 } + reserve_asset_deposited { + let (trusted_reserve, transferable_reserve_asset) = T::TrustedReserve::get() + .ok_or(BenchmarkError::Skip)?; + + let assets: MultiAssets = vec![ transferable_reserve_asset ].into(); + + let mut executor = new_executor::(trusted_reserve); + let instruction = Instruction::ReserveAssetDeposited(assets.clone()); + let xcm = Xcm(vec![instruction]); + }: { + executor.execute(xcm).map_err(|_| { + BenchmarkError::Override( + BenchmarkResult::from_weight(T::BlockWeights::get().max_block) + ) + })?; + } verify { + assert!(executor.holding.ensure_contains(&assets).is_ok()); + } + receive_teleported_asset { // If there is no trusted teleporter, then we skip this benchmark. let (trusted_teleporter, teleportable_asset) = T::TrustedTeleporter::get() diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index 19b982f074..3f7e4f8f26 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -132,7 +132,7 @@ impl xcm_executor::Config for XcmConfig { type XcmSender = DevNull; type AssetTransactor = AssetTransactor; type OriginConverter = (); - type IsReserve = (); + type IsReserve = TrustedReserves; type IsTeleporter = TrustedTeleporters; type LocationInverter = xcm_builder::LocationInverter; type Barrier = AllowUnpaidExecutionFrom; @@ -159,6 +159,7 @@ impl crate::Config for Test { } pub type TrustedTeleporters = (xcm_builder::Case,); +pub type TrustedReserves = (xcm_builder::Case,); parameter_types! { pub const CheckedAccount: Option = Some(100); @@ -167,14 +168,21 @@ parameter_types! { ChildTeleporter::get(), MultiAsset { id: Concrete(Here.into()), fun: Fungible(100) }, )); + pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some(( + ChildTeleporter::get(), + MultiAsset { id: Concrete(Here.into()), fun: Fungible(100) }, + )); pub const TeleConcreteFung: (MultiAssetFilter, MultiLocation) = (Wild(AllOf { fun: WildFungible, id: Concrete(Here.into()) }), ChildTeleporter::get()); + pub const RsrvConcreteFung: (MultiAssetFilter, MultiLocation) = + (Wild(AllOf { fun: WildFungible, id: Concrete(Here.into()) }), ChildTeleporter::get()); } impl xcm_balances_benchmark::Config for Test { type TransactAsset = Balances; type CheckedAccount = CheckedAccount; type TrustedTeleporter = TrustedTeleporter; + type TrustedReserve = TrustedReserve; fn get_multi_asset() -> MultiAsset { let amount = diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mod.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mod.rs index e5062c3104..1acf61cf00 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mod.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mod.rs @@ -38,6 +38,10 @@ pub mod pallet { /// A trusted location which we allow teleports from, and the asset we allow to teleport. type TrustedTeleporter: Get>; + /// A trusted location where reserve assets are stored, and the asset we allow to be + /// reserves. + type TrustedReserve: Get>; + /// Give me a fungible asset that your asset transactor is going to accept. fn get_multi_asset() -> xcm::latest::MultiAsset; }