From 999e8f7c9ba7d3d6581559ea819690d14cac1c8a Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Tue, 19 Jul 2022 17:45:30 +0200 Subject: [PATCH 01/56] [Feature] Add XCM benchmarark weights to Statemint and Statemine --- parachains/runtimes/assets/statemine/src/weights/temp | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 parachains/runtimes/assets/statemine/src/weights/temp diff --git a/parachains/runtimes/assets/statemine/src/weights/temp b/parachains/runtimes/assets/statemine/src/weights/temp new file mode 100644 index 00000000000..e69de29bb2d From 26457caac8b8540601af894dbcf639eb8672f3b1 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Tue, 19 Jul 2022 19:24:19 +0200 Subject: [PATCH 02/56] add xcm-bench-template --- templates/xcm-bench-template.hbs | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 templates/xcm-bench-template.hbs diff --git a/templates/xcm-bench-template.hbs b/templates/xcm-bench-template.hbs new file mode 100644 index 00000000000..cdb610bbc94 --- /dev/null +++ b/templates/xcm-bench-template.hbs @@ -0,0 +1,67 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + + +//! Autogenerated weights for `{{pallet}}` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} +//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` +//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}} + +// Executed Command: +{{#each args as |arg|}} +// {{arg}} +{{/each}} + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weights for `{{pallet}}`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + // {{comment}} + {{/each}} + pub(crate) fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + ({{underscore benchmark.base_weight}} as Weight) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight)) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight)) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))) + {{/each}} + } + {{/each}} +} From f07deed4b7a95c4b3abfd61d0658c865950370be Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 20 Jul 2022 17:37:53 +0200 Subject: [PATCH 03/56] add polkadot xcm bench pallet to statemint --- Cargo.lock | 1 + parachains/runtimes/assets/statemint/Cargo.toml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index f8674ad69e1..ffba92f462d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11488,6 +11488,7 @@ dependencies = [ "pallet-uniques", "pallet-utility", "pallet-xcm", + "pallet-xcm-benchmarks", "parachain-info", "parachains-common", "parity-scale-codec", diff --git a/parachains/runtimes/assets/statemint/Cargo.toml b/parachains/runtimes/assets/statemint/Cargo.toml index 410d5d40670..97c7821f32b 100644 --- a/parachains/runtimes/assets/statemint/Cargo.toml +++ b/parachains/runtimes/assets/statemint/Cargo.toml @@ -56,6 +56,8 @@ polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", d xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } +pallet-xcm-benchmarks = { git = "https://github.com/paritytech/polkadot", default-features = false, optional = true, branch = "master" } + # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -99,6 +101,7 @@ runtime-benchmarks = [ "cumulus-pallet-session-benchmarking/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "pallet-xcm-benchmarks", ] try-runtime = [ "frame-executive/try-runtime", From 9a179aadfa6a66fa8c6c06942a809824000cb8c7 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Fri, 22 Jul 2022 11:40:34 +0200 Subject: [PATCH 04/56] Sample benchmarking that compiles --- .../runtimes/assets/statemint/src/lib.rs | 80 ++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 3184f37e768..51fd78a1e8a 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -800,6 +800,9 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; + type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + let mut list = Vec::::new(); list_benchmarks!(list, extra); @@ -810,7 +813,7 @@ impl_runtime_apis! { fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey}; + use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey, BenchmarkError}; use frame_system_benchmarking::Pallet as SystemBench; impl frame_system_benchmarking::Config for Runtime {} @@ -818,6 +821,81 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} + use xcm::latest::{ + AssetId::*, Fungibility::*, Junctions::*, MultiAsset, MultiAssets, MultiLocation, + Response, + }; + use xcm_config::{Local, DotLocation}; + + impl pallet_xcm_benchmarks::Config for Runtime { + type XcmConfig = xcm_config::XcmConfig; + type AccountIdConverter = xcm_config::LocationToAccountId; + fn valid_destination() -> Result { + Ok(DotLocation::get()) + } + fn worst_case_holding() -> MultiAssets { + // Statemint only knows about DOT (?). + vec![MultiAsset{ + id: Concrete(Local::get()), + fun: Fungible(1_000_000 * UNITS), + }].into() + } + } + + //TODO: Not sure how this should work + parameter_types! { + pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( + Local::get(), + MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(DotLocation::get()) }, + )); + pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some(( + Local::get(), + MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(DotLocation::get()) }, + )); + } + + impl pallet_xcm_benchmarks::fungible::Config for Runtime { + type TransactAsset = Balances; + + type CheckedAccount = xcm_config::CheckingAccount; + type TrustedTeleporter = TrustedTeleporter; + type TrustedReserve = TrustedReserve; + + fn get_multi_asset() -> MultiAsset { + MultiAsset { + id: Concrete(DotLocation::get()), + fun: Fungible(1 * UNITS), + } + } + } + + impl pallet_xcm_benchmarks::generic::Config for Runtime { + type Call = Call; + + fn worst_case_response() -> (u64, Response) { + (0u64, Response::Version(Default::default())) + } + + fn transact_origin() -> Result { + Ok(DotLocation::get()) + } + + fn subscribe_origin() -> Result { + Ok(DotLocation::get()) + } + + fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { + let origin = DotLocation::get(); + let assets: MultiAssets = (Concrete(Local::get()), 1_000 * UNITS).into(); + let ticket = MultiLocation { parents: 0, interior: Here }; + Ok((origin, ticket, assets)) + } + } + + 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(), From 009a3c5d77aaf7cd9cb4d682a7dbeb023a7b8139 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Fri, 22 Jul 2022 14:40:41 +0200 Subject: [PATCH 05/56] add benches to the module --- parachains/runtimes/assets/statemint/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 51fd78a1e8a..bba8f0193d1 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -666,6 +666,10 @@ mod benches { [pallet_timestamp, Timestamp] [pallet_collator_selection, CollatorSelection] [cumulus_pallet_xcmp_queue, XcmpQueue] + // XCM + // NOTE: Make sure you point to the individual modules below. + [pallet_xcm_benchmarks::fungible, XcmBalances] + [pallet_xcm_benchmarks::generic, XcmGeneric] ); } From dc1b3ef74d9d8291c655ed78d662ee0cc65f8bcf Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Fri, 22 Jul 2022 16:50:25 +0200 Subject: [PATCH 06/56] Remove batches assertion and whitelist ActiveConfig --- parachains/runtimes/assets/statemint/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index bba8f0193d1..8690feef836 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -911,13 +911,15 @@ impl_runtime_apis! { hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), // System Events hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), + // Configuration ActiveConfig + hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(), ]; let mut batches = Vec::::new(); let params = (&config, &whitelist); add_benchmarks!(params, batches); - if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } + // if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) } } From c19763d3f5bc4d58b32d2521f960af0b66ac8ba1 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 22 Jul 2022 15:30:56 +0000 Subject: [PATCH 07/56] ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic --- .../xcm/pallet_xcm_benchmarks::generic.rs | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks::generic.rs diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks::generic.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks::generic.rs new file mode 100644 index 00000000000..dec6dc55543 --- /dev/null +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks::generic.rs @@ -0,0 +1,137 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + + +//! Autogenerated weights for `pallet_xcm_benchmarks::generic` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-07-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemint-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_xcm_benchmarks::generic +// --chain=statemint-dev +// --template=./templates/xcm-bench-template.hbs +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/cumulus/.git/.artifacts/bench.json +// --header=./file_header.txt +// --output=./parachains/runtimes/assets/statemint/src/weights/xcm + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weights for `pallet_xcm_benchmarks::generic`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn query_holding() -> Weight { + (18_958_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + pub(crate) fn buy_execution() -> Weight { + (3_487_000 as Weight) + } + // Storage: PolkadotXcm Queries (r:1 w:0) + pub(crate) fn query_response() -> Weight { + (13_263_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } + pub(crate) fn transact() -> Weight { + (16_418_000 as Weight) + } + pub(crate) fn refund_surplus() -> Weight { + (3_700_000 as Weight) + } + pub(crate) fn set_error_handler() -> Weight { + (3_438_000 as Weight) + } + pub(crate) fn set_appendix() -> Weight { + (3_503_000 as Weight) + } + pub(crate) fn clear_error() -> Weight { + (3_555_000 as Weight) + } + pub(crate) fn descend_origin() -> Weight { + (4_370_000 as Weight) + } + pub(crate) fn clear_origin() -> Weight { + (3_463_000 as Weight) + } + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn report_error() -> Weight { + (12_890_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: PolkadotXcm AssetTraps (r:1 w:1) + pub(crate) fn claim_asset() -> Weight { + (7_748_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + pub(crate) fn trap() -> Weight { + (3_461_000 as Weight) + } + // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn subscribe_version() -> Weight { + (16_483_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) + pub(crate) fn unsubscribe_version() -> Weight { + (5_622_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn initiate_reserve_withdraw() -> Weight { + (18_945_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} From 4435ac6a85efe41d255b431f990dcb9a6721227a Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 22 Jul 2022 19:48:02 +0000 Subject: [PATCH 08/56] ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic --- .../xcm/pallet_xcm_benchmarks_generic.rs | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs new file mode 100644 index 00000000000..d4170bb9c03 --- /dev/null +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -0,0 +1,137 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + + +//! Autogenerated weights for `pallet_xcm_benchmarks::generic` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-07-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemint-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_xcm_benchmarks::generic +// --chain=statemint-dev +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/cumulus/.git/.artifacts/bench.json +// --header=./file_header.txt +// --template=./templates/xcm-bench-template.hbs +// --output=./parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weights for `pallet_xcm_benchmarks::generic`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn query_holding() -> Weight { + (18_242_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + pub(crate) fn buy_execution() -> Weight { + (3_653_000 as Weight) + } + // Storage: PolkadotXcm Queries (r:1 w:0) + pub(crate) fn query_response() -> Weight { + (13_106_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } + pub(crate) fn transact() -> Weight { + (16_823_000 as Weight) + } + pub(crate) fn refund_surplus() -> Weight { + (3_787_000 as Weight) + } + pub(crate) fn set_error_handler() -> Weight { + (3_515_000 as Weight) + } + pub(crate) fn set_appendix() -> Weight { + (3_523_000 as Weight) + } + pub(crate) fn clear_error() -> Weight { + (3_652_000 as Weight) + } + pub(crate) fn descend_origin() -> Weight { + (4_259_000 as Weight) + } + pub(crate) fn clear_origin() -> Weight { + (3_565_000 as Weight) + } + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn report_error() -> Weight { + (13_230_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: PolkadotXcm AssetTraps (r:1 w:1) + pub(crate) fn claim_asset() -> Weight { + (7_846_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + pub(crate) fn trap() -> Weight { + (3_630_000 as Weight) + } + // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn subscribe_version() -> Weight { + (16_602_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) + pub(crate) fn unsubscribe_version() -> Weight { + (5_599_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn initiate_reserve_withdraw() -> Weight { + (19_397_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} From 0fe81349c96192be6bf1dde7cabe5f8b66e0aa1b Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Fri, 22 Jul 2022 21:51:49 +0200 Subject: [PATCH 09/56] fix benchmarks --- .../xcm/pallet_xcm_benchmarks::generic.rs | 137 ------------------ scripts/benchmarks.sh | 4 +- 2 files changed, 3 insertions(+), 138 deletions(-) delete mode 100644 parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks::generic.rs diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks::generic.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks::generic.rs deleted file mode 100644 index dec6dc55543..00000000000 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks::generic.rs +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - - -//! Autogenerated weights for `pallet_xcm_benchmarks::generic` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-07-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemint-dev"), DB CACHE: 1024 - -// Executed Command: -// /home/benchbot/cargo_target_dir/production/polkadot-parachain -// benchmark -// pallet -// --steps=50 -// --repeat=20 -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --pallet=pallet_xcm_benchmarks::generic -// --chain=statemint-dev -// --template=./templates/xcm-bench-template.hbs -// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/cumulus/.git/.artifacts/bench.json -// --header=./file_header.txt -// --output=./parachains/runtimes/assets/statemint/src/weights/xcm - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] - -use frame_support::{traits::Get, weights::Weight}; -use sp_std::marker::PhantomData; - -/// Weights for `pallet_xcm_benchmarks::generic`. -pub struct WeightInfo(PhantomData); -impl WeightInfo { - // Storage: ParachainInfo ParachainId (r:1 w:0) - // Storage: PolkadotXcm SupportedVersion (r:1 w:0) - // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) - // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) - // Storage: ParachainSystem HostConfiguration (r:1 w:0) - // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) - pub(crate) fn query_holding() -> Weight { - (18_958_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - pub(crate) fn buy_execution() -> Weight { - (3_487_000 as Weight) - } - // Storage: PolkadotXcm Queries (r:1 w:0) - pub(crate) fn query_response() -> Weight { - (13_263_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - } - pub(crate) fn transact() -> Weight { - (16_418_000 as Weight) - } - pub(crate) fn refund_surplus() -> Weight { - (3_700_000 as Weight) - } - pub(crate) fn set_error_handler() -> Weight { - (3_438_000 as Weight) - } - pub(crate) fn set_appendix() -> Weight { - (3_503_000 as Weight) - } - pub(crate) fn clear_error() -> Weight { - (3_555_000 as Weight) - } - pub(crate) fn descend_origin() -> Weight { - (4_370_000 as Weight) - } - pub(crate) fn clear_origin() -> Weight { - (3_463_000 as Weight) - } - // Storage: PolkadotXcm SupportedVersion (r:1 w:0) - // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) - // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) - // Storage: ParachainSystem HostConfiguration (r:1 w:0) - // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) - pub(crate) fn report_error() -> Weight { - (12_890_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - // Storage: PolkadotXcm AssetTraps (r:1 w:1) - pub(crate) fn claim_asset() -> Weight { - (7_748_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - pub(crate) fn trap() -> Weight { - (3_461_000 as Weight) - } - // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) - // Storage: PolkadotXcm SupportedVersion (r:1 w:0) - // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) - // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) - // Storage: ParachainSystem HostConfiguration (r:1 w:0) - // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) - pub(crate) fn subscribe_version() -> Weight { - (16_483_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) - } - // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) - pub(crate) fn unsubscribe_version() -> Weight { - (5_622_000 as Weight) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - // Storage: ParachainInfo ParachainId (r:1 w:0) - // Storage: PolkadotXcm SupportedVersion (r:1 w:0) - // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) - // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) - // Storage: ParachainSystem HostConfiguration (r:1 w:0) - // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) - pub(crate) fn initiate_reserve_withdraw() -> Weight { - (18_945_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } -} diff --git a/scripts/benchmarks.sh b/scripts/benchmarks.sh index a83b8cbcbb6..6be4aaca813 100755 --- a/scripts/benchmarks.sh +++ b/scripts/benchmarks.sh @@ -12,7 +12,7 @@ statemintChain=statemint-dev westmintChain=westmint-dev pallets=( - pallet_assets + pallet_assets pallet_balances pallet_collator_selection pallet_multisig @@ -23,6 +23,8 @@ pallets=( pallet_uniques cumulus_pallet_xcmp_queue frame_system + pallet_xcm_benchmarks::generic + pallet_xcm_benchmarks::fungible ) for p in ${pallets[@]} From c996d6eb74f573936de43393cb4b9882c444ca50 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Sun, 24 Jul 2022 12:16:06 +0200 Subject: [PATCH 10/56] fix get_multi_asset --- parachains/runtimes/assets/statemint/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 8690feef836..745a1d99d97 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -867,7 +867,7 @@ impl_runtime_apis! { fn get_multi_asset() -> MultiAsset { MultiAsset { - id: Concrete(DotLocation::get()), + id: Concrete(Local::get()), fun: Fungible(1 * UNITS), } } From 9845cdf72fb0fc203f20c9482be4ec8f9572ee01 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Tue, 26 Jul 2022 16:57:38 +0200 Subject: [PATCH 11/56] fmt and more bench fixes --- .../runtimes/assets/statemint/src/lib.rs | 94 +++++++++---------- scripts/benchmarks.sh | 2 +- 2 files changed, 47 insertions(+), 49 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 745a1d99d97..d50a1a5bf4a 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -349,57 +349,61 @@ impl InstanceFilter for ProxyType { fn filter(&self, c: &Call) -> bool { match self { ProxyType::Any => true, - ProxyType::NonTransfer => - !matches!(c, Call::Balances { .. } | Call::Assets { .. } | Call::Uniques { .. }), + ProxyType::NonTransfer => { + !matches!(c, Call::Balances { .. } | Call::Assets { .. } | Call::Uniques { .. }) + }, ProxyType::CancelProxy => matches!( c, - Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) | - Call::Utility { .. } | Call::Multisig { .. } + Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) + | Call::Utility { .. } + | Call::Multisig { .. } ), ProxyType::Assets => { matches!( c, - Call::Assets { .. } | - Call::Utility { .. } | Call::Multisig { .. } | - Call::Uniques { .. } + Call::Assets { .. } + | Call::Utility { .. } | Call::Multisig { .. } + | Call::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - Call::Assets(pallet_assets::Call::create { .. }) | - Call::Assets(pallet_assets::Call::destroy { .. }) | - Call::Assets(pallet_assets::Call::transfer_ownership { .. }) | - Call::Assets(pallet_assets::Call::set_team { .. }) | - Call::Assets(pallet_assets::Call::set_metadata { .. }) | - Call::Assets(pallet_assets::Call::clear_metadata { .. }) | - Call::Uniques(pallet_uniques::Call::create { .. }) | - Call::Uniques(pallet_uniques::Call::destroy { .. }) | - Call::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | - Call::Uniques(pallet_uniques::Call::set_team { .. }) | - Call::Uniques(pallet_uniques::Call::set_metadata { .. }) | - Call::Uniques(pallet_uniques::Call::set_attribute { .. }) | - Call::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | - Call::Uniques(pallet_uniques::Call::clear_metadata { .. }) | - Call::Uniques(pallet_uniques::Call::clear_attribute { .. }) | - Call::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | - Call::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | - Call::Utility { .. } | Call::Multisig { .. } + Call::Assets(pallet_assets::Call::create { .. }) + | Call::Assets(pallet_assets::Call::destroy { .. }) + | Call::Assets(pallet_assets::Call::transfer_ownership { .. }) + | Call::Assets(pallet_assets::Call::set_team { .. }) + | Call::Assets(pallet_assets::Call::set_metadata { .. }) + | Call::Assets(pallet_assets::Call::clear_metadata { .. }) + | Call::Uniques(pallet_uniques::Call::create { .. }) + | Call::Uniques(pallet_uniques::Call::destroy { .. }) + | Call::Uniques(pallet_uniques::Call::transfer_ownership { .. }) + | Call::Uniques(pallet_uniques::Call::set_team { .. }) + | Call::Uniques(pallet_uniques::Call::set_metadata { .. }) + | Call::Uniques(pallet_uniques::Call::set_attribute { .. }) + | Call::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) + | Call::Uniques(pallet_uniques::Call::clear_metadata { .. }) + | Call::Uniques(pallet_uniques::Call::clear_attribute { .. }) + | Call::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) + | Call::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) + | Call::Utility { .. } + | Call::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - Call::Assets(pallet_assets::Call::mint { .. }) | - Call::Assets(pallet_assets::Call::burn { .. }) | - Call::Assets(pallet_assets::Call::freeze { .. }) | - Call::Assets(pallet_assets::Call::thaw { .. }) | - Call::Assets(pallet_assets::Call::freeze_asset { .. }) | - Call::Assets(pallet_assets::Call::thaw_asset { .. }) | - Call::Uniques(pallet_uniques::Call::mint { .. }) | - Call::Uniques(pallet_uniques::Call::burn { .. }) | - Call::Uniques(pallet_uniques::Call::freeze { .. }) | - Call::Uniques(pallet_uniques::Call::thaw { .. }) | - Call::Uniques(pallet_uniques::Call::freeze_collection { .. }) | - Call::Uniques(pallet_uniques::Call::thaw_collection { .. }) | - Call::Utility { .. } | Call::Multisig { .. } + Call::Assets(pallet_assets::Call::mint { .. }) + | Call::Assets(pallet_assets::Call::burn { .. }) + | Call::Assets(pallet_assets::Call::freeze { .. }) + | Call::Assets(pallet_assets::Call::thaw { .. }) + | Call::Assets(pallet_assets::Call::freeze_asset { .. }) + | Call::Assets(pallet_assets::Call::thaw_asset { .. }) + | Call::Uniques(pallet_uniques::Call::mint { .. }) + | Call::Uniques(pallet_uniques::Call::burn { .. }) + | Call::Uniques(pallet_uniques::Call::freeze { .. }) + | Call::Uniques(pallet_uniques::Call::thaw { .. }) + | Call::Uniques(pallet_uniques::Call::freeze_collection { .. }) + | Call::Uniques(pallet_uniques::Call::thaw_collection { .. }) + | Call::Utility { .. } + | Call::Multisig { .. } ), ProxyType::Collator => matches!( c, @@ -804,9 +808,6 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; - type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - let mut list = Vec::::new(); list_benchmarks!(list, extra); @@ -825,10 +826,7 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} - use xcm::latest::{ - AssetId::*, Fungibility::*, Junctions::*, MultiAsset, MultiAssets, MultiLocation, - Response, - }; + use xcm::latest::prelude::*; use xcm_config::{Local, DotLocation}; impl pallet_xcm_benchmarks::Config for Runtime { @@ -838,9 +836,9 @@ impl_runtime_apis! { Ok(DotLocation::get()) } fn worst_case_holding() -> MultiAssets { - // Statemint only knows about DOT (?). + // TODO: Create some assets vec![MultiAsset{ - id: Concrete(Local::get()), + id: Concrete(DotLocation::get()), fun: Fungible(1_000_000 * UNITS), }].into() } @@ -867,7 +865,7 @@ impl_runtime_apis! { fn get_multi_asset() -> MultiAsset { MultiAsset { - id: Concrete(Local::get()), + id: Concrete(DotLocation::get()), fun: Fungible(1 * UNITS), } } diff --git a/scripts/benchmarks.sh b/scripts/benchmarks.sh index 6be4aaca813..b29a08319f7 100755 --- a/scripts/benchmarks.sh +++ b/scripts/benchmarks.sh @@ -12,7 +12,7 @@ statemintChain=statemint-dev westmintChain=westmint-dev pallets=( - pallet_assets + pallet_assets pallet_balances pallet_collator_selection pallet_multisig From bfa6b5bab6b1fc61566650ee6dc4e2f0345d08d0 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Tue, 26 Jul 2022 17:05:40 +0200 Subject: [PATCH 12/56] reformat --- .../runtimes/assets/statemint/src/lib.rs | 80 +++++++++---------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index d50a1a5bf4a..be091119ab1 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -349,61 +349,57 @@ impl InstanceFilter for ProxyType { fn filter(&self, c: &Call) -> bool { match self { ProxyType::Any => true, - ProxyType::NonTransfer => { - !matches!(c, Call::Balances { .. } | Call::Assets { .. } | Call::Uniques { .. }) - }, + ProxyType::NonTransfer => + !matches!(c, Call::Balances { .. } | Call::Assets { .. } | Call::Uniques { .. }), ProxyType::CancelProxy => matches!( c, - Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) - | Call::Utility { .. } - | Call::Multisig { .. } + Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) | + Call::Utility { .. } | Call::Multisig { .. } ), ProxyType::Assets => { matches!( c, - Call::Assets { .. } - | Call::Utility { .. } | Call::Multisig { .. } - | Call::Uniques { .. } + Call::Assets { .. } | + Call::Utility { .. } | Call::Multisig { .. } | + Call::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - Call::Assets(pallet_assets::Call::create { .. }) - | Call::Assets(pallet_assets::Call::destroy { .. }) - | Call::Assets(pallet_assets::Call::transfer_ownership { .. }) - | Call::Assets(pallet_assets::Call::set_team { .. }) - | Call::Assets(pallet_assets::Call::set_metadata { .. }) - | Call::Assets(pallet_assets::Call::clear_metadata { .. }) - | Call::Uniques(pallet_uniques::Call::create { .. }) - | Call::Uniques(pallet_uniques::Call::destroy { .. }) - | Call::Uniques(pallet_uniques::Call::transfer_ownership { .. }) - | Call::Uniques(pallet_uniques::Call::set_team { .. }) - | Call::Uniques(pallet_uniques::Call::set_metadata { .. }) - | Call::Uniques(pallet_uniques::Call::set_attribute { .. }) - | Call::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) - | Call::Uniques(pallet_uniques::Call::clear_metadata { .. }) - | Call::Uniques(pallet_uniques::Call::clear_attribute { .. }) - | Call::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) - | Call::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) - | Call::Utility { .. } - | Call::Multisig { .. } + Call::Assets(pallet_assets::Call::create { .. }) | + Call::Assets(pallet_assets::Call::destroy { .. }) | + Call::Assets(pallet_assets::Call::transfer_ownership { .. }) | + Call::Assets(pallet_assets::Call::set_team { .. }) | + Call::Assets(pallet_assets::Call::set_metadata { .. }) | + Call::Assets(pallet_assets::Call::clear_metadata { .. }) | + Call::Uniques(pallet_uniques::Call::create { .. }) | + Call::Uniques(pallet_uniques::Call::destroy { .. }) | + Call::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | + Call::Uniques(pallet_uniques::Call::set_team { .. }) | + Call::Uniques(pallet_uniques::Call::set_metadata { .. }) | + Call::Uniques(pallet_uniques::Call::set_attribute { .. }) | + Call::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | + Call::Uniques(pallet_uniques::Call::clear_metadata { .. }) | + Call::Uniques(pallet_uniques::Call::clear_attribute { .. }) | + Call::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | + Call::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | + Call::Utility { .. } | Call::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - Call::Assets(pallet_assets::Call::mint { .. }) - | Call::Assets(pallet_assets::Call::burn { .. }) - | Call::Assets(pallet_assets::Call::freeze { .. }) - | Call::Assets(pallet_assets::Call::thaw { .. }) - | Call::Assets(pallet_assets::Call::freeze_asset { .. }) - | Call::Assets(pallet_assets::Call::thaw_asset { .. }) - | Call::Uniques(pallet_uniques::Call::mint { .. }) - | Call::Uniques(pallet_uniques::Call::burn { .. }) - | Call::Uniques(pallet_uniques::Call::freeze { .. }) - | Call::Uniques(pallet_uniques::Call::thaw { .. }) - | Call::Uniques(pallet_uniques::Call::freeze_collection { .. }) - | Call::Uniques(pallet_uniques::Call::thaw_collection { .. }) - | Call::Utility { .. } - | Call::Multisig { .. } + Call::Assets(pallet_assets::Call::mint { .. }) | + Call::Assets(pallet_assets::Call::burn { .. }) | + Call::Assets(pallet_assets::Call::freeze { .. }) | + Call::Assets(pallet_assets::Call::thaw { .. }) | + Call::Assets(pallet_assets::Call::freeze_asset { .. }) | + Call::Assets(pallet_assets::Call::thaw_asset { .. }) | + Call::Uniques(pallet_uniques::Call::mint { .. }) | + Call::Uniques(pallet_uniques::Call::burn { .. }) | + Call::Uniques(pallet_uniques::Call::freeze { .. }) | + Call::Uniques(pallet_uniques::Call::thaw { .. }) | + Call::Uniques(pallet_uniques::Call::freeze_collection { .. }) | + Call::Uniques(pallet_uniques::Call::thaw_collection { .. }) | + Call::Utility { .. } | Call::Multisig { .. } ), ProxyType::Collator => matches!( c, From 0a8abcec285ef740071e5e40abac033109f5e60e Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Tue, 26 Jul 2022 17:27:00 +0200 Subject: [PATCH 13/56] move Xcm type definitions --- parachains/runtimes/assets/statemint/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index be091119ab1..d1324a06876 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -822,6 +822,9 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} + type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; + type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + use xcm::latest::prelude::*; use xcm_config::{Local, DotLocation}; @@ -890,9 +893,6 @@ impl_runtime_apis! { } } - type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; - type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - let whitelist: Vec = vec![ // Block Number From 408636471825cc683ad3b85be63685d895b1df5f Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 27 Jul 2022 09:06:21 +0200 Subject: [PATCH 14/56] define types twice --- parachains/runtimes/assets/statemint/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index d1324a06876..6b293d6a210 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -909,6 +909,9 @@ impl_runtime_apis! { hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(), ]; + type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; + type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + let mut batches = Vec::::new(); let params = (&config, &whitelist); add_benchmarks!(params, batches); From 09b9f020272e8ef6b7c21c33fa692fff3297928c Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 27 Jul 2022 09:09:08 +0200 Subject: [PATCH 15/56] remove commented out lines --- parachains/runtimes/assets/statemint/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 6b293d6a210..a037c740025 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -916,7 +916,6 @@ impl_runtime_apis! { let params = (&config, &whitelist); add_benchmarks!(params, batches); - // if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) } } From 4d28efa6d1f02a44f91da999b372589d5ed7be0b Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 27 Jul 2022 12:17:12 +0200 Subject: [PATCH 16/56] define Xcm bench types globally --- parachains/runtimes/assets/statemint/src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index a037c740025..0355f7781c0 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -795,6 +795,9 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { + type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; + type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + fn benchmark_metadata(extra: bool) -> ( Vec, Vec, @@ -822,9 +825,6 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} - type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; - type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - use xcm::latest::prelude::*; use xcm_config::{Local, DotLocation}; @@ -893,7 +893,6 @@ impl_runtime_apis! { } } - let whitelist: Vec = vec![ // Block Number hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), @@ -909,9 +908,6 @@ impl_runtime_apis! { hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(), ]; - type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; - type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - let mut batches = Vec::::new(); let params = (&config, &whitelist); add_benchmarks!(params, batches); From bf182ccdae77e6a5c1e493df5fc4086b6feadf19 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 27 Jul 2022 12:33:15 +0200 Subject: [PATCH 17/56] test use --- parachains/runtimes/assets/statemint/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 0355f7781c0..c87d890e43f 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -802,6 +802,7 @@ impl_runtime_apis! { Vec, Vec, ) { + use self::{XcmBalances, XcmGeneric} use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; @@ -893,6 +894,8 @@ impl_runtime_apis! { } } + use self::{XcmBalances, XcmGeneric} + let whitelist: Vec = vec![ // Block Number hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), From af885758dc377f1caccb81bb9f82b97ae7cf3988 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 27 Jul 2022 12:48:57 +0200 Subject: [PATCH 18/56] fix semi --- parachains/runtimes/assets/statemint/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index c87d890e43f..d28351257d6 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -802,7 +802,7 @@ impl_runtime_apis! { Vec, Vec, ) { - use self::{XcmBalances, XcmGeneric} + use self::{XcmBalances, XcmGeneric}; use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; @@ -894,7 +894,7 @@ impl_runtime_apis! { } } - use self::{XcmBalances, XcmGeneric} + use self::{XcmBalances, XcmGeneric}; let whitelist: Vec = vec![ // Block Number From 84bd7c7a1f7129becb391393a6dba1e6f968ae7e Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Thu, 28 Jul 2022 11:55:49 +0200 Subject: [PATCH 19/56] make sure the type definittion is properly documented --- parachains/runtimes/assets/statemint/src/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index d28351257d6..84818480831 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -795,19 +795,22 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { - type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; - type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - fn benchmark_metadata(extra: bool) -> ( Vec, Vec, ) { - use self::{XcmBalances, XcmGeneric}; + use frame_benchmarking::{Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + // This is defined once again in dispatch_benchmark, because list_benchmarks! + // and add_benchmarks! are macros exported by define_benchmarks! macros and those types + // are referenced in that call. + type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; + type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + let mut list = Vec::::new(); list_benchmarks!(list, extra); @@ -894,7 +897,9 @@ impl_runtime_apis! { } } - use self::{XcmBalances, XcmGeneric}; + type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; + type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + let whitelist: Vec = vec![ // Block Number From 1434df77947e34321ddd467b2d19a77923ba3380 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Thu, 28 Jul 2022 13:46:44 +0200 Subject: [PATCH 20/56] tweak TrustedTeleporter/Reserve --- parachains/runtimes/assets/statemint/src/lib.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 84818480831..f29c982d44b 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -850,13 +850,10 @@ impl_runtime_apis! { //TODO: Not sure how this should work parameter_types! { pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( - Local::get(), - MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(DotLocation::get()) }, - )); - pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some(( - Local::get(), - MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(DotLocation::get()) }, + DotLocation::get(), + MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(Local::get()) }, )); + pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; } impl pallet_xcm_benchmarks::fungible::Config for Runtime { From b1e472c2f258611c41e92d1c77907780909120a3 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Sun, 7 Aug 2022 15:21:42 +0200 Subject: [PATCH 21/56] use dots as asset --- parachains/runtimes/assets/statemint/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index f29c982d44b..a129cd0bde4 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -851,7 +851,7 @@ impl_runtime_apis! { parameter_types! { pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( DotLocation::get(), - MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(Local::get()) }, + MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(DotLocation::get()) }, )); pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; } @@ -888,7 +888,7 @@ impl_runtime_apis! { fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { let origin = DotLocation::get(); - let assets: MultiAssets = (Concrete(Local::get()), 1_000 * UNITS).into(); + let assets: MultiAssets = (Concrete(DotLocation::get()), 1_000 * UNITS).into(); let ticket = MultiLocation { parents: 0, interior: Here }; Ok((origin, ticket, assets)) } From 063fabcebaf588dab5cd4dbd76536d4edff33a3e Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Tue, 16 Aug 2022 16:45:30 +0200 Subject: [PATCH 22/56] copy benchmarks over, fix the ci script --- Cargo.lock | 31 +- pallets/pallet-xcm-benchmarks/Cargo.toml | 45 +++ .../src/fungible/benchmarking.rs | 242 +++++++++++++ .../src/fungible/mock.rs | 198 +++++++++++ .../pallet-xcm-benchmarks/src/fungible/mod.rs | 51 +++ .../src/generic/benchmarking.rs | 318 ++++++++++++++++++ .../pallet-xcm-benchmarks/src/generic/mock.rs | 176 ++++++++++ .../pallet-xcm-benchmarks/src/generic/mod.rs | 39 +++ pallets/pallet-xcm-benchmarks/src/lib.rs | 110 ++++++ pallets/pallet-xcm-benchmarks/src/mock.rs | 64 ++++ .../runtimes/assets/statemint/Cargo.toml | 2 +- .../runtimes/assets/statemint/src/lib.rs | 6 +- scripts/benchmarks-ci.sh | 17 +- 13 files changed, 1291 insertions(+), 8 deletions(-) create mode 100644 pallets/pallet-xcm-benchmarks/Cargo.toml create mode 100644 pallets/pallet-xcm-benchmarks/src/fungible/benchmarking.rs create mode 100644 pallets/pallet-xcm-benchmarks/src/fungible/mock.rs create mode 100644 pallets/pallet-xcm-benchmarks/src/fungible/mod.rs create mode 100644 pallets/pallet-xcm-benchmarks/src/generic/benchmarking.rs create mode 100644 pallets/pallet-xcm-benchmarks/src/generic/mock.rs create mode 100644 pallets/pallet-xcm-benchmarks/src/generic/mod.rs create mode 100644 pallets/pallet-xcm-benchmarks/src/lib.rs create mode 100644 pallets/pallet-xcm-benchmarks/src/mock.rs diff --git a/Cargo.lock b/Cargo.lock index 6112637cc14..d09472d5926 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3944,7 +3944,7 @@ dependencies = [ "pallet-utility", "pallet-vesting", "pallet-xcm", - "pallet-xcm-benchmarks", + "pallet-xcm-benchmarks 0.9.27 (git+https://github.com/paritytech/polkadot?branch=master)", "parity-scale-codec", "polkadot-primitives", "polkadot-runtime-common", @@ -6420,6 +6420,31 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "pallet-xcm-benchmarks" +version = "0.9.27" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-assets", + "pallet-balances", + "pallet-xcm", + "parity-scale-codec", + "polkadot-primitives", + "polkadot-runtime-common", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-tracing", + "xcm", + "xcm-builder", + "xcm-executor", +] + [[package]] name = "pallet-xcm-benchmarks" version = "0.9.27" @@ -11614,7 +11639,7 @@ dependencies = [ "pallet-uniques", "pallet-utility", "pallet-xcm", - "pallet-xcm-benchmarks", + "pallet-xcm-benchmarks 0.9.27", "parachain-info", "parachains-common", "parity-scale-codec", @@ -13006,7 +13031,7 @@ dependencies = [ "pallet-utility", "pallet-vesting", "pallet-xcm", - "pallet-xcm-benchmarks", + "pallet-xcm-benchmarks 0.9.27 (git+https://github.com/paritytech/polkadot?branch=master)", "parity-scale-codec", "polkadot-parachain 0.9.27", "polkadot-primitives", diff --git a/pallets/pallet-xcm-benchmarks/Cargo.toml b/pallets/pallet-xcm-benchmarks/Cargo.toml new file mode 100644 index 00000000000..92352266571 --- /dev/null +++ b/pallets/pallet-xcm-benchmarks/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "pallet-xcm-benchmarks" +authors = ["Parity Technologies "] +edition = "2021" +version = "0.9.27" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } +scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" } +sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" } +xcm-executor = {git = "https://github.com/paritytech/polkadot" , branch = "master", default-features = false, features = ["runtime-benchmarks"] } +frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" } +xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master", default-features = false, features = ["runtime-benchmarks"] } +log = "0.4.17" + +[dev-dependencies] +pallet-balances = { git = "https://github.com/paritytech/substrate" , branch = "master" } +pallet-assets = { git = "https://github.com/paritytech/substrate" , branch = "master" } +sp-core = { git = "https://github.com/paritytech/substrate" , branch = "master" } +sp-io = { git = "https://github.com/paritytech/substrate" , branch = "master" } +sp-tracing = { git = "https://github.com/paritytech/substrate" , branch = "master" } +xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "master" } +xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master" } +# temp +pallet-xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master" } +polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot" , branch = "master" } +# westend-runtime = { path = "../../runtime/westend", features = ["runtime-benchmarks"] } +polkadot-primitives = { git = "https://github.com/paritytech/polkadot" , branch = "master" } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-benchmarking/std", + "frame-support/std", + "frame-system/std", + "sp-runtime/std", + "sp-std/std" +] diff --git a/pallets/pallet-xcm-benchmarks/src/fungible/benchmarking.rs b/pallets/pallet-xcm-benchmarks/src/fungible/benchmarking.rs new file mode 100644 index 00000000000..e61bf4794d6 --- /dev/null +++ b/pallets/pallet-xcm-benchmarks/src/fungible/benchmarking.rs @@ -0,0 +1,242 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use super::*; +use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; +use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError, BenchmarkResult}; +use frame_support::{ + pallet_prelude::Get, + traits::fungible::{Inspect, Mutate}, +}; +use sp_runtime::traits::{Bounded, Zero}; +use sp_std::{prelude::*, vec}; +use xcm::latest::prelude::*; +use xcm_executor::traits::{Convert, TransactAsset}; + +benchmarks_instance_pallet! { + where_clause { where + < + < + T::TransactAsset + as + Inspect + >::Balance + as + TryInto + >::Error: sp_std::fmt::Debug, + } + + withdraw_asset { + let (sender_account, sender_location) = account_and_location::(1); + let worst_case_holding = T::worst_case_holding(); + let asset = T::get_multi_asset(); + + >::deposit_asset(&asset, &sender_location).unwrap(); + // check the assets of origin. + assert!(!T::TransactAsset::balance(&sender_account).is_zero()); + + let mut executor = new_executor::(sender_location); + executor.holding = worst_case_holding.into(); + let instruction = Instruction::>::WithdrawAsset(vec![asset.clone()].into()); + let xcm = Xcm(vec![instruction]); + }: { + executor.execute(xcm)?; + } verify { + // check one of the assets of origin. + assert!(T::TransactAsset::balance(&sender_account).is_zero()); + assert!(executor.holding.ensure_contains(&vec![asset].into()).is_ok()); + } + + transfer_asset { + let (sender_account, sender_location) = account_and_location::(1); + let asset = T::get_multi_asset(); + let assets: MultiAssets = vec![ asset.clone() ].into(); + // this xcm doesn't use holding + + let dest_location = T::valid_destination()?; + let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap(); + + >::deposit_asset(&asset, &sender_location).unwrap(); + assert!(T::TransactAsset::balance(&dest_account).is_zero()); + + let mut executor = new_executor::(sender_location); + let instruction = Instruction::TransferAsset { assets, beneficiary: dest_location }; + let xcm = Xcm(vec![instruction]); + }: { + executor.execute(xcm)?; + } verify { + assert!(T::TransactAsset::balance(&sender_account).is_zero()); + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + } + + transfer_reserve_asset { + let (sender_account, sender_location) = account_and_location::(1); + let dest_location = T::valid_destination()?; + let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap(); + + let asset = T::get_multi_asset(); + >::deposit_asset(&asset, &sender_location).unwrap(); + let assets: MultiAssets = vec![ asset ].into(); + assert!(T::TransactAsset::balance(&dest_account).is_zero()); + + let mut executor = new_executor::(sender_location); + let instruction = Instruction::TransferReserveAsset { + assets, + dest: dest_location, + xcm: Xcm::new() + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.execute(xcm)?; + } verify { + assert!(T::TransactAsset::balance(&sender_account).is_zero()); + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + // 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() + .ok_or(BenchmarkError::Skip)?; + + if let Some(checked_account) = T::CheckedAccount::get() { + T::TransactAsset::mint_into( + &checked_account, + < + T::TransactAsset + as + Inspect + >::Balance::max_value() / 2u32.into(), + )?; + } + + let assets: MultiAssets = vec![ teleportable_asset ].into(); + + let mut executor = new_executor::(trusted_teleporter); + let instruction = Instruction::ReceiveTeleportedAsset(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()); + } + + deposit_asset { + let asset = T::get_multi_asset(); + let mut holding = T::worst_case_holding(); + + // Add our asset to the holding. + holding.push(asset.clone()); + + // our dest must have no balance initially. + let dest_location = T::valid_destination()?; + let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap(); + assert!(T::TransactAsset::balance(&dest_account).is_zero()); + + let mut executor = new_executor::(Default::default()); + executor.holding = holding.into(); + let instruction = Instruction::>::DepositAsset { + assets: asset.into(), + max_assets: 1, + beneficiary: dest_location, + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.execute(xcm)?; + } verify { + // dest should have received some asset. + assert!(!T::TransactAsset::balance(&dest_account).is_zero()) + } + + deposit_reserve_asset { + let asset = T::get_multi_asset(); + let mut holding = T::worst_case_holding(); + + // Add our asset to the holding. + holding.push(asset.clone()); + + // our dest must have no balance initially. + let dest_location = T::valid_destination()?; + let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap(); + assert!(T::TransactAsset::balance(&dest_account).is_zero()); + + let mut executor = new_executor::(Default::default()); + executor.holding = holding.into(); + let instruction = Instruction::>::DepositReserveAsset { + assets: asset.into(), + max_assets: 1, + dest: dest_location, + xcm: Xcm::new(), + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.execute(xcm)?; + } verify { + // dest should have received some asset. + assert!(!T::TransactAsset::balance(&dest_account).is_zero()) + } + + initiate_teleport { + let asset = T::get_multi_asset(); + let mut holding = T::worst_case_holding(); + + // Add our asset to the holding. + holding.push(asset.clone()); + + let mut executor = new_executor::(Default::default()); + executor.holding = holding.into(); + let instruction = Instruction::>::InitiateTeleport { + assets: asset.into(), + dest: T::valid_destination()?, + xcm: Xcm::new(), + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.execute(xcm)?; + } verify { + // we're good as long as there's no error, checking account is bypassed when operating on + // native assets aka Dot + } + + impl_benchmark_test_suite!( + Pallet, + crate::fungible::mock::new_test_ext(), + crate::fungible::mock::Test + ); +} diff --git a/pallets/pallet-xcm-benchmarks/src/fungible/mock.rs b/pallets/pallet-xcm-benchmarks/src/fungible/mock.rs new file mode 100644 index 00000000000..3f7e4f8f26e --- /dev/null +++ b/pallets/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -0,0 +1,198 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! A mock runtime for XCM benchmarking. + +use crate::{fungible as xcm_balances_benchmark, mock::*}; +use frame_benchmarking::BenchmarkError; +use frame_support::{parameter_types, traits::Everything}; +use sp_core::H256; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, + BuildStorage, +}; +use xcm::latest::prelude::*; +use xcm_builder::AllowUnpaidExecutionFrom; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +// For testing the pallet, we construct a mock runtime. +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + XcmBalancesBenchmark: xcm_balances_benchmark::{Pallet}, + } +); + +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max(1024); +} +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type Origin = Origin; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Call = Call; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Header = Header; + type Event = Event; + type BlockHashCount = BlockHashCount; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +parameter_types! { + pub const ExistentialDeposit: u64 = 7; +} + +impl pallet_balances::Config for Test { + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type Balance = u64; + type DustRemoval = (); + type Event = Event; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} + +parameter_types! { + pub const AssetDeposit: u64 = 100 * ExistentialDeposit::get(); + pub const ApprovalDeposit: u64 = 1 * ExistentialDeposit::get(); + pub const StringLimit: u32 = 50; + pub const MetadataDepositBase: u64 = 10 * ExistentialDeposit::get(); + pub const MetadataDepositPerByte: u64 = 1 * ExistentialDeposit::get(); +} + +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 balances as the asset transactor. +pub type AssetTransactor = xcm_builder::CurrencyAdapter< + Balances, + MatchAnyFungible, + AccountIdConverter, + u64, + CheckedAccount, +>; + +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 struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type Call = Call; + type XcmSender = DevNull; + type AssetTransactor = AssetTransactor; + type OriginConverter = (); + type IsReserve = TrustedReserves; + type IsTeleporter = TrustedTeleporters; + type LocationInverter = xcm_builder::LocationInverter; + type Barrier = AllowUnpaidExecutionFrom; + type Weigher = xcm_builder::FixedWeightBounds; + type Trader = xcm_builder::FixedRateOfFungible; + type ResponseHandler = DevNull; + type AssetTrap = (); + type AssetClaims = (); + type SubscriptionService = (); +} + +impl crate::Config for Test { + type XcmConfig = XcmConfig; + type AccountIdConverter = AccountIdConverter; + fn valid_destination() -> Result { + let valid_destination: MultiLocation = + X1(AccountId32 { network: NetworkId::Any, id: [0u8; 32] }).into(); + + Ok(valid_destination) + } + fn worst_case_holding() -> MultiAssets { + crate::mock_worst_case_holding() + } +} + +pub type TrustedTeleporters = (xcm_builder::Case,); +pub type TrustedReserves = (xcm_builder::Case,); + +parameter_types! { + pub const CheckedAccount: Option = Some(100); + pub const ChildTeleporter: MultiLocation = Parachain(1000).into(); + pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( + 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 = + >::minimum_balance() as u128; + MultiAsset { id: Concrete(Here.into()), fun: Fungible(amount) } + } +} + +pub fn new_test_ext() -> sp_io::TestExternalities { + let t = GenesisConfig { ..Default::default() }.build_storage().unwrap(); + sp_tracing::try_init_simple(); + t.into() +} diff --git a/pallets/pallet-xcm-benchmarks/src/fungible/mod.rs b/pallets/pallet-xcm-benchmarks/src/fungible/mod.rs new file mode 100644 index 00000000000..1acf61cf001 --- /dev/null +++ b/pallets/pallet-xcm-benchmarks/src/fungible/mod.rs @@ -0,0 +1,51 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +// Benchmarking for the `AssetTransactor` trait via `Fungible`. + +pub use pallet::*; + +pub mod benchmarking; +#[cfg(test)] +mod mock; + +#[frame_support::pallet] +pub mod pallet { + use frame_support::pallet_prelude::Get; + #[pallet::config] + pub trait Config: frame_system::Config + crate::Config { + /// The type of `fungible` that is being used under the hood. + /// + /// This is useful for testing and checking. + type TransactAsset: frame_support::traits::fungible::Mutate; + + /// The account used to check assets being teleported. + type CheckedAccount: Get>; + + /// 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; + } + + #[pallet::pallet] + pub struct Pallet(_); +} diff --git a/pallets/pallet-xcm-benchmarks/src/generic/benchmarking.rs b/pallets/pallet-xcm-benchmarks/src/generic/benchmarking.rs new file mode 100644 index 00000000000..62d0df265c4 --- /dev/null +++ b/pallets/pallet-xcm-benchmarks/src/generic/benchmarking.rs @@ -0,0 +1,318 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use super::*; +use crate::{new_executor, XcmCallOf}; +use codec::Encode; +use frame_benchmarking::{benchmarks, BenchmarkError}; +use frame_support::dispatch::GetDispatchInfo; +use sp_std::vec; +use xcm::{ + latest::{prelude::*, MultiAssets}, + DoubleEncoded, +}; + +benchmarks! { + query_holding { + let holding = T::worst_case_holding(); + + let mut executor = new_executor::(Default::default()); + executor.holding = holding.clone().into(); + + let instruction = Instruction::>::QueryHolding { + query_id: Default::default(), + dest: T::valid_destination()?, + // Worst case is looking through all holdings for every asset explicitly. + assets: Definite(holding), + max_response_weight: u64::MAX, + }; + + let xcm = Xcm(vec![instruction]); + + } : { + executor.execute(xcm)?; + } verify { + // The completion of execution above is enough to validate this is completed. + } + + // This benchmark does not use any additional orders or instructions. This should be managed + // by the `deep` and `shallow` implementation. + buy_execution { + let holding = T::worst_case_holding().into(); + + let mut executor = new_executor::(Default::default()); + executor.holding = holding; + + let fee_asset = Concrete(Here.into()); + + let instruction = Instruction::>::BuyExecution { + fees: (fee_asset, 100_000_000).into(), // should be something inside of holding + weight_limit: WeightLimit::Unlimited, + }; + + let xcm = Xcm(vec![instruction]); + } : { + executor.execute(xcm)?; + } verify { + + } + + // Worst case scenario for this benchmark is a large number of assets to + // filter through the reserve. + reserve_asset_deposited { + const MAX_ASSETS: u32 = 100; // TODO when executor has a built in limit, use it here. #4426 + let mut executor = new_executor::(Default::default()); + let assets = (0..MAX_ASSETS).map(|i| MultiAsset { + id: Abstract(i.encode()), + fun: Fungible(i as u128), + + }).collect::>(); + let multiassets: MultiAssets = assets.into(); + + let instruction = Instruction::ReserveAssetDeposited(multiassets.clone()); + let xcm = Xcm(vec![instruction]); + }: { + executor.execute(xcm).map_err(|_| BenchmarkError::Skip)?; + } verify { + assert_eq!(executor.holding, multiassets.into()); + } + + query_response { + let mut executor = new_executor::(Default::default()); + let (query_id, response) = T::worst_case_response(); + let max_weight = u64::MAX; + let instruction = Instruction::QueryResponse { query_id, response, max_weight }; + let xcm = Xcm(vec![instruction]); + }: { + executor.execute(xcm)?; + } verify { + // The assert above is enough to show this XCM succeeded + } + + // We don't care about the call itself, since that is accounted for in the weight parameter + // and included in the final weight calculation. So this is just the overhead of submitting + // a noop call. + transact { + let origin = T::transact_origin()?; + let mut executor = new_executor::(origin); + let noop_call: ::Call = frame_system::Call::remark_with_event { + remark: Default::default() + }.into(); + let double_encoded_noop_call: DoubleEncoded<_> = noop_call.encode().into(); + + let instruction = Instruction::Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: noop_call.get_dispatch_info().weight, + call: double_encoded_noop_call, + }; + let xcm = Xcm(vec![instruction]); + + let num_events = frame_system::Pallet::::events().len(); + }: { + executor.execute(xcm)?; + } verify { + // TODO make better assertion? #4426 + let num_events2 = frame_system::Pallet::::events().len(); + assert_eq!(num_events + 1, num_events2); + } + + refund_surplus { + let holding = T::worst_case_holding().into(); + let mut executor = new_executor::(Default::default()); + executor.holding = holding; + executor.total_surplus = 1337; + executor.total_refunded = 0; + + let instruction = Instruction::>::RefundSurplus; + let xcm = Xcm(vec![instruction]); + } : { + let result = executor.execute(xcm)?; + } verify { + assert_eq!(executor.total_surplus, 1337); + assert_eq!(executor.total_refunded, 1337); + } + + set_error_handler { + let mut executor = new_executor::(Default::default()); + let instruction = Instruction::>::SetErrorHandler(Xcm(vec![])); + let xcm = Xcm(vec![instruction]); + } : { + executor.execute(xcm)?; + } verify { + assert_eq!(executor.error_handler, Xcm(vec![])); + } + + set_appendix { + let mut executor = new_executor::(Default::default()); + let appendix = Xcm(vec![]); + let instruction = Instruction::>::SetAppendix(appendix); + let xcm = Xcm(vec![instruction]); + } : { + executor.execute(xcm)?; + } verify { + assert_eq!(executor.appendix, Xcm(vec![])); + } + + clear_error { + let mut executor = new_executor::(Default::default()); + executor.error = Some((5u32, XcmError::Overflow)); + let instruction = Instruction::>::ClearError; + let xcm = Xcm(vec![instruction]); + } : { + executor.execute(xcm)?; + } verify { + assert!(executor.error.is_none()) + } + + descend_origin { + let mut executor = new_executor::(Default::default()); + let who = X2(OnlyChild, OnlyChild); + let instruction = Instruction::DescendOrigin(who.clone()); + let xcm = Xcm(vec![instruction]); + } : { + executor.execute(xcm)?; + } verify { + assert_eq!( + executor.origin, + Some(MultiLocation { + parents: 0, + interior: who, + }), + ); + } + + clear_origin { + let mut executor = new_executor::(Default::default()); + let instruction = Instruction::ClearOrigin; + let xcm = Xcm(vec![instruction]); + } : { + executor.execute(xcm)?; + } verify { + assert_eq!(executor.origin, None); + } + + report_error { + let mut executor = new_executor::(Default::default()); + executor.error = Some((0u32, XcmError::Unimplemented)); + let query_id = Default::default(); + let dest = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; + let max_response_weight = Default::default(); + + let instruction = Instruction::ReportError { query_id, dest, max_response_weight }; + let xcm = Xcm(vec![instruction]); + }: { + executor.execute(xcm)?; + } verify { + // the execution succeeding is all we need to verify this xcm was successful + } + + claim_asset { + use xcm_executor::traits::DropAssets; + + let (origin, ticket, assets) = T::claimable_asset()?; + + // We place some items into the asset trap to claim. + ::AssetTrap::drop_assets( + &origin, + assets.clone().into(), + ); + + // Assets should be in the trap now. + + let mut executor = new_executor::(origin); + let instruction = Instruction::ClaimAsset { assets: assets.clone(), ticket }; + let xcm = Xcm(vec![instruction]); + } :{ + executor.execute(xcm)?; + } verify { + assert!(executor.holding.ensure_contains(&assets).is_ok()); + } + + trap { + let mut executor = new_executor::(Default::default()); + let instruction = Instruction::Trap(10); + let xcm = Xcm(vec![instruction]); + // In order to access result in the verification below, it needs to be defined here. + let mut _result = Ok(()); + } : { + _result = executor.execute(xcm); + } verify { + match _result { + Err(error) if error.xcm_error == XcmError::Trap(10) => { + // This is the success condition + }, + _ => Err("xcm trap did not return the expected error")? + }; + } + + subscribe_version { + use xcm_executor::traits::VersionChangeNotifier; + let origin = T::subscribe_origin()?; + let query_id = Default::default(); + let max_response_weight = Default::default(); + let mut executor = new_executor::(origin.clone()); + let instruction = Instruction::SubscribeVersion { query_id, max_response_weight }; + let xcm = Xcm(vec![instruction]); + } : { + executor.execute(xcm)?; + } verify { + assert!(::SubscriptionService::is_subscribed(&origin)); + } + + unsubscribe_version { + use xcm_executor::traits::VersionChangeNotifier; + // First we need to subscribe to notifications. + let origin = T::transact_origin()?; + let query_id = Default::default(); + let max_response_weight = Default::default(); + ::SubscriptionService::start( + &origin, + query_id, + max_response_weight + ).map_err(|_| "Could not start subscription")?; + assert!(::SubscriptionService::is_subscribed(&origin)); + + let mut executor = new_executor::(origin.clone()); + let instruction = Instruction::UnsubscribeVersion; + let xcm = Xcm(vec![instruction]); + } : { + executor.execute(xcm)?; + } verify { + assert!(!::SubscriptionService::is_subscribed(&origin)); + } + + initiate_reserve_withdraw { + let holding = T::worst_case_holding(); + let assets_filter = MultiAssetFilter::Definite(holding.clone()); + let reserve = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; + let mut executor = new_executor::(Default::default()); + executor.holding = holding.into(); + let instruction = Instruction::InitiateReserveWithdraw { assets: assets_filter, reserve, xcm: Xcm(vec![]) }; + let xcm = Xcm(vec![instruction]); + }:{ + executor.execute(xcm)?; + } verify { + // The execute completing successfully is as good as we can check. + // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 + } + + impl_benchmark_test_suite!( + Pallet, + crate::generic::mock::new_test_ext(), + crate::generic::mock::Test + ); + +} diff --git a/pallets/pallet-xcm-benchmarks/src/generic/mock.rs b/pallets/pallet-xcm-benchmarks/src/generic/mock.rs new file mode 100644 index 00000000000..7782ba1d90e --- /dev/null +++ b/pallets/pallet-xcm-benchmarks/src/generic/mock.rs @@ -0,0 +1,176 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! A mock runtime for XCM benchmarking. + +use crate::{generic, mock::*, *}; +use codec::Decode; +use frame_support::{ + parameter_types, + traits::{Everything, OriginTrait}, +}; +use sp_core::H256; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput}, + BuildStorage, +}; +use xcm_builder::{ + test_utils::{Assets, TestAssetTrap, TestSubscriptionService}, + AllowUnpaidExecutionFrom, +}; +use xcm_executor::traits::ConvertOrigin; + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + XcmGenericBenchmarks: generic::{Pallet}, + } +); + +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max(1024); +} + +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type Origin = Origin; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Call = Call; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Header = Header; + type Event = Event; + type BlockHashCount = BlockHashCount; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +/// The benchmarks in this pallet should never need an asset transactor to begin with. +pub struct NoAssetTransactor; +impl xcm_executor::traits::TransactAsset for NoAssetTransactor { + fn deposit_asset(_: &MultiAsset, _: &MultiLocation) -> Result<(), XcmError> { + unreachable!(); + } + + fn withdraw_asset(_: &MultiAsset, _: &MultiLocation) -> Result { + unreachable!(); + } +} + +parameter_types! { + pub const MaxInstructions: u32 = 100; +} + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type Call = Call; + type XcmSender = DevNull; + type AssetTransactor = NoAssetTransactor; + type OriginConverter = AlwaysSignedByDefault; + type IsReserve = AllAssetLocationsPass; + type IsTeleporter = (); + type LocationInverter = xcm_builder::LocationInverter; + type Barrier = AllowUnpaidExecutionFrom; + type Weigher = xcm_builder::FixedWeightBounds; + type Trader = xcm_builder::FixedRateOfFungible; + type ResponseHandler = DevNull; + type AssetTrap = TestAssetTrap; + type AssetClaims = TestAssetTrap; + type SubscriptionService = TestSubscriptionService; +} + +impl crate::Config for Test { + type XcmConfig = XcmConfig; + type AccountIdConverter = AccountIdConverter; + fn valid_destination() -> Result { + let valid_destination: MultiLocation = + Junction::AccountId32 { network: NetworkId::Any, id: [0u8; 32] }.into(); + + Ok(valid_destination) + } + fn worst_case_holding() -> MultiAssets { + crate::mock_worst_case_holding() + } +} + +impl generic::Config for Test { + type Call = Call; + + fn worst_case_response() -> (u64, Response) { + let assets: MultiAssets = (Concrete(Here.into()), 100).into(); + (0, Response::Assets(assets)) + } + + fn transact_origin() -> Result { + Ok(Default::default()) + } + + fn subscribe_origin() -> Result { + Ok(Default::default()) + } + + fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { + let assets: MultiAssets = (Concrete(Here.into()), 100).into(); + let ticket = MultiLocation { parents: 0, interior: X1(GeneralIndex(0)) }; + Ok((Default::default(), ticket, assets)) + } +} + +pub fn new_test_ext() -> sp_io::TestExternalities { + let t = GenesisConfig { ..Default::default() }.build_storage().unwrap(); + sp_tracing::try_init_simple(); + t.into() +} + +pub struct AlwaysSignedByDefault(core::marker::PhantomData); +impl ConvertOrigin for AlwaysSignedByDefault +where + Origin: OriginTrait, + ::AccountId: Decode, +{ + fn convert_origin( + _origin: impl Into, + _kind: OriginKind, + ) -> Result { + Ok(Origin::signed( + ::AccountId::decode(&mut TrailingZeroInput::zeroes()) + .expect("infinite length input; no invalid inputs for type; qed"), + )) + } +} diff --git a/pallets/pallet-xcm-benchmarks/src/generic/mod.rs b/pallets/pallet-xcm-benchmarks/src/generic/mod.rs new file mode 100644 index 00000000000..270eaf896e7 --- /dev/null +++ b/pallets/pallet-xcm-benchmarks/src/generic/mod.rs @@ -0,0 +1,39 @@ +pub use pallet::*; + +pub mod benchmarking; +#[cfg(test)] +mod mock; + +#[frame_support::pallet] +pub mod pallet { + use frame_benchmarking::BenchmarkError; + use frame_support::{dispatch::Dispatchable, pallet_prelude::Encode, weights::GetDispatchInfo}; + use xcm::latest::{MultiAssets, MultiLocation, Response}; + + #[pallet::config] + pub trait Config: frame_system::Config + crate::Config { + type Call: Dispatchable + + GetDispatchInfo + + From> + + Encode; + + /// The response which causes the most runtime weight. + fn worst_case_response() -> (u64, Response); + + /// The `MultiLocation` used for successful transaction XCMs. + /// + /// If set to `None`, benchmarks which rely on a `transact_origin` will be skipped. + fn transact_origin() -> Result; + + /// A valid `MultiLocation` we can successfully subscribe to. + /// + /// If set to `None`, benchmarks which rely on a `subscribe_origin` will be skipped. + fn subscribe_origin() -> Result; + + /// Return an origin, ticket, and assets that can be trapped and claimed. + fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError>; + } + + #[pallet::pallet] + pub struct Pallet(_); +} diff --git a/pallets/pallet-xcm-benchmarks/src/lib.rs b/pallets/pallet-xcm-benchmarks/src/lib.rs new file mode 100644 index 00000000000..8492dac5a62 --- /dev/null +++ b/pallets/pallet-xcm-benchmarks/src/lib.rs @@ -0,0 +1,110 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Pallet that serves no other purpose than benchmarking raw messages [`Xcm`]. + +#![cfg_attr(not(feature = "std"), no_std)] + +use codec::Encode; +use frame_benchmarking::{account, BenchmarkError}; +use sp_std::prelude::*; +use xcm::latest::prelude::*; +use xcm_executor::traits::Convert; + +pub mod fungible; +pub mod generic; + +#[cfg(test)] +mod mock; + +/// A base trait for all individual pallets +pub trait Config: frame_system::Config { + /// The XCM configurations. + /// + /// These might affect the execution of XCM messages, such as defining how the + /// `TransactAsset` is implemented. + type XcmConfig: xcm_executor::Config; + + /// A converter between a multi-location to a sovereign account. + type AccountIdConverter: Convert; + + /// Does any necessary setup to create a valid destination for XCM messages. + /// Returns that destination's multi-location to be used in benchmarks. + fn valid_destination() -> Result; + + /// Worst case scenario for a holding account in this runtime. + fn worst_case_holding() -> MultiAssets; +} + +const SEED: u32 = 0; + +/// The XCM executor to use for doing stuff. +pub type ExecutorOf = xcm_executor::XcmExecutor<::XcmConfig>; +/// The overarching call type. +pub type OverArchingCallOf = ::Call; +/// The asset transactor of our executor +pub type AssetTransactorOf = <::XcmConfig as xcm_executor::Config>::AssetTransactor; +/// The call type of executor's config. Should eventually resolve to the same overarching call type. +pub type XcmCallOf = <::XcmConfig as xcm_executor::Config>::Call; + +pub fn mock_worst_case_holding() -> MultiAssets { + const HOLDING_FUNGIBLES: u32 = 99; + const HOLDING_NON_FUNGIBLES: u32 = 99; + let fungibles_amount: u128 = 100; + (0..HOLDING_FUNGIBLES) + .map(|i| { + MultiAsset { + id: Concrete(GeneralIndex(i as u128).into()), + fun: Fungible(fungibles_amount * i as u128), + } + .into() + }) + .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::>() + .into() +} + +pub fn asset_instance_from(x: u32) -> AssetInstance { + let bytes = x.encode(); + let mut instance = [0u8; 4]; + instance.copy_from_slice(&bytes); + AssetInstance::Array4(instance) +} + +pub fn new_executor(origin: MultiLocation) -> ExecutorOf { + ExecutorOf::::new(origin) +} + +/// Build a multi-location from an account id. +fn account_id_junction(index: u32) -> Junction { + let account: T::AccountId = account("account", index, SEED); + let mut encoded = account.encode(); + encoded.resize(32, 0u8); + let mut id = [0u8; 32]; + id.copy_from_slice(&encoded); + Junction::AccountId32 { network: NetworkId::Any, id } +} + +pub fn account_and_location(index: u32) -> (T::AccountId, MultiLocation) { + let location: MultiLocation = account_id_junction::(index).into(); + let account = T::AccountIdConverter::convert(location.clone()).unwrap(); + + (account, location) +} diff --git a/pallets/pallet-xcm-benchmarks/src/mock.rs b/pallets/pallet-xcm-benchmarks/src/mock.rs new file mode 100644 index 00000000000..d59cf338726 --- /dev/null +++ b/pallets/pallet-xcm-benchmarks/src/mock.rs @@ -0,0 +1,64 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +use crate::*; +use frame_support::{parameter_types, weights::Weight}; +use xcm_executor::traits::FilterAssetLocation; + +// An xcm sender/receiver akin to > /dev/null +pub struct DevNull; +impl xcm::opaque::latest::SendXcm for DevNull { + fn send_xcm(_: impl Into, _: Xcm<()>) -> SendResult { + Ok(()) + } +} + +impl xcm_executor::traits::OnResponse for DevNull { + fn expecting_response(_: &MultiLocation, _: u64) -> bool { + false + } + fn on_response(_: &MultiLocation, _: u64, _: Response, _: Weight) -> Weight { + 0 + } +} + +pub struct AccountIdConverter; +impl xcm_executor::traits::Convert for AccountIdConverter { + fn convert(ml: MultiLocation) -> Result { + match ml { + MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { id, .. }) } => + Ok(::decode(&mut &*id.to_vec()).unwrap()), + _ => Err(ml), + } + } + + fn reverse(acc: u64) -> Result { + Err(acc) + } +} + +parameter_types! { + pub Ancestry: MultiLocation = Junction::Parachain(101).into(); + pub UnitWeightCost: Weight = 10; + pub WeightPrice: (AssetId, u128) = (Concrete(Here.into()), 1_000_000); +} + +pub struct AllAssetLocationsPass; +impl FilterAssetLocation for AllAssetLocationsPass { + fn filter_asset_location(_: &MultiAsset, _: &MultiLocation) -> bool { + true + } +} diff --git a/parachains/runtimes/assets/statemint/Cargo.toml b/parachains/runtimes/assets/statemint/Cargo.toml index b3ac5456d2f..f1fecb91fd1 100644 --- a/parachains/runtimes/assets/statemint/Cargo.toml +++ b/parachains/runtimes/assets/statemint/Cargo.toml @@ -56,7 +56,7 @@ polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", d xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } -pallet-xcm-benchmarks = { git = "https://github.com/paritytech/polkadot", default-features = false, optional = true, branch = "master" } +pallet-xcm-benchmarks = { path = "../../../../pallets/pallet-xcm-benchmarks", default-features = false, optional = true } # Cumulus diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 91340e0eb36..9f69df4d5cf 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -831,7 +831,7 @@ impl_runtime_apis! { impl cumulus_pallet_session_benchmarking::Config for Runtime {} use xcm::latest::prelude::*; - use xcm_config::{Local, DotLocation}; + use xcm_config::DotLocation; impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; @@ -844,6 +844,10 @@ impl_runtime_apis! { vec![MultiAsset{ id: Concrete(DotLocation::get()), fun: Fungible(1_000_000 * UNITS), + }, + MultiAsset{ + id: Concrete(DotLocation::get()), + fun: Fungible(1_000_000 * UNITS), }].into() } } diff --git a/scripts/benchmarks-ci.sh b/scripts/benchmarks-ci.sh index ff87c643a09..467ff294c6b 100755 --- a/scripts/benchmarks-ci.sh +++ b/scripts/benchmarks-ci.sh @@ -42,8 +42,20 @@ else exit 1 fi +if [[ $runtimeName == "statemint" ]]; then + pallets+=( + pallet_xcm_benchmarks::generic + pallet_xcm_benchmarks::fungible + ) +fi + for pallet in ${pallets[@]} do + # a little hack for xcm benchmarks + output_file="${pallet//::/_}" + if [[ "$pallet" == *"xcm"* ]]; then + output_file="xcm/$output_file" + fi $artifactsDir/polkadot-parachain benchmark pallet \ --chain=$benchmarkRuntimeName \ --execution=wasm \ @@ -53,7 +65,6 @@ do --steps=$steps \ --repeat=$repeat \ --json \ - --header=./file_header.txt \ - --output=$benchmarkOutput >> $artifactsDir/${pallet}_benchmark.json - + --header=./file_header.txt \ + --output="${benchmarkOutput}/${output_file}.rs" >> $artifactsDir/${pallet}_benchmark.json done From 0972d9d1e281724fa15fc7d33a13c907b4ef5237 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Tue, 16 Aug 2022 16:55:25 +0200 Subject: [PATCH 23/56] remove extra asset --- parachains/runtimes/assets/statemint/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 9f69df4d5cf..fd63c2ad21f 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -844,10 +844,6 @@ impl_runtime_apis! { vec![MultiAsset{ id: Concrete(DotLocation::get()), fun: Fungible(1_000_000 * UNITS), - }, - MultiAsset{ - id: Concrete(DotLocation::get()), - fun: Fungible(1_000_000 * UNITS), }].into() } } From dc64b57a5777aaa63e9a7c069e88e38117304b4c Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 16 Aug 2022 16:37:54 +0000 Subject: [PATCH 24/56] ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic --- .../xcm/pallet_xcm_benchmarks_generic.rs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index d4170bb9c03..19d9d983d38 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `pallet_xcm_benchmarks::generic` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-07-22, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-08-16, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemint-dev"), DB CACHE: 1024 // Executed Command: @@ -55,38 +55,38 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn query_holding() -> Weight { - (18_242_000 as Weight) + (17_707_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } pub(crate) fn buy_execution() -> Weight { - (3_653_000 as Weight) + (3_467_000 as Weight) } // Storage: PolkadotXcm Queries (r:1 w:0) pub(crate) fn query_response() -> Weight { - (13_106_000 as Weight) + (12_772_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) } pub(crate) fn transact() -> Weight { - (16_823_000 as Weight) + (16_027_000 as Weight) } pub(crate) fn refund_surplus() -> Weight { - (3_787_000 as Weight) + (3_563_000 as Weight) } pub(crate) fn set_error_handler() -> Weight { - (3_515_000 as Weight) + (3_393_000 as Weight) } pub(crate) fn set_appendix() -> Weight { - (3_523_000 as Weight) + (3_412_000 as Weight) } pub(crate) fn clear_error() -> Weight { - (3_652_000 as Weight) + (3_359_000 as Weight) } pub(crate) fn descend_origin() -> Weight { - (4_259_000 as Weight) + (4_152_000 as Weight) } pub(crate) fn clear_origin() -> Weight { - (3_565_000 as Weight) + (3_401_000 as Weight) } // Storage: PolkadotXcm SupportedVersion (r:1 w:0) // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) @@ -94,18 +94,18 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn report_error() -> Weight { - (13_230_000 as Weight) + (13_080_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: PolkadotXcm AssetTraps (r:1 w:1) pub(crate) fn claim_asset() -> Weight { - (7_846_000 as Weight) + (7_559_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } pub(crate) fn trap() -> Weight { - (3_630_000 as Weight) + (3_242_000 as Weight) } // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -114,13 +114,13 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn subscribe_version() -> Weight { - (16_602_000 as Weight) + (16_566_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) pub(crate) fn unsubscribe_version() -> Weight { - (5_599_000 as Weight) + (5_349_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: ParachainInfo ParachainId (r:1 w:0) @@ -130,7 +130,7 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn initiate_reserve_withdraw() -> Weight { - (19_397_000 as Weight) + (18_841_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } From 6c94d5c01a3b254b063855c00551ea4b3d7b9432 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 17 Aug 2022 10:26:12 +0200 Subject: [PATCH 25/56] benchmarks setup for statemint/e and westmint --- Cargo.lock | 2 + .../runtimes/assets/statemine/Cargo.toml | 2 + .../runtimes/assets/statemine/src/lib.rs | 101 +++++++++++++++++- .../runtimes/assets/statemint/Cargo.toml | 3 +- .../runtimes/assets/statemint/src/lib.rs | 32 ++++-- .../runtimes/assets/westmint/Cargo.toml | 2 + .../runtimes/assets/westmint/src/lib.rs | 99 ++++++++++++++++- scripts/benchmarks-ci.sh | 13 +-- 8 files changed, 233 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db656c120fa..2f5a93a2b5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11579,6 +11579,7 @@ dependencies = [ "pallet-uniques", "pallet-utility", "pallet-xcm", + "pallet-xcm-benchmarks 0.9.27", "parachain-info", "parachains-common", "parity-scale-codec", @@ -13122,6 +13123,7 @@ dependencies = [ "pallet-uniques", "pallet-utility", "pallet-xcm", + "pallet-xcm-benchmarks 0.9.27", "parachain-info", "parachains-common", "parity-scale-codec", diff --git a/parachains/runtimes/assets/statemine/Cargo.toml b/parachains/runtimes/assets/statemine/Cargo.toml index a73e694dcb2..644ff9e9b3c 100644 --- a/parachains/runtimes/assets/statemine/Cargo.toml +++ b/parachains/runtimes/assets/statemine/Cargo.toml @@ -71,6 +71,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } +pallet-xcm-benchmarks = { path = "../../../../pallets/pallet-xcm-benchmarks", default-features = false, optional = true } [dev-dependencies] @@ -101,6 +102,7 @@ runtime-benchmarks = [ "cumulus-pallet-session-benchmarking/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "pallet-xcm-benchmarks", ] try-runtime = [ "frame-executive/try-runtime", diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index 1312b06c6d6..130e12a9eeb 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -638,6 +638,10 @@ mod benches { [pallet_timestamp, Timestamp] [pallet_collator_selection, CollatorSelection] [cumulus_pallet_xcmp_queue, XcmpQueue] + // XCM + // NOTE: Make sure you point to the individual modules below. + [pallet_xcm_benchmarks::fungible, XcmBalances] + [pallet_xcm_benchmarks::generic, XcmGeneric] ); } @@ -772,6 +776,12 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + // This is defined once again in dispatch_benchmark, because list_benchmarks! + // and add_benchmarks! are macros exported by define_benchmarks! macros and those types + // are referenced in that call. + type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; + type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + let mut list = Vec::::new(); list_benchmarks!(list, extra); @@ -782,7 +792,8 @@ impl_runtime_apis! { fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey}; + use frame_benchmarking::{Benchmarking, BenchmarkBatch, BenchmarkError, + TrackedStorageKey}; use frame_system_benchmarking::Pallet as SystemBench; impl frame_system_benchmarking::Config for Runtime {} @@ -790,6 +801,93 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} + use xcm::latest::prelude::*; + use xcm_config::KsmLocation; + use pallet_xcm_benchmarks::asset_instance_from; + + impl pallet_xcm_benchmarks::Config for Runtime { + type XcmConfig = xcm_config::XcmConfig; + type AccountIdConverter = xcm_config::LocationToAccountId; + fn valid_destination() -> Result { + Ok(KsmLocation::get()) + } + fn worst_case_holding() -> MultiAssets { + // A mix of fungible, non-fungible, and concrete assets. + const HOLDING_FUNGIBLES: u32 = 100; + const HOLDING_NON_FUNGIBLES: u32 = 100; + let fungibles_amount: u128 = 100; + let mut assets = (0..HOLDING_FUNGIBLES) + .map(|i| { + MultiAsset { + id: Concrete(GeneralIndex(i as u128).into()), + fun: Fungible(fungibles_amount * i as u128), + } + .into() + }) + .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(KsmLocation::get()), + fun: Fungible(1_000_000 * UNITS), + }); + assets.into() + } + } + + parameter_types! { + pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( + KsmLocation::get(), + MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(KsmLocation::get()) }, + )); + pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; + } + + impl pallet_xcm_benchmarks::fungible::Config for Runtime { + type TransactAsset = Balances; + + type CheckedAccount = xcm_config::CheckingAccount; + type TrustedTeleporter = TrustedTeleporter; + type TrustedReserve = TrustedReserve; + + fn get_multi_asset() -> MultiAsset { + MultiAsset { + id: Concrete(KsmLocation::get()), + fun: Fungible(1 * UNITS), + } + } + } + + impl pallet_xcm_benchmarks::generic::Config for Runtime { + type Call = Call; + + fn worst_case_response() -> (u64, Response) { + (0u64, Response::Version(Default::default())) + } + + fn transact_origin() -> Result { + Ok(KsmLocation::get()) + } + + fn subscribe_origin() -> Result { + Ok(KsmLocation::get()) + } + + fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { + let origin = KsmLocation::get(); + let assets: MultiAssets = (Concrete(KsmLocation::get()), 1_000 * UNITS).into(); + let ticket = MultiLocation { parents: 0, interior: Here }; + Ok((origin, ticket, assets)) + } + } + + 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(), @@ -807,7 +905,6 @@ impl_runtime_apis! { let params = (&config, &whitelist); add_benchmarks!(params, batches); - if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) } } diff --git a/parachains/runtimes/assets/statemint/Cargo.toml b/parachains/runtimes/assets/statemint/Cargo.toml index f1fecb91fd1..326a9361971 100644 --- a/parachains/runtimes/assets/statemint/Cargo.toml +++ b/parachains/runtimes/assets/statemint/Cargo.toml @@ -56,8 +56,6 @@ polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", d xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } -pallet-xcm-benchmarks = { path = "../../../../pallets/pallet-xcm-benchmarks", default-features = false, optional = true } - # Cumulus cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false } @@ -73,6 +71,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } +pallet-xcm-benchmarks = { path = "../../../../pallets/pallet-xcm-benchmarks", default-features = false, optional = true } [dev-dependencies] hex-literal = "0.3.4" diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index fd63c2ad21f..09b291378ec 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -832,6 +832,7 @@ impl_runtime_apis! { use xcm::latest::prelude::*; use xcm_config::DotLocation; + use pallet_xcm_benchmarks::asset_instance_from; impl pallet_xcm_benchmarks::Config for Runtime { type XcmConfig = xcm_config::XcmConfig; @@ -840,15 +841,33 @@ impl_runtime_apis! { Ok(DotLocation::get()) } fn worst_case_holding() -> MultiAssets { - // TODO: Create some assets - vec![MultiAsset{ - id: Concrete(DotLocation::get()), - fun: Fungible(1_000_000 * UNITS), - }].into() + // A mix of fungible, non-fungible, and concrete assets. + const HOLDING_FUNGIBLES: u32 = 100; + const HOLDING_NON_FUNGIBLES: u32 = 100; + let fungibles_amount: u128 = 100; + let mut assets = (0..HOLDING_FUNGIBLES) + .map(|i| { + MultiAsset { + id: Concrete(GeneralIndex(i as u128).into()), + fun: Fungible(fungibles_amount * i as u128), + } + .into() + }) + .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 * UNITS), + }); + assets.into() } } - //TODO: Not sure how this should work parameter_types! { pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( DotLocation::get(), @@ -898,7 +917,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/parachains/runtimes/assets/westmint/Cargo.toml b/parachains/runtimes/assets/westmint/Cargo.toml index e9b6091a3c3..85d34db8286 100644 --- a/parachains/runtimes/assets/westmint/Cargo.toml +++ b/parachains/runtimes/assets/westmint/Cargo.toml @@ -71,6 +71,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } +pallet-xcm-benchmarks = { path = "../../../../pallets/pallet-xcm-benchmarks", default-features = false, optional = true } [dev-dependencies] hex-literal = "0.3.4" @@ -100,6 +101,7 @@ runtime-benchmarks = [ "cumulus-pallet-session-benchmarking/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "pallet-xcm-benchmarks", ] try-runtime = [ "frame-executive/try-runtime", diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index dfcfc8ffa18..5651834b559 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -628,6 +628,10 @@ mod benches { [pallet_timestamp, Timestamp] [pallet_collator_selection, CollatorSelection] [cumulus_pallet_xcmp_queue, XcmpQueue] + // XCM + // NOTE: Make sure you point to the individual modules below. + [pallet_xcm_benchmarks::fungible, XcmBalances] + [pallet_xcm_benchmarks::generic, XcmGeneric] ); } @@ -762,6 +766,12 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + // This is defined once again in dispatch_benchmark, because list_benchmarks! + // and add_benchmarks! are macros exported by define_benchmarks! macros and those types + // are referenced in that call. + type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; + type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + let mut list = Vec::::new(); list_benchmarks!(list, extra); @@ -772,7 +782,7 @@ impl_runtime_apis! { fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey}; + use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey, BenchmarkError}; use frame_system_benchmarking::Pallet as SystemBench; impl frame_system_benchmarking::Config for Runtime {} @@ -780,6 +790,93 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} + use xcm::latest::prelude::*; + use xcm_config::WestendLocation; + use pallet_xcm_benchmarks::asset_instance_from; + + impl pallet_xcm_benchmarks::Config for Runtime { + type XcmConfig = xcm_config::XcmConfig; + type AccountIdConverter = xcm_config::LocationToAccountId; + fn valid_destination() -> Result { + Ok(WestendLocation::get()) + } + fn worst_case_holding() -> MultiAssets { + // A mix of fungible, non-fungible, and concrete assets. + const HOLDING_FUNGIBLES: u32 = 100; + const HOLDING_NON_FUNGIBLES: u32 = 100; + let fungibles_amount: u128 = 100; + let mut assets = (0..HOLDING_FUNGIBLES) + .map(|i| { + MultiAsset { + id: Concrete(GeneralIndex(i as u128).into()), + fun: Fungible(fungibles_amount * i as u128), + } + .into() + }) + .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(WestendLocation::get()), + fun: Fungible(1_000_000 * UNITS), + }); + assets.into() + } + } + + parameter_types! { + pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( + WestendLocation::get(), + MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(WestendLocation::get()) }, + )); + pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; + } + + impl pallet_xcm_benchmarks::fungible::Config for Runtime { + type TransactAsset = Balances; + + type CheckedAccount = xcm_config::CheckingAccount; + type TrustedTeleporter = TrustedTeleporter; + type TrustedReserve = TrustedReserve; + + fn get_multi_asset() -> MultiAsset { + MultiAsset { + id: Concrete(WestendLocation::get()), + fun: Fungible(1 * UNITS), + } + } + } + + impl pallet_xcm_benchmarks::generic::Config for Runtime { + type Call = Call; + + fn worst_case_response() -> (u64, Response) { + (0u64, Response::Version(Default::default())) + } + + fn transact_origin() -> Result { + Ok(WestendLocation::get()) + } + + fn subscribe_origin() -> Result { + Ok(WestendLocation::get()) + } + + fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { + let origin = WestendLocation::get(); + let assets: MultiAssets = (Concrete(WestendLocation::get()), 1_000 * UNITS).into(); + let ticket = MultiLocation { parents: 0, interior: Here }; + Ok((origin, ticket, assets)) + } + } + + 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/scripts/benchmarks-ci.sh b/scripts/benchmarks-ci.sh index 467ff294c6b..de27fc2ac10 100755 --- a/scripts/benchmarks-ci.sh +++ b/scripts/benchmarks-ci.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -steps=50 -repeat=20 +steps=2 +repeat=1 category=$1 runtimeName=$2 artifactsDir=$3 @@ -22,6 +22,8 @@ if [[ $runtimeName == "statemint" ]] || [[ $runtimeName == "statemine" ]] || [[ pallet_uniques cumulus_pallet_xcmp_queue frame_system + pallet_xcm_benchmarks::generic + pallet_xcm_benchmarks::fungible ) elif [[ $runtimeName == "collectives-polkadot" ]]; then pallets=( @@ -42,13 +44,6 @@ else exit 1 fi -if [[ $runtimeName == "statemint" ]]; then - pallets+=( - pallet_xcm_benchmarks::generic - pallet_xcm_benchmarks::fungible - ) -fi - for pallet in ${pallets[@]} do # a little hack for xcm benchmarks From 5dddc6012c980097383e336df637bf26d2fe9636 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 17 Aug 2022 09:20:24 +0000 Subject: [PATCH 26/56] ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::fungible --- .../xcm/pallet_xcm_benchmarks_fungible.rs | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs new file mode 100644 index 00000000000..d7d82a376ba --- /dev/null +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -0,0 +1,107 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + + +//! Autogenerated weights for `pallet_xcm_benchmarks::fungible` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-08-17, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemint-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_xcm_benchmarks::fungible +// --chain=statemint-dev +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/cumulus/.git/.artifacts/bench.json +// --header=./file_header.txt +// --template=./templates/xcm-bench-template.hbs +// --output=./parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weights for `pallet_xcm_benchmarks::fungible`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + // Storage: System Account (r:1 w:1) + pub(crate) fn withdraw_asset() -> Weight { + (29_342_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 { + (34_436_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: System Account (r:2 w:2) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn transfer_reserve_asset() -> Weight { + (49_261_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + pub(crate) fn receive_teleported_asset() -> Weight { + (4_952_000 as Weight) + } + // Storage: System Account (r:1 w:1) + pub(crate) fn deposit_asset() -> Weight { + (30_539_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) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn deposit_reserve_asset() -> Weight { + (46_058_000 as Weight) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn initiate_teleport() -> Weight { + (23_806_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} From 3481ffad460943e9e8ac9b2e8d06f3a17f0ed399 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 17 Aug 2022 10:37:02 +0000 Subject: [PATCH 27/56] ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::generic --- .../xcm/pallet_xcm_benchmarks_generic.rs | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs new file mode 100644 index 00000000000..0d515df4d5a --- /dev/null +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -0,0 +1,137 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + + +//! Autogenerated weights for `pallet_xcm_benchmarks::generic` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-08-17, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemine-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_xcm_benchmarks::generic +// --chain=statemine-dev +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/cumulus/.git/.artifacts/bench.json +// --header=./file_header.txt +// --template=./templates/xcm-bench-template.hbs +// --output=./parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weights for `pallet_xcm_benchmarks::generic`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn query_holding() -> Weight { + (694_466_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + pub(crate) fn buy_execution() -> Weight { + (7_095_000 as Weight) + } + // Storage: PolkadotXcm Queries (r:1 w:0) + pub(crate) fn query_response() -> Weight { + (13_270_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } + pub(crate) fn transact() -> Weight { + (16_375_000 as Weight) + } + pub(crate) fn refund_surplus() -> Weight { + (7_319_000 as Weight) + } + pub(crate) fn set_error_handler() -> Weight { + (3_515_000 as Weight) + } + pub(crate) fn set_appendix() -> Weight { + (3_501_000 as Weight) + } + pub(crate) fn clear_error() -> Weight { + (3_459_000 as Weight) + } + pub(crate) fn descend_origin() -> Weight { + (4_319_000 as Weight) + } + pub(crate) fn clear_origin() -> Weight { + (3_511_000 as Weight) + } + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn report_error() -> Weight { + (13_284_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: PolkadotXcm AssetTraps (r:1 w:1) + pub(crate) fn claim_asset() -> Weight { + (7_985_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + pub(crate) fn trap() -> Weight { + (3_515_000 as Weight) + } + // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn subscribe_version() -> Weight { + (16_657_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) + pub(crate) fn unsubscribe_version() -> Weight { + (5_622_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn initiate_reserve_withdraw() -> Weight { + (878_786_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} From 3eeeea280cf2dc9ccb7121ecdd2c1bc029d7ce68 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 17 Aug 2022 11:26:09 +0000 Subject: [PATCH 28/56] ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::fungible --- .../xcm/pallet_xcm_benchmarks_fungible.rs | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs new file mode 100644 index 00000000000..ea480c283f0 --- /dev/null +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -0,0 +1,107 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + + +//! Autogenerated weights for `pallet_xcm_benchmarks::fungible` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-08-17, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemine-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_xcm_benchmarks::fungible +// --chain=statemine-dev +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/cumulus/.git/.artifacts/bench.json +// --header=./file_header.txt +// --template=./templates/xcm-bench-template.hbs +// --output=./parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weights for `pallet_xcm_benchmarks::fungible`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + // Storage: System Account (r:1 w:1) + pub(crate) fn withdraw_asset() -> Weight { + (29_190_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 { + (34_102_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: System Account (r:2 w:2) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn transfer_reserve_asset() -> Weight { + (49_386_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + pub(crate) fn receive_teleported_asset() -> Weight { + (4_937_000 as Weight) + } + // Storage: System Account (r:1 w:1) + pub(crate) fn deposit_asset() -> Weight { + (30_853_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) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn deposit_reserve_asset() -> Weight { + (45_866_000 as Weight) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn initiate_teleport() -> Weight { + (23_964_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} From 33e808ed79976bc1f65854abff15a22af48694ad Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 17 Aug 2022 14:59:51 +0200 Subject: [PATCH 29/56] remove a check --- parachains/runtimes/assets/westmint/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index 5651834b559..9b601a88987 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -894,7 +894,6 @@ impl_runtime_apis! { let params = (&config, &whitelist); add_benchmarks!(params, batches); - if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) } } From 2ff069fb9d35a65581dbf51fa5debb59afc36f95 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 17 Aug 2022 13:24:40 +0000 Subject: [PATCH 30/56] ".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmarks::fungible --- .../xcm/pallet_xcm_benchmarks_fungible.rs | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs new file mode 100644 index 00000000000..961f94e8c82 --- /dev/null +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -0,0 +1,107 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + + +//! Autogenerated weights for `pallet_xcm_benchmarks::fungible` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-08-17, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westmint-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_xcm_benchmarks::fungible +// --chain=westmint-dev +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/cumulus/.git/.artifacts/bench.json +// --header=./file_header.txt +// --template=./templates/xcm-bench-template.hbs +// --output=./parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weights for `pallet_xcm_benchmarks::fungible`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + // Storage: System Account (r:1 w:1) + pub(crate) fn withdraw_asset() -> Weight { + (28_725_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 { + (33_865_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: System Account (r:2 w:2) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn transfer_reserve_asset() -> Weight { + (48_839_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + pub(crate) fn receive_teleported_asset() -> Weight { + (4_849_000 as Weight) + } + // Storage: System Account (r:1 w:1) + pub(crate) fn deposit_asset() -> Weight { + (29_778_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) + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn deposit_reserve_asset() -> Weight { + (45_355_000 as Weight) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn initiate_teleport() -> Weight { + (23_451_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} From bebc96bd2bad23690d0905c56c38cd92c7f132e4 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 17 Aug 2022 15:05:04 +0000 Subject: [PATCH 31/56] ".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmarks::generic --- .../xcm/pallet_xcm_benchmarks_generic.rs | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs new file mode 100644 index 00000000000..8cd224661a9 --- /dev/null +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -0,0 +1,137 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + + +//! Autogenerated weights for `pallet_xcm_benchmarks::generic` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-08-17, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westmint-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_xcm_benchmarks::generic +// --chain=westmint-dev +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/cumulus/.git/.artifacts/bench.json +// --header=./file_header.txt +// --template=./templates/xcm-bench-template.hbs +// --output=./parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weights for `pallet_xcm_benchmarks::generic`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn query_holding() -> Weight { + (676_316_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + pub(crate) fn buy_execution() -> Weight { + (7_030_000 as Weight) + } + // Storage: PolkadotXcm Queries (r:1 w:0) + pub(crate) fn query_response() -> Weight { + (12_574_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } + pub(crate) fn transact() -> Weight { + (15_764_000 as Weight) + } + pub(crate) fn refund_surplus() -> Weight { + (7_200_000 as Weight) + } + pub(crate) fn set_error_handler() -> Weight { + (3_310_000 as Weight) + } + pub(crate) fn set_appendix() -> Weight { + (3_260_000 as Weight) + } + pub(crate) fn clear_error() -> Weight { + (3_277_000 as Weight) + } + pub(crate) fn descend_origin() -> Weight { + (3_913_000 as Weight) + } + pub(crate) fn clear_origin() -> Weight { + (3_354_000 as Weight) + } + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn report_error() -> Weight { + (13_028_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: PolkadotXcm AssetTraps (r:1 w:1) + pub(crate) fn claim_asset() -> Weight { + (7_739_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + pub(crate) fn trap() -> Weight { + (3_351_000 as Weight) + } + // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn subscribe_version() -> Weight { + (16_051_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) + pub(crate) fn unsubscribe_version() -> Weight { + (5_477_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: ParachainInfo ParachainId (r:1 w:0) + // Storage: PolkadotXcm SupportedVersion (r:1 w:0) + // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + // Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + // Storage: ParachainSystem HostConfiguration (r:1 w:0) + // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + pub(crate) fn initiate_reserve_withdraw() -> Weight { + (874_435_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} From 08cc6e9b4e7c00f012a03ef91b4b5dbed972e629 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Thu, 18 Aug 2022 12:49:14 +0200 Subject: [PATCH 32/56] implement WeightInfoBounds for all the asset runtimes --- .../assets/statemine/src/weights/mod.rs | 1 + .../assets/statemine/src/weights/xcm/mod.rs | 164 ++++++++++++++++++ .../assets/statemine/src/xcm_config.rs | 20 +-- .../assets/statemint/src/weights/mod.rs | 1 + .../assets/statemint/src/weights/xcm/mod.rs | 164 ++++++++++++++++++ .../assets/statemint/src/xcm_config.rs | 19 +- .../assets/westmint/src/weights/mod.rs | 1 + .../assets/westmint/src/weights/xcm/mod.rs | 164 ++++++++++++++++++ .../assets/westmint/src/xcm_config.rs | 19 +- 9 files changed, 523 insertions(+), 30 deletions(-) create mode 100644 parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs create mode 100644 parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs create mode 100644 parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs diff --git a/parachains/runtimes/assets/statemine/src/weights/mod.rs b/parachains/runtimes/assets/statemine/src/weights/mod.rs index bfe3c7bba5f..080584f2cfa 100644 --- a/parachains/runtimes/assets/statemine/src/weights/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/mod.rs @@ -13,6 +13,7 @@ pub mod pallet_uniques; pub mod pallet_utility; pub mod paritydb_weights; pub mod rocksdb_weights; +pub mod xcm; pub use block_weights::constants::BlockExecutionWeight; pub use extrinsic_weights::constants::ExtrinsicBaseWeight; diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs new file mode 100644 index 00000000000..30f048f193b --- /dev/null +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -0,0 +1,164 @@ +mod pallet_xcm_benchmarks_fungible; +mod pallet_xcm_benchmarks_generic; + +use crate::Runtime; +use frame_support::weights::Weight; +use sp_std::prelude::*; +use xcm::{latest::prelude::*, DoubleEncoded}; + +use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; +use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; + +trait WeighMultiAssets { + fn weigh_multi_assets(&self, weight: Weight) -> Weight; +} + +// TODO: This needs to be changed, not sure what to +const MAX_ASSETS: u32 = 1; + +impl WeighMultiAssets for MultiAssetFilter { + fn weigh_multi_assets(&self, weight: Weight) -> Weight { + match self { + Self::Definite(assets) => + (assets.inner().into_iter().count() as Weight).saturating_mul(weight), + Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(weight), + } + } +} + +impl WeighMultiAssets for MultiAssets { + fn weigh_multi_assets(&self, weight: Weight) -> Weight { + (self.inner().into_iter().count() as Weight).saturating_mul(weight) + } +} + +pub struct StatemineXcmWeight(core::marker::PhantomData); +impl XcmWeightInfo for StatemineXcmWeight { + fn withdraw_asset(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::withdraw_asset()) + } + //TODO: We don't have a trustedReserve, but still good to check if this is correct + fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight { + Weight::MAX + } + fn receive_teleported_asset(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::receive_teleported_asset()) + } + fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> Weight { + XcmGeneric::::query_response() + } + fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::transfer_asset()) + } + fn transfer_reserve_asset( + assets: &MultiAssets, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::transfer_reserve_asset()) + } + fn transact( + _origin_type: &OriginKind, + _require_weight_at_most: &u64, + _call: &DoubleEncoded, + ) -> Weight { + XcmGeneric::::transact() + } + fn hrmp_new_channel_open_request( + _sender: &u32, + _max_message_size: &u32, + _max_capacity: &u32, + ) -> Weight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn hrmp_channel_accepted(_recipient: &u32) -> Weight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn clear_origin() -> Weight { + XcmGeneric::::clear_origin() + } + fn descend_origin(_who: &InteriorMultiLocation) -> Weight { + XcmGeneric::::descend_origin() + } + fn report_error( + _query_id: &QueryId, + _dest: &MultiLocation, + _max_response_weight: &u64, + ) -> Weight { + XcmGeneric::::report_error() + } + + fn deposit_asset( + assets: &MultiAssetFilter, + _max_assets: &u32, // TODO use max assets? + _dest: &MultiLocation, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) + } + fn deposit_reserve_asset( + assets: &MultiAssetFilter, + _max_assets: &u32, // TODO use max assets? + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) + } + fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight { + Weight::MAX // todo fix + } + fn initiate_reserve_withdraw( + assets: &MultiAssetFilter, + _reserve: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) + } + fn initiate_teleport( + assets: &MultiAssetFilter, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + } + fn query_holding( + _query_id: &u64, + _dest: &MultiLocation, + _assets: &MultiAssetFilter, + _max_response_weight: &u64, + ) -> Weight { + XcmGeneric::::query_holding() + } + fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight { + XcmGeneric::::buy_execution() + } + fn refund_surplus() -> Weight { + XcmGeneric::::refund_surplus() + } + fn set_error_handler(_xcm: &Xcm) -> Weight { + XcmGeneric::::set_error_handler() + } + fn set_appendix(_xcm: &Xcm) -> Weight { + XcmGeneric::::set_appendix() + } + fn clear_error() -> Weight { + XcmGeneric::::clear_error() + } + fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight { + XcmGeneric::::claim_asset() + } + fn trap(_code: &u64) -> Weight { + XcmGeneric::::trap() + } + fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> Weight { + XcmGeneric::::subscribe_version() + } + fn unsubscribe_version() -> Weight { + XcmGeneric::::unsubscribe_version() + } +} diff --git a/parachains/runtimes/assets/statemine/src/xcm_config.rs b/parachains/runtimes/assets/statemine/src/xcm_config.rs index 3875cf7901b..d8f59ffcb69 100644 --- a/parachains/runtimes/assets/statemine/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemine/src/xcm_config.rs @@ -20,7 +20,6 @@ use super::{ use frame_support::{ match_types, parameter_types, traits::{Everything, Nothing, PalletInfoAccess}, - weights::Weight, }; use pallet_xcm::XcmPassthrough; use parachains_common::{ @@ -35,11 +34,11 @@ use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, - ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, - FungiblesAdapter, IsConcrete, LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - UsingComponents, + ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete, + LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, + WeightInfoBounds, }; use xcm_executor::{traits::JustTry, XcmExecutor}; @@ -129,8 +128,6 @@ pub type XcmOriginToTransactDispatchOrigin = ( ); parameter_types! { - // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - pub UnitWeightCost: Weight = 1_000_000_000; pub const MaxInstructions: u32 = 100; pub XcmAssetFeesReceiver: Option = Authorship::author(); } @@ -173,7 +170,8 @@ impl xcm_executor::Config for XcmConfig { type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of KSM type LocationInverter = LocationInverter; type Barrier = Barrier; - type Weigher = FixedWeightBounds; + type Weigher = + WeightInfoBounds, Call, MaxInstructions>; type Trader = ( UsingComponents>, cumulus_primitives_utility::TakeFirstAssetTrader< @@ -228,7 +226,9 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Everything; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; + type Weigher = + WeightInfoBounds, Call, MaxInstructions>; + type LocationInverter = LocationInverter; type Origin = Origin; type Call = Call; diff --git a/parachains/runtimes/assets/statemint/src/weights/mod.rs b/parachains/runtimes/assets/statemint/src/weights/mod.rs index bfe3c7bba5f..080584f2cfa 100644 --- a/parachains/runtimes/assets/statemint/src/weights/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/mod.rs @@ -13,6 +13,7 @@ pub mod pallet_uniques; pub mod pallet_utility; pub mod paritydb_weights; pub mod rocksdb_weights; +pub mod xcm; pub use block_weights::constants::BlockExecutionWeight; pub use extrinsic_weights::constants::ExtrinsicBaseWeight; diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs new file mode 100644 index 00000000000..18230a41537 --- /dev/null +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -0,0 +1,164 @@ +mod pallet_xcm_benchmarks_fungible; +mod pallet_xcm_benchmarks_generic; + +use crate::Runtime; +use frame_support::weights::Weight; +use sp_std::prelude::*; +use xcm::{latest::prelude::*, DoubleEncoded}; + +use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; +use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; + +trait WeighMultiAssets { + fn weigh_multi_assets(&self, weight: Weight) -> Weight; +} + +// TODO: This needs to be changed, not sure what to +const MAX_ASSETS: u32 = 1; + +impl WeighMultiAssets for MultiAssetFilter { + fn weigh_multi_assets(&self, weight: Weight) -> Weight { + match self { + Self::Definite(assets) => + (assets.inner().into_iter().count() as Weight).saturating_mul(weight), + Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(weight), + } + } +} + +impl WeighMultiAssets for MultiAssets { + fn weigh_multi_assets(&self, weight: Weight) -> Weight { + (self.inner().into_iter().count() as Weight).saturating_mul(weight) + } +} + +pub struct StatemintXcmWeight(core::marker::PhantomData); +impl XcmWeightInfo for StatemintXcmWeight { + fn withdraw_asset(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::withdraw_asset()) + } + //TODO: We don't have a trustedReserve, but still good to check if this is correct + fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight { + Weight::MAX + } + fn receive_teleported_asset(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::receive_teleported_asset()) + } + fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> Weight { + XcmGeneric::::query_response() + } + fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::transfer_asset()) + } + fn transfer_reserve_asset( + assets: &MultiAssets, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::transfer_reserve_asset()) + } + fn transact( + _origin_type: &OriginKind, + _require_weight_at_most: &u64, + _call: &DoubleEncoded, + ) -> Weight { + XcmGeneric::::transact() + } + fn hrmp_new_channel_open_request( + _sender: &u32, + _max_message_size: &u32, + _max_capacity: &u32, + ) -> Weight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn hrmp_channel_accepted(_recipient: &u32) -> Weight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn clear_origin() -> Weight { + XcmGeneric::::clear_origin() + } + fn descend_origin(_who: &InteriorMultiLocation) -> Weight { + XcmGeneric::::descend_origin() + } + fn report_error( + _query_id: &QueryId, + _dest: &MultiLocation, + _max_response_weight: &u64, + ) -> Weight { + XcmGeneric::::report_error() + } + + fn deposit_asset( + assets: &MultiAssetFilter, + _max_assets: &u32, // TODO use max assets? + _dest: &MultiLocation, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) + } + fn deposit_reserve_asset( + assets: &MultiAssetFilter, + _max_assets: &u32, // TODO use max assets? + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) + } + fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight { + Weight::MAX // todo fix + } + fn initiate_reserve_withdraw( + assets: &MultiAssetFilter, + _reserve: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) + } + fn initiate_teleport( + assets: &MultiAssetFilter, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + } + fn query_holding( + _query_id: &u64, + _dest: &MultiLocation, + _assets: &MultiAssetFilter, + _max_response_weight: &u64, + ) -> Weight { + XcmGeneric::::query_holding() + } + fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight { + XcmGeneric::::buy_execution() + } + fn refund_surplus() -> Weight { + XcmGeneric::::refund_surplus() + } + fn set_error_handler(_xcm: &Xcm) -> Weight { + XcmGeneric::::set_error_handler() + } + fn set_appendix(_xcm: &Xcm) -> Weight { + XcmGeneric::::set_appendix() + } + fn clear_error() -> Weight { + XcmGeneric::::clear_error() + } + fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight { + XcmGeneric::::claim_asset() + } + fn trap(_code: &u64) -> Weight { + XcmGeneric::::trap() + } + fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> Weight { + XcmGeneric::::subscribe_version() + } + fn unsubscribe_version() -> Weight { + XcmGeneric::::unsubscribe_version() + } +} diff --git a/parachains/runtimes/assets/statemint/src/xcm_config.rs b/parachains/runtimes/assets/statemint/src/xcm_config.rs index abfe9bb9865..a8bf77b6d34 100644 --- a/parachains/runtimes/assets/statemint/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemint/src/xcm_config.rs @@ -20,7 +20,6 @@ use super::{ use frame_support::{ match_types, parameter_types, traits::{Everything, Nothing, PalletInfoAccess}, - weights::Weight, }; use pallet_xcm::XcmPassthrough; use parachains_common::{ @@ -32,11 +31,11 @@ use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, - ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, - FungiblesAdapter, IsConcrete, LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - UsingComponents, + ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete, + LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, + WeightInfoBounds, }; use xcm_executor::{traits::JustTry, XcmExecutor}; @@ -126,8 +125,6 @@ pub type XcmOriginToTransactDispatchOrigin = ( ); parameter_types! { - // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - pub UnitWeightCost: Weight = 1_000_000_000; pub const MaxInstructions: u32 = 100; pub XcmAssetFeesReceiver: Option = Authorship::author(); } @@ -170,7 +167,8 @@ impl xcm_executor::Config for XcmConfig { type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of DOT type LocationInverter = LocationInverter; type Barrier = Barrier; - type Weigher = FixedWeightBounds; + type Weigher = + WeightInfoBounds, Call, MaxInstructions>; type Trader = UsingComponents>; type ResponseHandler = PolkadotXcm; @@ -204,7 +202,8 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Everything; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; + type Weigher = + WeightInfoBounds, Call, MaxInstructions>; type LocationInverter = LocationInverter; type Origin = Origin; type Call = Call; diff --git a/parachains/runtimes/assets/westmint/src/weights/mod.rs b/parachains/runtimes/assets/westmint/src/weights/mod.rs index bfe3c7bba5f..080584f2cfa 100644 --- a/parachains/runtimes/assets/westmint/src/weights/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/mod.rs @@ -13,6 +13,7 @@ pub mod pallet_uniques; pub mod pallet_utility; pub mod paritydb_weights; pub mod rocksdb_weights; +pub mod xcm; pub use block_weights::constants::BlockExecutionWeight; pub use extrinsic_weights::constants::ExtrinsicBaseWeight; diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs new file mode 100644 index 00000000000..8c0c5cb7cbb --- /dev/null +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -0,0 +1,164 @@ +mod pallet_xcm_benchmarks_fungible; +mod pallet_xcm_benchmarks_generic; + +use crate::Runtime; +use frame_support::weights::Weight; +use sp_std::prelude::*; +use xcm::{latest::prelude::*, DoubleEncoded}; + +use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; +use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; + +trait WeighMultiAssets { + fn weigh_multi_assets(&self, weight: Weight) -> Weight; +} + +// TODO: This needs to be changed, not sure what to +const MAX_ASSETS: u32 = 1; + +impl WeighMultiAssets for MultiAssetFilter { + fn weigh_multi_assets(&self, weight: Weight) -> Weight { + match self { + Self::Definite(assets) => + (assets.inner().into_iter().count() as Weight).saturating_mul(weight), + Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(weight), + } + } +} + +impl WeighMultiAssets for MultiAssets { + fn weigh_multi_assets(&self, weight: Weight) -> Weight { + (self.inner().into_iter().count() as Weight).saturating_mul(weight) + } +} + +pub struct WestmintXcmWeight(core::marker::PhantomData); +impl XcmWeightInfo for WestmintXcmWeight { + fn withdraw_asset(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::withdraw_asset()) + } + //TODO: We don't have a trustedReserve, but still good to check if this is correct + fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight { + Weight::MAX + } + fn receive_teleported_asset(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::receive_teleported_asset()) + } + fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> Weight { + XcmGeneric::::query_response() + } + fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::transfer_asset()) + } + fn transfer_reserve_asset( + assets: &MultiAssets, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::transfer_reserve_asset()) + } + fn transact( + _origin_type: &OriginKind, + _require_weight_at_most: &u64, + _call: &DoubleEncoded, + ) -> Weight { + XcmGeneric::::transact() + } + fn hrmp_new_channel_open_request( + _sender: &u32, + _max_message_size: &u32, + _max_capacity: &u32, + ) -> Weight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn hrmp_channel_accepted(_recipient: &u32) -> Weight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn clear_origin() -> Weight { + XcmGeneric::::clear_origin() + } + fn descend_origin(_who: &InteriorMultiLocation) -> Weight { + XcmGeneric::::descend_origin() + } + fn report_error( + _query_id: &QueryId, + _dest: &MultiLocation, + _max_response_weight: &u64, + ) -> Weight { + XcmGeneric::::report_error() + } + + fn deposit_asset( + assets: &MultiAssetFilter, + _max_assets: &u32, // TODO use max assets? + _dest: &MultiLocation, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) + } + fn deposit_reserve_asset( + assets: &MultiAssetFilter, + _max_assets: &u32, // TODO use max assets? + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) + } + fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight { + Weight::MAX // todo fix + } + fn initiate_reserve_withdraw( + assets: &MultiAssetFilter, + _reserve: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) + } + fn initiate_teleport( + assets: &MultiAssetFilter, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> Weight { + assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) + } + fn query_holding( + _query_id: &u64, + _dest: &MultiLocation, + _assets: &MultiAssetFilter, + _max_response_weight: &u64, + ) -> Weight { + XcmGeneric::::query_holding() + } + fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight { + XcmGeneric::::buy_execution() + } + fn refund_surplus() -> Weight { + XcmGeneric::::refund_surplus() + } + fn set_error_handler(_xcm: &Xcm) -> Weight { + XcmGeneric::::set_error_handler() + } + fn set_appendix(_xcm: &Xcm) -> Weight { + XcmGeneric::::set_appendix() + } + fn clear_error() -> Weight { + XcmGeneric::::clear_error() + } + fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight { + XcmGeneric::::claim_asset() + } + fn trap(_code: &u64) -> Weight { + XcmGeneric::::trap() + } + fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> Weight { + XcmGeneric::::subscribe_version() + } + fn unsubscribe_version() -> Weight { + XcmGeneric::::unsubscribe_version() + } +} diff --git a/parachains/runtimes/assets/westmint/src/xcm_config.rs b/parachains/runtimes/assets/westmint/src/xcm_config.rs index 4a2daa3380e..94a6ba6528a 100644 --- a/parachains/runtimes/assets/westmint/src/xcm_config.rs +++ b/parachains/runtimes/assets/westmint/src/xcm_config.rs @@ -20,7 +20,6 @@ use super::{ use frame_support::{ match_types, parameter_types, traits::{Everything, PalletInfoAccess}, - weights::Weight, }; use pallet_xcm::XcmPassthrough; use parachains_common::{ @@ -35,11 +34,11 @@ use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, - ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, - FungiblesAdapter, IsConcrete, LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - UsingComponents, + ConvertedConcreteAssetId, CurrencyAdapter, EnsureXcmOrigin, FungiblesAdapter, IsConcrete, + LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, + WeightInfoBounds, }; use xcm_executor::{traits::JustTry, XcmExecutor}; @@ -130,8 +129,6 @@ pub type XcmOriginToTransactDispatchOrigin = ( ); parameter_types! { - // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - pub UnitWeightCost: Weight = 1_000_000_000; pub const MaxInstructions: u32 = 100; pub XcmAssetFeesReceiver: Option = Authorship::author(); } @@ -170,7 +167,8 @@ impl xcm_executor::Config for XcmConfig { type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of WND type LocationInverter = LocationInverter; type Barrier = Barrier; - type Weigher = FixedWeightBounds; + type Weigher = + WeightInfoBounds, Call, MaxInstructions>; type Trader = ( UsingComponents>, cumulus_primitives_utility::TakeFirstAssetTrader< @@ -221,7 +219,8 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Everything; type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; + type Weigher = + WeightInfoBounds, Call, MaxInstructions>; type LocationInverter = LocationInverter; type Origin = Origin; type Call = Call; From b90102572afd1f0829b37013cdb24277beae7e0c Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Thu, 18 Aug 2022 15:22:53 +0200 Subject: [PATCH 33/56] update Cargo.lock --- Cargo.lock | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 2ef3e42b7c9..5b765fc84c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6438,6 +6438,48 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "pallet-xcm-benchmarks" +version = "0.9.27" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-assets", + "pallet-balances", + "pallet-xcm", + "parity-scale-codec", + "polkadot-primitives", + "polkadot-runtime-common", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-tracing", + "xcm", + "xcm-builder", + "xcm-executor", +] + +[[package]] +name = "pallet-xcm-benchmarks" +version = "0.9.27" +source = "git+https://github.com/paritytech/polkadot?branch=master#520e10b3932af03cacc2659a6d7f3ce4c5e9948c" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", + "xcm", + "xcm-executor", +] + [[package]] name = "parachain-info" version = "0.1.0" From aec4b364ee3827b08d0bd579eb7d0b8afb110a15 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Tue, 23 Aug 2022 14:36:52 +0200 Subject: [PATCH 34/56] fix Muharem's comments --- .../Cargo.toml | 2 -- .../src/fungible/benchmarking.rs | 0 .../src/fungible/mock.rs | 0 .../src/fungible/mod.rs | 0 .../src/generic/benchmarking.rs | 0 .../src/generic/mock.rs | 0 .../src/generic/mod.rs | 0 .../src/lib.rs | 0 .../src/mock.rs | 0 parachains/runtimes/assets/statemine/Cargo.toml | 2 +- .../assets/statemine/src/weights/xcm/mod.rs | 16 ++++++++++++++++ parachains/runtimes/assets/statemint/Cargo.toml | 2 +- .../assets/statemint/src/weights/xcm/mod.rs | 16 ++++++++++++++++ parachains/runtimes/assets/westmint/Cargo.toml | 2 +- .../assets/westmint/src/weights/xcm/mod.rs | 16 ++++++++++++++++ scripts/benchmarks-ci.sh | 4 ++-- 16 files changed, 53 insertions(+), 7 deletions(-) rename pallets/{pallet-xcm-benchmarks => xcm-benchmarks}/Cargo.toml (95%) rename pallets/{pallet-xcm-benchmarks => xcm-benchmarks}/src/fungible/benchmarking.rs (100%) rename pallets/{pallet-xcm-benchmarks => xcm-benchmarks}/src/fungible/mock.rs (100%) rename pallets/{pallet-xcm-benchmarks => xcm-benchmarks}/src/fungible/mod.rs (100%) rename pallets/{pallet-xcm-benchmarks => xcm-benchmarks}/src/generic/benchmarking.rs (100%) rename pallets/{pallet-xcm-benchmarks => xcm-benchmarks}/src/generic/mock.rs (100%) rename pallets/{pallet-xcm-benchmarks => xcm-benchmarks}/src/generic/mod.rs (100%) rename pallets/{pallet-xcm-benchmarks => xcm-benchmarks}/src/lib.rs (100%) rename pallets/{pallet-xcm-benchmarks => xcm-benchmarks}/src/mock.rs (100%) diff --git a/pallets/pallet-xcm-benchmarks/Cargo.toml b/pallets/xcm-benchmarks/Cargo.toml similarity index 95% rename from pallets/pallet-xcm-benchmarks/Cargo.toml rename to pallets/xcm-benchmarks/Cargo.toml index 92352266571..f04d02cc97c 100644 --- a/pallets/pallet-xcm-benchmarks/Cargo.toml +++ b/pallets/xcm-benchmarks/Cargo.toml @@ -27,10 +27,8 @@ sp-io = { git = "https://github.com/paritytech/substrate" , branch = "master" } sp-tracing = { git = "https://github.com/paritytech/substrate" , branch = "master" } xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "master" } xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master" } -# temp pallet-xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master" } polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot" , branch = "master" } -# westend-runtime = { path = "../../runtime/westend", features = ["runtime-benchmarks"] } polkadot-primitives = { git = "https://github.com/paritytech/polkadot" , branch = "master" } [features] diff --git a/pallets/pallet-xcm-benchmarks/src/fungible/benchmarking.rs b/pallets/xcm-benchmarks/src/fungible/benchmarking.rs similarity index 100% rename from pallets/pallet-xcm-benchmarks/src/fungible/benchmarking.rs rename to pallets/xcm-benchmarks/src/fungible/benchmarking.rs diff --git a/pallets/pallet-xcm-benchmarks/src/fungible/mock.rs b/pallets/xcm-benchmarks/src/fungible/mock.rs similarity index 100% rename from pallets/pallet-xcm-benchmarks/src/fungible/mock.rs rename to pallets/xcm-benchmarks/src/fungible/mock.rs diff --git a/pallets/pallet-xcm-benchmarks/src/fungible/mod.rs b/pallets/xcm-benchmarks/src/fungible/mod.rs similarity index 100% rename from pallets/pallet-xcm-benchmarks/src/fungible/mod.rs rename to pallets/xcm-benchmarks/src/fungible/mod.rs diff --git a/pallets/pallet-xcm-benchmarks/src/generic/benchmarking.rs b/pallets/xcm-benchmarks/src/generic/benchmarking.rs similarity index 100% rename from pallets/pallet-xcm-benchmarks/src/generic/benchmarking.rs rename to pallets/xcm-benchmarks/src/generic/benchmarking.rs diff --git a/pallets/pallet-xcm-benchmarks/src/generic/mock.rs b/pallets/xcm-benchmarks/src/generic/mock.rs similarity index 100% rename from pallets/pallet-xcm-benchmarks/src/generic/mock.rs rename to pallets/xcm-benchmarks/src/generic/mock.rs diff --git a/pallets/pallet-xcm-benchmarks/src/generic/mod.rs b/pallets/xcm-benchmarks/src/generic/mod.rs similarity index 100% rename from pallets/pallet-xcm-benchmarks/src/generic/mod.rs rename to pallets/xcm-benchmarks/src/generic/mod.rs diff --git a/pallets/pallet-xcm-benchmarks/src/lib.rs b/pallets/xcm-benchmarks/src/lib.rs similarity index 100% rename from pallets/pallet-xcm-benchmarks/src/lib.rs rename to pallets/xcm-benchmarks/src/lib.rs diff --git a/pallets/pallet-xcm-benchmarks/src/mock.rs b/pallets/xcm-benchmarks/src/mock.rs similarity index 100% rename from pallets/pallet-xcm-benchmarks/src/mock.rs rename to pallets/xcm-benchmarks/src/mock.rs diff --git a/parachains/runtimes/assets/statemine/Cargo.toml b/parachains/runtimes/assets/statemine/Cargo.toml index 644ff9e9b3c..a8a27944049 100644 --- a/parachains/runtimes/assets/statemine/Cargo.toml +++ b/parachains/runtimes/assets/statemine/Cargo.toml @@ -71,7 +71,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } -pallet-xcm-benchmarks = { path = "../../../../pallets/pallet-xcm-benchmarks", default-features = false, optional = true } +pallet-xcm-benchmarks = { path = "../../../../pallets/xcm-benchmarks", default-features = false, optional = true } [dev-dependencies] diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index 30f048f193b..d0a1d105e58 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -1,3 +1,19 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; diff --git a/parachains/runtimes/assets/statemint/Cargo.toml b/parachains/runtimes/assets/statemint/Cargo.toml index 326a9361971..0e36b43d70a 100644 --- a/parachains/runtimes/assets/statemint/Cargo.toml +++ b/parachains/runtimes/assets/statemint/Cargo.toml @@ -71,7 +71,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } -pallet-xcm-benchmarks = { path = "../../../../pallets/pallet-xcm-benchmarks", default-features = false, optional = true } +pallet-xcm-benchmarks = { path = "../../../../pallets/xcm-benchmarks", default-features = false, optional = true } [dev-dependencies] hex-literal = "0.3.4" diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index 18230a41537..fc2494a5a09 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -1,3 +1,19 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; diff --git a/parachains/runtimes/assets/westmint/Cargo.toml b/parachains/runtimes/assets/westmint/Cargo.toml index 85d34db8286..453407fec6d 100644 --- a/parachains/runtimes/assets/westmint/Cargo.toml +++ b/parachains/runtimes/assets/westmint/Cargo.toml @@ -71,7 +71,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } -pallet-xcm-benchmarks = { path = "../../../../pallets/pallet-xcm-benchmarks", default-features = false, optional = true } +pallet-xcm-benchmarks = { path = "../../../../pallets/xcm-benchmarks", default-features = false, optional = true } [dev-dependencies] hex-literal = "0.3.4" diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index 8c0c5cb7cbb..31462db75d3 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -1,3 +1,19 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; diff --git a/scripts/benchmarks-ci.sh b/scripts/benchmarks-ci.sh index de27fc2ac10..6ac63e9ab34 100755 --- a/scripts/benchmarks-ci.sh +++ b/scripts/benchmarks-ci.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -steps=2 -repeat=1 +steps=50 +repeat=20 category=$1 runtimeName=$2 artifactsDir=$3 From de97475c6c5a7864cb4ab97294960a9e5f384b93 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 24 Aug 2022 11:44:33 +0000 Subject: [PATCH 35/56] ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic --- .../xcm/pallet_xcm_benchmarks_generic.rs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index 19d9d983d38..3d32d38a5c7 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `pallet_xcm_benchmarks::generic` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-08-16, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-08-24, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemint-dev"), DB CACHE: 1024 // Executed Command: @@ -55,38 +55,38 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn query_holding() -> Weight { - (17_707_000 as Weight) + (698_433_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } pub(crate) fn buy_execution() -> Weight { - (3_467_000 as Weight) + (9_297_000 as Weight) } // Storage: PolkadotXcm Queries (r:1 w:0) pub(crate) fn query_response() -> Weight { - (12_772_000 as Weight) + (17_405_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) } pub(crate) fn transact() -> Weight { - (16_027_000 as Weight) + (20_639_000 as Weight) } pub(crate) fn refund_surplus() -> Weight { - (3_563_000 as Weight) + (9_411_000 as Weight) } pub(crate) fn set_error_handler() -> Weight { - (3_393_000 as Weight) + (5_426_000 as Weight) } pub(crate) fn set_appendix() -> Weight { - (3_412_000 as Weight) + (5_585_000 as Weight) } pub(crate) fn clear_error() -> Weight { - (3_359_000 as Weight) + (5_546_000 as Weight) } pub(crate) fn descend_origin() -> Weight { - (4_152_000 as Weight) + (6_414_000 as Weight) } pub(crate) fn clear_origin() -> Weight { - (3_401_000 as Weight) + (5_582_000 as Weight) } // Storage: PolkadotXcm SupportedVersion (r:1 w:0) // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) @@ -94,18 +94,18 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn report_error() -> Weight { - (13_080_000 as Weight) + (15_973_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: PolkadotXcm AssetTraps (r:1 w:1) pub(crate) fn claim_asset() -> Weight { - (7_559_000 as Weight) + (12_078_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } pub(crate) fn trap() -> Weight { - (3_242_000 as Weight) + (5_731_000 as Weight) } // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -114,13 +114,13 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn subscribe_version() -> Weight { - (16_566_000 as Weight) + (19_435_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) pub(crate) fn unsubscribe_version() -> Weight { - (5_349_000 as Weight) + (8_897_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: ParachainInfo ParachainId (r:1 w:0) @@ -130,7 +130,7 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn initiate_reserve_withdraw() -> Weight { - (18_841_000 as Weight) + (881_396_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } From 80faa1dec9d41ce45bfa27f3de58b6ff2a122136 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 24 Aug 2022 14:16:21 +0200 Subject: [PATCH 36/56] Update parachains/runtimes/assets/statemint/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- parachains/runtimes/assets/statemint/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index c3c9634f283..89dc4317343 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -945,7 +945,7 @@ impl_runtime_apis! { hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), // System Events hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - // Configuration ActiveConfig + // ACTIVE_CONFIG hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(), ]; From 5dabe9e4692e81895d78f7e1b86b7e9b448fad18 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 24 Aug 2022 14:25:44 +0200 Subject: [PATCH 37/56] fix some review comments --- .../runtimes/assets/statemine/src/weights/xcm/mod.rs | 6 +++--- .../runtimes/assets/statemint/src/weights/xcm/mod.rs | 7 +++---- parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index d0a1d105e58..fcc4a79c849 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -30,7 +30,7 @@ trait WeighMultiAssets { } // TODO: This needs to be changed, not sure what to -const MAX_ASSETS: u32 = 1; +const MAX_ASSETS: u32 = 100; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> Weight { @@ -53,9 +53,9 @@ impl XcmWeightInfo for StatemineXcmWeight { fn withdraw_asset(assets: &MultiAssets) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::withdraw_asset()) } - //TODO: We don't have a trustedReserve, but still good to check if this is correct + // Currently there is no trusted reserve fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight { - Weight::MAX + unimplemented!() } fn receive_teleported_asset(assets: &MultiAssets) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::receive_teleported_asset()) diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index fc2494a5a09..59c08529094 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -29,8 +29,7 @@ trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> Weight; } -// TODO: This needs to be changed, not sure what to -const MAX_ASSETS: u32 = 1; +const MAX_ASSETS: u32 = 100; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> Weight { @@ -53,9 +52,9 @@ impl XcmWeightInfo for StatemintXcmWeight { fn withdraw_asset(assets: &MultiAssets) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::withdraw_asset()) } - //TODO: We don't have a trustedReserve, but still good to check if this is correct + // Currently there is no trusted reserve fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight { - Weight::MAX + unimplemented!() } fn receive_teleported_asset(assets: &MultiAssets) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::receive_teleported_asset()) diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index 31462db75d3..992a6867f7c 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -30,7 +30,7 @@ trait WeighMultiAssets { } // TODO: This needs to be changed, not sure what to -const MAX_ASSETS: u32 = 1; +const MAX_ASSETS: u32 = 100; impl WeighMultiAssets for MultiAssetFilter { fn weigh_multi_assets(&self, weight: Weight) -> Weight { @@ -53,9 +53,9 @@ impl XcmWeightInfo for WestmintXcmWeight { fn withdraw_asset(assets: &MultiAssets) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::withdraw_asset()) } - //TODO: We don't have a trustedReserve, but still good to check if this is correct + // Currently there is no trusted reserve fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight { - Weight::MAX + unimplemented!() } fn receive_teleported_asset(assets: &MultiAssets) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::receive_teleported_asset()) From 274a576d24501fd7301617878274fce320fe39e9 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 24 Aug 2022 14:31:41 +0200 Subject: [PATCH 38/56] fix file headers --- pallets/xcm-benchmarks/src/fungible/benchmarking.rs | 4 ++-- pallets/xcm-benchmarks/src/fungible/mock.rs | 4 ++-- pallets/xcm-benchmarks/src/fungible/mod.rs | 4 ++-- pallets/xcm-benchmarks/src/generic/benchmarking.rs | 4 ++-- pallets/xcm-benchmarks/src/generic/mock.rs | 4 ++-- pallets/xcm-benchmarks/src/lib.rs | 4 ++-- pallets/xcm-benchmarks/src/mock.rs | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pallets/xcm-benchmarks/src/fungible/benchmarking.rs b/pallets/xcm-benchmarks/src/fungible/benchmarking.rs index e61bf4794d6..3b5f12699e3 100644 --- a/pallets/xcm-benchmarks/src/fungible/benchmarking.rs +++ b/pallets/xcm-benchmarks/src/fungible/benchmarking.rs @@ -1,5 +1,5 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. // Polkadot is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/pallets/xcm-benchmarks/src/fungible/mock.rs b/pallets/xcm-benchmarks/src/fungible/mock.rs index 3f7e4f8f26e..f45783cd2ea 100644 --- a/pallets/xcm-benchmarks/src/fungible/mock.rs +++ b/pallets/xcm-benchmarks/src/fungible/mock.rs @@ -1,5 +1,5 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. // Polkadot is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/pallets/xcm-benchmarks/src/fungible/mod.rs b/pallets/xcm-benchmarks/src/fungible/mod.rs index 1acf61cf001..47bf42a13d1 100644 --- a/pallets/xcm-benchmarks/src/fungible/mod.rs +++ b/pallets/xcm-benchmarks/src/fungible/mod.rs @@ -1,5 +1,5 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. // Polkadot is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/pallets/xcm-benchmarks/src/generic/benchmarking.rs b/pallets/xcm-benchmarks/src/generic/benchmarking.rs index 62d0df265c4..5d694a86ed0 100644 --- a/pallets/xcm-benchmarks/src/generic/benchmarking.rs +++ b/pallets/xcm-benchmarks/src/generic/benchmarking.rs @@ -1,5 +1,5 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. // Polkadot is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/pallets/xcm-benchmarks/src/generic/mock.rs b/pallets/xcm-benchmarks/src/generic/mock.rs index 7782ba1d90e..45770ed1412 100644 --- a/pallets/xcm-benchmarks/src/generic/mock.rs +++ b/pallets/xcm-benchmarks/src/generic/mock.rs @@ -1,5 +1,5 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. // Polkadot is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/pallets/xcm-benchmarks/src/lib.rs b/pallets/xcm-benchmarks/src/lib.rs index 8492dac5a62..0d9fec14de0 100644 --- a/pallets/xcm-benchmarks/src/lib.rs +++ b/pallets/xcm-benchmarks/src/lib.rs @@ -1,5 +1,5 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. // Polkadot is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/pallets/xcm-benchmarks/src/mock.rs b/pallets/xcm-benchmarks/src/mock.rs index d59cf338726..b9431850220 100644 --- a/pallets/xcm-benchmarks/src/mock.rs +++ b/pallets/xcm-benchmarks/src/mock.rs @@ -1,5 +1,5 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. // Polkadot is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by From c50d468d4812cfe73a0b15f83bbba236496e05f1 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 24 Aug 2022 16:53:03 +0200 Subject: [PATCH 39/56] more fixes to licenses and such --- pallets/xcm-benchmarks/Cargo.toml | 5 +++++ pallets/xcm-benchmarks/README.md | 1 + pallets/xcm-benchmarks/src/fungible/benchmarking.rs | 6 +++--- pallets/xcm-benchmarks/src/fungible/mock.rs | 6 +++--- pallets/xcm-benchmarks/src/fungible/mod.rs | 6 +++--- pallets/xcm-benchmarks/src/generic/benchmarking.rs | 6 +++--- pallets/xcm-benchmarks/src/generic/mock.rs | 6 +++--- pallets/xcm-benchmarks/src/lib.rs | 6 +++--- pallets/xcm-benchmarks/src/mock.rs | 6 +++--- 9 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 pallets/xcm-benchmarks/README.md diff --git a/pallets/xcm-benchmarks/Cargo.toml b/pallets/xcm-benchmarks/Cargo.toml index f04d02cc97c..ead0b7d4d28 100644 --- a/pallets/xcm-benchmarks/Cargo.toml +++ b/pallets/xcm-benchmarks/Cargo.toml @@ -3,6 +3,11 @@ name = "pallet-xcm-benchmarks" authors = ["Parity Technologies "] edition = "2021" version = "0.9.27" +description = "A pallet to benchmark XCM interactions." +homepage = "https://substrate.io" +license = "Gpl3_0" +readme = "README.md" +repository = "https://github.com/paritytech/cumulus/" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/pallets/xcm-benchmarks/README.md b/pallets/xcm-benchmarks/README.md new file mode 100644 index 00000000000..e19c115ecfc --- /dev/null +++ b/pallets/xcm-benchmarks/README.md @@ -0,0 +1 @@ +License: Gpl3_0 diff --git a/pallets/xcm-benchmarks/src/fungible/benchmarking.rs b/pallets/xcm-benchmarks/src/fungible/benchmarking.rs index 3b5f12699e3..e5f1879c445 100644 --- a/pallets/xcm-benchmarks/src/fungible/benchmarking.rs +++ b/pallets/xcm-benchmarks/src/fungible/benchmarking.rs @@ -1,18 +1,18 @@ // Copyright 2022 Parity Technologies (UK) Ltd. // This file is part of Cumulus. -// Polkadot is free software: you can redistribute it and/or modify +// Cumulus is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Polkadot is distributed in the hope that it will be useful, +// Cumulus is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . +// along with Cumulus. If not, see . use super::*; use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; diff --git a/pallets/xcm-benchmarks/src/fungible/mock.rs b/pallets/xcm-benchmarks/src/fungible/mock.rs index f45783cd2ea..0598e04f7d2 100644 --- a/pallets/xcm-benchmarks/src/fungible/mock.rs +++ b/pallets/xcm-benchmarks/src/fungible/mock.rs @@ -1,18 +1,18 @@ // Copyright 2022 Parity Technologies (UK) Ltd. // This file is part of Cumulus. -// Polkadot is free software: you can redistribute it and/or modify +// Cumulus is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Polkadot is distributed in the hope that it will be useful, +// Cumulus is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . +// along with Cumulus. If not, see . //! A mock runtime for XCM benchmarking. diff --git a/pallets/xcm-benchmarks/src/fungible/mod.rs b/pallets/xcm-benchmarks/src/fungible/mod.rs index 47bf42a13d1..821c75cb831 100644 --- a/pallets/xcm-benchmarks/src/fungible/mod.rs +++ b/pallets/xcm-benchmarks/src/fungible/mod.rs @@ -1,18 +1,18 @@ // Copyright 2022 Parity Technologies (UK) Ltd. // This file is part of Cumulus. -// Polkadot is free software: you can redistribute it and/or modify +// Cumulus is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Polkadot is distributed in the hope that it will be useful, +// Cumulus is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . +// along with Cumulus. If not, see . // Benchmarking for the `AssetTransactor` trait via `Fungible`. diff --git a/pallets/xcm-benchmarks/src/generic/benchmarking.rs b/pallets/xcm-benchmarks/src/generic/benchmarking.rs index 5d694a86ed0..bf472717ae0 100644 --- a/pallets/xcm-benchmarks/src/generic/benchmarking.rs +++ b/pallets/xcm-benchmarks/src/generic/benchmarking.rs @@ -1,18 +1,18 @@ // Copyright 2022 Parity Technologies (UK) Ltd. // This file is part of Cumulus. -// Polkadot is free software: you can redistribute it and/or modify +// Cumulus is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Polkadot is distributed in the hope that it will be useful, +// Cumulus is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . +// along with Cumulus. If not, see . use super::*; use crate::{new_executor, XcmCallOf}; diff --git a/pallets/xcm-benchmarks/src/generic/mock.rs b/pallets/xcm-benchmarks/src/generic/mock.rs index 45770ed1412..e15382089de 100644 --- a/pallets/xcm-benchmarks/src/generic/mock.rs +++ b/pallets/xcm-benchmarks/src/generic/mock.rs @@ -1,18 +1,18 @@ // Copyright 2022 Parity Technologies (UK) Ltd. // This file is part of Cumulus. -// Polkadot is free software: you can redistribute it and/or modify +// Cumulus is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Polkadot is distributed in the hope that it will be useful, +// Cumulus is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . +// along with Cumulus. If not, see . //! A mock runtime for XCM benchmarking. diff --git a/pallets/xcm-benchmarks/src/lib.rs b/pallets/xcm-benchmarks/src/lib.rs index 0d9fec14de0..dcbeac050bf 100644 --- a/pallets/xcm-benchmarks/src/lib.rs +++ b/pallets/xcm-benchmarks/src/lib.rs @@ -1,18 +1,18 @@ // Copyright 2022 Parity Technologies (UK) Ltd. // This file is part of Cumulus. -// Polkadot is free software: you can redistribute it and/or modify +// Cumulus is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Polkadot is distributed in the hope that it will be useful, +// Cumulus is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . +// along with Cumulus. If not, see . //! Pallet that serves no other purpose than benchmarking raw messages [`Xcm`]. diff --git a/pallets/xcm-benchmarks/src/mock.rs b/pallets/xcm-benchmarks/src/mock.rs index b9431850220..3ceac640a84 100644 --- a/pallets/xcm-benchmarks/src/mock.rs +++ b/pallets/xcm-benchmarks/src/mock.rs @@ -1,18 +1,18 @@ // Copyright 2022 Parity Technologies (UK) Ltd. // This file is part of Cumulus. -// Polkadot is free software: you can redistribute it and/or modify +// Cumulus is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Polkadot is distributed in the hope that it will be useful, +// Cumulus is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . +// along with Cumulus. If not, see . use crate::*; use frame_support::{parameter_types, weights::Weight}; From 0fc3bf02cc48b5ae6c6a2504a7d0033e8b438e0f Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 24 Aug 2022 17:04:23 +0200 Subject: [PATCH 40/56] fix another inconsistency --- parachains/runtimes/assets/statemine/src/lib.rs | 2 ++ parachains/runtimes/assets/statemint/src/lib.rs | 2 +- parachains/runtimes/assets/westmint/src/lib.rs | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index 92ef7e4c67f..11228b4c3a9 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -916,6 +916,8 @@ impl_runtime_apis! { hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), // System Events hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), + //TODO: use from relay_well_known_keys::ACTIVE_CONFIG + hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(), ]; let mut batches = Vec::::new(); diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index 89dc4317343..bff02586b81 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -945,7 +945,7 @@ impl_runtime_apis! { hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), // System Events hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - // ACTIVE_CONFIG + //TODO: use from relay_well_known_keys::ACTIVE_CONFIG hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(), ]; diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index 7e8b9013795..c458090242e 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -905,6 +905,8 @@ impl_runtime_apis! { hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), // System Events hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), + //TODO: use from relay_well_known_keys::ACTIVE_CONFIG + hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(), ]; let mut batches = Vec::::new(); From e6859c0f5402bedb4f0c191f16e374905e9bbf75 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 25 Aug 2022 12:07:31 +0200 Subject: [PATCH 41/56] Extend weights template Signed-off-by: Oliver Tale-Yazdi --- templates/xcm-bench-template.hbs | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/xcm-bench-template.hbs b/templates/xcm-bench-template.hbs index cdb610bbc94..c2155933608 100644 --- a/templates/xcm-bench-template.hbs +++ b/templates/xcm-bench-template.hbs @@ -19,6 +19,7 @@ //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} //! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` +//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}` //! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}} // Executed Command: From 10b07ee6b1170380ee645aa3d05a64005df74047 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Thu, 25 Aug 2022 12:09:57 +0200 Subject: [PATCH 42/56] remove a placeholder --- parachains/runtimes/assets/statemine/src/weights/temp | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 parachains/runtimes/assets/statemine/src/weights/temp diff --git a/parachains/runtimes/assets/statemine/src/weights/temp b/parachains/runtimes/assets/statemine/src/weights/temp deleted file mode 100644 index e69de29bb2d..00000000000 From d239b604775aab7aadb4e78dadf6c3c9513d7ead Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Thu, 25 Aug 2022 12:32:30 +0200 Subject: [PATCH 43/56] remove redundant overrides --- pallets/xcm-benchmarks/src/fungible/benchmarking.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pallets/xcm-benchmarks/src/fungible/benchmarking.rs b/pallets/xcm-benchmarks/src/fungible/benchmarking.rs index e5f1879c445..47d603be06a 100644 --- a/pallets/xcm-benchmarks/src/fungible/benchmarking.rs +++ b/pallets/xcm-benchmarks/src/fungible/benchmarking.rs @@ -117,11 +117,7 @@ benchmarks_instance_pallet! { 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) - ) - })?; + executor.execute(xcm)?; } verify { assert!(executor.holding.ensure_contains(&assets).is_ok()); } @@ -148,11 +144,7 @@ benchmarks_instance_pallet! { let instruction = Instruction::ReceiveTeleportedAsset(assets.clone()); let xcm = Xcm(vec![instruction]); }: { - executor.execute(xcm).map_err(|_| { - BenchmarkError::Override( - BenchmarkResult::from_weight(T::BlockWeights::get().max_block) - ) - })?; + executor.execute(xcm)?; } verify { assert!(executor.holding.ensure_contains(&assets).is_ok()); } From 3b869fe64cfa6a26201e46541663ec17aafc803a Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Thu, 25 Aug 2022 10:56:57 +0000 Subject: [PATCH 44/56] ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::fungible --- .../xcm/pallet_xcm_benchmarks_fungible.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs index d7d82a376ba..628c709ed4e 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -18,7 +18,8 @@ //! Autogenerated weights for `pallet_xcm_benchmarks::fungible` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-08-17, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-08-25, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemint-dev"), DB CACHE: 1024 // Executed Command: @@ -50,13 +51,13 @@ pub struct WeightInfo(PhantomData); impl WeightInfo { // Storage: System Account (r:1 w:1) pub(crate) fn withdraw_asset() -> Weight { - (29_342_000 as Weight) + (34_002_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 { - (34_436_000 as Weight) + (38_285_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -68,16 +69,16 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn transfer_reserve_asset() -> Weight { - (49_261_000 as Weight) + (55_068_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } pub(crate) fn receive_teleported_asset() -> Weight { - (4_952_000 as Weight) + (7_796_000 as Weight) } // Storage: System Account (r:1 w:1) pub(crate) fn deposit_asset() -> Weight { - (30_539_000 as Weight) + (35_092_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -89,7 +90,7 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn deposit_reserve_asset() -> Weight { - (46_058_000 as Weight) + (50_590_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -100,7 +101,7 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn initiate_teleport() -> Weight { - (23_806_000 as Weight) + (27_220_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } From 168f0b36a8195a6390c5fd3cfcda157c5c591d34 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Thu, 25 Aug 2022 14:11:47 +0200 Subject: [PATCH 45/56] Update benchmarking.rs --- pallets/xcm-benchmarks/src/fungible/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/xcm-benchmarks/src/fungible/benchmarking.rs b/pallets/xcm-benchmarks/src/fungible/benchmarking.rs index 47d603be06a..3c7e0188af9 100644 --- a/pallets/xcm-benchmarks/src/fungible/benchmarking.rs +++ b/pallets/xcm-benchmarks/src/fungible/benchmarking.rs @@ -16,7 +16,7 @@ use super::*; use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; -use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError, BenchmarkResult}; +use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError}; use frame_support::{ pallet_prelude::Get, traits::fungible::{Inspect, Mutate}, From 59ab737954b9fce2e69ca010a658c26eee146452 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Thu, 25 Aug 2022 14:41:21 +0200 Subject: [PATCH 46/56] remove redundant bench --- .../src/generic/benchmarking.rs | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/pallets/xcm-benchmarks/src/generic/benchmarking.rs b/pallets/xcm-benchmarks/src/generic/benchmarking.rs index bf472717ae0..35d2056e719 100644 --- a/pallets/xcm-benchmarks/src/generic/benchmarking.rs +++ b/pallets/xcm-benchmarks/src/generic/benchmarking.rs @@ -70,26 +70,6 @@ benchmarks! { } - // Worst case scenario for this benchmark is a large number of assets to - // filter through the reserve. - reserve_asset_deposited { - const MAX_ASSETS: u32 = 100; // TODO when executor has a built in limit, use it here. #4426 - let mut executor = new_executor::(Default::default()); - let assets = (0..MAX_ASSETS).map(|i| MultiAsset { - id: Abstract(i.encode()), - fun: Fungible(i as u128), - - }).collect::>(); - let multiassets: MultiAssets = assets.into(); - - let instruction = Instruction::ReserveAssetDeposited(multiassets.clone()); - let xcm = Xcm(vec![instruction]); - }: { - executor.execute(xcm).map_err(|_| BenchmarkError::Skip)?; - } verify { - assert_eq!(executor.holding, multiassets.into()); - } - query_response { let mut executor = new_executor::(Default::default()); let (query_id, response) = T::worst_case_response(); From 898b8bf0e8afd1b239084c03ee1ce8af378eef05 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Thu, 25 Aug 2022 16:23:24 +0200 Subject: [PATCH 47/56] fix --- pallets/xcm-benchmarks/src/generic/benchmarking.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/xcm-benchmarks/src/generic/benchmarking.rs b/pallets/xcm-benchmarks/src/generic/benchmarking.rs index 35d2056e719..e7b4d6d9731 100644 --- a/pallets/xcm-benchmarks/src/generic/benchmarking.rs +++ b/pallets/xcm-benchmarks/src/generic/benchmarking.rs @@ -20,10 +20,7 @@ use codec::Encode; use frame_benchmarking::{benchmarks, BenchmarkError}; use frame_support::dispatch::GetDispatchInfo; use sp_std::vec; -use xcm::{ - latest::{prelude::*, MultiAssets}, - DoubleEncoded, -}; +use xcm::{latest::prelude::*, DoubleEncoded}; benchmarks! { query_holding { From 8cf49f1c4921c94601869b601534b91e7c031026 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Thu, 25 Aug 2022 15:56:50 +0000 Subject: [PATCH 48/56] ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic --- .../xcm/pallet_xcm_benchmarks_generic.rs | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index 3d32d38a5c7..e77663c109e 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -18,7 +18,8 @@ //! Autogenerated weights for `pallet_xcm_benchmarks::generic` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-08-24, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-08-25, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemint-dev"), DB CACHE: 1024 // Executed Command: @@ -55,38 +56,38 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn query_holding() -> Weight { - (698_433_000 as Weight) + (682_639_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } pub(crate) fn buy_execution() -> Weight { - (9_297_000 as Weight) + (9_272_000 as Weight) } // Storage: PolkadotXcm Queries (r:1 w:0) pub(crate) fn query_response() -> Weight { - (17_405_000 as Weight) + (17_084_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) } pub(crate) fn transact() -> Weight { - (20_639_000 as Weight) + (20_265_000 as Weight) } pub(crate) fn refund_surplus() -> Weight { - (9_411_000 as Weight) + (9_422_000 as Weight) } pub(crate) fn set_error_handler() -> Weight { - (5_426_000 as Weight) + (5_545_000 as Weight) } pub(crate) fn set_appendix() -> Weight { - (5_585_000 as Weight) + (5_450_000 as Weight) } pub(crate) fn clear_error() -> Weight { - (5_546_000 as Weight) + (5_519_000 as Weight) } pub(crate) fn descend_origin() -> Weight { - (6_414_000 as Weight) + (6_398_000 as Weight) } pub(crate) fn clear_origin() -> Weight { - (5_582_000 as Weight) + (5_498_000 as Weight) } // Storage: PolkadotXcm SupportedVersion (r:1 w:0) // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) @@ -94,18 +95,18 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn report_error() -> Weight { - (15_973_000 as Weight) + (15_784_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: PolkadotXcm AssetTraps (r:1 w:1) pub(crate) fn claim_asset() -> Weight { - (12_078_000 as Weight) + (11_861_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } pub(crate) fn trap() -> Weight { - (5_731_000 as Weight) + (5_462_000 as Weight) } // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -114,13 +115,13 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn subscribe_version() -> Weight { - (19_435_000 as Weight) + (18_997_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) pub(crate) fn unsubscribe_version() -> Weight { - (8_897_000 as Weight) + (8_684_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: ParachainInfo ParachainId (r:1 w:0) @@ -130,7 +131,7 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn initiate_reserve_withdraw() -> Weight { - (881_396_000 as Weight) + (883_121_000 as Weight) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } From 3b4133f3ef400e9a3f333958116d85fe5a2e9bfb Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Sat, 27 Aug 2022 12:17:14 +0200 Subject: [PATCH 49/56] Update pallets/xcm-benchmarks/src/fungible/mock.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- pallets/xcm-benchmarks/src/fungible/mock.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/xcm-benchmarks/src/fungible/mock.rs b/pallets/xcm-benchmarks/src/fungible/mock.rs index 0598e04f7d2..c5b8354bf90 100644 --- a/pallets/xcm-benchmarks/src/fungible/mock.rs +++ b/pallets/xcm-benchmarks/src/fungible/mock.rs @@ -38,9 +38,9 @@ frame_support::construct_runtime!( NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - XcmBalancesBenchmark: xcm_balances_benchmark::{Pallet}, + System: frame_system, + Balances: pallet_balances, + XcmBalancesBenchmark: xcm_balances_benchmark, } ); From 571ca7842bae079a2d0b615d2a7bb86dfe045993 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Sat, 27 Aug 2022 12:10:18 +0200 Subject: [PATCH 50/56] remove TODO's --- .../runtimes/assets/statemine/src/weights/xcm/mod.rs | 5 ++--- .../runtimes/assets/statemint/src/weights/xcm/mod.rs | 6 +++--- parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs | 7 +++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index fcc4a79c849..211dd4b438c 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -29,7 +29,6 @@ trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> Weight; } -// TODO: This needs to be changed, not sure what to const MAX_ASSETS: u32 = 100; impl WeighMultiAssets for MultiAssetFilter { @@ -112,14 +111,14 @@ impl XcmWeightInfo for StatemineXcmWeight { fn deposit_asset( assets: &MultiAssetFilter, - _max_assets: &u32, // TODO use max assets? + _max_assets: &u32, _dest: &MultiLocation, ) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( assets: &MultiAssetFilter, - _max_assets: &u32, // TODO use max assets? + _max_assets: &u32, _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> Weight { diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index 59c08529094..0477df1b27e 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -111,21 +111,21 @@ impl XcmWeightInfo for StatemintXcmWeight { fn deposit_asset( assets: &MultiAssetFilter, - _max_assets: &u32, // TODO use max assets? + _max_assets: &u32, _dest: &MultiLocation, ) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( assets: &MultiAssetFilter, - _max_assets: &u32, // TODO use max assets? + _max_assets: &u32, _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) } fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight { - Weight::MAX // todo fix + Weight::MAX } fn initiate_reserve_withdraw( assets: &MultiAssetFilter, diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index 992a6867f7c..f02c89f5b2e 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -29,7 +29,6 @@ trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> Weight; } -// TODO: This needs to be changed, not sure what to const MAX_ASSETS: u32 = 100; impl WeighMultiAssets for MultiAssetFilter { @@ -112,21 +111,21 @@ impl XcmWeightInfo for WestmintXcmWeight { fn deposit_asset( assets: &MultiAssetFilter, - _max_assets: &u32, // TODO use max assets? + _max_assets: &u32, _dest: &MultiLocation, ) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( assets: &MultiAssetFilter, - _max_assets: &u32, // TODO use max assets? + _max_assets: &u32, _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> Weight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) } fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight { - Weight::MAX // todo fix + Weight::MAX } fn initiate_reserve_withdraw( assets: &MultiAssetFilter, From 5499ef288a4371d7e1871d76ae88e6a4847bb37d Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Mon, 29 Aug 2022 13:07:14 +0200 Subject: [PATCH 51/56] remove local xcm-benchmark-pallet impl --- Cargo.lock | 35 +-- pallets/xcm-benchmarks/Cargo.toml | 48 --- pallets/xcm-benchmarks/README.md | 1 - .../src/fungible/benchmarking.rs | 234 -------------- pallets/xcm-benchmarks/src/fungible/mock.rs | 198 ------------ pallets/xcm-benchmarks/src/fungible/mod.rs | 51 --- .../src/generic/benchmarking.rs | 295 ------------------ pallets/xcm-benchmarks/src/generic/mock.rs | 176 ----------- pallets/xcm-benchmarks/src/generic/mod.rs | 39 --- pallets/xcm-benchmarks/src/lib.rs | 110 ------- pallets/xcm-benchmarks/src/mock.rs | 64 ---- .../runtimes/assets/statemine/Cargo.toml | 2 +- .../runtimes/assets/statemint/Cargo.toml | 2 +- .../runtimes/assets/westmint/Cargo.toml | 2 +- 14 files changed, 8 insertions(+), 1249 deletions(-) delete mode 100644 pallets/xcm-benchmarks/Cargo.toml delete mode 100644 pallets/xcm-benchmarks/README.md delete mode 100644 pallets/xcm-benchmarks/src/fungible/benchmarking.rs delete mode 100644 pallets/xcm-benchmarks/src/fungible/mock.rs delete mode 100644 pallets/xcm-benchmarks/src/fungible/mod.rs delete mode 100644 pallets/xcm-benchmarks/src/generic/benchmarking.rs delete mode 100644 pallets/xcm-benchmarks/src/generic/mock.rs delete mode 100644 pallets/xcm-benchmarks/src/generic/mod.rs delete mode 100644 pallets/xcm-benchmarks/src/lib.rs delete mode 100644 pallets/xcm-benchmarks/src/mock.rs diff --git a/Cargo.lock b/Cargo.lock index 207a93b165d..e10389a138c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3960,7 +3960,7 @@ dependencies = [ "pallet-utility", "pallet-vesting", "pallet-xcm", - "pallet-xcm-benchmarks 0.9.27 (git+https://github.com/paritytech/polkadot?branch=master)", + "pallet-xcm-benchmarks", "parity-scale-codec", "polkadot-primitives", "polkadot-runtime-common", @@ -6438,31 +6438,6 @@ dependencies = [ "xcm-executor", ] -[[package]] -name = "pallet-xcm-benchmarks" -version = "0.9.27" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "log", - "pallet-assets", - "pallet-balances", - "pallet-xcm", - "parity-scale-codec", - "polkadot-primitives", - "polkadot-runtime-common", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", - "sp-tracing", - "xcm", - "xcm-builder", - "xcm-executor", -] - [[package]] name = "pallet-xcm-benchmarks" version = "0.9.27" @@ -11607,7 +11582,7 @@ dependencies = [ "pallet-uniques", "pallet-utility", "pallet-xcm", - "pallet-xcm-benchmarks 0.9.27", + "pallet-xcm-benchmarks", "parachain-info", "parachains-common", "parity-scale-codec", @@ -11674,7 +11649,7 @@ dependencies = [ "pallet-uniques", "pallet-utility", "pallet-xcm", - "pallet-xcm-benchmarks 0.9.27", + "pallet-xcm-benchmarks", "parachain-info", "parachains-common", "parity-scale-codec", @@ -13066,7 +13041,7 @@ dependencies = [ "pallet-utility", "pallet-vesting", "pallet-xcm", - "pallet-xcm-benchmarks 0.9.27 (git+https://github.com/paritytech/polkadot?branch=master)", + "pallet-xcm-benchmarks", "parity-scale-codec", "polkadot-parachain 0.9.27", "polkadot-primitives", @@ -13151,7 +13126,7 @@ dependencies = [ "pallet-uniques", "pallet-utility", "pallet-xcm", - "pallet-xcm-benchmarks 0.9.27", + "pallet-xcm-benchmarks", "parachain-info", "parachains-common", "parity-scale-codec", diff --git a/pallets/xcm-benchmarks/Cargo.toml b/pallets/xcm-benchmarks/Cargo.toml deleted file mode 100644 index ead0b7d4d28..00000000000 --- a/pallets/xcm-benchmarks/Cargo.toml +++ /dev/null @@ -1,48 +0,0 @@ -[package] -name = "pallet-xcm-benchmarks" -authors = ["Parity Technologies "] -edition = "2021" -version = "0.9.27" -description = "A pallet to benchmark XCM interactions." -homepage = "https://substrate.io" -license = "Gpl3_0" -readme = "README.md" -repository = "https://github.com/paritytech/cumulus/" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" } -xcm-executor = {git = "https://github.com/paritytech/polkadot" , branch = "master", default-features = false, features = ["runtime-benchmarks"] } -frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" } -xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master", default-features = false, features = ["runtime-benchmarks"] } -log = "0.4.17" - -[dev-dependencies] -pallet-balances = { git = "https://github.com/paritytech/substrate" , branch = "master" } -pallet-assets = { git = "https://github.com/paritytech/substrate" , branch = "master" } -sp-core = { git = "https://github.com/paritytech/substrate" , branch = "master" } -sp-io = { git = "https://github.com/paritytech/substrate" , branch = "master" } -sp-tracing = { git = "https://github.com/paritytech/substrate" , branch = "master" } -xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "master" } -xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master" } -pallet-xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master" } -polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot" , branch = "master" } -polkadot-primitives = { git = "https://github.com/paritytech/polkadot" , branch = "master" } - -[features] -default = ["std"] -std = [ - "codec/std", - "frame-benchmarking/std", - "frame-support/std", - "frame-system/std", - "sp-runtime/std", - "sp-std/std" -] diff --git a/pallets/xcm-benchmarks/README.md b/pallets/xcm-benchmarks/README.md deleted file mode 100644 index e19c115ecfc..00000000000 --- a/pallets/xcm-benchmarks/README.md +++ /dev/null @@ -1 +0,0 @@ -License: Gpl3_0 diff --git a/pallets/xcm-benchmarks/src/fungible/benchmarking.rs b/pallets/xcm-benchmarks/src/fungible/benchmarking.rs deleted file mode 100644 index 3c7e0188af9..00000000000 --- a/pallets/xcm-benchmarks/src/fungible/benchmarking.rs +++ /dev/null @@ -1,234 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -use super::*; -use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; -use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError}; -use frame_support::{ - pallet_prelude::Get, - traits::fungible::{Inspect, Mutate}, -}; -use sp_runtime::traits::{Bounded, Zero}; -use sp_std::{prelude::*, vec}; -use xcm::latest::prelude::*; -use xcm_executor::traits::{Convert, TransactAsset}; - -benchmarks_instance_pallet! { - where_clause { where - < - < - T::TransactAsset - as - Inspect - >::Balance - as - TryInto - >::Error: sp_std::fmt::Debug, - } - - withdraw_asset { - let (sender_account, sender_location) = account_and_location::(1); - let worst_case_holding = T::worst_case_holding(); - let asset = T::get_multi_asset(); - - >::deposit_asset(&asset, &sender_location).unwrap(); - // check the assets of origin. - assert!(!T::TransactAsset::balance(&sender_account).is_zero()); - - let mut executor = new_executor::(sender_location); - executor.holding = worst_case_holding.into(); - let instruction = Instruction::>::WithdrawAsset(vec![asset.clone()].into()); - let xcm = Xcm(vec![instruction]); - }: { - executor.execute(xcm)?; - } verify { - // check one of the assets of origin. - assert!(T::TransactAsset::balance(&sender_account).is_zero()); - assert!(executor.holding.ensure_contains(&vec![asset].into()).is_ok()); - } - - transfer_asset { - let (sender_account, sender_location) = account_and_location::(1); - let asset = T::get_multi_asset(); - let assets: MultiAssets = vec![ asset.clone() ].into(); - // this xcm doesn't use holding - - let dest_location = T::valid_destination()?; - let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap(); - - >::deposit_asset(&asset, &sender_location).unwrap(); - assert!(T::TransactAsset::balance(&dest_account).is_zero()); - - let mut executor = new_executor::(sender_location); - let instruction = Instruction::TransferAsset { assets, beneficiary: dest_location }; - let xcm = Xcm(vec![instruction]); - }: { - executor.execute(xcm)?; - } verify { - assert!(T::TransactAsset::balance(&sender_account).is_zero()); - assert!(!T::TransactAsset::balance(&dest_account).is_zero()); - } - - transfer_reserve_asset { - let (sender_account, sender_location) = account_and_location::(1); - let dest_location = T::valid_destination()?; - let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap(); - - let asset = T::get_multi_asset(); - >::deposit_asset(&asset, &sender_location).unwrap(); - let assets: MultiAssets = vec![ asset ].into(); - assert!(T::TransactAsset::balance(&dest_account).is_zero()); - - let mut executor = new_executor::(sender_location); - let instruction = Instruction::TransferReserveAsset { - assets, - dest: dest_location, - xcm: Xcm::new() - }; - let xcm = Xcm(vec![instruction]); - }: { - executor.execute(xcm)?; - } verify { - assert!(T::TransactAsset::balance(&sender_account).is_zero()); - assert!(!T::TransactAsset::balance(&dest_account).is_zero()); - // 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)?; - } 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() - .ok_or(BenchmarkError::Skip)?; - - if let Some(checked_account) = T::CheckedAccount::get() { - T::TransactAsset::mint_into( - &checked_account, - < - T::TransactAsset - as - Inspect - >::Balance::max_value() / 2u32.into(), - )?; - } - - let assets: MultiAssets = vec![ teleportable_asset ].into(); - - let mut executor = new_executor::(trusted_teleporter); - let instruction = Instruction::ReceiveTeleportedAsset(assets.clone()); - let xcm = Xcm(vec![instruction]); - }: { - executor.execute(xcm)?; - } verify { - assert!(executor.holding.ensure_contains(&assets).is_ok()); - } - - deposit_asset { - let asset = T::get_multi_asset(); - let mut holding = T::worst_case_holding(); - - // Add our asset to the holding. - holding.push(asset.clone()); - - // our dest must have no balance initially. - let dest_location = T::valid_destination()?; - let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap(); - assert!(T::TransactAsset::balance(&dest_account).is_zero()); - - let mut executor = new_executor::(Default::default()); - executor.holding = holding.into(); - let instruction = Instruction::>::DepositAsset { - assets: asset.into(), - max_assets: 1, - beneficiary: dest_location, - }; - let xcm = Xcm(vec![instruction]); - }: { - executor.execute(xcm)?; - } verify { - // dest should have received some asset. - assert!(!T::TransactAsset::balance(&dest_account).is_zero()) - } - - deposit_reserve_asset { - let asset = T::get_multi_asset(); - let mut holding = T::worst_case_holding(); - - // Add our asset to the holding. - holding.push(asset.clone()); - - // our dest must have no balance initially. - let dest_location = T::valid_destination()?; - let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap(); - assert!(T::TransactAsset::balance(&dest_account).is_zero()); - - let mut executor = new_executor::(Default::default()); - executor.holding = holding.into(); - let instruction = Instruction::>::DepositReserveAsset { - assets: asset.into(), - max_assets: 1, - dest: dest_location, - xcm: Xcm::new(), - }; - let xcm = Xcm(vec![instruction]); - }: { - executor.execute(xcm)?; - } verify { - // dest should have received some asset. - assert!(!T::TransactAsset::balance(&dest_account).is_zero()) - } - - initiate_teleport { - let asset = T::get_multi_asset(); - let mut holding = T::worst_case_holding(); - - // Add our asset to the holding. - holding.push(asset.clone()); - - let mut executor = new_executor::(Default::default()); - executor.holding = holding.into(); - let instruction = Instruction::>::InitiateTeleport { - assets: asset.into(), - dest: T::valid_destination()?, - xcm: Xcm::new(), - }; - let xcm = Xcm(vec![instruction]); - }: { - executor.execute(xcm)?; - } verify { - // we're good as long as there's no error, checking account is bypassed when operating on - // native assets aka Dot - } - - impl_benchmark_test_suite!( - Pallet, - crate::fungible::mock::new_test_ext(), - crate::fungible::mock::Test - ); -} diff --git a/pallets/xcm-benchmarks/src/fungible/mock.rs b/pallets/xcm-benchmarks/src/fungible/mock.rs deleted file mode 100644 index c5b8354bf90..00000000000 --- a/pallets/xcm-benchmarks/src/fungible/mock.rs +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -//! A mock runtime for XCM benchmarking. - -use crate::{fungible as xcm_balances_benchmark, mock::*}; -use frame_benchmarking::BenchmarkError; -use frame_support::{parameter_types, traits::Everything}; -use sp_core::H256; -use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, -}; -use xcm::latest::prelude::*; -use xcm_builder::AllowUnpaidExecutionFrom; - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; - -// For testing the pallet, we construct a mock runtime. -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system, - Balances: pallet_balances, - XcmBalancesBenchmark: xcm_balances_benchmark, - } -); - -parameter_types! { - pub const BlockHashCount: u64 = 250; - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(1024); -} -impl frame_system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type Origin = Origin; - type Index = u64; - type BlockNumber = u64; - type Hash = H256; - type Call = Call; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -parameter_types! { - pub const ExistentialDeposit: u64 = 7; -} - -impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type Balance = u64; - type DustRemoval = (); - type Event = Event; - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); -} - -parameter_types! { - pub const AssetDeposit: u64 = 100 * ExistentialDeposit::get(); - pub const ApprovalDeposit: u64 = 1 * ExistentialDeposit::get(); - pub const StringLimit: u32 = 50; - pub const MetadataDepositBase: u64 = 10 * ExistentialDeposit::get(); - pub const MetadataDepositPerByte: u64 = 1 * ExistentialDeposit::get(); -} - -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 balances as the asset transactor. -pub type AssetTransactor = xcm_builder::CurrencyAdapter< - Balances, - MatchAnyFungible, - AccountIdConverter, - u64, - CheckedAccount, ->; - -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 struct XcmConfig; -impl xcm_executor::Config for XcmConfig { - type Call = Call; - type XcmSender = DevNull; - type AssetTransactor = AssetTransactor; - type OriginConverter = (); - type IsReserve = TrustedReserves; - type IsTeleporter = TrustedTeleporters; - type LocationInverter = xcm_builder::LocationInverter; - type Barrier = AllowUnpaidExecutionFrom; - type Weigher = xcm_builder::FixedWeightBounds; - type Trader = xcm_builder::FixedRateOfFungible; - type ResponseHandler = DevNull; - type AssetTrap = (); - type AssetClaims = (); - type SubscriptionService = (); -} - -impl crate::Config for Test { - type XcmConfig = XcmConfig; - type AccountIdConverter = AccountIdConverter; - fn valid_destination() -> Result { - let valid_destination: MultiLocation = - X1(AccountId32 { network: NetworkId::Any, id: [0u8; 32] }).into(); - - Ok(valid_destination) - } - fn worst_case_holding() -> MultiAssets { - crate::mock_worst_case_holding() - } -} - -pub type TrustedTeleporters = (xcm_builder::Case,); -pub type TrustedReserves = (xcm_builder::Case,); - -parameter_types! { - pub const CheckedAccount: Option = Some(100); - pub const ChildTeleporter: MultiLocation = Parachain(1000).into(); - pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( - 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 = - >::minimum_balance() as u128; - MultiAsset { id: Concrete(Here.into()), fun: Fungible(amount) } - } -} - -pub fn new_test_ext() -> sp_io::TestExternalities { - let t = GenesisConfig { ..Default::default() }.build_storage().unwrap(); - sp_tracing::try_init_simple(); - t.into() -} diff --git a/pallets/xcm-benchmarks/src/fungible/mod.rs b/pallets/xcm-benchmarks/src/fungible/mod.rs deleted file mode 100644 index 821c75cb831..00000000000 --- a/pallets/xcm-benchmarks/src/fungible/mod.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -// Benchmarking for the `AssetTransactor` trait via `Fungible`. - -pub use pallet::*; - -pub mod benchmarking; -#[cfg(test)] -mod mock; - -#[frame_support::pallet] -pub mod pallet { - use frame_support::pallet_prelude::Get; - #[pallet::config] - pub trait Config: frame_system::Config + crate::Config { - /// The type of `fungible` that is being used under the hood. - /// - /// This is useful for testing and checking. - type TransactAsset: frame_support::traits::fungible::Mutate; - - /// The account used to check assets being teleported. - type CheckedAccount: Get>; - - /// 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; - } - - #[pallet::pallet] - pub struct Pallet(_); -} diff --git a/pallets/xcm-benchmarks/src/generic/benchmarking.rs b/pallets/xcm-benchmarks/src/generic/benchmarking.rs deleted file mode 100644 index e7b4d6d9731..00000000000 --- a/pallets/xcm-benchmarks/src/generic/benchmarking.rs +++ /dev/null @@ -1,295 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -use super::*; -use crate::{new_executor, XcmCallOf}; -use codec::Encode; -use frame_benchmarking::{benchmarks, BenchmarkError}; -use frame_support::dispatch::GetDispatchInfo; -use sp_std::vec; -use xcm::{latest::prelude::*, DoubleEncoded}; - -benchmarks! { - query_holding { - let holding = T::worst_case_holding(); - - let mut executor = new_executor::(Default::default()); - executor.holding = holding.clone().into(); - - let instruction = Instruction::>::QueryHolding { - query_id: Default::default(), - dest: T::valid_destination()?, - // Worst case is looking through all holdings for every asset explicitly. - assets: Definite(holding), - max_response_weight: u64::MAX, - }; - - let xcm = Xcm(vec![instruction]); - - } : { - executor.execute(xcm)?; - } verify { - // The completion of execution above is enough to validate this is completed. - } - - // This benchmark does not use any additional orders or instructions. This should be managed - // by the `deep` and `shallow` implementation. - buy_execution { - let holding = T::worst_case_holding().into(); - - let mut executor = new_executor::(Default::default()); - executor.holding = holding; - - let fee_asset = Concrete(Here.into()); - - let instruction = Instruction::>::BuyExecution { - fees: (fee_asset, 100_000_000).into(), // should be something inside of holding - weight_limit: WeightLimit::Unlimited, - }; - - let xcm = Xcm(vec![instruction]); - } : { - executor.execute(xcm)?; - } verify { - - } - - query_response { - let mut executor = new_executor::(Default::default()); - let (query_id, response) = T::worst_case_response(); - let max_weight = u64::MAX; - let instruction = Instruction::QueryResponse { query_id, response, max_weight }; - let xcm = Xcm(vec![instruction]); - }: { - executor.execute(xcm)?; - } verify { - // The assert above is enough to show this XCM succeeded - } - - // We don't care about the call itself, since that is accounted for in the weight parameter - // and included in the final weight calculation. So this is just the overhead of submitting - // a noop call. - transact { - let origin = T::transact_origin()?; - let mut executor = new_executor::(origin); - let noop_call: ::Call = frame_system::Call::remark_with_event { - remark: Default::default() - }.into(); - let double_encoded_noop_call: DoubleEncoded<_> = noop_call.encode().into(); - - let instruction = Instruction::Transact { - origin_type: OriginKind::SovereignAccount, - require_weight_at_most: noop_call.get_dispatch_info().weight, - call: double_encoded_noop_call, - }; - let xcm = Xcm(vec![instruction]); - - let num_events = frame_system::Pallet::::events().len(); - }: { - executor.execute(xcm)?; - } verify { - // TODO make better assertion? #4426 - let num_events2 = frame_system::Pallet::::events().len(); - assert_eq!(num_events + 1, num_events2); - } - - refund_surplus { - let holding = T::worst_case_holding().into(); - let mut executor = new_executor::(Default::default()); - executor.holding = holding; - executor.total_surplus = 1337; - executor.total_refunded = 0; - - let instruction = Instruction::>::RefundSurplus; - let xcm = Xcm(vec![instruction]); - } : { - let result = executor.execute(xcm)?; - } verify { - assert_eq!(executor.total_surplus, 1337); - assert_eq!(executor.total_refunded, 1337); - } - - set_error_handler { - let mut executor = new_executor::(Default::default()); - let instruction = Instruction::>::SetErrorHandler(Xcm(vec![])); - let xcm = Xcm(vec![instruction]); - } : { - executor.execute(xcm)?; - } verify { - assert_eq!(executor.error_handler, Xcm(vec![])); - } - - set_appendix { - let mut executor = new_executor::(Default::default()); - let appendix = Xcm(vec![]); - let instruction = Instruction::>::SetAppendix(appendix); - let xcm = Xcm(vec![instruction]); - } : { - executor.execute(xcm)?; - } verify { - assert_eq!(executor.appendix, Xcm(vec![])); - } - - clear_error { - let mut executor = new_executor::(Default::default()); - executor.error = Some((5u32, XcmError::Overflow)); - let instruction = Instruction::>::ClearError; - let xcm = Xcm(vec![instruction]); - } : { - executor.execute(xcm)?; - } verify { - assert!(executor.error.is_none()) - } - - descend_origin { - let mut executor = new_executor::(Default::default()); - let who = X2(OnlyChild, OnlyChild); - let instruction = Instruction::DescendOrigin(who.clone()); - let xcm = Xcm(vec![instruction]); - } : { - executor.execute(xcm)?; - } verify { - assert_eq!( - executor.origin, - Some(MultiLocation { - parents: 0, - interior: who, - }), - ); - } - - clear_origin { - let mut executor = new_executor::(Default::default()); - let instruction = Instruction::ClearOrigin; - let xcm = Xcm(vec![instruction]); - } : { - executor.execute(xcm)?; - } verify { - assert_eq!(executor.origin, None); - } - - report_error { - let mut executor = new_executor::(Default::default()); - executor.error = Some((0u32, XcmError::Unimplemented)); - let query_id = Default::default(); - let dest = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; - let max_response_weight = Default::default(); - - let instruction = Instruction::ReportError { query_id, dest, max_response_weight }; - let xcm = Xcm(vec![instruction]); - }: { - executor.execute(xcm)?; - } verify { - // the execution succeeding is all we need to verify this xcm was successful - } - - claim_asset { - use xcm_executor::traits::DropAssets; - - let (origin, ticket, assets) = T::claimable_asset()?; - - // We place some items into the asset trap to claim. - ::AssetTrap::drop_assets( - &origin, - assets.clone().into(), - ); - - // Assets should be in the trap now. - - let mut executor = new_executor::(origin); - let instruction = Instruction::ClaimAsset { assets: assets.clone(), ticket }; - let xcm = Xcm(vec![instruction]); - } :{ - executor.execute(xcm)?; - } verify { - assert!(executor.holding.ensure_contains(&assets).is_ok()); - } - - trap { - let mut executor = new_executor::(Default::default()); - let instruction = Instruction::Trap(10); - let xcm = Xcm(vec![instruction]); - // In order to access result in the verification below, it needs to be defined here. - let mut _result = Ok(()); - } : { - _result = executor.execute(xcm); - } verify { - match _result { - Err(error) if error.xcm_error == XcmError::Trap(10) => { - // This is the success condition - }, - _ => Err("xcm trap did not return the expected error")? - }; - } - - subscribe_version { - use xcm_executor::traits::VersionChangeNotifier; - let origin = T::subscribe_origin()?; - let query_id = Default::default(); - let max_response_weight = Default::default(); - let mut executor = new_executor::(origin.clone()); - let instruction = Instruction::SubscribeVersion { query_id, max_response_weight }; - let xcm = Xcm(vec![instruction]); - } : { - executor.execute(xcm)?; - } verify { - assert!(::SubscriptionService::is_subscribed(&origin)); - } - - unsubscribe_version { - use xcm_executor::traits::VersionChangeNotifier; - // First we need to subscribe to notifications. - let origin = T::transact_origin()?; - let query_id = Default::default(); - let max_response_weight = Default::default(); - ::SubscriptionService::start( - &origin, - query_id, - max_response_weight - ).map_err(|_| "Could not start subscription")?; - assert!(::SubscriptionService::is_subscribed(&origin)); - - let mut executor = new_executor::(origin.clone()); - let instruction = Instruction::UnsubscribeVersion; - let xcm = Xcm(vec![instruction]); - } : { - executor.execute(xcm)?; - } verify { - assert!(!::SubscriptionService::is_subscribed(&origin)); - } - - initiate_reserve_withdraw { - let holding = T::worst_case_holding(); - let assets_filter = MultiAssetFilter::Definite(holding.clone()); - let reserve = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; - let mut executor = new_executor::(Default::default()); - executor.holding = holding.into(); - let instruction = Instruction::InitiateReserveWithdraw { assets: assets_filter, reserve, xcm: Xcm(vec![]) }; - let xcm = Xcm(vec![instruction]); - }:{ - executor.execute(xcm)?; - } verify { - // The execute completing successfully is as good as we can check. - // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 - } - - impl_benchmark_test_suite!( - Pallet, - crate::generic::mock::new_test_ext(), - crate::generic::mock::Test - ); - -} diff --git a/pallets/xcm-benchmarks/src/generic/mock.rs b/pallets/xcm-benchmarks/src/generic/mock.rs deleted file mode 100644 index e15382089de..00000000000 --- a/pallets/xcm-benchmarks/src/generic/mock.rs +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -//! A mock runtime for XCM benchmarking. - -use crate::{generic, mock::*, *}; -use codec::Decode; -use frame_support::{ - parameter_types, - traits::{Everything, OriginTrait}, -}; -use sp_core::H256; -use sp_runtime::{ - testing::Header, - traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput}, - BuildStorage, -}; -use xcm_builder::{ - test_utils::{Assets, TestAssetTrap, TestSubscriptionService}, - AllowUnpaidExecutionFrom, -}; -use xcm_executor::traits::ConvertOrigin; - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; - -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - XcmGenericBenchmarks: generic::{Pallet}, - } -); - -parameter_types! { - pub const BlockHashCount: u64 = 250; - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(1024); -} - -impl frame_system::Config for Test { - type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type Origin = Origin; - type Index = u64; - type BlockNumber = u64; - type Hash = H256; - type Call = Call; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -/// The benchmarks in this pallet should never need an asset transactor to begin with. -pub struct NoAssetTransactor; -impl xcm_executor::traits::TransactAsset for NoAssetTransactor { - fn deposit_asset(_: &MultiAsset, _: &MultiLocation) -> Result<(), XcmError> { - unreachable!(); - } - - fn withdraw_asset(_: &MultiAsset, _: &MultiLocation) -> Result { - unreachable!(); - } -} - -parameter_types! { - pub const MaxInstructions: u32 = 100; -} - -pub struct XcmConfig; -impl xcm_executor::Config for XcmConfig { - type Call = Call; - type XcmSender = DevNull; - type AssetTransactor = NoAssetTransactor; - type OriginConverter = AlwaysSignedByDefault; - type IsReserve = AllAssetLocationsPass; - type IsTeleporter = (); - type LocationInverter = xcm_builder::LocationInverter; - type Barrier = AllowUnpaidExecutionFrom; - type Weigher = xcm_builder::FixedWeightBounds; - type Trader = xcm_builder::FixedRateOfFungible; - type ResponseHandler = DevNull; - type AssetTrap = TestAssetTrap; - type AssetClaims = TestAssetTrap; - type SubscriptionService = TestSubscriptionService; -} - -impl crate::Config for Test { - type XcmConfig = XcmConfig; - type AccountIdConverter = AccountIdConverter; - fn valid_destination() -> Result { - let valid_destination: MultiLocation = - Junction::AccountId32 { network: NetworkId::Any, id: [0u8; 32] }.into(); - - Ok(valid_destination) - } - fn worst_case_holding() -> MultiAssets { - crate::mock_worst_case_holding() - } -} - -impl generic::Config for Test { - type Call = Call; - - fn worst_case_response() -> (u64, Response) { - let assets: MultiAssets = (Concrete(Here.into()), 100).into(); - (0, Response::Assets(assets)) - } - - fn transact_origin() -> Result { - Ok(Default::default()) - } - - fn subscribe_origin() -> Result { - Ok(Default::default()) - } - - fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { - let assets: MultiAssets = (Concrete(Here.into()), 100).into(); - let ticket = MultiLocation { parents: 0, interior: X1(GeneralIndex(0)) }; - Ok((Default::default(), ticket, assets)) - } -} - -pub fn new_test_ext() -> sp_io::TestExternalities { - let t = GenesisConfig { ..Default::default() }.build_storage().unwrap(); - sp_tracing::try_init_simple(); - t.into() -} - -pub struct AlwaysSignedByDefault(core::marker::PhantomData); -impl ConvertOrigin for AlwaysSignedByDefault -where - Origin: OriginTrait, - ::AccountId: Decode, -{ - fn convert_origin( - _origin: impl Into, - _kind: OriginKind, - ) -> Result { - Ok(Origin::signed( - ::AccountId::decode(&mut TrailingZeroInput::zeroes()) - .expect("infinite length input; no invalid inputs for type; qed"), - )) - } -} diff --git a/pallets/xcm-benchmarks/src/generic/mod.rs b/pallets/xcm-benchmarks/src/generic/mod.rs deleted file mode 100644 index 270eaf896e7..00000000000 --- a/pallets/xcm-benchmarks/src/generic/mod.rs +++ /dev/null @@ -1,39 +0,0 @@ -pub use pallet::*; - -pub mod benchmarking; -#[cfg(test)] -mod mock; - -#[frame_support::pallet] -pub mod pallet { - use frame_benchmarking::BenchmarkError; - use frame_support::{dispatch::Dispatchable, pallet_prelude::Encode, weights::GetDispatchInfo}; - use xcm::latest::{MultiAssets, MultiLocation, Response}; - - #[pallet::config] - pub trait Config: frame_system::Config + crate::Config { - type Call: Dispatchable - + GetDispatchInfo - + From> - + Encode; - - /// The response which causes the most runtime weight. - fn worst_case_response() -> (u64, Response); - - /// The `MultiLocation` used for successful transaction XCMs. - /// - /// If set to `None`, benchmarks which rely on a `transact_origin` will be skipped. - fn transact_origin() -> Result; - - /// A valid `MultiLocation` we can successfully subscribe to. - /// - /// If set to `None`, benchmarks which rely on a `subscribe_origin` will be skipped. - fn subscribe_origin() -> Result; - - /// Return an origin, ticket, and assets that can be trapped and claimed. - fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError>; - } - - #[pallet::pallet] - pub struct Pallet(_); -} diff --git a/pallets/xcm-benchmarks/src/lib.rs b/pallets/xcm-benchmarks/src/lib.rs deleted file mode 100644 index dcbeac050bf..00000000000 --- a/pallets/xcm-benchmarks/src/lib.rs +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -//! Pallet that serves no other purpose than benchmarking raw messages [`Xcm`]. - -#![cfg_attr(not(feature = "std"), no_std)] - -use codec::Encode; -use frame_benchmarking::{account, BenchmarkError}; -use sp_std::prelude::*; -use xcm::latest::prelude::*; -use xcm_executor::traits::Convert; - -pub mod fungible; -pub mod generic; - -#[cfg(test)] -mod mock; - -/// A base trait for all individual pallets -pub trait Config: frame_system::Config { - /// The XCM configurations. - /// - /// These might affect the execution of XCM messages, such as defining how the - /// `TransactAsset` is implemented. - type XcmConfig: xcm_executor::Config; - - /// A converter between a multi-location to a sovereign account. - type AccountIdConverter: Convert; - - /// Does any necessary setup to create a valid destination for XCM messages. - /// Returns that destination's multi-location to be used in benchmarks. - fn valid_destination() -> Result; - - /// Worst case scenario for a holding account in this runtime. - fn worst_case_holding() -> MultiAssets; -} - -const SEED: u32 = 0; - -/// The XCM executor to use for doing stuff. -pub type ExecutorOf = xcm_executor::XcmExecutor<::XcmConfig>; -/// The overarching call type. -pub type OverArchingCallOf = ::Call; -/// The asset transactor of our executor -pub type AssetTransactorOf = <::XcmConfig as xcm_executor::Config>::AssetTransactor; -/// The call type of executor's config. Should eventually resolve to the same overarching call type. -pub type XcmCallOf = <::XcmConfig as xcm_executor::Config>::Call; - -pub fn mock_worst_case_holding() -> MultiAssets { - const HOLDING_FUNGIBLES: u32 = 99; - const HOLDING_NON_FUNGIBLES: u32 = 99; - let fungibles_amount: u128 = 100; - (0..HOLDING_FUNGIBLES) - .map(|i| { - MultiAsset { - id: Concrete(GeneralIndex(i as u128).into()), - fun: Fungible(fungibles_amount * i as u128), - } - .into() - }) - .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::>() - .into() -} - -pub fn asset_instance_from(x: u32) -> AssetInstance { - let bytes = x.encode(); - let mut instance = [0u8; 4]; - instance.copy_from_slice(&bytes); - AssetInstance::Array4(instance) -} - -pub fn new_executor(origin: MultiLocation) -> ExecutorOf { - ExecutorOf::::new(origin) -} - -/// Build a multi-location from an account id. -fn account_id_junction(index: u32) -> Junction { - let account: T::AccountId = account("account", index, SEED); - let mut encoded = account.encode(); - encoded.resize(32, 0u8); - let mut id = [0u8; 32]; - id.copy_from_slice(&encoded); - Junction::AccountId32 { network: NetworkId::Any, id } -} - -pub fn account_and_location(index: u32) -> (T::AccountId, MultiLocation) { - let location: MultiLocation = account_id_junction::(index).into(); - let account = T::AccountIdConverter::convert(location.clone()).unwrap(); - - (account, location) -} diff --git a/pallets/xcm-benchmarks/src/mock.rs b/pallets/xcm-benchmarks/src/mock.rs deleted file mode 100644 index 3ceac640a84..00000000000 --- a/pallets/xcm-benchmarks/src/mock.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -use crate::*; -use frame_support::{parameter_types, weights::Weight}; -use xcm_executor::traits::FilterAssetLocation; - -// An xcm sender/receiver akin to > /dev/null -pub struct DevNull; -impl xcm::opaque::latest::SendXcm for DevNull { - fn send_xcm(_: impl Into, _: Xcm<()>) -> SendResult { - Ok(()) - } -} - -impl xcm_executor::traits::OnResponse for DevNull { - fn expecting_response(_: &MultiLocation, _: u64) -> bool { - false - } - fn on_response(_: &MultiLocation, _: u64, _: Response, _: Weight) -> Weight { - 0 - } -} - -pub struct AccountIdConverter; -impl xcm_executor::traits::Convert for AccountIdConverter { - fn convert(ml: MultiLocation) -> Result { - match ml { - MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { id, .. }) } => - Ok(::decode(&mut &*id.to_vec()).unwrap()), - _ => Err(ml), - } - } - - fn reverse(acc: u64) -> Result { - Err(acc) - } -} - -parameter_types! { - pub Ancestry: MultiLocation = Junction::Parachain(101).into(); - pub UnitWeightCost: Weight = 10; - pub WeightPrice: (AssetId, u128) = (Concrete(Here.into()), 1_000_000); -} - -pub struct AllAssetLocationsPass; -impl FilterAssetLocation for AllAssetLocationsPass { - fn filter_asset_location(_: &MultiAsset, _: &MultiLocation) -> bool { - true - } -} diff --git a/parachains/runtimes/assets/statemine/Cargo.toml b/parachains/runtimes/assets/statemine/Cargo.toml index 428c2f701b7..63e3cf1b1bc 100644 --- a/parachains/runtimes/assets/statemine/Cargo.toml +++ b/parachains/runtimes/assets/statemine/Cargo.toml @@ -71,7 +71,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } -pallet-xcm-benchmarks = { path = "../../../../pallets/xcm-benchmarks", default-features = false, optional = true } +pallet-xcm-benchmarks = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false, optional = true } [dev-dependencies] diff --git a/parachains/runtimes/assets/statemint/Cargo.toml b/parachains/runtimes/assets/statemint/Cargo.toml index d112bc9297e..186b4839ea8 100644 --- a/parachains/runtimes/assets/statemint/Cargo.toml +++ b/parachains/runtimes/assets/statemint/Cargo.toml @@ -71,7 +71,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } -pallet-xcm-benchmarks = { path = "../../../../pallets/xcm-benchmarks", default-features = false, optional = true } +pallet-xcm-benchmarks = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false, optional = true } [dev-dependencies] hex-literal = "0.3.4" diff --git a/parachains/runtimes/assets/westmint/Cargo.toml b/parachains/runtimes/assets/westmint/Cargo.toml index c2346fc54d1..2133accf0e2 100644 --- a/parachains/runtimes/assets/westmint/Cargo.toml +++ b/parachains/runtimes/assets/westmint/Cargo.toml @@ -71,7 +71,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default- pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } parachain-info = { path = "../../../pallets/parachain-info", default-features = false } parachains-common = { path = "../../../common", default-features = false } -pallet-xcm-benchmarks = { path = "../../../../pallets/xcm-benchmarks", default-features = false, optional = true } +pallet-xcm-benchmarks = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false, optional = true } [dev-dependencies] hex-literal = "0.3.4" From a09960e56f82a0cfa7b2eedc230b1e7dde13732f Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Mon, 29 Aug 2022 13:16:40 +0200 Subject: [PATCH 52/56] disable CheckedAccount in benches --- parachains/runtimes/assets/statemine/src/lib.rs | 4 +++- parachains/runtimes/assets/statemint/src/lib.rs | 3 ++- parachains/runtimes/assets/westmint/src/lib.rs | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/lib.rs b/parachains/runtimes/assets/statemine/src/lib.rs index 11228b4c3a9..f1d85b80cc9 100644 --- a/parachains/runtimes/assets/statemine/src/lib.rs +++ b/parachains/runtimes/assets/statemine/src/lib.rs @@ -862,12 +862,14 @@ impl_runtime_apis! { MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(KsmLocation::get()) }, )); pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; + pub const CheckedAccount: Option = None; + } impl pallet_xcm_benchmarks::fungible::Config for Runtime { type TransactAsset = Balances; - type CheckedAccount = xcm_config::CheckingAccount; + type CheckedAccount = CheckedAccount; type TrustedTeleporter = TrustedTeleporter; type TrustedReserve = TrustedReserve; diff --git a/parachains/runtimes/assets/statemint/src/lib.rs b/parachains/runtimes/assets/statemint/src/lib.rs index bff02586b81..b40195a313c 100644 --- a/parachains/runtimes/assets/statemint/src/lib.rs +++ b/parachains/runtimes/assets/statemint/src/lib.rs @@ -891,12 +891,13 @@ impl_runtime_apis! { MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(DotLocation::get()) }, )); pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; + pub const CheckedAccount: Option = None; } impl pallet_xcm_benchmarks::fungible::Config for Runtime { type TransactAsset = Balances; - type CheckedAccount = xcm_config::CheckingAccount; + type CheckedAccount = CheckedAccount; type TrustedTeleporter = TrustedTeleporter; type TrustedReserve = TrustedReserve; diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index c458090242e..0bed656b5d4 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -851,12 +851,14 @@ impl_runtime_apis! { MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(WestendLocation::get()) }, )); pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None; + pub const CheckedAccount: Option = None; + } impl pallet_xcm_benchmarks::fungible::Config for Runtime { type TransactAsset = Balances; - type CheckedAccount = xcm_config::CheckingAccount; + type CheckedAccount = CheckedAccount; type TrustedTeleporter = TrustedTeleporter; type TrustedReserve = TrustedReserve; From b8d6186ca93d111acbaee374a23e2659f397a1c0 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 31 Aug 2022 16:37:20 +0200 Subject: [PATCH 53/56] update template --- templates/xcm-bench-template.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/xcm-bench-template.hbs b/templates/xcm-bench-template.hbs index c2155933608..e741e4bd57a 100644 --- a/templates/xcm-bench-template.hbs +++ b/templates/xcm-bench-template.hbs @@ -31,7 +31,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{RefTimeWeight, Weight}}; use sp_std::marker::PhantomData; /// Weights for `{{pallet}}`. From a12e37d557ef500cdfd456d7f593e0252d31598f Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 31 Aug 2022 16:46:25 +0200 Subject: [PATCH 54/56] fix up imports --- .../statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs | 2 +- .../statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs | 2 +- .../statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs | 2 +- .../statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs | 2 +- .../westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs | 2 +- .../westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs index ea480c283f0..67183ab2497 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -42,7 +42,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{RefTimeWeight, Weight}}; use sp_std::marker::PhantomData; /// Weights for `pallet_xcm_benchmarks::fungible`. diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index 0d515df4d5a..9fff03143c0 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -42,7 +42,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{RefTimeWeight, Weight}}; use sp_std::marker::PhantomData; /// Weights for `pallet_xcm_benchmarks::generic`. diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs index 628c709ed4e..d1be0d32c33 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -43,7 +43,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{RefTimeWeight, Weight}}; use sp_std::marker::PhantomData; /// Weights for `pallet_xcm_benchmarks::fungible`. diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index e77663c109e..1a269d89f76 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -43,7 +43,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{RefTimeWeight, Weight}}; use sp_std::marker::PhantomData; /// Weights for `pallet_xcm_benchmarks::generic`. diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs index 961f94e8c82..5e72affee38 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -42,7 +42,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{RefTimeWeight, Weight}}; use sp_std::marker::PhantomData; /// Weights for `pallet_xcm_benchmarks::fungible`. diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index 8cd224661a9..6949bc6df88 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -42,7 +42,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{RefTimeWeight, Weight}}; use sp_std::marker::PhantomData; /// Weights for `pallet_xcm_benchmarks::generic`. From 1cb21e6b534ae4c0148889a06d1fd4abf1d2a260 Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 31 Aug 2022 18:24:55 +0200 Subject: [PATCH 55/56] fix xcm --- .../assets/statemine/src/weights/xcm/mod.rs | 119 +++++++++--------- .../xcm/pallet_xcm_benchmarks_fungible.rs | 38 +++--- .../xcm/pallet_xcm_benchmarks_generic.rs | 56 ++++----- .../assets/statemint/src/weights/xcm/mod.rs | 119 +++++++++--------- .../xcm/pallet_xcm_benchmarks_fungible.rs | 38 +++--- .../xcm/pallet_xcm_benchmarks_generic.rs | 56 ++++----- .../assets/westmint/src/weights/xcm/mod.rs | 119 +++++++++--------- .../xcm/pallet_xcm_benchmarks_fungible.rs | 38 +++--- .../xcm/pallet_xcm_benchmarks_generic.rs | 56 ++++----- 9 files changed, 324 insertions(+), 315 deletions(-) diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs index 211dd4b438c..10d4e18902f 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs @@ -19,101 +19,104 @@ mod pallet_xcm_benchmarks_generic; use crate::Runtime; use frame_support::weights::Weight; -use sp_std::prelude::*; -use xcm::{latest::prelude::*, DoubleEncoded}; - use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; +use sp_std::prelude::*; +use xcm::{ + latest::{prelude::*, Weight as XCMWeight}, + DoubleEncoded, +}; trait WeighMultiAssets { - fn weigh_multi_assets(&self, weight: Weight) -> Weight; + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } const MAX_ASSETS: u32 = 100; impl WeighMultiAssets for MultiAssetFilter { - fn weigh_multi_assets(&self, weight: Weight) -> Weight { - match self { + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { + let weight = match self { Self::Definite(assets) => - (assets.inner().into_iter().count() as Weight).saturating_mul(weight), - Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(weight), - } + weight.scalar_saturating_mul(assets.inner().into_iter().count() as u64), + Self::Wild(_) => weight.scalar_saturating_mul(MAX_ASSETS as u64), + }; + weight.ref_time() } } impl WeighMultiAssets for MultiAssets { - fn weigh_multi_assets(&self, weight: Weight) -> Weight { - (self.inner().into_iter().count() as Weight).saturating_mul(weight) + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { + weight.scalar_saturating_mul(self.inner().into_iter().count() as u64).ref_time() } } pub struct StatemineXcmWeight(core::marker::PhantomData); impl XcmWeightInfo for StatemineXcmWeight { - fn withdraw_asset(assets: &MultiAssets) -> Weight { + fn withdraw_asset(assets: &MultiAssets) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::withdraw_asset()) } // Currently there is no trusted reserve - fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight { + fn reserve_asset_deposited(_assets: &MultiAssets) -> XCMWeight { unimplemented!() } - fn receive_teleported_asset(assets: &MultiAssets) -> Weight { + fn receive_teleported_asset(assets: &MultiAssets) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::receive_teleported_asset()) } - fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> Weight { - XcmGeneric::::query_response() + fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> XCMWeight { + XcmGeneric::::query_response().ref_time() } - fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight { + fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::transfer_asset()) } fn transfer_reserve_asset( assets: &MultiAssets, _dest: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::transfer_reserve_asset()) } fn transact( _origin_type: &OriginKind, _require_weight_at_most: &u64, _call: &DoubleEncoded, - ) -> Weight { - XcmGeneric::::transact() + ) -> XCMWeight { + XcmGeneric::::transact().ref_time() } fn hrmp_new_channel_open_request( _sender: &u32, _max_message_size: &u32, _max_capacity: &u32, - ) -> Weight { + ) -> XCMWeight { // XCM Executor does not currently support HRMP channel operations - Weight::MAX + Weight::MAX.ref_time() } - fn hrmp_channel_accepted(_recipient: &u32) -> Weight { + fn hrmp_channel_accepted(_recipient: &u32) -> XCMWeight { // XCM Executor does not currently support HRMP channel operations - Weight::MAX + Weight::MAX.ref_time() } - fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight { + fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> XCMWeight { // XCM Executor does not currently support HRMP channel operations - Weight::MAX + Weight::MAX.ref_time() } - fn clear_origin() -> Weight { - XcmGeneric::::clear_origin() + fn clear_origin() -> XCMWeight { + XcmGeneric::::clear_origin().ref_time() } - fn descend_origin(_who: &InteriorMultiLocation) -> Weight { - XcmGeneric::::descend_origin() + fn descend_origin(_who: &InteriorMultiLocation) -> XCMWeight { + XcmGeneric::::descend_origin().ref_time() } fn report_error( _query_id: &QueryId, _dest: &MultiLocation, _max_response_weight: &u64, - ) -> Weight { - XcmGeneric::::report_error() + ) -> XCMWeight { + XcmGeneric::::report_error().ref_time() } fn deposit_asset( assets: &MultiAssetFilter, _max_assets: &u32, _dest: &MultiLocation, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( @@ -121,24 +124,24 @@ impl XcmWeightInfo for StatemineXcmWeight { _max_assets: &u32, _dest: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) } - fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight { - Weight::MAX // todo fix + fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight { + Weight::MAX.ref_time() } fn initiate_reserve_withdraw( assets: &MultiAssetFilter, _reserve: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) } fn initiate_teleport( assets: &MultiAssetFilter, _dest: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) } fn query_holding( @@ -146,34 +149,34 @@ impl XcmWeightInfo for StatemineXcmWeight { _dest: &MultiLocation, _assets: &MultiAssetFilter, _max_response_weight: &u64, - ) -> Weight { - XcmGeneric::::query_holding() + ) -> XCMWeight { + XcmGeneric::::query_holding().ref_time() } - fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight { - XcmGeneric::::buy_execution() + fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> XCMWeight { + XcmGeneric::::buy_execution().ref_time() } - fn refund_surplus() -> Weight { - XcmGeneric::::refund_surplus() + fn refund_surplus() -> XCMWeight { + XcmGeneric::::refund_surplus().ref_time() } - fn set_error_handler(_xcm: &Xcm) -> Weight { - XcmGeneric::::set_error_handler() + fn set_error_handler(_xcm: &Xcm) -> XCMWeight { + XcmGeneric::::set_error_handler().ref_time() } - fn set_appendix(_xcm: &Xcm) -> Weight { - XcmGeneric::::set_appendix() + fn set_appendix(_xcm: &Xcm) -> XCMWeight { + XcmGeneric::::set_appendix().ref_time() } - fn clear_error() -> Weight { - XcmGeneric::::clear_error() + fn clear_error() -> XCMWeight { + XcmGeneric::::clear_error().ref_time() } - fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight { - XcmGeneric::::claim_asset() + fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> XCMWeight { + XcmGeneric::::claim_asset().ref_time() } - fn trap(_code: &u64) -> Weight { - XcmGeneric::::trap() + fn trap(_code: &u64) -> XCMWeight { + XcmGeneric::::trap().ref_time() } - fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> Weight { - XcmGeneric::::subscribe_version() + fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> XCMWeight { + XcmGeneric::::subscribe_version().ref_time() } - fn unsubscribe_version() -> Weight { - XcmGeneric::::unsubscribe_version() + fn unsubscribe_version() -> XCMWeight { + XcmGeneric::::unsubscribe_version().ref_time() } } diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs index 67183ab2497..9df4a3c5490 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -50,15 +50,15 @@ pub struct WeightInfo(PhantomData); impl WeightInfo { // Storage: System Account (r:1 w:1) pub(crate) fn withdraw_asset() -> Weight { - (29_190_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(29_190_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } // Storage: System Account (r:2 w:2) pub(crate) fn transfer_asset() -> Weight { - (34_102_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(34_102_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(2 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } // Storage: System Account (r:2 w:2) // Storage: ParachainInfo ParachainId (r:1 w:0) @@ -68,18 +68,18 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn transfer_reserve_asset() -> Weight { - (49_386_000 as Weight) - .saturating_add(T::DbWeight::get().reads(8 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + Weight::from_ref_time(49_386_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(8 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(4 as RefTimeWeight)) } pub(crate) fn receive_teleported_asset() -> Weight { - (4_937_000 as Weight) + Weight::from_ref_time(4_937_000 as RefTimeWeight) } // Storage: System Account (r:1 w:1) pub(crate) fn deposit_asset() -> Weight { - (30_853_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(30_853_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } // Storage: System Account (r:1 w:1) // Storage: ParachainInfo ParachainId (r:1 w:0) @@ -89,9 +89,9 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn deposit_reserve_asset() -> Weight { - (45_866_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + Weight::from_ref_time(45_866_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(7 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(3 as RefTimeWeight)) } // Storage: ParachainInfo ParachainId (r:1 w:0) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -100,8 +100,8 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn initiate_teleport() -> Weight { - (23_964_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(23_964_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } } diff --git a/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index 9fff03143c0..72237c90e96 100644 --- a/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/parachains/runtimes/assets/statemine/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -55,38 +55,38 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn query_holding() -> Weight { - (694_466_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(694_466_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } pub(crate) fn buy_execution() -> Weight { - (7_095_000 as Weight) + Weight::from_ref_time(7_095_000 as RefTimeWeight) } // Storage: PolkadotXcm Queries (r:1 w:0) pub(crate) fn query_response() -> Weight { - (13_270_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) + Weight::from_ref_time(13_270_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) } pub(crate) fn transact() -> Weight { - (16_375_000 as Weight) + Weight::from_ref_time(16_375_000 as RefTimeWeight) } pub(crate) fn refund_surplus() -> Weight { - (7_319_000 as Weight) + Weight::from_ref_time(7_319_000 as RefTimeWeight) } pub(crate) fn set_error_handler() -> Weight { - (3_515_000 as Weight) + Weight::from_ref_time(3_515_000 as RefTimeWeight) } pub(crate) fn set_appendix() -> Weight { - (3_501_000 as Weight) + Weight::from_ref_time(3_501_000 as RefTimeWeight) } pub(crate) fn clear_error() -> Weight { - (3_459_000 as Weight) + Weight::from_ref_time(3_459_000 as RefTimeWeight) } pub(crate) fn descend_origin() -> Weight { - (4_319_000 as Weight) + Weight::from_ref_time(4_319_000 as RefTimeWeight) } pub(crate) fn clear_origin() -> Weight { - (3_511_000 as Weight) + Weight::from_ref_time(3_511_000 as RefTimeWeight) } // Storage: PolkadotXcm SupportedVersion (r:1 w:0) // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) @@ -94,18 +94,18 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn report_error() -> Weight { - (13_284_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(13_284_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(5 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } // Storage: PolkadotXcm AssetTraps (r:1 w:1) pub(crate) fn claim_asset() -> Weight { - (7_985_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(7_985_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } pub(crate) fn trap() -> Weight { - (3_515_000 as Weight) + Weight::from_ref_time(3_515_000 as RefTimeWeight) } // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -114,14 +114,14 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn subscribe_version() -> Weight { - (16_657_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + Weight::from_ref_time(16_657_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(3 as RefTimeWeight)) } // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) pub(crate) fn unsubscribe_version() -> Weight { - (5_622_000 as Weight) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(5_622_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } // Storage: ParachainInfo ParachainId (r:1 w:0) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -130,8 +130,8 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn initiate_reserve_withdraw() -> Weight { - (878_786_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(878_786_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } } diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs index 0477df1b27e..438b1742e1f 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs @@ -19,101 +19,104 @@ mod pallet_xcm_benchmarks_generic; use crate::Runtime; use frame_support::weights::Weight; -use sp_std::prelude::*; -use xcm::{latest::prelude::*, DoubleEncoded}; - use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; +use sp_std::prelude::*; +use xcm::{ + latest::{prelude::*, Weight as XCMWeight}, + DoubleEncoded, +}; trait WeighMultiAssets { - fn weigh_multi_assets(&self, weight: Weight) -> Weight; + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } const MAX_ASSETS: u32 = 100; impl WeighMultiAssets for MultiAssetFilter { - fn weigh_multi_assets(&self, weight: Weight) -> Weight { - match self { + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { + let weight = match self { Self::Definite(assets) => - (assets.inner().into_iter().count() as Weight).saturating_mul(weight), - Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(weight), - } + weight.scalar_saturating_mul(assets.inner().into_iter().count() as u64), + Self::Wild(_) => weight.scalar_saturating_mul(MAX_ASSETS as u64), + }; + weight.ref_time() } } impl WeighMultiAssets for MultiAssets { - fn weigh_multi_assets(&self, weight: Weight) -> Weight { - (self.inner().into_iter().count() as Weight).saturating_mul(weight) + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { + weight.scalar_saturating_mul(self.inner().into_iter().count() as u64).ref_time() } } pub struct StatemintXcmWeight(core::marker::PhantomData); impl XcmWeightInfo for StatemintXcmWeight { - fn withdraw_asset(assets: &MultiAssets) -> Weight { + fn withdraw_asset(assets: &MultiAssets) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::withdraw_asset()) } // Currently there is no trusted reserve - fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight { + fn reserve_asset_deposited(_assets: &MultiAssets) -> XCMWeight { unimplemented!() } - fn receive_teleported_asset(assets: &MultiAssets) -> Weight { + fn receive_teleported_asset(assets: &MultiAssets) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::receive_teleported_asset()) } - fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> Weight { - XcmGeneric::::query_response() + fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> XCMWeight { + XcmGeneric::::query_response().ref_time() } - fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight { + fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::transfer_asset()) } fn transfer_reserve_asset( assets: &MultiAssets, _dest: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::transfer_reserve_asset()) } fn transact( _origin_type: &OriginKind, _require_weight_at_most: &u64, _call: &DoubleEncoded, - ) -> Weight { - XcmGeneric::::transact() + ) -> XCMWeight { + XcmGeneric::::transact().ref_time() } fn hrmp_new_channel_open_request( _sender: &u32, _max_message_size: &u32, _max_capacity: &u32, - ) -> Weight { + ) -> XCMWeight { // XCM Executor does not currently support HRMP channel operations - Weight::MAX + Weight::MAX.ref_time() } - fn hrmp_channel_accepted(_recipient: &u32) -> Weight { + fn hrmp_channel_accepted(_recipient: &u32) -> XCMWeight { // XCM Executor does not currently support HRMP channel operations - Weight::MAX + Weight::MAX.ref_time() } - fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight { + fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> XCMWeight { // XCM Executor does not currently support HRMP channel operations - Weight::MAX + Weight::MAX.ref_time() } - fn clear_origin() -> Weight { - XcmGeneric::::clear_origin() + fn clear_origin() -> XCMWeight { + XcmGeneric::::clear_origin().ref_time() } - fn descend_origin(_who: &InteriorMultiLocation) -> Weight { - XcmGeneric::::descend_origin() + fn descend_origin(_who: &InteriorMultiLocation) -> XCMWeight { + XcmGeneric::::descend_origin().ref_time() } fn report_error( _query_id: &QueryId, _dest: &MultiLocation, _max_response_weight: &u64, - ) -> Weight { - XcmGeneric::::report_error() + ) -> XCMWeight { + XcmGeneric::::report_error().ref_time() } fn deposit_asset( assets: &MultiAssetFilter, _max_assets: &u32, _dest: &MultiLocation, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( @@ -121,24 +124,24 @@ impl XcmWeightInfo for StatemintXcmWeight { _max_assets: &u32, _dest: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) } - fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight { - Weight::MAX + fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight { + Weight::MAX.ref_time() } fn initiate_reserve_withdraw( assets: &MultiAssetFilter, _reserve: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) } fn initiate_teleport( assets: &MultiAssetFilter, _dest: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) } fn query_holding( @@ -146,34 +149,34 @@ impl XcmWeightInfo for StatemintXcmWeight { _dest: &MultiLocation, _assets: &MultiAssetFilter, _max_response_weight: &u64, - ) -> Weight { - XcmGeneric::::query_holding() + ) -> XCMWeight { + XcmGeneric::::query_holding().ref_time() } - fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight { - XcmGeneric::::buy_execution() + fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> XCMWeight { + XcmGeneric::::buy_execution().ref_time() } - fn refund_surplus() -> Weight { - XcmGeneric::::refund_surplus() + fn refund_surplus() -> XCMWeight { + XcmGeneric::::refund_surplus().ref_time() } - fn set_error_handler(_xcm: &Xcm) -> Weight { - XcmGeneric::::set_error_handler() + fn set_error_handler(_xcm: &Xcm) -> XCMWeight { + XcmGeneric::::set_error_handler().ref_time() } - fn set_appendix(_xcm: &Xcm) -> Weight { - XcmGeneric::::set_appendix() + fn set_appendix(_xcm: &Xcm) -> XCMWeight { + XcmGeneric::::set_appendix().ref_time() } - fn clear_error() -> Weight { - XcmGeneric::::clear_error() + fn clear_error() -> XCMWeight { + XcmGeneric::::clear_error().ref_time() } - fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight { - XcmGeneric::::claim_asset() + fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> XCMWeight { + XcmGeneric::::claim_asset().ref_time() } - fn trap(_code: &u64) -> Weight { - XcmGeneric::::trap() + fn trap(_code: &u64) -> XCMWeight { + XcmGeneric::::trap().ref_time() } - fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> Weight { - XcmGeneric::::subscribe_version() + fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> XCMWeight { + XcmGeneric::::subscribe_version().ref_time() } - fn unsubscribe_version() -> Weight { - XcmGeneric::::unsubscribe_version() + fn unsubscribe_version() -> XCMWeight { + XcmGeneric::::unsubscribe_version().ref_time() } } diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs index d1be0d32c33..8bcdcc3b039 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -51,15 +51,15 @@ pub struct WeightInfo(PhantomData); impl WeightInfo { // Storage: System Account (r:1 w:1) pub(crate) fn withdraw_asset() -> Weight { - (34_002_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(34_002_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } // Storage: System Account (r:2 w:2) pub(crate) fn transfer_asset() -> Weight { - (38_285_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(38_285_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(2 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } // Storage: System Account (r:2 w:2) // Storage: ParachainInfo ParachainId (r:1 w:0) @@ -69,18 +69,18 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn transfer_reserve_asset() -> Weight { - (55_068_000 as Weight) - .saturating_add(T::DbWeight::get().reads(8 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + Weight::from_ref_time(55_068_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(8 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(4 as RefTimeWeight)) } pub(crate) fn receive_teleported_asset() -> Weight { - (7_796_000 as Weight) + Weight::from_ref_time(7_796_000 as RefTimeWeight) } // Storage: System Account (r:1 w:1) pub(crate) fn deposit_asset() -> Weight { - (35_092_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(35_092_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } // Storage: System Account (r:1 w:1) // Storage: ParachainInfo ParachainId (r:1 w:0) @@ -90,9 +90,9 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn deposit_reserve_asset() -> Weight { - (50_590_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + Weight::from_ref_time(50_590_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(7 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(3 as RefTimeWeight)) } // Storage: ParachainInfo ParachainId (r:1 w:0) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -101,8 +101,8 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn initiate_teleport() -> Weight { - (27_220_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(27_220_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } } diff --git a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index 1a269d89f76..2c42c5619ba 100644 --- a/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/parachains/runtimes/assets/statemint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -56,38 +56,38 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn query_holding() -> Weight { - (682_639_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(682_639_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } pub(crate) fn buy_execution() -> Weight { - (9_272_000 as Weight) + Weight::from_ref_time(9_272_000 as RefTimeWeight) } // Storage: PolkadotXcm Queries (r:1 w:0) pub(crate) fn query_response() -> Weight { - (17_084_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) + Weight::from_ref_time(17_084_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) } pub(crate) fn transact() -> Weight { - (20_265_000 as Weight) + Weight::from_ref_time(20_265_000 as RefTimeWeight) } pub(crate) fn refund_surplus() -> Weight { - (9_422_000 as Weight) + Weight::from_ref_time(9_422_000 as RefTimeWeight) } pub(crate) fn set_error_handler() -> Weight { - (5_545_000 as Weight) + Weight::from_ref_time(5_545_000 as RefTimeWeight) } pub(crate) fn set_appendix() -> Weight { - (5_450_000 as Weight) + Weight::from_ref_time(5_450_000 as RefTimeWeight) } pub(crate) fn clear_error() -> Weight { - (5_519_000 as Weight) + Weight::from_ref_time(5_519_000 as RefTimeWeight) } pub(crate) fn descend_origin() -> Weight { - (6_398_000 as Weight) + Weight::from_ref_time(6_398_000 as RefTimeWeight) } pub(crate) fn clear_origin() -> Weight { - (5_498_000 as Weight) + Weight::from_ref_time(5_498_000 as RefTimeWeight) } // Storage: PolkadotXcm SupportedVersion (r:1 w:0) // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) @@ -95,18 +95,18 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn report_error() -> Weight { - (15_784_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(15_784_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(5 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } // Storage: PolkadotXcm AssetTraps (r:1 w:1) pub(crate) fn claim_asset() -> Weight { - (11_861_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(11_861_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } pub(crate) fn trap() -> Weight { - (5_462_000 as Weight) + Weight::from_ref_time(5_462_000 as RefTimeWeight) } // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -115,14 +115,14 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn subscribe_version() -> Weight { - (18_997_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + Weight::from_ref_time(18_997_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(3 as RefTimeWeight)) } // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) pub(crate) fn unsubscribe_version() -> Weight { - (8_684_000 as Weight) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(8_684_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } // Storage: ParachainInfo ParachainId (r:1 w:0) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -131,8 +131,8 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn initiate_reserve_withdraw() -> Weight { - (883_121_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(883_121_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } } diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs index f02c89f5b2e..2254b4e66cd 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs @@ -19,101 +19,104 @@ mod pallet_xcm_benchmarks_generic; use crate::Runtime; use frame_support::weights::Weight; -use sp_std::prelude::*; -use xcm::{latest::prelude::*, DoubleEncoded}; - use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; +use sp_std::prelude::*; +use xcm::{ + latest::{prelude::*, Weight as XCMWeight}, + DoubleEncoded, +}; trait WeighMultiAssets { - fn weigh_multi_assets(&self, weight: Weight) -> Weight; + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } const MAX_ASSETS: u32 = 100; impl WeighMultiAssets for MultiAssetFilter { - fn weigh_multi_assets(&self, weight: Weight) -> Weight { - match self { + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { + let weight = match self { Self::Definite(assets) => - (assets.inner().into_iter().count() as Weight).saturating_mul(weight), - Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(weight), - } + weight.scalar_saturating_mul(assets.inner().into_iter().count() as u64), + Self::Wild(_) => weight.scalar_saturating_mul(MAX_ASSETS as u64), + }; + weight.ref_time() } } impl WeighMultiAssets for MultiAssets { - fn weigh_multi_assets(&self, weight: Weight) -> Weight { - (self.inner().into_iter().count() as Weight).saturating_mul(weight) + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { + weight.scalar_saturating_mul(self.inner().into_iter().count() as u64).ref_time() } } pub struct WestmintXcmWeight(core::marker::PhantomData); impl XcmWeightInfo for WestmintXcmWeight { - fn withdraw_asset(assets: &MultiAssets) -> Weight { + fn withdraw_asset(assets: &MultiAssets) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::withdraw_asset()) } // Currently there is no trusted reserve - fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight { + fn reserve_asset_deposited(_assets: &MultiAssets) -> XCMWeight { unimplemented!() } - fn receive_teleported_asset(assets: &MultiAssets) -> Weight { + fn receive_teleported_asset(assets: &MultiAssets) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::receive_teleported_asset()) } - fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> Weight { - XcmGeneric::::query_response() + fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> XCMWeight { + XcmGeneric::::query_response().ref_time() } - fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight { + fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::transfer_asset()) } fn transfer_reserve_asset( assets: &MultiAssets, _dest: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::transfer_reserve_asset()) } fn transact( _origin_type: &OriginKind, _require_weight_at_most: &u64, _call: &DoubleEncoded, - ) -> Weight { - XcmGeneric::::transact() + ) -> XCMWeight { + XcmGeneric::::transact().ref_time() } fn hrmp_new_channel_open_request( _sender: &u32, _max_message_size: &u32, _max_capacity: &u32, - ) -> Weight { + ) -> XCMWeight { // XCM Executor does not currently support HRMP channel operations - Weight::MAX + Weight::MAX.ref_time() } - fn hrmp_channel_accepted(_recipient: &u32) -> Weight { + fn hrmp_channel_accepted(_recipient: &u32) -> XCMWeight { // XCM Executor does not currently support HRMP channel operations - Weight::MAX + Weight::MAX.ref_time() } - fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight { + fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> XCMWeight { // XCM Executor does not currently support HRMP channel operations - Weight::MAX + Weight::MAX.ref_time() } - fn clear_origin() -> Weight { - XcmGeneric::::clear_origin() + fn clear_origin() -> XCMWeight { + XcmGeneric::::clear_origin().ref_time() } - fn descend_origin(_who: &InteriorMultiLocation) -> Weight { - XcmGeneric::::descend_origin() + fn descend_origin(_who: &InteriorMultiLocation) -> XCMWeight { + XcmGeneric::::descend_origin().ref_time() } fn report_error( _query_id: &QueryId, _dest: &MultiLocation, _max_response_weight: &u64, - ) -> Weight { - XcmGeneric::::report_error() + ) -> XCMWeight { + XcmGeneric::::report_error().ref_time() } fn deposit_asset( assets: &MultiAssetFilter, _max_assets: &u32, _dest: &MultiLocation, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_asset()) } fn deposit_reserve_asset( @@ -121,24 +124,24 @@ impl XcmWeightInfo for WestmintXcmWeight { _max_assets: &u32, _dest: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::deposit_reserve_asset()) } - fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight { - Weight::MAX + fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight { + Weight::MAX.ref_time() } fn initiate_reserve_withdraw( assets: &MultiAssetFilter, _reserve: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) } fn initiate_teleport( assets: &MultiAssetFilter, _dest: &MultiLocation, _xcm: &Xcm<()>, - ) -> Weight { + ) -> XCMWeight { assets.weigh_multi_assets(XcmFungibleWeight::::initiate_teleport()) } fn query_holding( @@ -146,34 +149,34 @@ impl XcmWeightInfo for WestmintXcmWeight { _dest: &MultiLocation, _assets: &MultiAssetFilter, _max_response_weight: &u64, - ) -> Weight { - XcmGeneric::::query_holding() + ) -> XCMWeight { + XcmGeneric::::query_holding().ref_time() } - fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight { - XcmGeneric::::buy_execution() + fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> XCMWeight { + XcmGeneric::::buy_execution().ref_time() } - fn refund_surplus() -> Weight { - XcmGeneric::::refund_surplus() + fn refund_surplus() -> XCMWeight { + XcmGeneric::::refund_surplus().ref_time() } - fn set_error_handler(_xcm: &Xcm) -> Weight { - XcmGeneric::::set_error_handler() + fn set_error_handler(_xcm: &Xcm) -> XCMWeight { + XcmGeneric::::set_error_handler().ref_time() } - fn set_appendix(_xcm: &Xcm) -> Weight { - XcmGeneric::::set_appendix() + fn set_appendix(_xcm: &Xcm) -> XCMWeight { + XcmGeneric::::set_appendix().ref_time() } - fn clear_error() -> Weight { - XcmGeneric::::clear_error() + fn clear_error() -> XCMWeight { + XcmGeneric::::clear_error().ref_time() } - fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight { - XcmGeneric::::claim_asset() + fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> XCMWeight { + XcmGeneric::::claim_asset().ref_time() } - fn trap(_code: &u64) -> Weight { - XcmGeneric::::trap() + fn trap(_code: &u64) -> XCMWeight { + XcmGeneric::::trap().ref_time() } - fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> Weight { - XcmGeneric::::subscribe_version() + fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> XCMWeight { + XcmGeneric::::subscribe_version().ref_time() } - fn unsubscribe_version() -> Weight { - XcmGeneric::::unsubscribe_version() + fn unsubscribe_version() -> XCMWeight { + XcmGeneric::::unsubscribe_version().ref_time() } } diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs index 5e72affee38..6cc7e3e48e6 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -50,15 +50,15 @@ pub struct WeightInfo(PhantomData); impl WeightInfo { // Storage: System Account (r:1 w:1) pub(crate) fn withdraw_asset() -> Weight { - (28_725_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(28_725_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } // Storage: System Account (r:2 w:2) pub(crate) fn transfer_asset() -> Weight { - (33_865_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(33_865_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(2 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } // Storage: System Account (r:2 w:2) // Storage: ParachainInfo ParachainId (r:1 w:0) @@ -68,18 +68,18 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn transfer_reserve_asset() -> Weight { - (48_839_000 as Weight) - .saturating_add(T::DbWeight::get().reads(8 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + Weight::from_ref_time(48_839_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(8 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(4 as RefTimeWeight)) } pub(crate) fn receive_teleported_asset() -> Weight { - (4_849_000 as Weight) + Weight::from_ref_time(4_849_000 as RefTimeWeight) } // Storage: System Account (r:1 w:1) pub(crate) fn deposit_asset() -> Weight { - (29_778_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(29_778_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } // Storage: System Account (r:1 w:1) // Storage: ParachainInfo ParachainId (r:1 w:0) @@ -89,9 +89,9 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn deposit_reserve_asset() -> Weight { - (45_355_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + Weight::from_ref_time(45_355_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(7 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(3 as RefTimeWeight)) } // Storage: ParachainInfo ParachainId (r:1 w:0) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -100,8 +100,8 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn initiate_teleport() -> Weight { - (23_451_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(23_451_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } } diff --git a/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index 6949bc6df88..1922a3ab4cf 100644 --- a/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/parachains/runtimes/assets/westmint/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -55,38 +55,38 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn query_holding() -> Weight { - (676_316_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(676_316_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } pub(crate) fn buy_execution() -> Weight { - (7_030_000 as Weight) + Weight::from_ref_time(7_030_000 as RefTimeWeight) } // Storage: PolkadotXcm Queries (r:1 w:0) pub(crate) fn query_response() -> Weight { - (12_574_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) + Weight::from_ref_time(12_574_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) } pub(crate) fn transact() -> Weight { - (15_764_000 as Weight) + Weight::from_ref_time(15_764_000 as RefTimeWeight) } pub(crate) fn refund_surplus() -> Weight { - (7_200_000 as Weight) + Weight::from_ref_time(7_200_000 as RefTimeWeight) } pub(crate) fn set_error_handler() -> Weight { - (3_310_000 as Weight) + Weight::from_ref_time(3_310_000 as RefTimeWeight) } pub(crate) fn set_appendix() -> Weight { - (3_260_000 as Weight) + Weight::from_ref_time(3_260_000 as RefTimeWeight) } pub(crate) fn clear_error() -> Weight { - (3_277_000 as Weight) + Weight::from_ref_time(3_277_000 as RefTimeWeight) } pub(crate) fn descend_origin() -> Weight { - (3_913_000 as Weight) + Weight::from_ref_time(3_913_000 as RefTimeWeight) } pub(crate) fn clear_origin() -> Weight { - (3_354_000 as Weight) + Weight::from_ref_time(3_354_000 as RefTimeWeight) } // Storage: PolkadotXcm SupportedVersion (r:1 w:0) // Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) @@ -94,18 +94,18 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn report_error() -> Weight { - (13_028_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(13_028_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(5 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } // Storage: PolkadotXcm AssetTraps (r:1 w:1) pub(crate) fn claim_asset() -> Weight { - (7_739_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(7_739_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } pub(crate) fn trap() -> Weight { - (3_351_000 as Weight) + Weight::from_ref_time(3_351_000 as RefTimeWeight) } // Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -114,14 +114,14 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn subscribe_version() -> Weight { - (16_051_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + Weight::from_ref_time(16_051_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(3 as RefTimeWeight)) } // Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) pub(crate) fn unsubscribe_version() -> Weight { - (5_477_000 as Weight) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + Weight::from_ref_time(5_477_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight)) } // Storage: ParachainInfo ParachainId (r:1 w:0) // Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -130,8 +130,8 @@ impl WeightInfo { // Storage: ParachainSystem HostConfiguration (r:1 w:0) // Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) pub(crate) fn initiate_reserve_withdraw() -> Weight { - (874_435_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + Weight::from_ref_time(874_435_000 as RefTimeWeight) + .saturating_add(T::DbWeight::get().reads(6 as RefTimeWeight)) + .saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight)) } } From 0eab44119dbee9d84a23a4330810a5288952319c Mon Sep 17 00:00:00 2001 From: Roman Useinov Date: Wed, 31 Aug 2022 18:32:12 +0200 Subject: [PATCH 56/56] fix the template --- templates/xcm-bench-template.hbs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/xcm-bench-template.hbs b/templates/xcm-bench-template.hbs index e741e4bd57a..31cfef0d93e 100644 --- a/templates/xcm-bench-template.hbs +++ b/templates/xcm-bench-template.hbs @@ -46,22 +46,22 @@ impl WeightInfo { {{~#each benchmark.components as |c| ~}} {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} ) -> Weight { - ({{underscore benchmark.base_weight}} as Weight) + Weight::from_ref_time({{underscore benchmark.base_weight}} as RefTimeWeight) {{#each benchmark.component_weight as |cw|}} // Standard Error: {{underscore cw.error}} - .saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)) + .saturating_add(Weight::from_ref_time({{underscore cw.slope}}).scalar_saturating_mul({{cw.name}} as RefTimeWeight)) {{/each}} {{#if (ne benchmark.base_reads "0")}} - .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight)) + .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as RefTimeWeight)) {{/if}} {{#each benchmark.component_reads as |cr|}} - .saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight))) + .saturating_add(T::DbWeight::get().reads(({{cr.slope}} as RefTimeWeight).scalar_saturating_mul({{cr.name}} as RefTimeWeight))) {{/each}} {{#if (ne benchmark.base_writes "0")}} - .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight)) + .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as RefTimeWeight)) {{/if}} {{#each benchmark.component_writes as |cw|}} - .saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))) + .saturating_add(T::DbWeight::get().writes(({{cw.slope}} as RefTimeWeight).scalar_saturating_mul({{cw.name}} as RefTimeWeight))) {{/each}} } {{/each}}