From d0cb1ffda273285314bf35e7d73abde97a395a5b Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Mon, 28 Aug 2023 14:30:36 +0530 Subject: [PATCH 01/20] add constants --- Cargo.lock | 1 + Cargo.toml | 1 + primitives/src/xcm/constants.rs | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 primitives/src/xcm/constants.rs diff --git a/Cargo.lock b/Cargo.lock index 49ee57f0b1..8b1a46d14e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12428,6 +12428,7 @@ dependencies = [ "pallet-vesting", "pallet-xc-asset-config", "pallet-xcm 0.9.40", + "pallet-xcm-benchmarks", "pallet-xvm", "parachain-info", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 6e3948a47f..5f512c54bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -253,6 +253,7 @@ polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "r # (wasm) cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.43", default-features = false } xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43", default-features = false } +pallet-xcm-benchmarks = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43", default-features = false } xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43", default-features = false } xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43", default-features = false } xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43", default-features = false } diff --git a/primitives/src/xcm/constants.rs b/primitives/src/xcm/constants.rs new file mode 100644 index 0000000000..8f8cfda8c7 --- /dev/null +++ b/primitives/src/xcm/constants.rs @@ -0,0 +1,19 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . + +pub const MAX_ASSETS: u32 = 64; \ No newline at end of file From 52b47f6cae8f7c052f9d84d3ff253e1f560682bb Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Mon, 28 Aug 2023 14:31:52 +0530 Subject: [PATCH 02/20] setup for generic instructions benchmarks --- primitives/src/xcm/mod.rs | 1 + runtime/shibuya/Cargo.toml | 2 + runtime/shibuya/src/lib.rs | 74 +++- runtime/shibuya/src/weights/mod.rs | 1 + runtime/shibuya/src/weights/xcm/mod.rs | 259 +++++++++++++ .../xcm/pallet_xcm_benchmarks_fungible.rs | 148 ++++++++ .../xcm/pallet_xcm_benchmarks_generic.rs | 351 ++++++++++++++++++ runtime/shibuya/src/xcm_config.rs | 11 +- 8 files changed, 843 insertions(+), 4 deletions(-) create mode 100644 runtime/shibuya/src/weights/xcm/mod.rs create mode 100644 runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs create mode 100644 runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs diff --git a/primitives/src/xcm/mod.rs b/primitives/src/xcm/mod.rs index e59e01283b..9760a31b7f 100644 --- a/primitives/src/xcm/mod.rs +++ b/primitives/src/xcm/mod.rs @@ -51,6 +51,7 @@ use orml_traits::location::{RelativeReserveProvider, Reserve}; use pallet_xc_asset_config::{ExecutionPaymentRate, XcAssetLocation}; +pub mod constants; #[cfg(test)] mod tests; diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index a62e030061..6de9b11526 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -70,6 +70,7 @@ pallet-transaction-payment-rpc-runtime-api = { workspace = true } pallet-treasury = { workspace = true } pallet-utility = { workspace = true } pallet-vesting = { workspace = true } +pallet-xcm-benchmarks = { workspace = true } # cumulus dependencies cumulus-pallet-aura-ext = { workspace = true } @@ -258,6 +259,7 @@ runtime-benchmarks = [ "orml-xtokens/runtime-benchmarks", "astar-primitives/runtime-benchmarks", "pallet-assets/runtime-benchmarks", + "pallet-xcm-benchmarks/runtime-benchmarks" ] try-runtime = [ "fp-self-contained/try-runtime", diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 5da4ebbc53..800c26411b 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -1420,6 +1420,7 @@ mod benches { [pallet_xcm, PolkadotXcm] [pallet_ethereum_checked, EthereumChecked] [pallet_xvm, Xvm] + [pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::] ); } @@ -1899,14 +1900,85 @@ impl_runtime_apis! { fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch, TrackedStorageKey}; + use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch, TrackedStorageKey, BenchmarkError}; use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; + use xcm_config::{XcmConfig, LocationToAccountId, ShibuyaLocation}; + use xcm::latest::prelude::*; impl frame_system_benchmarking::Config for Runtime {} impl baseline::Config for Runtime {} use frame_support::traits::WhitelistedStorageKeys; + impl pallet_xcm_benchmarks::Config for Runtime { + type XcmConfig = XcmConfig; + type AccountIdConverter = LocationToAccountId; + fn valid_destination() -> Result { + let valid_destination: MultiLocation = Junction::AccountId32 { + network: None, + id: [0u8; 32], + } + .into(); + + Ok(valid_destination) + } + fn worst_case_holding(_depositable_count: u32) -> MultiAssets { + let assets: Vec = vec![MultiAsset { + id: Concrete(MultiLocation::parent()), + fun: Fungible(u128::MAX), + }]; + assets.into() + } + } + impl pallet_xcm_benchmarks::generic::Config for Runtime { + type RuntimeCall = RuntimeCall; + + fn worst_case_response() -> (u64, Response) { + // not sure what will be the worst case for Response + // either `Assets(MultiAssets)` or `PalletsInfo(BoundedVec)` + // in either case, what will be the worst case? + (0u64, Response::Version(Default::default())) + } + + fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> { + // Shibuya doesn't support asset exchanges + Err(BenchmarkError::Skip) + } + + fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> { + // The XCM executor of Shibuya doesn't have a configured `UniversalAliases` + Err(BenchmarkError::Skip) + } + + fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> { + // 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. + Ok((ShibuyaLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) + } + + fn subscribe_origin() -> Result { + Ok(ShibuyaLocation::get()) + } + + 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)) + } + + fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> { + // Shibuya doesn't support asset locking + Err(BenchmarkError::Skip) + } + + fn export_message_origin_and_destination( + ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> { + // Shibuya doesn't support exporting messages + Err(BenchmarkError::Skip) + } + } + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); diff --git a/runtime/shibuya/src/weights/mod.rs b/runtime/shibuya/src/weights/mod.rs index 2db3ac12ab..c82a93d72a 100644 --- a/runtime/shibuya/src/weights/mod.rs +++ b/runtime/shibuya/src/weights/mod.rs @@ -17,3 +17,4 @@ // along with Astar. If not, see . pub mod pallet_assets; +pub mod xcm; \ No newline at end of file diff --git a/runtime/shibuya/src/weights/xcm/mod.rs b/runtime/shibuya/src/weights/xcm/mod.rs new file mode 100644 index 0000000000..0efb9fdc13 --- /dev/null +++ b/runtime/shibuya/src/weights/xcm/mod.rs @@ -0,0 +1,259 @@ +// Copyright (C) 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 . + +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::*,Weight as XCMWeight}, DoubleEncoded}; + +use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; +use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; +use astar_primitives::xcm::constants::MAX_ASSETS; +use core::cmp::min; + +trait WeighMultiAssets { + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; +} + +trait WeighMultiAssetsFilter { + fn weigh_multi_assets_filter(&self, weight: Weight) -> XCMWeight; +} + +impl WeighMultiAssetsFilter for MultiAssetFilter { + fn weigh_multi_assets_filter(&self, weight: Weight) -> XCMWeight { + match self { + Self::Definite(assets) => { + weight.saturating_mul(assets.inner().into_iter().count() as u64) + } + Self::Wild(AllCounted(count) | AllOfCounted { count, .. }) => { + weight.saturating_mul(min(MAX_ASSETS, *count) as u64) + } + Self::Wild(All | AllOf { .. }) => weight.saturating_mul(MAX_ASSETS as u64), + } + } +} + +impl WeighMultiAssets for MultiAssets { + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { + weight.saturating_mul(self.inner().into_iter().count() as u64) + } +} + +pub struct ShibuyaXcmWeight(core::marker::PhantomData); +impl XcmWeightInfo for ShibuyaXcmWeight { + fn withdraw_asset(assets: &MultiAssets) -> XCMWeight { + assets.inner().iter().fold(Weight::zero(), |acc, asset| { + acc.saturating_add(XcmFungibleWeight::::withdraw_asset()) + }) + } + // Currently there is no trusted reserve + fn reserve_asset_deposited(_assets: &MultiAssets) -> XCMWeight { + XcmFungibleWeight::::reserve_asset_deposited() + } + 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: &Weight, + _querier: &Option, + ) -> XCMWeight { + XcmGeneric::::query_response() + } + fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> XCMWeight { + assets.inner().iter().fold(Weight::zero(), |acc, _asset| { + acc.saturating_add(XcmFungibleWeight::::transfer_asset()) + }) + } + fn transfer_reserve_asset( + assets: &MultiAssets, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> XCMWeight { + assets.inner().iter().fold(Weight::zero(), |acc, _asset| { + acc.saturating_add(XcmFungibleWeight::::transfer_reserve_asset()) + }) + } + fn transact( + _origin_type: &OriginKind, + _require_weight_at_most: &Weight, + _call: &DoubleEncoded, + ) -> XCMWeight { + XcmGeneric::::transact() + } + fn hrmp_new_channel_open_request( + _sender: &u32, + _max_message_size: &u32, + _max_capacity: &u32, + ) -> XCMWeight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn hrmp_channel_accepted(_recipient: &u32) -> XCMWeight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> XCMWeight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn clear_origin() -> XCMWeight { + XcmGeneric::::clear_origin() + } + fn descend_origin(_who: &InteriorMultiLocation) -> XCMWeight { + XcmGeneric::::descend_origin() + } + fn report_error(_query_response_info: &QueryResponseInfo) -> XCMWeight { + XcmGeneric::::report_error() + } + fn deposit_asset(assets: &MultiAssetFilter, _dest: &MultiLocation) -> XCMWeight { + assets.weigh_multi_assets_filter(XcmFungibleWeight::::deposit_asset()) + } + fn deposit_reserve_asset( + assets: &MultiAssetFilter, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> XCMWeight { + assets.weigh_multi_assets_filter(XcmFungibleWeight::::deposit_reserve_asset()) + } + fn exchange_asset( + _give: &MultiAssetFilter, + _receive: &MultiAssets, + _maximal: &bool, + ) -> XCMWeight { + Weight::MAX + } + fn initiate_reserve_withdraw( + _assets: &MultiAssetFilter, + _reserve: &MultiLocation, + _xcm: &Xcm<()>, + ) -> XCMWeight { + // This is not correct. initiate reserve withdraw does not to that many db reads + // the only thing it does based on number of assets is a take from a local variable + //assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) + XcmGeneric::::initiate_reserve_withdraw() + } + fn initiate_teleport( + _assets: &MultiAssetFilter, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> XCMWeight { + XcmFungibleWeight::::initiate_teleport() + } + fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight { + XcmGeneric::::report_holding() + } + fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> XCMWeight { + XcmGeneric::::buy_execution() + } + fn refund_surplus() -> XCMWeight { + XcmGeneric::::refund_surplus() + } + fn set_error_handler(_xcm: &Xcm) -> XCMWeight { + XcmGeneric::::set_error_handler() + } + fn set_appendix(_xcm: &Xcm) -> XCMWeight { + XcmGeneric::::set_appendix() + } + fn clear_error() -> XCMWeight { + XcmGeneric::::clear_error() + } + fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> XCMWeight { + XcmGeneric::::claim_asset() + } + fn trap(_code: &u64) -> XCMWeight { + XcmGeneric::::trap() + } + fn subscribe_version(_query_id: &QueryId, _max_response_weight: &Weight) -> XCMWeight { + XcmGeneric::::subscribe_version() + } + fn unsubscribe_version() -> XCMWeight { + XcmGeneric::::unsubscribe_version() + } + fn burn_asset(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmGeneric::::burn_asset()) + } + fn expect_asset(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmGeneric::::expect_asset()) + } + fn expect_origin(_origin: &Option) -> Weight { + XcmGeneric::::expect_origin() + } + fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight { + XcmGeneric::::expect_error() + } + fn expect_transact_status(_transact_status: &MaybeErrorCode) -> Weight { + XcmGeneric::::expect_transact_status() + } + fn query_pallet(_module_name: &Vec, _response_info: &QueryResponseInfo) -> Weight { + XcmGeneric::::query_pallet() + } + fn expect_pallet( + _index: &u32, + _name: &Vec, + _module_name: &Vec, + _crate_major: &u32, + _min_crate_minor: &u32, + ) -> Weight { + XcmGeneric::::expect_pallet() + } + fn report_transact_status(_response_info: &QueryResponseInfo) -> Weight { + XcmGeneric::::report_transact_status() + } + fn clear_transact_status() -> Weight { + XcmGeneric::::clear_transact_status() + } + fn universal_origin(_: &Junction) -> Weight { + Weight::MAX + } + fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight { + Weight::MAX + } + fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { + Weight::MAX + } + fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { + Weight::MAX + } + fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight { + Weight::MAX + } + fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight { + Weight::MAX + } + fn set_fees_mode(_: &bool) -> Weight { + XcmGeneric::::set_fees_mode() + } + fn set_topic(_topic: &[u8; 32]) -> Weight { + XcmGeneric::::set_topic() + } + fn clear_topic() -> Weight { + XcmGeneric::::clear_topic() + } + fn alias_origin(_: &MultiLocation) -> Weight { + // XCM Executor does not currently support alias origin operations + Weight::MAX + } + fn unpaid_execution(_: &WeightLimit, _: &Option) -> Weight { + XcmGeneric::::unpaid_execution() + } +} + + diff --git a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs new file mode 100644 index 0000000000..5aa2a35391 --- /dev/null +++ b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -0,0 +1,148 @@ +// Copyright (C) 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 . + +//! Autogenerated weights for `pallet_xcm_benchmarks::fungible` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-07-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-gghbxkbs-project-163-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot/.git/.artifacts/bench.json +// --pallet=pallet_xcm_benchmarks::fungible +// --chain=kusama-dev +// --header=./file_header.txt +// --template=./xcm/pallet-xcm-benchmarks/template.hbs +// --output=./runtime/kusama/src/weights/xcm/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +const DEFAULT_REF_TIME:u64 = 1_000_000_000; +const DEFAULT_PROOF_SIZE:u64 = 64 * 1024; + +/// Weight functions for `pallet_xcm_benchmarks::fungible`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + pub(crate) fn withdraw_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `101` + // Estimated: `3593` + // Minimum execution time: 23_950_000 picoseconds. + Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) + } + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + pub(crate) fn transfer_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `101` + // Estimated: `6196` + // Minimum execution time: 51_687_000 picoseconds. + Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) + } + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) + /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) + pub(crate) fn transfer_reserve_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `177` + // Estimated: `6196` + // Minimum execution time: 75_438_000 picoseconds. + Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) + } + /// Storage: `Benchmark::Override` (r:0 w:0) + /// Proof: `Benchmark::Override` (`max_values`: None, `max_size`: None, mode: `Measured`) + pub(crate) fn reserve_asset_deposited() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_000_000_000_000 picoseconds. + Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) + } + /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) + /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) + pub(crate) fn initiate_reserve_withdraw() -> Weight { + Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + pub(crate) fn receive_teleported_asset() -> Weight { + // Instruction disabled + Weight::MAX + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + pub(crate) fn deposit_asset() -> Weight { + Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) + /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) + pub(crate) fn deposit_reserve_asset() -> Weight { + Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) + /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) + pub(crate) fn initiate_teleport() -> Weight { + // Instruction disabled + Weight::MAX + } +} diff --git a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs new file mode 100644 index 0000000000..0c411d32af --- /dev/null +++ b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -0,0 +1,351 @@ +// Copyright (C) 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 . + +//! Autogenerated weights for `pallet_xcm_benchmarks::generic` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-06-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/polkadot +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/polkadot/.git/.artifacts/bench.json +// --pallet=pallet_xcm_benchmarks::generic +// --chain=kusama-dev +// --header=./file_header.txt +// --template=./xcm/pallet-xcm-benchmarks/template.hbs +// --output=./runtime/kusama/src/weights/xcm/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_xcm_benchmarks::generic`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + /// Storage: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) + /// Proof Skipped: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) + /// Storage: Dmp DeliveryFeeFactor (r:1 w:0) + /// Proof Skipped: Dmp DeliveryFeeFactor (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmPallet SupportedVersion (r:1 w:0) + /// Proof Skipped: XcmPallet SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmPallet VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: XcmPallet VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: XcmPallet SafeXcmVersion (r:1 w:0) + /// Proof Skipped: XcmPallet SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Dmp DownwardMessageQueues (r:1 w:1) + /// Proof Skipped: Dmp DownwardMessageQueues (max_values: None, max_size: None, mode: Measured) + /// Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + /// Proof Skipped: Dmp DownwardMessageQueueHeads (max_values: None, max_size: None, mode: Measured) + pub(crate) fn report_holding() -> Weight { + // Proof Size summary in bytes: + // Measured: `211` + // Estimated: `3676` + // Minimum execution time: 32_102_000 picoseconds. + Weight::from_parts(33_749_000, 3676) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(4)) + } + pub(crate) fn initiate_reserve_withdraw() -> Weight { + // Proof Size summary in bytes: + // Measured: `145` + // Estimated: `10130` + // Minimum execution time: 713_056_000 picoseconds. + Weight::from_parts(715_975_000, 10130) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + + pub(crate) fn buy_execution() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_624_000 picoseconds. + Weight::from_parts(2_714_000, 0) + } + /// Storage: XcmPallet Queries (r:1 w:0) + /// Proof Skipped: XcmPallet Queries (max_values: None, max_size: None, mode: Measured) + pub(crate) fn query_response() -> Weight { + // Proof Size summary in bytes: + // Measured: `169` + // Estimated: `3634` + // Minimum execution time: 10_599_000 picoseconds. + Weight::from_parts(10_882_000, 3634) + .saturating_add(T::DbWeight::get().reads(1)) + } + pub(crate) fn transact() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 11_985_000 picoseconds. + Weight::from_parts(12_274_000, 0) + } + pub(crate) fn refund_surplus() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_739_000 picoseconds. + Weight::from_parts(2_862_000, 0) + } + pub(crate) fn set_error_handler() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_533_000 picoseconds. + Weight::from_parts(2_646_000, 0) + } + pub(crate) fn set_appendix() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_563_000 picoseconds. + Weight::from_parts(2_647_000, 0) + } + pub(crate) fn clear_error() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_512_000 picoseconds. + Weight::from_parts(2_574_000, 0) + } + pub(crate) fn descend_origin() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_307_000 picoseconds. + Weight::from_parts(3_448_000, 0) + } + pub(crate) fn clear_origin() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_524_000 picoseconds. + Weight::from_parts(2_614_000, 0) + } + /// Storage: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) + /// Proof Skipped: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) + /// Storage: Dmp DeliveryFeeFactor (r:1 w:0) + /// Proof Skipped: Dmp DeliveryFeeFactor (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmPallet SupportedVersion (r:1 w:0) + /// Proof Skipped: XcmPallet SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmPallet VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: XcmPallet VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: XcmPallet SafeXcmVersion (r:1 w:0) + /// Proof Skipped: XcmPallet SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Dmp DownwardMessageQueues (r:1 w:1) + /// Proof Skipped: Dmp DownwardMessageQueues (max_values: None, max_size: None, mode: Measured) + /// Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + /// Proof Skipped: Dmp DownwardMessageQueueHeads (max_values: None, max_size: None, mode: Measured) + pub(crate) fn report_error() -> Weight { + // Proof Size summary in bytes: + // Measured: `211` + // Estimated: `3676` + // Minimum execution time: 27_275_000 picoseconds. + Weight::from_parts(27_861_000, 3676) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: XcmPallet AssetTraps (r:1 w:1) + /// Proof Skipped: XcmPallet AssetTraps (max_values: None, max_size: None, mode: Measured) + pub(crate) fn claim_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `226` + // Estimated: `3691` + // Minimum execution time: 14_731_000 picoseconds. + Weight::from_parts(15_006_000, 3691) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + pub(crate) fn trap() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_446_000 picoseconds. + Weight::from_parts(2_581_000, 0) + } + /// Storage: XcmPallet VersionNotifyTargets (r:1 w:1) + /// Proof Skipped: XcmPallet VersionNotifyTargets (max_values: None, max_size: None, mode: Measured) + /// Storage: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) + /// Proof Skipped: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) + /// Storage: Dmp DeliveryFeeFactor (r:1 w:0) + /// Proof Skipped: Dmp DeliveryFeeFactor (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmPallet SupportedVersion (r:1 w:0) + /// Proof Skipped: XcmPallet SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmPallet VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: XcmPallet VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: XcmPallet SafeXcmVersion (r:1 w:0) + /// Proof Skipped: XcmPallet SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Dmp DownwardMessageQueues (r:1 w:1) + /// Proof Skipped: Dmp DownwardMessageQueues (max_values: None, max_size: None, mode: Measured) + /// Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + /// Proof Skipped: Dmp DownwardMessageQueueHeads (max_values: None, max_size: None, mode: Measured) + pub(crate) fn subscribe_version() -> Weight { + // Proof Size summary in bytes: + // Measured: `211` + // Estimated: `3676` + // Minimum execution time: 34_319_000 picoseconds. + Weight::from_parts(34_708_000, 3676) + .saturating_add(T::DbWeight::get().reads(8)) + .saturating_add(T::DbWeight::get().writes(5)) + } + /// Storage: XcmPallet VersionNotifyTargets (r:0 w:1) + /// Proof Skipped: XcmPallet VersionNotifyTargets (max_values: None, max_size: None, mode: Measured) + pub(crate) fn unsubscribe_version() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 4_974_000 picoseconds. + Weight::from_parts(5_155_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) + } + pub(crate) fn burn_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 4_059_000 picoseconds. + Weight::from_parts(4_125_000, 0) + } + pub(crate) fn expect_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_657_000 picoseconds. + Weight::from_parts(2_741_000, 0) + } + pub(crate) fn expect_origin() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_585_000 picoseconds. + Weight::from_parts(2_653_000, 0) + } + pub(crate) fn expect_error() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_552_000 picoseconds. + Weight::from_parts(2_632_000, 0) + } + pub(crate) fn expect_transact_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_682_000 picoseconds. + Weight::from_parts(2_763_000, 0) + } + /// Storage: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) + /// Proof Skipped: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) + /// Storage: Dmp DeliveryFeeFactor (r:1 w:0) + /// Proof Skipped: Dmp DeliveryFeeFactor (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmPallet SupportedVersion (r:1 w:0) + /// Proof Skipped: XcmPallet SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmPallet VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: XcmPallet VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: XcmPallet SafeXcmVersion (r:1 w:0) + /// Proof Skipped: XcmPallet SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Dmp DownwardMessageQueues (r:1 w:1) + /// Proof Skipped: Dmp DownwardMessageQueues (max_values: None, max_size: None, mode: Measured) + /// Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + /// Proof Skipped: Dmp DownwardMessageQueueHeads (max_values: None, max_size: None, mode: Measured) + pub(crate) fn query_pallet() -> Weight { + // Proof Size summary in bytes: + // Measured: `211` + // Estimated: `3676` + // Minimum execution time: 34_316_000 picoseconds. + Weight::from_parts(34_682_000, 3676) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(4)) + } + pub(crate) fn expect_pallet() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 7_938_000 picoseconds. + Weight::from_parts(8_071_000, 0) + } + /// Storage: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) + /// Proof Skipped: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) + /// Storage: Dmp DeliveryFeeFactor (r:1 w:0) + /// Proof Skipped: Dmp DeliveryFeeFactor (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmPallet SupportedVersion (r:1 w:0) + /// Proof Skipped: XcmPallet SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: XcmPallet VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: XcmPallet VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: XcmPallet SafeXcmVersion (r:1 w:0) + /// Proof Skipped: XcmPallet SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: Dmp DownwardMessageQueues (r:1 w:1) + /// Proof Skipped: Dmp DownwardMessageQueues (max_values: None, max_size: None, mode: Measured) + /// Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) + /// Proof Skipped: Dmp DownwardMessageQueueHeads (max_values: None, max_size: None, mode: Measured) + pub(crate) fn report_transact_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `211` + // Estimated: `3676` + // Minimum execution time: 28_002_000 picoseconds. + Weight::from_parts(28_184_000, 3676) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(4)) + } + pub(crate) fn clear_transact_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_520_000 picoseconds. + Weight::from_parts(2_617_000, 0) + } + pub(crate) fn set_topic() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_506_000 picoseconds. + Weight::from_parts(2_560_000, 0) + } + pub(crate) fn clear_topic() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_503_000 picoseconds. + Weight::from_parts(2_605_000, 0) + } + pub(crate) fn set_fees_mode() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_511_000 picoseconds. + Weight::from_parts(2_597_000, 0) + } + pub(crate) fn unpaid_execution() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_617_000 picoseconds. + Weight::from_parts(2_715_000, 0) + } +} diff --git a/runtime/shibuya/src/xcm_config.rs b/runtime/shibuya/src/xcm_config.rs index 3848b0bd1a..6e7eb82a2b 100644 --- a/runtime/shibuya/src/xcm_config.rs +++ b/runtime/shibuya/src/xcm_config.rs @@ -35,10 +35,10 @@ use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ConvertedConcreteId, CurrencyAdapter, - EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, IsConcrete, NoChecking, + EnsureXcmOrigin, FungiblesAdapter, IsConcrete, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WithComputedOrigin, + SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WithComputedOrigin, WeightInfoBounds }; use xcm_executor::{ traits::{Convert as XcmConvert, JustTry}, @@ -171,7 +171,12 @@ pub type ShibuyaXcmFungibleFeeHandler = XcmFungibleFeeHandler< TreasuryAccountId, >; -pub type Weigher = FixedWeightBounds; +// pub type Weigher = FixedWeightBounds; +pub type Weigher = WeightInfoBounds< +crate::weights::xcm::ShibuyaXcmWeight, +RuntimeCall, +MaxInstructions, +>; pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { From b1050db137df2b8a717e9b9bdcfa4220cc0c43a5 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Mon, 28 Aug 2023 14:32:19 +0530 Subject: [PATCH 03/20] fmt --- primitives/src/xcm/constants.rs | 2 +- runtime/shibuya/src/lib.rs | 100 +++--- runtime/shibuya/src/weights/mod.rs | 2 +- runtime/shibuya/src/weights/xcm/mod.rs | 437 +++++++++++++------------ runtime/shibuya/src/xcm_config.rs | 14 +- 5 files changed, 278 insertions(+), 277 deletions(-) diff --git a/primitives/src/xcm/constants.rs b/primitives/src/xcm/constants.rs index 8f8cfda8c7..e5dd8fa0d9 100644 --- a/primitives/src/xcm/constants.rs +++ b/primitives/src/xcm/constants.rs @@ -16,4 +16,4 @@ // You should have received a copy of the GNU General Public License // along with Astar. If not, see . -pub const MAX_ASSETS: u32 = 64; \ No newline at end of file +pub const MAX_ASSETS: u32 = 64; diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 800c26411b..5fe6dc43af 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -1420,7 +1420,7 @@ mod benches { [pallet_xcm, PolkadotXcm] [pallet_ethereum_checked, EthereumChecked] [pallet_xvm, Xvm] - [pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::] + [pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::] ); } @@ -1911,73 +1911,73 @@ impl_runtime_apis! { use frame_support::traits::WhitelistedStorageKeys; impl pallet_xcm_benchmarks::Config for Runtime { - type XcmConfig = XcmConfig; - type AccountIdConverter = LocationToAccountId; - fn valid_destination() -> Result { - let valid_destination: MultiLocation = Junction::AccountId32 { + type XcmConfig = XcmConfig; + type AccountIdConverter = LocationToAccountId; + fn valid_destination() -> Result { + let valid_destination: MultiLocation = Junction::AccountId32 { network: None, id: [0u8; 32], } .into(); - + Ok(valid_destination) - } - fn worst_case_holding(_depositable_count: u32) -> MultiAssets { - let assets: Vec = vec![MultiAsset { + } + fn worst_case_holding(_depositable_count: u32) -> MultiAssets { + let assets: Vec = vec![MultiAsset { id: Concrete(MultiLocation::parent()), fun: Fungible(u128::MAX), }]; assets.into() - } + } } - impl pallet_xcm_benchmarks::generic::Config for Runtime { - type RuntimeCall = RuntimeCall; + impl pallet_xcm_benchmarks::generic::Config for Runtime { + type RuntimeCall = RuntimeCall; - fn worst_case_response() -> (u64, Response) { + fn worst_case_response() -> (u64, Response) { // not sure what will be the worst case for Response // either `Assets(MultiAssets)` or `PalletsInfo(BoundedVec)` // in either case, what will be the worst case? - (0u64, Response::Version(Default::default())) - } + (0u64, Response::Version(Default::default())) + } - fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> { - // Shibuya doesn't support asset exchanges - Err(BenchmarkError::Skip) - } + fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> { + // Shibuya doesn't support asset exchanges + Err(BenchmarkError::Skip) + } - fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> { - // The XCM executor of Shibuya doesn't have a configured `UniversalAliases` - Err(BenchmarkError::Skip) - } + fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> { + // The XCM executor of Shibuya doesn't have a configured `UniversalAliases` + Err(BenchmarkError::Skip) + } - fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> { + fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> { // 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. - Ok((ShibuyaLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) - } - - fn subscribe_origin() -> Result { - Ok(ShibuyaLocation::get()) - } - - 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)) - } - - fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> { - // Shibuya doesn't support asset locking - Err(BenchmarkError::Skip) - } - - fn export_message_origin_and_destination( - ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> { - // Shibuya doesn't support exporting messages - Err(BenchmarkError::Skip) - } - } + // and included in the final weight calculation. So this is just the overhead of submitting + // a noop call. + Ok((ShibuyaLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) + } + + fn subscribe_origin() -> Result { + Ok(ShibuyaLocation::get()) + } + + 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)) + } + + fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> { + // Shibuya doesn't support asset locking + Err(BenchmarkError::Skip) + } + + fn export_message_origin_and_destination( + ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> { + // Shibuya doesn't support exporting messages + Err(BenchmarkError::Skip) + } + } let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); diff --git a/runtime/shibuya/src/weights/mod.rs b/runtime/shibuya/src/weights/mod.rs index c82a93d72a..723fc93b59 100644 --- a/runtime/shibuya/src/weights/mod.rs +++ b/runtime/shibuya/src/weights/mod.rs @@ -17,4 +17,4 @@ // along with Astar. If not, see . pub mod pallet_assets; -pub mod xcm; \ No newline at end of file +pub mod xcm; diff --git a/runtime/shibuya/src/weights/xcm/mod.rs b/runtime/shibuya/src/weights/xcm/mod.rs index 0efb9fdc13..01f852485c 100644 --- a/runtime/shibuya/src/weights/xcm/mod.rs +++ b/runtime/shibuya/src/weights/xcm/mod.rs @@ -20,240 +20,241 @@ mod pallet_xcm_benchmarks_generic; use crate::Runtime; use frame_support::weights::Weight; use sp_std::prelude::*; -use xcm::{latest::{prelude::*,Weight as XCMWeight}, DoubleEncoded}; +use xcm::{ + latest::{prelude::*, Weight as XCMWeight}, + DoubleEncoded, +}; -use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; -use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; use astar_primitives::xcm::constants::MAX_ASSETS; use core::cmp::min; +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) -> XCMWeight; + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } trait WeighMultiAssetsFilter { - fn weigh_multi_assets_filter(&self, weight: Weight) -> XCMWeight; + fn weigh_multi_assets_filter(&self, weight: Weight) -> XCMWeight; } impl WeighMultiAssetsFilter for MultiAssetFilter { - fn weigh_multi_assets_filter(&self, weight: Weight) -> XCMWeight { - match self { - Self::Definite(assets) => { - weight.saturating_mul(assets.inner().into_iter().count() as u64) - } - Self::Wild(AllCounted(count) | AllOfCounted { count, .. }) => { - weight.saturating_mul(min(MAX_ASSETS, *count) as u64) - } - Self::Wild(All | AllOf { .. }) => weight.saturating_mul(MAX_ASSETS as u64), - } - } + fn weigh_multi_assets_filter(&self, weight: Weight) -> XCMWeight { + match self { + Self::Definite(assets) => { + weight.saturating_mul(assets.inner().into_iter().count() as u64) + } + Self::Wild(AllCounted(count) | AllOfCounted { count, .. }) => { + weight.saturating_mul(min(MAX_ASSETS, *count) as u64) + } + Self::Wild(All | AllOf { .. }) => weight.saturating_mul(MAX_ASSETS as u64), + } + } } impl WeighMultiAssets for MultiAssets { - fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { - weight.saturating_mul(self.inner().into_iter().count() as u64) - } + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { + weight.saturating_mul(self.inner().into_iter().count() as u64) + } } pub struct ShibuyaXcmWeight(core::marker::PhantomData); impl XcmWeightInfo for ShibuyaXcmWeight { - fn withdraw_asset(assets: &MultiAssets) -> XCMWeight { - assets.inner().iter().fold(Weight::zero(), |acc, asset| { - acc.saturating_add(XcmFungibleWeight::::withdraw_asset()) - }) - } - // Currently there is no trusted reserve - fn reserve_asset_deposited(_assets: &MultiAssets) -> XCMWeight { - XcmFungibleWeight::::reserve_asset_deposited() - } - 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: &Weight, - _querier: &Option, - ) -> XCMWeight { - XcmGeneric::::query_response() - } - fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> XCMWeight { - assets.inner().iter().fold(Weight::zero(), |acc, _asset| { - acc.saturating_add(XcmFungibleWeight::::transfer_asset()) - }) - } - fn transfer_reserve_asset( - assets: &MultiAssets, - _dest: &MultiLocation, - _xcm: &Xcm<()>, - ) -> XCMWeight { - assets.inner().iter().fold(Weight::zero(), |acc, _asset| { - acc.saturating_add(XcmFungibleWeight::::transfer_reserve_asset()) - }) - } - fn transact( - _origin_type: &OriginKind, - _require_weight_at_most: &Weight, - _call: &DoubleEncoded, - ) -> XCMWeight { - XcmGeneric::::transact() - } - fn hrmp_new_channel_open_request( - _sender: &u32, - _max_message_size: &u32, - _max_capacity: &u32, - ) -> XCMWeight { - // XCM Executor does not currently support HRMP channel operations - Weight::MAX - } - fn hrmp_channel_accepted(_recipient: &u32) -> XCMWeight { - // XCM Executor does not currently support HRMP channel operations - Weight::MAX - } - fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> XCMWeight { - // XCM Executor does not currently support HRMP channel operations - Weight::MAX - } - fn clear_origin() -> XCMWeight { - XcmGeneric::::clear_origin() - } - fn descend_origin(_who: &InteriorMultiLocation) -> XCMWeight { - XcmGeneric::::descend_origin() - } - fn report_error(_query_response_info: &QueryResponseInfo) -> XCMWeight { - XcmGeneric::::report_error() - } - fn deposit_asset(assets: &MultiAssetFilter, _dest: &MultiLocation) -> XCMWeight { - assets.weigh_multi_assets_filter(XcmFungibleWeight::::deposit_asset()) - } - fn deposit_reserve_asset( - assets: &MultiAssetFilter, - _dest: &MultiLocation, - _xcm: &Xcm<()>, - ) -> XCMWeight { - assets.weigh_multi_assets_filter(XcmFungibleWeight::::deposit_reserve_asset()) - } - fn exchange_asset( - _give: &MultiAssetFilter, - _receive: &MultiAssets, - _maximal: &bool, - ) -> XCMWeight { - Weight::MAX - } - fn initiate_reserve_withdraw( - _assets: &MultiAssetFilter, - _reserve: &MultiLocation, - _xcm: &Xcm<()>, - ) -> XCMWeight { - // This is not correct. initiate reserve withdraw does not to that many db reads - // the only thing it does based on number of assets is a take from a local variable - //assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) - XcmGeneric::::initiate_reserve_withdraw() - } - fn initiate_teleport( - _assets: &MultiAssetFilter, - _dest: &MultiLocation, - _xcm: &Xcm<()>, - ) -> XCMWeight { - XcmFungibleWeight::::initiate_teleport() - } - fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight { - XcmGeneric::::report_holding() - } - fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> XCMWeight { - XcmGeneric::::buy_execution() - } - fn refund_surplus() -> XCMWeight { - XcmGeneric::::refund_surplus() - } - fn set_error_handler(_xcm: &Xcm) -> XCMWeight { - XcmGeneric::::set_error_handler() - } - fn set_appendix(_xcm: &Xcm) -> XCMWeight { - XcmGeneric::::set_appendix() - } - fn clear_error() -> XCMWeight { - XcmGeneric::::clear_error() - } - fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> XCMWeight { - XcmGeneric::::claim_asset() - } - fn trap(_code: &u64) -> XCMWeight { - XcmGeneric::::trap() - } - fn subscribe_version(_query_id: &QueryId, _max_response_weight: &Weight) -> XCMWeight { - XcmGeneric::::subscribe_version() - } - fn unsubscribe_version() -> XCMWeight { - XcmGeneric::::unsubscribe_version() - } - fn burn_asset(assets: &MultiAssets) -> Weight { - assets.weigh_multi_assets(XcmGeneric::::burn_asset()) - } - fn expect_asset(assets: &MultiAssets) -> Weight { - assets.weigh_multi_assets(XcmGeneric::::expect_asset()) - } - fn expect_origin(_origin: &Option) -> Weight { - XcmGeneric::::expect_origin() - } - fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight { - XcmGeneric::::expect_error() - } - fn expect_transact_status(_transact_status: &MaybeErrorCode) -> Weight { - XcmGeneric::::expect_transact_status() - } - fn query_pallet(_module_name: &Vec, _response_info: &QueryResponseInfo) -> Weight { - XcmGeneric::::query_pallet() - } - fn expect_pallet( - _index: &u32, - _name: &Vec, - _module_name: &Vec, - _crate_major: &u32, - _min_crate_minor: &u32, - ) -> Weight { - XcmGeneric::::expect_pallet() - } - fn report_transact_status(_response_info: &QueryResponseInfo) -> Weight { - XcmGeneric::::report_transact_status() - } - fn clear_transact_status() -> Weight { - XcmGeneric::::clear_transact_status() - } - fn universal_origin(_: &Junction) -> Weight { - Weight::MAX - } - fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight { - Weight::MAX - } - fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { - Weight::MAX - } - fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { - Weight::MAX - } - fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight { - Weight::MAX - } - fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight { - Weight::MAX - } - fn set_fees_mode(_: &bool) -> Weight { - XcmGeneric::::set_fees_mode() - } - fn set_topic(_topic: &[u8; 32]) -> Weight { - XcmGeneric::::set_topic() - } - fn clear_topic() -> Weight { - XcmGeneric::::clear_topic() - } - fn alias_origin(_: &MultiLocation) -> Weight { - // XCM Executor does not currently support alias origin operations - Weight::MAX - } - fn unpaid_execution(_: &WeightLimit, _: &Option) -> Weight { - XcmGeneric::::unpaid_execution() - } + fn withdraw_asset(assets: &MultiAssets) -> XCMWeight { + assets.inner().iter().fold(Weight::zero(), |acc, asset| { + acc.saturating_add(XcmFungibleWeight::::withdraw_asset()) + }) + } + // Currently there is no trusted reserve + fn reserve_asset_deposited(_assets: &MultiAssets) -> XCMWeight { + XcmFungibleWeight::::reserve_asset_deposited() + } + 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: &Weight, + _querier: &Option, + ) -> XCMWeight { + XcmGeneric::::query_response() + } + fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> XCMWeight { + assets.inner().iter().fold(Weight::zero(), |acc, _asset| { + acc.saturating_add(XcmFungibleWeight::::transfer_asset()) + }) + } + fn transfer_reserve_asset( + assets: &MultiAssets, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> XCMWeight { + assets.inner().iter().fold(Weight::zero(), |acc, _asset| { + acc.saturating_add(XcmFungibleWeight::::transfer_reserve_asset()) + }) + } + fn transact( + _origin_type: &OriginKind, + _require_weight_at_most: &Weight, + _call: &DoubleEncoded, + ) -> XCMWeight { + XcmGeneric::::transact() + } + fn hrmp_new_channel_open_request( + _sender: &u32, + _max_message_size: &u32, + _max_capacity: &u32, + ) -> XCMWeight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn hrmp_channel_accepted(_recipient: &u32) -> XCMWeight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> XCMWeight { + // XCM Executor does not currently support HRMP channel operations + Weight::MAX + } + fn clear_origin() -> XCMWeight { + XcmGeneric::::clear_origin() + } + fn descend_origin(_who: &InteriorMultiLocation) -> XCMWeight { + XcmGeneric::::descend_origin() + } + fn report_error(_query_response_info: &QueryResponseInfo) -> XCMWeight { + XcmGeneric::::report_error() + } + fn deposit_asset(assets: &MultiAssetFilter, _dest: &MultiLocation) -> XCMWeight { + assets.weigh_multi_assets_filter(XcmFungibleWeight::::deposit_asset()) + } + fn deposit_reserve_asset( + assets: &MultiAssetFilter, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> XCMWeight { + assets.weigh_multi_assets_filter(XcmFungibleWeight::::deposit_reserve_asset()) + } + fn exchange_asset( + _give: &MultiAssetFilter, + _receive: &MultiAssets, + _maximal: &bool, + ) -> XCMWeight { + Weight::MAX + } + fn initiate_reserve_withdraw( + _assets: &MultiAssetFilter, + _reserve: &MultiLocation, + _xcm: &Xcm<()>, + ) -> XCMWeight { + // This is not correct. initiate reserve withdraw does not to that many db reads + // the only thing it does based on number of assets is a take from a local variable + //assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) + XcmGeneric::::initiate_reserve_withdraw() + } + fn initiate_teleport( + _assets: &MultiAssetFilter, + _dest: &MultiLocation, + _xcm: &Xcm<()>, + ) -> XCMWeight { + XcmFungibleWeight::::initiate_teleport() + } + fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight { + XcmGeneric::::report_holding() + } + fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> XCMWeight { + XcmGeneric::::buy_execution() + } + fn refund_surplus() -> XCMWeight { + XcmGeneric::::refund_surplus() + } + fn set_error_handler(_xcm: &Xcm) -> XCMWeight { + XcmGeneric::::set_error_handler() + } + fn set_appendix(_xcm: &Xcm) -> XCMWeight { + XcmGeneric::::set_appendix() + } + fn clear_error() -> XCMWeight { + XcmGeneric::::clear_error() + } + fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> XCMWeight { + XcmGeneric::::claim_asset() + } + fn trap(_code: &u64) -> XCMWeight { + XcmGeneric::::trap() + } + fn subscribe_version(_query_id: &QueryId, _max_response_weight: &Weight) -> XCMWeight { + XcmGeneric::::subscribe_version() + } + fn unsubscribe_version() -> XCMWeight { + XcmGeneric::::unsubscribe_version() + } + fn burn_asset(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmGeneric::::burn_asset()) + } + fn expect_asset(assets: &MultiAssets) -> Weight { + assets.weigh_multi_assets(XcmGeneric::::expect_asset()) + } + fn expect_origin(_origin: &Option) -> Weight { + XcmGeneric::::expect_origin() + } + fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight { + XcmGeneric::::expect_error() + } + fn expect_transact_status(_transact_status: &MaybeErrorCode) -> Weight { + XcmGeneric::::expect_transact_status() + } + fn query_pallet(_module_name: &Vec, _response_info: &QueryResponseInfo) -> Weight { + XcmGeneric::::query_pallet() + } + fn expect_pallet( + _index: &u32, + _name: &Vec, + _module_name: &Vec, + _crate_major: &u32, + _min_crate_minor: &u32, + ) -> Weight { + XcmGeneric::::expect_pallet() + } + fn report_transact_status(_response_info: &QueryResponseInfo) -> Weight { + XcmGeneric::::report_transact_status() + } + fn clear_transact_status() -> Weight { + XcmGeneric::::clear_transact_status() + } + fn universal_origin(_: &Junction) -> Weight { + Weight::MAX + } + fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight { + Weight::MAX + } + fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { + Weight::MAX + } + fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { + Weight::MAX + } + fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight { + Weight::MAX + } + fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight { + Weight::MAX + } + fn set_fees_mode(_: &bool) -> Weight { + XcmGeneric::::set_fees_mode() + } + fn set_topic(_topic: &[u8; 32]) -> Weight { + XcmGeneric::::set_topic() + } + fn clear_topic() -> Weight { + XcmGeneric::::clear_topic() + } + fn alias_origin(_: &MultiLocation) -> Weight { + // XCM Executor does not currently support alias origin operations + Weight::MAX + } + fn unpaid_execution(_: &WeightLimit, _: &Option) -> Weight { + XcmGeneric::::unpaid_execution() + } } - - diff --git a/runtime/shibuya/src/xcm_config.rs b/runtime/shibuya/src/xcm_config.rs index 6e7eb82a2b..e24dd575d3 100644 --- a/runtime/shibuya/src/xcm_config.rs +++ b/runtime/shibuya/src/xcm_config.rs @@ -35,10 +35,10 @@ use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ConvertedConcreteId, CurrencyAdapter, - EnsureXcmOrigin, FungiblesAdapter, IsConcrete, NoChecking, - ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WithComputedOrigin, WeightInfoBounds + EnsureXcmOrigin, FungiblesAdapter, IsConcrete, NoChecking, ParentAsSuperuser, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + UsingComponents, WeightInfoBounds, WithComputedOrigin, }; use xcm_executor::{ traits::{Convert as XcmConvert, JustTry}, @@ -173,9 +173,9 @@ pub type ShibuyaXcmFungibleFeeHandler = XcmFungibleFeeHandler< // pub type Weigher = FixedWeightBounds; pub type Weigher = WeightInfoBounds< -crate::weights::xcm::ShibuyaXcmWeight, -RuntimeCall, -MaxInstructions, + crate::weights::xcm::ShibuyaXcmWeight, + RuntimeCall, + MaxInstructions, >; pub struct XcmConfig; From ec64063ae980695b6830f6cf00a8800b04b3203e Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Mon, 28 Aug 2023 14:32:41 +0530 Subject: [PATCH 04/20] taplo --- runtime/shibuya/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index 6de9b11526..94f0f9e312 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -259,7 +259,7 @@ runtime-benchmarks = [ "orml-xtokens/runtime-benchmarks", "astar-primitives/runtime-benchmarks", "pallet-assets/runtime-benchmarks", - "pallet-xcm-benchmarks/runtime-benchmarks" + "pallet-xcm-benchmarks/runtime-benchmarks", ] try-runtime = [ "fp-self-contained/try-runtime", From 0cfbbd5094068b798d998a816df4c8cff6f9469e Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Mon, 28 Aug 2023 14:42:53 +0530 Subject: [PATCH 05/20] header fix --- runtime/shibuya/src/weights/xcm/mod.rs | 12 +++++++----- .../weights/xcm/pallet_xcm_benchmarks_fungible.rs | 12 +++++++----- .../src/weights/xcm/pallet_xcm_benchmarks_generic.rs | 12 +++++++----- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/runtime/shibuya/src/weights/xcm/mod.rs b/runtime/shibuya/src/weights/xcm/mod.rs index 01f852485c..ce7c6112e1 100644 --- a/runtime/shibuya/src/weights/xcm/mod.rs +++ b/runtime/shibuya/src/weights/xcm/mod.rs @@ -1,18 +1,20 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. -// Polkadot is free software: you can redistribute it and/or modify +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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, +// Astar 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 Astar. If not, see . mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; diff --git a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs index 5aa2a35391..92258dacbd 100644 --- a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs @@ -1,18 +1,20 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. -// Polkadot is free software: you can redistribute it and/or modify +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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, +// Astar 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 Astar. If not, see . //! Autogenerated weights for `pallet_xcm_benchmarks::fungible` //! diff --git a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index 0c411d32af..2dbdcb8e91 100644 --- a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -1,18 +1,20 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. -// Polkadot is free software: you can redistribute it and/or modify +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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, +// Astar 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 Astar. If not, see . //! Autogenerated weights for `pallet_xcm_benchmarks::generic` //! From 78b5a2be1f8bb1a794e1913c37e4be5c5e7b6968 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Mon, 28 Aug 2023 15:39:44 +0530 Subject: [PATCH 06/20] warnings fix --- runtime/shibuya/src/weights/xcm/mod.rs | 4 ++-- .../src/weights/xcm/pallet_xcm_benchmarks_generic.rs | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/runtime/shibuya/src/weights/xcm/mod.rs b/runtime/shibuya/src/weights/xcm/mod.rs index ce7c6112e1..fd7e19e9e6 100644 --- a/runtime/shibuya/src/weights/xcm/mod.rs +++ b/runtime/shibuya/src/weights/xcm/mod.rs @@ -63,7 +63,7 @@ impl WeighMultiAssets for MultiAssets { pub struct ShibuyaXcmWeight(core::marker::PhantomData); impl XcmWeightInfo for ShibuyaXcmWeight { fn withdraw_asset(assets: &MultiAssets) -> XCMWeight { - assets.inner().iter().fold(Weight::zero(), |acc, asset| { + assets.inner().iter().fold(Weight::zero(), |acc, _asset| { acc.saturating_add(XcmFungibleWeight::::withdraw_asset()) }) } @@ -153,7 +153,7 @@ impl XcmWeightInfo for ShibuyaXcmWeight { // This is not correct. initiate reserve withdraw does not to that many db reads // the only thing it does based on number of assets is a take from a local variable //assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) - XcmGeneric::::initiate_reserve_withdraw() + XcmFungibleWeight::::initiate_reserve_withdraw() } fn initiate_teleport( _assets: &MultiAssetFilter, diff --git a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index 2dbdcb8e91..fa5e9969c7 100644 --- a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -75,15 +75,6 @@ impl WeightInfo { .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) } - pub(crate) fn initiate_reserve_withdraw() -> Weight { - // Proof Size summary in bytes: - // Measured: `145` - // Estimated: `10130` - // Minimum execution time: 713_056_000 picoseconds. - Weight::from_parts(715_975_000, 10130) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } pub(crate) fn buy_execution() -> Weight { // Proof Size summary in bytes: From e350c4f19aa2e16ed2d3d1700b237093a54372f9 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Mon, 16 Oct 2023 19:55:01 +0530 Subject: [PATCH 07/20] add astar-xcm-benchmarks --- Cargo.lock | 26 +- Cargo.toml | 1 + pallets/astar-xcm-benchmarks/Cargo.toml | 58 ++ .../src/fungible/benchmarking.rs | 250 ++++++++ .../astar-xcm-benchmarks/src/fungible/mock.rs | 220 ++++++++ .../astar-xcm-benchmarks/src/fungible/mod.rs | 48 ++ .../src/generic/benchmarking.rs | 532 ++++++++++++++++++ .../astar-xcm-benchmarks/src/generic/mock.rs | 249 ++++++++ .../astar-xcm-benchmarks/src/generic/mod.rs | 92 +++ pallets/astar-xcm-benchmarks/src/lib.rs | 113 ++++ pallets/astar-xcm-benchmarks/src/mock.rs | 73 +++ primitives/src/xcm/constants.rs | 19 - primitives/src/xcm/mod.rs | 5 +- runtime/astar/src/xcm_config.rs | 2 +- runtime/shibuya/Cargo.toml | 4 +- runtime/shibuya/src/lib.rs | 68 ++- runtime/shibuya/src/weights/xcm/mod.rs | 4 +- runtime/shibuya/src/xcm_config.rs | 2 +- runtime/shiden/src/xcm_config.rs | 2 +- 19 files changed, 1719 insertions(+), 49 deletions(-) create mode 100644 pallets/astar-xcm-benchmarks/Cargo.toml create mode 100644 pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs create mode 100644 pallets/astar-xcm-benchmarks/src/fungible/mock.rs create mode 100644 pallets/astar-xcm-benchmarks/src/fungible/mod.rs create mode 100644 pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs create mode 100644 pallets/astar-xcm-benchmarks/src/generic/mock.rs create mode 100644 pallets/astar-xcm-benchmarks/src/generic/mod.rs create mode 100644 pallets/astar-xcm-benchmarks/src/lib.rs create mode 100644 pallets/astar-xcm-benchmarks/src/mock.rs delete mode 100644 primitives/src/xcm/constants.rs diff --git a/Cargo.lock b/Cargo.lock index 8b1a46d14e..87fd328a2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -626,6 +626,30 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "astar-xcm-benchmarks" +version = "0.1.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-assets", + "pallet-balances", + "pallet-xcm 0.9.40", + "pallet-xcm-benchmarks", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "xcm", + "xcm-builder", + "xcm-executor", +] + [[package]] name = "async-channel" version = "1.9.0" @@ -12354,6 +12378,7 @@ version = "5.17.0" dependencies = [ "array-bytes 6.1.0", "astar-primitives", + "astar-xcm-benchmarks", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -12428,7 +12453,6 @@ dependencies = [ "pallet-vesting", "pallet-xc-asset-config", "pallet-xcm 0.9.40", - "pallet-xcm-benchmarks", "pallet-xvm", "parachain-info", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 5f512c54bc..6438b631f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -277,6 +277,7 @@ pallet-dapps-staking = { path = "./pallets/dapps-staking", default-features = fa pallet-xc-asset-config = { path = "./pallets/xc-asset-config", default-features = false } pallet-xvm = { path = "./pallets/xvm", default-features = false } pallet-xcm = { path = "./pallets/pallet-xcm", default-features = false } +astar-xcm-benchmarks = { path = "./pallets/astar-xcm-benchmarks", default-features = false } pallet-ethereum-checked = { path = "./pallets/ethereum-checked", default-features = false } astar-primitives = { path = "./primitives", default-features = false } diff --git a/pallets/astar-xcm-benchmarks/Cargo.toml b/pallets/astar-xcm-benchmarks/Cargo.toml new file mode 100644 index 0000000000..fabc6ab3a0 --- /dev/null +++ b/pallets/astar-xcm-benchmarks/Cargo.toml @@ -0,0 +1,58 @@ +[package] +name = "astar-xcm-benchmarks" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +log = { workspace = true } +serde = { workspace = true, optional = true } + +# Substrate +frame-support = { workspace = true, default-features = false } +frame-system = { workspace = true } +parity-scale-codec = { workspace = true, features = ["derive"] } +scale-info = { workspace = true, features = ["derive"] } +sp-std = { workspace = true } + +# Polkadot / XCM +pallet-xcm-benchmarks = { workspace = true } +sp-io = { workspace = true } +sp-runtime = { workspace = true } +xcm = { workspace = true } +xcm-builder = { workspace = true } +xcm-executor = { workspace = true } + +# Benchmarks +frame-benchmarking = { workspace = true, optional = true } + +[dev-dependencies] +pallet-assets = { workspace = true } +pallet-balances = { workspace = true } +pallet-xcm = { workspace = true } +sp-core = { workspace = true } + +[features] +default = ["std", "runtime-benchmarks"] +std = [ + "frame-benchmarking/std", + "frame-support/std", + "frame-system/std", + "parity-scale-codec/std", + "sp-std/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm/std", + "sp-io/std", + "sp-runtime/std", +] + +runtime-benchmarks = [ + "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", + "frame-benchmarking", + "frame-system/runtime-benchmarks", + "frame-support/runtime-benchmarks", +] diff --git a/pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs new file mode 100644 index 0000000000..fbfead2c27 --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs @@ -0,0 +1,250 @@ +// Copyright (C) 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(0); + let asset = T::get_multi_asset(); + + >::deposit_asset( + &asset, + &sender_location, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).unwrap(); + // check the assets of origin. + assert!(!T::TransactAsset::balance(&sender_account).is_zero()); + + let mut executor = new_executor::(sender_location); + executor.set_holding(worst_case_holding.into()); + let instruction = Instruction::>::WithdrawAsset(vec![asset.clone()].into()); + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(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, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).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.bench_process(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, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).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.bench_process(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 + } + + 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.bench_process(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(1); + + // 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.set_holding(holding.into()); + let instruction = Instruction::>::DepositAsset { + assets: asset.into(), + beneficiary: dest_location, + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(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(1); + + // 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.set_holding(holding.into()); + let instruction = Instruction::>::DepositReserveAsset { + assets: asset.into(), + dest: dest_location, + xcm: Xcm::new(), + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(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(0); + + // Add our asset to the holding. + holding.push(asset.clone()); + + // Checked account starts at zero + assert!(T::CheckedAccount::get().map_or(true, |(c, _)| T::TransactAsset::balance(&c).is_zero())); + + let mut executor = new_executor::(Default::default()); + executor.set_holding(holding.into()); + let instruction = Instruction::>::InitiateTeleport { + assets: asset.into(), + dest: T::valid_destination()?, + xcm: Xcm::new(), + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + if let Some((checked_account, _)) = T::CheckedAccount::get() { + // teleport checked account should have received some asset. + assert!(!T::TransactAsset::balance(&checked_account).is_zero()); + } + } + + impl_benchmark_test_suite!( + Pallet, + crate::fungible::mock::new_test_ext(), + crate::fungible::mock::Test + ); +} diff --git a/pallets/astar-xcm-benchmarks/src/fungible/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/mock.rs new file mode 100644 index 0000000000..fa867a43b7 --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/fungible/mock.rs @@ -0,0 +1,220 @@ +// Copyright (C) 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::{ConstU32, Everything, Nothing}, + weights::Weight, +}; +use sp_core::H256; +use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; +use xcm::latest::prelude::*; +use xcm_builder::{AllowUnpaidExecutionFrom, MintLocation}; + +type Block = frame_system::mocking::MockBlock; + +// For testing the pallet, we construct a mock runtime. +frame_support::construct_runtime!( + pub enum Test + { + 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(Weight::from_parts(1024, u64::MAX)); +} +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type RuntimeOrigin = RuntimeOrigin; + type Nonce = u64; + type Hash = H256; + type RuntimeCall = RuntimeCall; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + 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 = 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 RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type RuntimeHoldReason = RuntimeHoldReason; + type FreezeIdentifier = (); + type MaxHolds = ConstU32<0>; + type MaxFreezes = ConstU32<0>; +} + +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, + CheckingAccount, +>; + +parameter_types! { + /// Maximum number of instructions in a single XCM fragment. A sanity check against weight + /// calculations getting too crazy. + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = DevNull; + type AssetTransactor = AssetTransactor; + type OriginConverter = (); + type IsReserve = (); + type IsTeleporter = TrustedTeleporters; + type UniversalLocation = UniversalLocation; + type Barrier = AllowUnpaidExecutionFrom; + type Weigher = xcm_builder::FixedWeightBounds; + type Trader = xcm_builder::FixedRateOfFungible; + type ResponseHandler = DevNull; + type AssetTrap = (); + type AssetLocker = (); + type AssetExchanger = (); + type AssetClaims = (); + type SubscriptionService = (); + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; +} + +impl crate::Config for Test { + type XcmConfig = XcmConfig; + type AccountIdConverter = AccountIdConverter; + fn valid_destination() -> Result { + let valid_destination: MultiLocation = X1(AccountId32 { + network: None, + id: [0u8; 32], + }) + .into(); + + Ok(valid_destination) + } + fn worst_case_holding(depositable_count: u32) -> MultiAssets { + crate::mock_worst_case_holding( + depositable_count, + ::MaxAssetsIntoHolding::get(), + ) + } +} + +pub type TrustedTeleporters = (xcm_builder::Case,); + +parameter_types! { + pub const CheckingAccount: Option<(u64, MintLocation)> = Some((100, MintLocation::Local)); + pub const ChildTeleporter: MultiLocation = Parachain(1000).into_location(); + pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( + ChildTeleporter::get(), + MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(100) }, + )); + pub const TeleportConcreteFungible: (MultiAssetFilter, MultiLocation) = + (Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get()); + pub const ReserveConcreteFungible: (MultiAssetFilter, MultiLocation) = + (Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get()); +} + +impl xcm_balances_benchmark::Config for Test { + type TransactAsset = Balances; + type CheckedAccount = CheckingAccount; + type TrustedTeleporter = TrustedTeleporter; + + fn get_multi_asset() -> MultiAsset { + let amount = + >::minimum_balance() as u128; + MultiAsset { + id: Concrete(Here.into()), + fun: Fungible(amount), + } + } +} + +#[cfg(feature = "runtime-benchmarks")] +pub fn new_test_ext() -> sp_io::TestExternalities { + use sp_runtime::BuildStorage; + let t = RuntimeGenesisConfig { + ..Default::default() + } + .build_storage() + .unwrap(); + sp_tracing::try_init_simple(); + t.into() +} diff --git a/pallets/astar-xcm-benchmarks/src/fungible/mod.rs b/pallets/astar-xcm-benchmarks/src/fungible/mod.rs new file mode 100644 index 0000000000..a400db9f7d --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/fungible/mod.rs @@ -0,0 +1,48 @@ +// Copyright (C) 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::*; + +#[cfg(feature = "runtime-benchmarks")] +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>; + + /// 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/astar-xcm-benchmarks/src/generic/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs new file mode 100644 index 0000000000..5f3b1f3e08 --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs @@ -0,0 +1,532 @@ +// Copyright (C) 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 frame_benchmarking::{benchmarks, BenchmarkError, BenchmarkResult}; +use frame_support::dispatch::GetDispatchInfo; +use parity_scale_codec::Encode; +use sp_std::vec; +use xcm::{ + latest::{prelude::*, MaxDispatchErrorLen, MaybeErrorCode, Weight}, + DoubleEncoded, +}; +use xcm_executor::{ExecutorError, FeesMode}; + +benchmarks! { + report_holding { + let holding = T::worst_case_holding(0); + + let mut executor = new_executor::(Default::default()); + executor.set_holding(holding.clone().into()); + + let instruction = Instruction::>::ReportHolding { + response_info: QueryResponseInfo { + destination: T::valid_destination()?, + query_id: Default::default(), + max_weight: Weight::MAX, + }, + // Worst case is looking through all holdings for every asset explicitly. + assets: Definite(holding), + }; + + let xcm = Xcm(vec![instruction]); + + } : { + executor.bench_process(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(0).into(); + + let mut executor = new_executor::(Default::default()); + executor.set_holding(holding); + + let fee_asset = Concrete(Here.into()); + + let instruction = Instruction::>::BuyExecution { + fees: (fee_asset, 100_000_000u128).into(), // should be something inside of holding + weight_limit: WeightLimit::Limited(Weight::from_parts(1u64, 64*1024)), + }; + + let xcm = Xcm(vec![instruction]); + } : { + executor.bench_process(xcm)?; + } verify { + + } + + query_response { + let mut executor = new_executor::(Default::default()); + let (query_id, response) = T::worst_case_response(); + let max_weight = Weight::MAX; + let querier: Option = Some(Here.into()); + let instruction = Instruction::QueryResponse { query_id, response, max_weight, querier }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(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, noop_call) = T::transact_origin_and_runtime_call()?; + let mut executor = new_executor::(origin); + let double_encoded_noop_call: DoubleEncoded<_> = noop_call.encode().into(); + + let instruction = Instruction::Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: noop_call.get_dispatch_info().weight, + call: double_encoded_noop_call, + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + // TODO Make the assertion configurable? + } + + refund_surplus { + let holding = T::worst_case_holding(0).into(); + let mut executor = new_executor::(Default::default()); + executor.set_holding(holding); + executor.set_total_surplus(Weight::from_parts(1337, 1337)); + executor.set_total_refunded(Weight::zero()); + + let instruction = Instruction::>::RefundSurplus; + let xcm = Xcm(vec![instruction]); + } : { + let result = executor.bench_process(xcm)?; + } verify { + assert_eq!(executor.total_surplus(), &Weight::from_parts(1337, 1337)); + assert_eq!(executor.total_refunded(), &Weight::from_parts(1337, 1337)); + } + + set_error_handler { + let mut executor = new_executor::(Default::default()); + let instruction = Instruction::>::SetErrorHandler(Xcm(vec![])); + let xcm = Xcm(vec![instruction]); + } : { + executor.bench_process(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.bench_process(xcm)?; + } verify { + assert_eq!(executor.appendix(), &Xcm(vec![])); + } + + clear_error { + let mut executor = new_executor::(Default::default()); + executor.set_error(Some((5u32, XcmError::Overflow))); + let instruction = Instruction::>::ClearError; + let xcm = Xcm(vec![instruction]); + } : { + executor.bench_process(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.bench_process(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.bench_process(xcm)?; + } verify { + assert_eq!(executor.origin(), &None); + } + + report_error { + let mut executor = new_executor::(Default::default()); + executor.set_error(Some((0u32, XcmError::Unimplemented))); + let query_id = Default::default(); + let destination = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; + let max_weight = Default::default(); + + let instruction = Instruction::ReportError(QueryResponseInfo { + query_id, destination, max_weight + }); + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(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(), + &XcmContext { + origin: Some(origin.clone()), + message_hash: [0; 32], + topic: None, + }, + ); + + // 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.bench_process(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.bench_process(xcm); + } verify { + assert!(matches!(_result, Err(ExecutorError { + xcm_error: XcmError::Trap(10), + .. + }))); + } + + 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.bench_process(xcm)?; + } verify { + assert!(::SubscriptionService::is_subscribed(&origin)); + } + + unsubscribe_version { + use xcm_executor::traits::VersionChangeNotifier; + // First we need to subscribe to notifications. + let origin = T::subscribe_origin()?; + let query_id = Default::default(); + let max_response_weight = Default::default(); + ::SubscriptionService::start( + &origin, + query_id, + max_response_weight, + &XcmContext { + origin: Some(origin.clone()), + message_hash: [0; 32], + topic: None, + }, + ).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.bench_process(xcm)?; + } verify { + assert!(!::SubscriptionService::is_subscribed(&origin)); + } + + initiate_reserve_withdraw { + let holding = T::worst_case_holding(1); + let assets_filter = MultiAssetFilter::Definite(holding.clone()); + let reserve = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; + let mut executor = new_executor::(Default::default()); + executor.set_holding(holding.into()); + let instruction = Instruction::InitiateReserveWithdraw { assets: assets_filter, reserve, xcm: Xcm(vec![]) }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(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 + } + + burn_asset { + let holding = T::worst_case_holding(0); + let assets = holding.clone(); + + let mut executor = new_executor::(Default::default()); + executor.set_holding(holding.into()); + + let instruction = Instruction::BurnAsset(assets.into()); + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + assert!(executor.holding().is_empty()); + } + + expect_asset { + let holding = T::worst_case_holding(0); + let assets = holding.clone(); + + let mut executor = new_executor::(Default::default()); + executor.set_holding(holding.into()); + + let instruction = Instruction::ExpectAsset(assets.into()); + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + // `execute` completing successfully is as good as we can check. + } + + expect_origin { + let expected_origin = Parent.into(); + let mut executor = new_executor::(Default::default()); + + let instruction = Instruction::ExpectOrigin(Some(expected_origin)); + let xcm = Xcm(vec![instruction]); + let mut _result = Ok(()); + }: { + _result = executor.bench_process(xcm); + } verify { + assert!(matches!(_result, Err(ExecutorError { + xcm_error: XcmError::ExpectationFalse, + .. + }))); + } + + expect_error { + let mut executor = new_executor::(Default::default()); + executor.set_error(Some((3u32, XcmError::Overflow))); + + let instruction = Instruction::ExpectError(None); + let xcm = Xcm(vec![instruction]); + let mut _result = Ok(()); + }: { + _result = executor.bench_process(xcm); + } verify { + assert!(matches!(_result, Err(ExecutorError { + xcm_error: XcmError::ExpectationFalse, + .. + }))); + } + + expect_transact_status { + let mut executor = new_executor::(Default::default()); + let worst_error = || -> MaybeErrorCode { + vec![0; MaxDispatchErrorLen::get() as usize].into() + }; + executor.set_transact_status(worst_error()); + + let instruction = Instruction::ExpectTransactStatus(worst_error()); + let xcm = Xcm(vec![instruction]); + let mut _result = Ok(()); + }: { + _result = executor.bench_process(xcm); + } verify { + assert!(matches!(_result, Ok(..))); + } + + query_pallet { + let query_id = Default::default(); + let destination = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; + let max_weight = Default::default(); + let mut executor = new_executor::(Default::default()); + + let instruction = Instruction::QueryPallet { + module_name: b"frame_system".to_vec(), + response_info: QueryResponseInfo { destination, query_id, max_weight }, + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 + } + + expect_pallet { + let mut executor = new_executor::(Default::default()); + + let instruction = Instruction::ExpectPallet { + index: 10, + name: b"System".to_vec(), + module_name: b"frame_system".to_vec(), + crate_major: 4, + min_crate_minor: 0, + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + // the execution succeeding is all we need to verify this xcm was successful + } + + report_transact_status { + let query_id = Default::default(); + let destination = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; + let max_weight = Default::default(); + + let mut executor = new_executor::(Default::default()); + executor.set_transact_status(b"MyError".to_vec().into()); + + let instruction = Instruction::ReportTransactStatus(QueryResponseInfo { + query_id, + destination, + max_weight, + }); + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 + } + + clear_transact_status { + let mut executor = new_executor::(Default::default()); + executor.set_transact_status(b"MyError".to_vec().into()); + + let instruction = Instruction::ClearTransactStatus; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + assert_eq!(executor.transact_status(), &MaybeErrorCode::Success); + } + + set_topic { + let mut executor = new_executor::(Default::default()); + + let instruction = Instruction::SetTopic([1; 32]); + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + assert_eq!(executor.topic(), &Some([1; 32])); + } + + clear_topic { + let mut executor = new_executor::(Default::default()); + executor.set_topic(Some([2; 32])); + + let instruction = Instruction::ClearTopic; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + assert_eq!(executor.topic(), &None); + } + + set_fees_mode { + let mut executor = new_executor::(Default::default()); + executor.set_fees_mode(FeesMode { jit_withdraw: false }); + + let instruction = Instruction::SetFeesMode { jit_withdraw: true }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + assert_eq!(executor.fees_mode(), &FeesMode { jit_withdraw: true }); + } + + unpaid_execution { + let mut executor = new_executor::(Default::default()); + executor.set_origin(Some(Here.into())); + + let instruction = Instruction::>::UnpaidExecution { + weight_limit: WeightLimit::Unlimited, + check_origin: Some(Here.into()), + }; + + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } + + exchange_asset { + } : { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + export_message { + } : { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + lock_asset { + } : { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + unlock_asset { + } : { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + note_unlockable { + } : { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + request_unlock { + } : { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + universal_origin { + } : { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + impl_benchmark_test_suite!( + Pallet, + crate::generic::mock::new_test_ext(), + crate::generic::mock::Test + ); +} diff --git a/pallets/astar-xcm-benchmarks/src/generic/mock.rs b/pallets/astar-xcm-benchmarks/src/generic/mock.rs new file mode 100644 index 0000000000..e43c311bcb --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/generic/mock.rs @@ -0,0 +1,249 @@ +// Copyright (C) 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::{ + match_types, parameter_types, + traits::{Everything, OriginTrait}, + weights::Weight, +}; +use sp_core::H256; +use sp_runtime::traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput}; +use xcm_builder::{ + test_utils::{ + Assets, TestAssetExchanger, TestAssetLocker, TestAssetTrap, TestSubscriptionService, + TestUniversalAliases, + }, + AliasForeignAccountId32, AllowUnpaidExecutionFrom, +}; +use xcm_executor::traits::ConvertOrigin; + +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test + { + 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(Weight::from_parts(1024, u64::MAX)); +} + +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type RuntimeOrigin = RuntimeOrigin; + type Nonce = u64; + type Hash = H256; + type RuntimeCall = RuntimeCall; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + 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, _: &XcmContext) -> Result<(), XcmError> { + unreachable!(); + } + + fn withdraw_asset( + _: &MultiAsset, + _: &MultiLocation, + _: Option<&XcmContext>, + ) -> Result { + unreachable!(); + } +} + +parameter_types! { + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +match_types! { + pub type OnlyParachains: impl Contains = { + MultiLocation { parents: 0, interior: X1(Parachain(_)) } + }; +} + +type Aliasers = AliasForeignAccountId32; +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = DevNull; + type AssetTransactor = NoAssetTransactor; + type OriginConverter = AlwaysSignedByDefault; + type IsReserve = AllAssetLocationsPass; + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type Barrier = AllowUnpaidExecutionFrom; + type Weigher = xcm_builder::FixedWeightBounds; + type Trader = xcm_builder::FixedRateOfFungible; + type ResponseHandler = DevNull; + type AssetTrap = TestAssetTrap; + type AssetLocker = TestAssetLocker; + type AssetExchanger = TestAssetExchanger; + type AssetClaims = TestAssetTrap; + type SubscriptionService = TestSubscriptionService; + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + // No bridges yet... + type MessageExporter = (); + type UniversalAliases = TestUniversalAliases; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Aliasers; +} + +impl crate::Config for Test { + type XcmConfig = XcmConfig; + type AccountIdConverter = AccountIdConverter; + fn valid_destination() -> Result { + let valid_destination: MultiLocation = Junction::AccountId32 { + network: None, + id: [0u8; 32], + } + .into(); + + Ok(valid_destination) + } + fn worst_case_holding(depositable_count: u32) -> MultiAssets { + crate::mock_worst_case_holding( + depositable_count, + ::MaxAssetsIntoHolding::get(), + ) + } +} + +impl generic::Config for Test { + type RuntimeCall = RuntimeCall; + + fn worst_case_response() -> (u64, Response) { + let assets: MultiAssets = (Concrete(Here.into()), 100).into(); + (0, Response::Assets(assets)) + } + + fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> { + Ok(Default::default()) + } + + fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> { + Ok((Here.into(), GlobalConsensus(ByGenesis([0; 32])))) + } + + fn transact_origin_and_runtime_call( + ) -> Result<(MultiLocation, ::RuntimeCall), BenchmarkError> { + Ok(( + Default::default(), + frame_system::Call::remark_with_event { remark: vec![] }.into(), + )) + } + + 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)) + } + + fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> { + let assets: MultiAsset = (Concrete(Here.into()), 100).into(); + Ok((Default::default(), Default::default(), assets)) + } + + fn export_message_origin_and_destination( + ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> { + // No MessageExporter in tests + Err(BenchmarkError::Skip) + } + + fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> { + let origin: MultiLocation = ( + Parachain(1), + AccountId32 { + network: None, + id: [0; 32], + }, + ) + .into(); + let target: MultiLocation = AccountId32 { + network: None, + id: [0; 32], + } + .into(); + Ok((origin, target)) + } +} + +#[cfg(feature = "runtime-benchmarks")] +pub fn new_test_ext() -> sp_io::TestExternalities { + use sp_runtime::BuildStorage; + let t = RuntimeGenesisConfig { + ..Default::default() + } + .build_storage() + .unwrap(); + sp_tracing::try_init_simple(); + t.into() +} + +pub struct AlwaysSignedByDefault(core::marker::PhantomData); +impl ConvertOrigin for AlwaysSignedByDefault +where + RuntimeOrigin: OriginTrait, + ::AccountId: Decode, +{ + fn convert_origin( + _origin: impl Into, + _kind: OriginKind, + ) -> Result { + Ok(RuntimeOrigin::signed( + ::AccountId::decode(&mut TrailingZeroInput::zeroes()) + .expect("infinite length input; no invalid inputs for type; qed"), + )) + } +} diff --git a/pallets/astar-xcm-benchmarks/src/generic/mod.rs b/pallets/astar-xcm-benchmarks/src/generic/mod.rs new file mode 100644 index 0000000000..5034dd6d0b --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/generic/mod.rs @@ -0,0 +1,92 @@ +// Copyright (C) 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 . + +pub use pallet::*; + +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; +#[cfg(test)] +mod mock; + +#[frame_support::pallet] +pub mod pallet { + use frame_benchmarking::BenchmarkError; + use frame_support::{ + dispatch::{Dispatchable, GetDispatchInfo}, + pallet_prelude::Encode, + }; + use xcm::latest::{ + InteriorMultiLocation, Junction, MultiAsset, MultiAssets, MultiLocation, NetworkId, + Response, + }; + + #[pallet::config] + pub trait Config: frame_system::Config + crate::Config { + type RuntimeCall: Dispatchable + + GetDispatchInfo + + From> + + Encode; + + /// The response which causes the most runtime weight. + fn worst_case_response() -> (u64, Response); + + /// The pair of asset collections which causes the most runtime weight if demanded to be + /// exchanged. + /// + /// The first element in the returned tuple represents the assets that are being exchanged + /// from, whereas the second element represents the assets that are being exchanged to. + /// + /// If set to `Err`, benchmarks which rely on an `exchange_asset` will be skipped. + fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError>; + + /// A `(MultiLocation, Junction)` that is one of the `UniversalAliases` configured by the XCM executor. + /// + /// If set to `Err`, benchmarks which rely on a universal alias will be skipped. + fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError>; + + /// The `MultiLocation` and `RuntimeCall` used for successful transaction XCMs. + /// + /// If set to `Err`, benchmarks which rely on a `transact_origin_and_runtime_call` will be + /// skipped. + fn transact_origin_and_runtime_call() -> Result< + ( + MultiLocation, + >::RuntimeCall, + ), + BenchmarkError, + >; + + /// A valid `MultiLocation` we can successfully subscribe to. + /// + /// If set to `Err`, 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>; + + /// Return an unlocker, owner and assets that can be locked and unlocked. + fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError>; + + /// A `(MultiLocation, NetworkId, InteriorMultiLocation)` we can successfully export message to. + /// + /// If set to `Err`, benchmarks which rely on `export_message` will be skipped. + fn export_message_origin_and_destination( + ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError>; + } + + #[pallet::pallet] + pub struct Pallet(_); +} diff --git a/pallets/astar-xcm-benchmarks/src/lib.rs b/pallets/astar-xcm-benchmarks/src/lib.rs new file mode 100644 index 0000000000..1bdd06d69f --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/lib.rs @@ -0,0 +1,113 @@ +// Copyright (C) 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 frame_benchmarking::{account, BenchmarkError}; +use parity_scale_codec::Encode; +use sp_std::prelude::*; +use xcm::latest::prelude::*; +use xcm_executor::{traits::Convert, Config as XcmConfig}; + +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: XcmConfig; + + /// 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(depositable_count: u32) -> 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 = ::RuntimeCall; +/// The asset transactor of our executor +pub type AssetTransactorOf = <::XcmConfig as XcmConfig>::AssetTransactor; +/// The call type of executor's config. Should eventually resolve to the same overarching call type. +pub type XcmCallOf = <::XcmConfig as XcmConfig>::RuntimeCall; + +pub fn mock_worst_case_holding(depositable_count: u32, max_assets: u32) -> MultiAssets { + let fungibles_amount: u128 = 100; + let holding_fungibles = max_assets / 2 - depositable_count; + let holding_non_fungibles = holding_fungibles; + (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, [0; 32]) +} + +/// 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: None, 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/astar-xcm-benchmarks/src/mock.rs b/pallets/astar-xcm-benchmarks/src/mock.rs new file mode 100644 index 0000000000..7d4a07289a --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/mock.rs @@ -0,0 +1,73 @@ +// Copyright (C) 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, traits::ContainsPair}; +use xcm::latest::Weight; + +// An xcm sender/receiver akin to > /dev/null +pub struct DevNull; +impl xcm::opaque::latest::SendXcm for DevNull { + type Ticket = (); + fn validate(_: &mut Option, _: &mut Option>) -> SendResult<()> { + Ok(((), MultiAssets::new())) + } + fn deliver(_: ()) -> Result { + Ok([0; 32]) + } +} + +impl xcm_executor::traits::OnResponse for DevNull { + fn expecting_response(_: &MultiLocation, _: u64, _: Option<&MultiLocation>) -> bool { + false + } + fn on_response( + _: &MultiLocation, + _: u64, + _: Option<&MultiLocation>, + _: Response, + _: Weight, + _: &XcmContext, + ) -> Weight { + Weight::zero() + } +} + +pub struct AccountIdConverter; +impl xcm_executor::traits::ConvertLocation for AccountIdConverter { + fn convert_location(ml: &MultiLocation) -> Option { + match ml { + MultiLocation { + parents: 0, + interior: X1(Junction::AccountId32 { id, .. }), + } => Some(::decode(&mut &*id.to_vec()).unwrap()), + _ => None, + } + } +} + +parameter_types! { + pub UniversalLocation: InteriorMultiLocation = Junction::Parachain(101).into(); + pub UnitWeightCost: Weight = Weight::from_parts(10, 10); + pub WeightPrice: (AssetId, u128, u128) = (Concrete(Here.into()), 1_000_000, 1024); +} + +pub struct AllAssetLocationsPass; +impl ContainsPair for AllAssetLocationsPass { + fn contains(_: &MultiAsset, _: &MultiLocation) -> bool { + true + } +} diff --git a/primitives/src/xcm/constants.rs b/primitives/src/xcm/constants.rs deleted file mode 100644 index e5dd8fa0d9..0000000000 --- a/primitives/src/xcm/constants.rs +++ /dev/null @@ -1,19 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later - -// Astar 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. - -// Astar 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 Astar. If not, see . - -pub const MAX_ASSETS: u32 = 64; diff --git a/primitives/src/xcm/mod.rs b/primitives/src/xcm/mod.rs index 9760a31b7f..b5cb42a89c 100644 --- a/primitives/src/xcm/mod.rs +++ b/primitives/src/xcm/mod.rs @@ -51,7 +51,10 @@ use orml_traits::location::{RelativeReserveProvider, Reserve}; use pallet_xc_asset_config::{ExecutionPaymentRate, XcAssetLocation}; -pub mod constants; +/// Max assets allowed in holding register +pub const MAX_ASSETS: u64 = 64; +/// Default Proof Size for XCM +pub const DEFAULT_PROOF_SIZE: u64 = 64 * 1024; #[cfg(test)] mod tests; diff --git a/runtime/astar/src/xcm_config.rs b/runtime/astar/src/xcm_config.rs index 5c86c9e93f..08d1dfdcce 100644 --- a/runtime/astar/src/xcm_config.rs +++ b/runtime/astar/src/xcm_config.rs @@ -137,7 +137,7 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. // For the PoV size, we estimate 64 kB per instruction - which will is once again very conservative. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, astar_primitives::xcm::DEFAULT_PROOF_SIZE); pub const MaxInstructions: u32 = 100; } diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index 94f0f9e312..49dfd5cd97 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -33,6 +33,7 @@ sp-transaction-pool = { workspace = true } sp-version = { workspace = true } # frame dependencies +astar-xcm-benchmarks = { workspace = true } frame-executive = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } @@ -70,7 +71,6 @@ pallet-transaction-payment-rpc-runtime-api = { workspace = true } pallet-treasury = { workspace = true } pallet-utility = { workspace = true } pallet-vesting = { workspace = true } -pallet-xcm-benchmarks = { workspace = true } # cumulus dependencies cumulus-pallet-aura-ext = { workspace = true } @@ -259,7 +259,7 @@ runtime-benchmarks = [ "orml-xtokens/runtime-benchmarks", "astar-primitives/runtime-benchmarks", "pallet-assets/runtime-benchmarks", - "pallet-xcm-benchmarks/runtime-benchmarks", + "astar-xcm-benchmarks/runtime-benchmarks", ] try-runtime = [ "fp-self-contained/try-runtime", diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 5fe6dc43af..b8741b6ad8 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -1420,7 +1420,7 @@ mod benches { [pallet_xcm, PolkadotXcm] [pallet_ethereum_checked, EthereumChecked] [pallet_xvm, Xvm] - [pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::] + [astar_xcm_benchmarks::generic, astar_xcm_benchmarks::generic::Pallet::] ); } @@ -1903,41 +1903,63 @@ impl_runtime_apis! { use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch, TrackedStorageKey, BenchmarkError}; use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; - use xcm_config::{XcmConfig, LocationToAccountId, ShibuyaLocation}; + use xcm_config::{XcmConfig, LocationToAccountId}; use xcm::latest::prelude::*; impl frame_system_benchmarking::Config for Runtime {} impl baseline::Config for Runtime {} use frame_support::traits::WhitelistedStorageKeys; - impl pallet_xcm_benchmarks::Config for Runtime { + impl astar_xcm_benchmarks::Config for Runtime { type XcmConfig = XcmConfig; type AccountIdConverter = LocationToAccountId; fn valid_destination() -> Result { - let valid_destination: MultiLocation = Junction::AccountId32 { - network: None, - id: [0u8; 32], - } - .into(); - - Ok(valid_destination) + Ok(MultiLocation::parent()) } fn worst_case_holding(_depositable_count: u32) -> MultiAssets { - let assets: Vec = vec![MultiAsset { - id: Concrete(MultiLocation::parent()), - fun: Fungible(u128::MAX), - }]; + const HOLDING_FUNGIBLES: u32 = 62; + let fungibles_amount: u128 = 100; + let assets = (0..HOLDING_FUNGIBLES).map(|i| { + let location: MultiLocation = GeneralIndex(i as u128).into(); + MultiAsset { + id: Concrete(location), + fun: Fungible(fungibles_amount * i as u128), + } + .into() + }) + .chain( + core::iter::once( + MultiAsset { + id: Concrete(MultiLocation::parent()), + fun: Fungible(u128::MAX) + } + ) + ) + .chain( + core::iter::once( + MultiAsset { + id: Concrete(MultiLocation::here()), + fun: Fungible(u128::MAX) + } + ) + ) + .collect::>(); assets.into() } } - impl pallet_xcm_benchmarks::generic::Config for Runtime { + impl astar_xcm_benchmarks::generic::Config for Runtime { type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { // not sure what will be the worst case for Response // either `Assets(MultiAssets)` or `PalletsInfo(BoundedVec)` // in either case, what will be the worst case? - (0u64, Response::Version(Default::default())) + let assets: Vec = vec![MultiAsset { + id: Concrete(MultiLocation::parent()), + fun: Fungible(u128::MAX), + }]; + (0u64, Response::Assets(assets.into())) + } fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> { @@ -1954,17 +1976,21 @@ impl_runtime_apis! { // 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. - Ok((ShibuyaLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into())) + Ok((MultiLocation::parent(), frame_system::Call::remark_with_event { + remark: vec![] + }.into())) } fn subscribe_origin() -> Result { - Ok(ShibuyaLocation::get()) + Ok(MultiLocation::parent()) } 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)) + let origin = MultiLocation::parent(); + let assets: MultiAssets = (Concrete(MultiLocation::parent()), 1_000u128) + .into(); + let ticket = MultiLocation { parents: 0, interior: Here }; + Ok((origin, ticket, assets)) } fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> { diff --git a/runtime/shibuya/src/weights/xcm/mod.rs b/runtime/shibuya/src/weights/xcm/mod.rs index fd7e19e9e6..1715a3fa80 100644 --- a/runtime/shibuya/src/weights/xcm/mod.rs +++ b/runtime/shibuya/src/weights/xcm/mod.rs @@ -27,7 +27,7 @@ use xcm::{ DoubleEncoded, }; -use astar_primitives::xcm::constants::MAX_ASSETS; +use astar_primitives::xcm::MAX_ASSETS; use core::cmp::min; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; @@ -47,7 +47,7 @@ impl WeighMultiAssetsFilter for MultiAssetFilter { weight.saturating_mul(assets.inner().into_iter().count() as u64) } Self::Wild(AllCounted(count) | AllOfCounted { count, .. }) => { - weight.saturating_mul(min(MAX_ASSETS, *count) as u64) + weight.saturating_mul(min(MAX_ASSETS, (*count).into()) as u64) } Self::Wild(All | AllOf { .. }) => weight.saturating_mul(MAX_ASSETS as u64), } diff --git a/runtime/shibuya/src/xcm_config.rs b/runtime/shibuya/src/xcm_config.rs index e24dd575d3..ebc08d982c 100644 --- a/runtime/shibuya/src/xcm_config.rs +++ b/runtime/shibuya/src/xcm_config.rs @@ -139,7 +139,7 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. // For the PoV size, we estimate 64 kB per instruction - which will is once again very conservative. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, astar_primitives::xcm::DEFAULT_PROOF_SIZE); pub const MaxInstructions: u32 = 100; } diff --git a/runtime/shiden/src/xcm_config.rs b/runtime/shiden/src/xcm_config.rs index 981c906c5c..9d418cb30b 100644 --- a/runtime/shiden/src/xcm_config.rs +++ b/runtime/shiden/src/xcm_config.rs @@ -139,7 +139,7 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. // For the PoV size, we estimate 64 kB per instruction - which will is once again very conservative. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, astar_primitives::xcm::DEFAULT_PROOF_SIZE); pub const MaxInstructions: u32 = 100; } From ea71a9449d0169d8ec960938cf5a9adf83e5a4a3 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Mon, 16 Oct 2023 20:01:50 +0530 Subject: [PATCH 08/20] license update --- .../src/fungible/benchmarking.rs | 13 ++++++++----- pallets/astar-xcm-benchmarks/src/fungible/mock.rs | 13 ++++++++----- pallets/astar-xcm-benchmarks/src/fungible/mod.rs | 13 ++++++++----- .../src/generic/benchmarking.rs | 14 +++++++++----- pallets/astar-xcm-benchmarks/src/generic/mock.rs | 13 ++++++++----- pallets/astar-xcm-benchmarks/src/generic/mod.rs | 13 ++++++++----- pallets/astar-xcm-benchmarks/src/lib.rs | 14 +++++++++----- pallets/astar-xcm-benchmarks/src/mock.rs | 13 ++++++++----- 8 files changed, 66 insertions(+), 40 deletions(-) diff --git a/pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs index fbfead2c27..a8b8a8cd55 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs @@ -1,19 +1,22 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later -// Polkadot is free software: you can redistribute it and/or modify +// Astar 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, +// Astar 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 Astar. If not, see . +// Copyright (C) Parity Technologies (UK) Ltd. use super::*; use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError, BenchmarkResult}; diff --git a/pallets/astar-xcm-benchmarks/src/fungible/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/mock.rs index fa867a43b7..76f5f46a7e 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/mock.rs @@ -1,19 +1,22 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later -// Polkadot is free software: you can redistribute it and/or modify +// Astar 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, +// Astar 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 Astar. If not, see . +// Copyright (C) Parity Technologies (UK) Ltd. //! A mock runtime for XCM benchmarking. use crate::{fungible as xcm_balances_benchmark, mock::*}; diff --git a/pallets/astar-xcm-benchmarks/src/fungible/mod.rs b/pallets/astar-xcm-benchmarks/src/fungible/mod.rs index a400db9f7d..1fa633681e 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/mod.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/mod.rs @@ -1,19 +1,22 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later -// Polkadot is free software: you can redistribute it and/or modify +// Astar 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, +// Astar 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 Astar. If not, see . +// Copyright (C) Parity Technologies (UK) Ltd. // Benchmarking for the `AssetTransactor` trait via `Fungible`. pub use pallet::*; diff --git a/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs index 5f3b1f3e08..4336dcd3bf 100644 --- a/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs +++ b/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs @@ -1,18 +1,22 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later -// Polkadot is free software: you can redistribute it and/or modify +// Astar 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, +// Astar 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 Astar. If not, see . + +// Copyright (C) Parity Technologies (UK) Ltd. use super::*; use crate::{new_executor, XcmCallOf}; diff --git a/pallets/astar-xcm-benchmarks/src/generic/mock.rs b/pallets/astar-xcm-benchmarks/src/generic/mock.rs index e43c311bcb..6edce1f896 100644 --- a/pallets/astar-xcm-benchmarks/src/generic/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/generic/mock.rs @@ -1,19 +1,22 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later -// Polkadot is free software: you can redistribute it and/or modify +// Astar 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, +// Astar 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 Astar. If not, see . +// Copyright (C) Parity Technologies (UK) Ltd. //! A mock runtime for XCM benchmarking. use crate::{generic, mock::*, *}; diff --git a/pallets/astar-xcm-benchmarks/src/generic/mod.rs b/pallets/astar-xcm-benchmarks/src/generic/mod.rs index 5034dd6d0b..7c00229365 100644 --- a/pallets/astar-xcm-benchmarks/src/generic/mod.rs +++ b/pallets/astar-xcm-benchmarks/src/generic/mod.rs @@ -1,19 +1,22 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later -// Polkadot is free software: you can redistribute it and/or modify +// Astar 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, +// Astar 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 Astar. If not, see . +// Copyright (C) Parity Technologies (UK) Ltd. pub use pallet::*; #[cfg(feature = "runtime-benchmarks")] diff --git a/pallets/astar-xcm-benchmarks/src/lib.rs b/pallets/astar-xcm-benchmarks/src/lib.rs index 1bdd06d69f..30df67e0ef 100644 --- a/pallets/astar-xcm-benchmarks/src/lib.rs +++ b/pallets/astar-xcm-benchmarks/src/lib.rs @@ -1,18 +1,22 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. -// Polkadot is free software: you can redistribute it and/or modify +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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, +// Astar 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 Astar. If not, see . + +// Copyright (C) Parity Technologies (UK) Ltd.ww.gnu.org/licenses/>. //! Pallet that serves no other purpose than benchmarking raw messages [`Xcm`]. diff --git a/pallets/astar-xcm-benchmarks/src/mock.rs b/pallets/astar-xcm-benchmarks/src/mock.rs index 7d4a07289a..45170bfc6d 100644 --- a/pallets/astar-xcm-benchmarks/src/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/mock.rs @@ -1,19 +1,22 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later -// Polkadot is free software: you can redistribute it and/or modify +// Astar 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, +// Astar 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 Astar. If not, see . +// Copyright (C) Parity Technologies (UK) Ltd. use crate::*; use frame_support::{parameter_types, traits::ContainsPair}; use xcm::latest::Weight; From ad2c526006ecca3c8dcb01f6db7cf00614c5e1d5 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Mon, 16 Oct 2023 21:24:41 +0530 Subject: [PATCH 09/20] .toml fix --- pallets/astar-xcm-benchmarks/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/astar-xcm-benchmarks/Cargo.toml b/pallets/astar-xcm-benchmarks/Cargo.toml index fabc6ab3a0..4d804a8844 100644 --- a/pallets/astar-xcm-benchmarks/Cargo.toml +++ b/pallets/astar-xcm-benchmarks/Cargo.toml @@ -26,7 +26,7 @@ xcm-builder = { workspace = true } xcm-executor = { workspace = true } # Benchmarks -frame-benchmarking = { workspace = true, optional = true } +frame-benchmarking = { workspace = true } [dev-dependencies] pallet-assets = { workspace = true } @@ -35,7 +35,7 @@ pallet-xcm = { workspace = true } sp-core = { workspace = true } [features] -default = ["std", "runtime-benchmarks"] +default = ["std"] std = [ "frame-benchmarking/std", "frame-support/std", @@ -52,7 +52,7 @@ std = [ runtime-benchmarks = [ "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", - "frame-benchmarking", + "frame-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "frame-support/runtime-benchmarks", ] From 5039bf7b9a8c6e9a7dbe7aca13eed339295f0a53 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Tue, 17 Oct 2023 09:38:04 +0530 Subject: [PATCH 10/20] temporary fix --- pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs | 2 +- pallets/astar-xcm-benchmarks/src/lib.rs | 3 +++ runtime/shibuya/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs index 4336dcd3bf..0a56832391 100644 --- a/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs +++ b/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs @@ -66,7 +66,7 @@ benchmarks! { let fee_asset = Concrete(Here.into()); let instruction = Instruction::>::BuyExecution { - fees: (fee_asset, 100_000_000u128).into(), // should be something inside of holding + fees: (fee_asset, 100_000_000_000u128).into(), // should be something inside of holding weight_limit: WeightLimit::Limited(Weight::from_parts(1u64, 64*1024)), }; diff --git a/pallets/astar-xcm-benchmarks/src/lib.rs b/pallets/astar-xcm-benchmarks/src/lib.rs index 30df67e0ef..4de6e2aaf2 100644 --- a/pallets/astar-xcm-benchmarks/src/lib.rs +++ b/pallets/astar-xcm-benchmarks/src/lib.rs @@ -31,6 +31,9 @@ use xcm_executor::{traits::Convert, Config as XcmConfig}; pub mod fungible; pub mod generic; +#[cfg(feature = "runtime-benchmarks")] +pub use generic::{benchmarking, Pallet}; + #[cfg(test)] mod mock; diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index b891eec371..53fcc474e5 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -1441,7 +1441,7 @@ mod benches { [pallet_xvm, Xvm] [pallet_dynamic_evm_base_fee, DynamicEvmBaseFee] [pallet_unified_accounts, UnifiedAccounts] - [astar_xcm_benchmarks::generic, astar_xcm_benchmarks::generic::Pallet::] + [astar_xcm_benchmarks, astar_xcm_benchmarks::Pallet::] ); } From a2515beeb57d4aa390f5d155d033f87d636c639e Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Thu, 19 Oct 2023 01:34:07 +0530 Subject: [PATCH 11/20] add support for fungible benchmarks --- .../src/fungible/assets/benchmarking.rs | 242 +++++++++++++++ .../src/fungible/assets/mock.rs | 276 ++++++++++++++++++ .../src/fungible/assets/mod.rs | 51 ++++ .../src/fungible/balances/benchmarking.rs | 201 +++++++++++++ .../src/fungible/{ => balances}/mock.rs | 0 .../src/fungible/balances/mod.rs | 51 ++++ .../astar-xcm-benchmarks/src/fungible/mod.rs | 33 +-- runtime/shibuya/src/lib.rs | 64 +++- 8 files changed, 881 insertions(+), 37 deletions(-) create mode 100644 pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs create mode 100644 pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs create mode 100644 pallets/astar-xcm-benchmarks/src/fungible/assets/mod.rs create mode 100644 pallets/astar-xcm-benchmarks/src/fungible/balances/benchmarking.rs rename pallets/astar-xcm-benchmarks/src/fungible/{ => balances}/mock.rs (100%) create mode 100644 pallets/astar-xcm-benchmarks/src/fungible/balances/mod.rs diff --git a/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs new file mode 100644 index 0000000000..70a92e0a58 --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs @@ -0,0 +1,242 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . + +// Copyright (C) Parity Technologies (UK) Ltd. +use super::*; +use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; +use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError, BenchmarkResult}; +use frame_support::traits::fungible::Inspect; +use sp_runtime::traits::Zero; +use sp_std::{prelude::*, vec}; +use xcm::latest::{prelude::*, Weight}; +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(0); + let asset = T::get_multi_asset(); + + >::deposit_asset( + &asset, + &sender_location, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).unwrap(); + // check the assets of origin. + assert!(!T::TransactAsset::balance(&sender_account).is_zero()); + + let mut executor = new_executor::(sender_location); + executor.set_holding(worst_case_holding.into()); + let instruction = Instruction::>::WithdrawAsset(vec![asset.clone()].into()); + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(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 mut 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, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).unwrap(); + assert!(T::TransactAsset::balance(&dest_account).is_zero()); + // reducing some assets for Existential deposit + if let Fungible(x) = asset.fun { + asset.fun = Fungible(x/10) + }; + + log::trace!( + target: "xcm::process", + "asset is {:?}",asset.clone()); + let assets: MultiAssets = vec![ asset.clone() ].into(); + log::trace!( + target: "xcm::process", + "assets is {:?}",assets.clone()); + + >::transfer_asset( + &asset, + &sender_location, + &dest_location, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).unwrap(); + let mut executor = new_executor::(sender_location); + let instruction = Instruction::TransferAsset { assets, beneficiary: dest_location }; + let xcm = Xcm(vec![instruction]); + log::trace!( + target: "xcm::process", + "destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + }: { + executor.bench_process(xcm)?; + } verify { + log::trace!( + target: "xcm::process", + "destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + } + + 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 mut asset = T::get_multi_asset(); + >::deposit_asset( + &asset, + &sender_location, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).unwrap(); + + assert!(T::TransactAsset::balance(&dest_account).is_zero()); + + if let Fungible(x) = asset.fun { + asset.fun = Fungible(x/10) + }; + + >::transfer_asset( + &asset, + &sender_location, + &dest_location, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).unwrap(); + let assets: MultiAssets = vec![ asset ].into(); + let mut executor = new_executor::(sender_location); + let instruction = Instruction::TransferReserveAsset { + assets, + dest: dest_location, + xcm: Xcm::new() + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + } + + receive_teleported_asset { + } : { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + deposit_asset { + let asset = T::get_multi_asset(); + let mut holding = T::worst_case_holding(1); + + // 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.set_holding(holding.into()); + let instruction = Instruction::>::DepositAsset { + assets: asset.into(), + beneficiary: dest_location, + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(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(1); + + // 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.set_holding(holding.into()); + let instruction = Instruction::>::DepositReserveAsset { + assets: asset.into(), + dest: dest_location, + xcm: Xcm::new(), + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + // dest should have received some asset. + assert!(!T::TransactAsset::balance(&dest_account).is_zero()) + } + + initiate_teleport { + }: { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + impl_benchmark_test_suite!( + Pallet, + crate::fungible::mock::new_test_ext(), + crate::fungible::mock::Test + ); +} diff --git a/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs new file mode 100644 index 0000000000..9de8238fb2 --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs @@ -0,0 +1,276 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . + +// Copyright (C) Parity Technologies (UK) Ltd. +//! A mock runtime for XCM benchmarking. + +use crate::{fungible::assets as xcm_assets_benchmark, mock::*}; +use frame_benchmarking::BenchmarkError; +use frame_support::{ + parameter_types, + traits::{ConstU32, Everything, Nothing}, + weights::Weight, +}; +use sp_core::H256; +use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; +use xcm::latest::prelude::*; +use xcm_builder::{AllowUnpaidExecutionFrom, ConvertedConcreteId, IsConcrete, MintLocation}; +use xcm_executor::traits::JustTry; + +type Block = frame_system::mocking::MockBlock; + +// For testing the pallet, we construct a mock runtime. +frame_support::construct_runtime!( + pub enum Test + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + XcmAssetsBenchmark: xcm_assets_benchmark::{Pallet}, + Assets : pallet_balances::{Pallet, Call, Storage, Config, Event}, + } +); + +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, u64::MAX)); +} +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type RuntimeOrigin = RuntimeOrigin; + type Nonce = u64; + type Hash = H256; + type RuntimeCall = RuntimeCall; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + 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 = 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 RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type RuntimeHoldReason = RuntimeHoldReason; + type FreezeIdentifier = (); + type MaxHolds = ConstU32<0>; + type MaxFreezes = ConstU32<0>; +} + +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 const AssetAccountDeposit: u64 = 1 * ExistentialDeposit::get(); + const AssetsStringLimit: u32 = 50; + +} + +impl pallet_assets::Config for Test { + type RuntimeEvent = RuntimeEvent; + type Balance = u64; + type AssetId = u64; + type Currency = Balances; + type CreateOrigin = AsEnsureOriginWithArg>; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type AssetAccountDeposit = AssetAccountDeposit; + type ApprovalDeposit = ExistentialDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type WeightInfo = (); + type RemoveItemsLimit = ConstU32<1000>; + type AssetIdParameter = Compact; + type CallbackHandle = (); + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = (); +} +// pub struct MatchAnyFungible; +// impl xcm_executor::traits::MatchesFungible for MatchAnyFungible { +// fn matches_fungible(m: &MultiAsset) -> Option { +// use sp_runtime::traits::SaturatedConversion; +// match m { +// MultiAsset { +// fun: Fungible(amount), +// .. +// } => Some((*amount).saturated_into::()), +// _ => None, +// } +// } +// } + +// Use fungible transactor as the asset transactor. +pub type AssetTransactor = xcm_builder::FungiblesAdapter< + Assets, + ConvertedConcreteId, + AccountIdConverter, + u64, + xcm_builder::NoChecking, + 0, +>; + +pub struct AssetLocationIdConverter; +impl Convert for AssetLocationIdConverter { + fn convert_ref(location: impl Borrow) -> Result { + if let X1(GeneralIndex(i)) = location.borrow().clone().interior { + Ok(i.into()) + } else { + Err(()) + } + } + + fn reverse_ref(id: impl Borrow) -> Result { + Ok(Junction::GeneralIndex(id.borrow().clone().into()).into()) + } +} + +parameter_types! { + /// Maximum number of instructions in a single XCM fragment. A sanity check against weight + /// calculations getting too crazy. + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = DevNull; + type AssetTransactor = AssetTransactor; + type OriginConverter = (); + type IsReserve = (); + type IsTeleporter = TrustedTeleporters; + type UniversalLocation = UniversalLocation; + type Barrier = AllowUnpaidExecutionFrom; + type Weigher = xcm_builder::FixedWeightBounds; + type Trader = xcm_builder::FixedRateOfFungible; + type ResponseHandler = DevNull; + type AssetTrap = (); + type AssetLocker = (); + type AssetExchanger = (); + type AssetClaims = (); + type SubscriptionService = (); + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; +} + +impl crate::Config for Test { + type XcmConfig = XcmConfig; + type AccountIdConverter = AccountIdConverter; + fn valid_destination() -> Result { + let valid_destination: MultiLocation = X1(AccountId32 { + network: None, + id: [0u8; 32], + }) + .into(); + + Ok(valid_destination) + } + fn worst_case_holding(depositable_count: u32) -> MultiAssets { + crate::mock_worst_case_holding( + depositable_count, + ::MaxAssetsIntoHolding::get(), + ) + } +} + +pub type TrustedTeleporters = (xcm_builder::Case,); + +parameter_types! { + pub const CheckingAccount: Option<(u64, MintLocation)> = Some((100, MintLocation::Local)); + pub const ChildTeleporter: MultiLocation = Parachain(1000).into_location(); + pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some(( + ChildTeleporter::get(), + MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(100) }, + )); + pub const TeleportConcreteFungible: (MultiAssetFilter, MultiLocation) = + (Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get()); + pub const ReserveConcreteFungible: (MultiAssetFilter, MultiLocation) = + (Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get()); +} + +impl xcm_assets_benchmark::Config for Test { + type TransactAsset = Balances; + type CheckedAccount = CheckingAccount; + type TrustedTeleporter = TrustedTeleporter; + + fn get_multi_asset() -> MultiAsset { + let amount = + >::minimum_balance() as u128; + let location = MultiLocation { + parents: 1, + interior: X2( + Parachain(1000), + AccountId32 { + network: None, + id: [152; 32], + }, + ), + }; + MultiAsset { + id: Concrete(location), + fun: Fungible(amount), + } + } +} + +#[cfg(feature = "runtime-benchmarks")] +pub fn new_test_ext() -> sp_io::TestExternalities { + use sp_runtime::BuildStorage; + let t = RuntimeGenesisConfig { + ..Default::default() + } + .build_storage() + .unwrap(); + sp_tracing::try_init_simple(); + t.into() +} diff --git a/pallets/astar-xcm-benchmarks/src/fungible/assets/mod.rs b/pallets/astar-xcm-benchmarks/src/fungible/assets/mod.rs new file mode 100644 index 0000000000..1fa633681e --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/fungible/assets/mod.rs @@ -0,0 +1,51 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . + +// Copyright (C) Parity Technologies (UK) Ltd. +// Benchmarking for the `AssetTransactor` trait via `Fungible`. + +pub use pallet::*; + +#[cfg(feature = "runtime-benchmarks")] +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>; + + /// 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/astar-xcm-benchmarks/src/fungible/balances/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/fungible/balances/benchmarking.rs new file mode 100644 index 0000000000..312b0141fd --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/fungible/balances/benchmarking.rs @@ -0,0 +1,201 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . + +// Copyright (C) Parity Technologies (UK) Ltd. +use super::*; +use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; +use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError, BenchmarkResult}; +use frame_support::traits::fungible::Inspect; +use sp_runtime::traits::Zero; +use sp_std::{prelude::*, vec}; +use xcm::latest::{prelude::*, Weight}; +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(0); + let asset = T::get_multi_asset(); + + >::deposit_asset( + &asset, + &sender_location, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).unwrap(); + // check the assets of origin. + assert!(!T::TransactAsset::balance(&sender_account).is_zero()); + + let mut executor = new_executor::(sender_location); + executor.set_holding(worst_case_holding.into()); + let instruction = Instruction::>::WithdrawAsset(vec![asset.clone()].into()); + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(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, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).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.bench_process(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, + &XcmContext { + origin: Some(sender_location.clone()), + message_hash: [0; 32], + topic: None, + }, + ).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.bench_process(xcm)?; + } verify { + assert!(T::TransactAsset::balance(&sender_account).is_zero()); + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + } + + receive_teleported_asset { + } : { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + deposit_asset { + let asset = T::get_multi_asset(); + let mut holding = T::worst_case_holding(1); + + // 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.set_holding(holding.into()); + let instruction = Instruction::>::DepositAsset { + assets: asset.into(), + beneficiary: dest_location, + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(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(1); + + // 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.set_holding(holding.into()); + let instruction = Instruction::>::DepositReserveAsset { + assets: asset.into(), + dest: dest_location, + xcm: Xcm::new(), + }; + let xcm = Xcm(vec![instruction]); + }: { + executor.bench_process(xcm)?; + } verify { + // dest should have received some asset. + assert!(!T::TransactAsset::balance(&dest_account).is_zero()) + } + + initiate_teleport { + }: { + Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + } + + impl_benchmark_test_suite!( + Pallet, + crate::fungible::mock::new_test_ext(), + crate::fungible::mock::Test + ); +} diff --git a/pallets/astar-xcm-benchmarks/src/fungible/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs similarity index 100% rename from pallets/astar-xcm-benchmarks/src/fungible/mock.rs rename to pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs diff --git a/pallets/astar-xcm-benchmarks/src/fungible/balances/mod.rs b/pallets/astar-xcm-benchmarks/src/fungible/balances/mod.rs new file mode 100644 index 0000000000..1fa633681e --- /dev/null +++ b/pallets/astar-xcm-benchmarks/src/fungible/balances/mod.rs @@ -0,0 +1,51 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . + +// Copyright (C) Parity Technologies (UK) Ltd. +// Benchmarking for the `AssetTransactor` trait via `Fungible`. + +pub use pallet::*; + +#[cfg(feature = "runtime-benchmarks")] +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>; + + /// 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/astar-xcm-benchmarks/src/fungible/mod.rs b/pallets/astar-xcm-benchmarks/src/fungible/mod.rs index 1fa633681e..629e2b80e3 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/mod.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/mod.rs @@ -17,35 +17,6 @@ // along with Astar. If not, see . // Copyright (C) Parity Technologies (UK) Ltd. -// Benchmarking for the `AssetTransactor` trait via `Fungible`. -pub use pallet::*; - -#[cfg(feature = "runtime-benchmarks")] -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>; - - /// 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(_); -} +pub mod assets; +pub mod balances; diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 53fcc474e5..7c2af331bb 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -28,9 +28,9 @@ use frame_support::{ dispatch::DispatchClass, parameter_types, traits::{ - AsEnsureOriginWithArg, ConstU32, Contains, Currency, EitherOfDiverse, EqualPrivilegeOnly, - FindAuthor, Get, Imbalance, InstanceFilter, Nothing, OnFinalize, OnUnbalanced, - WithdrawReasons, + fungible::ItemOf, AsEnsureOriginWithArg, ConstU32, Contains, Currency, EitherOfDiverse, + EqualPrivilegeOnly, FindAuthor, Get, Imbalance, InstanceFilter, Nothing, OnFinalize, + OnUnbalanced, WithdrawReasons, }, weights::{ constants::{ @@ -53,7 +53,7 @@ use pallet_transaction_payment::{ use parity_scale_codec::{Compact, Decode, Encode, MaxEncodedLen}; use polkadot_runtime_common::BlockHashCount; use sp_api::impl_runtime_apis; -use sp_core::{ConstBool, OpaqueMetadata, H160, H256, U256}; +use sp_core::{ConstBool, ConstU128, OpaqueMetadata, H160, H256, U256}; use sp_inherents::{CheckInherentsResult, InherentData}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, @@ -1441,7 +1441,9 @@ mod benches { [pallet_xvm, Xvm] [pallet_dynamic_evm_base_fee, DynamicEvmBaseFee] [pallet_unified_accounts, UnifiedAccounts] - [astar_xcm_benchmarks, astar_xcm_benchmarks::Pallet::] + [astar_xcm_benchmarks::generic, astar_xcm_benchmarks::generic::Pallet::] + [astar_xcm_benchmarks::fungible::balances, astar_xcm_benchmarks::fungible::balances::Pallet::] + [astar_xcm_benchmarks::fungible::assets, astar_xcm_benchmarks::fungible::assets::Pallet::] ); } @@ -1926,11 +1928,17 @@ impl_runtime_apis! { use baseline::Pallet as BaselineBench; use xcm_config::{XcmConfig, LocationToAccountId}; use xcm::latest::prelude::*; + use xcm_builder::MintLocation; + use sp_runtime::AccountId32; impl frame_system_benchmarking::Config for Runtime {} impl baseline::Config for Runtime {} - use frame_support::traits::WhitelistedStorageKeys; + parameter_types! { + pub const NoCheckingAccount: Option<(::AccountId, MintLocation)> = None; + pub const NoTeleporter: Option<(xcm::latest::MultiLocation, xcm::latest::MultiAsset)> = None; + } + use frame_support::{traits::WhitelistedStorageKeys,assert_ok}; impl astar_xcm_benchmarks::Config for Runtime { type XcmConfig = XcmConfig; type AccountIdConverter = LocationToAccountId; @@ -2026,6 +2034,50 @@ impl_runtime_apis! { } } + impl astar_xcm_benchmarks::fungible::balances::Config for Runtime { + type TransactAsset = Balances; + + /// The account used to check assets being teleported. + type CheckedAccount = NoCheckingAccount; + + /// A trusted location which we allow teleports from, and the asset we allow to teleport. + type TrustedTeleporter = NoTeleporter; + + /// Give me a fungible asset that your asset transactor is going to accept. + fn get_multi_asset() -> MultiAsset { + MultiAsset { + id: Concrete(Here.into()), + fun: Fungible(u128::MAX), + } + } + } + + impl astar_xcm_benchmarks::fungible::assets::Config for Runtime { + type TransactAsset = ItemOf, AccountId>; + + /// The account used to check assets being teleported. + type CheckedAccount = NoCheckingAccount; + + /// A trusted location which we allow teleports from, and the asset we allow to teleport. + type TrustedTeleporter = NoTeleporter; + + /// Give me a fungible asset that your asset transactor is going to accept. + fn get_multi_asset() -> MultiAsset { + // send some token to alice for existential deposit + + // create an asset + assert_ok!(pallet_assets::Pallet::::force_create(RuntimeOrigin::root(),parity_scale_codec::Compact(1),sp_runtime::MultiAddress::Id(AccountId32::new([0u8; 32])),true,1)); + let location = MultiLocation { parents : 0, interior :X1(GeneralIndex(1)) }; + // convert mapping for asset id + assert_ok!(pallet_xc_asset_config::Pallet::::register_asset_location(RuntimeOrigin::root(),Box::new(location.clone().into_versioned()),1)); + + MultiAsset { + id: Concrete(location), + fun: Fungible(100_000_000_000u128), + } + } + } + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); From 94da10a9bb02cb47613232dbb9595e5058b470be Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Thu, 19 Oct 2023 04:38:46 +0530 Subject: [PATCH 12/20] change to weightinfobounds --- runtime/shibuya/src/weights/mod.rs | 1 + .../xcm/pallet_xcm_benchmarks_fungible.rs | 150 ------ .../xcm/pallet_xcm_benchmarks_generic.rs | 344 -------------- .../fungible_assets_benchmarks.rs | 176 +++++++ .../fungible_balances_benchmarks.rs | 177 +++++++ .../generic_benchmarks.rs | 440 ++++++++++++++++++ .../mod.rs | 75 +-- runtime/shibuya/src/xcm_config.rs | 20 +- 8 files changed, 852 insertions(+), 531 deletions(-) delete mode 100644 runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs delete mode 100644 runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs create mode 100644 runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs create mode 100644 runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs create mode 100644 runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs rename runtime/shibuya/src/weights/{xcm => xcm_instruction_benchmarks}/mod.rs (80%) diff --git a/runtime/shibuya/src/weights/mod.rs b/runtime/shibuya/src/weights/mod.rs index f1df12d585..f71ef213ad 100644 --- a/runtime/shibuya/src/weights/mod.rs +++ b/runtime/shibuya/src/weights/mod.rs @@ -19,3 +19,4 @@ pub mod pallet_assets; pub mod pallet_balances; pub mod pallet_xcm; +pub mod xcm_instruction_benchmarks; diff --git a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs deleted file mode 100644 index 92258dacbd..0000000000 --- a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs +++ /dev/null @@ -1,150 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later - -// Astar 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. - -// Astar 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 Astar. 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: 2023-07-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-gghbxkbs-project-163-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024 - -// Executed Command: -// target/production/polkadot -// benchmark -// pallet -// --steps=50 -// --repeat=20 -// --extrinsic=* -// --wasm-execution=compiled -// --heap-pages=4096 -// --json-file=/builds/parity/mirrors/polkadot/.git/.artifacts/bench.json -// --pallet=pallet_xcm_benchmarks::fungible -// --chain=kusama-dev -// --header=./file_header.txt -// --template=./xcm/pallet-xcm-benchmarks/template.hbs -// --output=./runtime/kusama/src/weights/xcm/ - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -const DEFAULT_REF_TIME:u64 = 1_000_000_000; -const DEFAULT_PROOF_SIZE:u64 = 64 * 1024; - -/// Weight functions for `pallet_xcm_benchmarks::fungible`. -pub struct WeightInfo(PhantomData); -impl WeightInfo { - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - pub(crate) fn withdraw_asset() -> Weight { - // Proof Size summary in bytes: - // Measured: `101` - // Estimated: `3593` - // Minimum execution time: 23_950_000 picoseconds. - Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) - } - /// Storage: `System::Account` (r:2 w:2) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - pub(crate) fn transfer_asset() -> Weight { - // Proof Size summary in bytes: - // Measured: `101` - // Estimated: `6196` - // Minimum execution time: 51_687_000 picoseconds. - Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) - } - /// Storage: `System::Account` (r:2 w:2) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) - /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) - /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) - /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) - /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) - pub(crate) fn transfer_reserve_asset() -> Weight { - // Proof Size summary in bytes: - // Measured: `177` - // Estimated: `6196` - // Minimum execution time: 75_438_000 picoseconds. - Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) - } - /// Storage: `Benchmark::Override` (r:0 w:0) - /// Proof: `Benchmark::Override` (`max_values`: None, `max_size`: None, mode: `Measured`) - pub(crate) fn reserve_asset_deposited() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_000_000_000_000 picoseconds. - Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) - } - /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) - /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) - /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) - /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) - /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) - pub(crate) fn initiate_reserve_withdraw() -> Weight { - Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) - } - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - pub(crate) fn receive_teleported_asset() -> Weight { - // Instruction disabled - Weight::MAX - } - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - pub(crate) fn deposit_asset() -> Weight { - Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) - } - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) - /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) - /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) - /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) - /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) - pub(crate) fn deposit_reserve_asset() -> Weight { - Weight::from_parts(DEFAULT_REF_TIME, DEFAULT_PROOF_SIZE) - } - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) - /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) - /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) - /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) - /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) - pub(crate) fn initiate_teleport() -> Weight { - // Instruction disabled - Weight::MAX - } -} diff --git a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs deleted file mode 100644 index fa5e9969c7..0000000000 --- a/runtime/shibuya/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ /dev/null @@ -1,344 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later - -// Astar 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. - -// Astar 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 Astar. 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: 2023-06-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024 - -// Executed Command: -// ./target/production/polkadot -// benchmark -// pallet -// --steps=50 -// --repeat=20 -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 -// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/polkadot/.git/.artifacts/bench.json -// --pallet=pallet_xcm_benchmarks::generic -// --chain=kusama-dev -// --header=./file_header.txt -// --template=./xcm/pallet-xcm-benchmarks/template.hbs -// --output=./runtime/kusama/src/weights/xcm/ - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `pallet_xcm_benchmarks::generic`. -pub struct WeightInfo(PhantomData); -impl WeightInfo { - /// Storage: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) - /// Proof Skipped: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) - /// Storage: Dmp DeliveryFeeFactor (r:1 w:0) - /// Proof Skipped: Dmp DeliveryFeeFactor (max_values: None, max_size: None, mode: Measured) - /// Storage: XcmPallet SupportedVersion (r:1 w:0) - /// Proof Skipped: XcmPallet SupportedVersion (max_values: None, max_size: None, mode: Measured) - /// Storage: XcmPallet VersionDiscoveryQueue (r:1 w:1) - /// Proof Skipped: XcmPallet VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: XcmPallet SafeXcmVersion (r:1 w:0) - /// Proof Skipped: XcmPallet SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Dmp DownwardMessageQueues (r:1 w:1) - /// Proof Skipped: Dmp DownwardMessageQueues (max_values: None, max_size: None, mode: Measured) - /// Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) - /// Proof Skipped: Dmp DownwardMessageQueueHeads (max_values: None, max_size: None, mode: Measured) - pub(crate) fn report_holding() -> Weight { - // Proof Size summary in bytes: - // Measured: `211` - // Estimated: `3676` - // Minimum execution time: 32_102_000 picoseconds. - Weight::from_parts(33_749_000, 3676) - .saturating_add(T::DbWeight::get().reads(7)) - .saturating_add(T::DbWeight::get().writes(4)) - } - - pub(crate) fn buy_execution() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_624_000 picoseconds. - Weight::from_parts(2_714_000, 0) - } - /// Storage: XcmPallet Queries (r:1 w:0) - /// Proof Skipped: XcmPallet Queries (max_values: None, max_size: None, mode: Measured) - pub(crate) fn query_response() -> Weight { - // Proof Size summary in bytes: - // Measured: `169` - // Estimated: `3634` - // Minimum execution time: 10_599_000 picoseconds. - Weight::from_parts(10_882_000, 3634) - .saturating_add(T::DbWeight::get().reads(1)) - } - pub(crate) fn transact() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_985_000 picoseconds. - Weight::from_parts(12_274_000, 0) - } - pub(crate) fn refund_surplus() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_739_000 picoseconds. - Weight::from_parts(2_862_000, 0) - } - pub(crate) fn set_error_handler() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_533_000 picoseconds. - Weight::from_parts(2_646_000, 0) - } - pub(crate) fn set_appendix() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_563_000 picoseconds. - Weight::from_parts(2_647_000, 0) - } - pub(crate) fn clear_error() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_512_000 picoseconds. - Weight::from_parts(2_574_000, 0) - } - pub(crate) fn descend_origin() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 3_307_000 picoseconds. - Weight::from_parts(3_448_000, 0) - } - pub(crate) fn clear_origin() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_524_000 picoseconds. - Weight::from_parts(2_614_000, 0) - } - /// Storage: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) - /// Proof Skipped: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) - /// Storage: Dmp DeliveryFeeFactor (r:1 w:0) - /// Proof Skipped: Dmp DeliveryFeeFactor (max_values: None, max_size: None, mode: Measured) - /// Storage: XcmPallet SupportedVersion (r:1 w:0) - /// Proof Skipped: XcmPallet SupportedVersion (max_values: None, max_size: None, mode: Measured) - /// Storage: XcmPallet VersionDiscoveryQueue (r:1 w:1) - /// Proof Skipped: XcmPallet VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: XcmPallet SafeXcmVersion (r:1 w:0) - /// Proof Skipped: XcmPallet SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Dmp DownwardMessageQueues (r:1 w:1) - /// Proof Skipped: Dmp DownwardMessageQueues (max_values: None, max_size: None, mode: Measured) - /// Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) - /// Proof Skipped: Dmp DownwardMessageQueueHeads (max_values: None, max_size: None, mode: Measured) - pub(crate) fn report_error() -> Weight { - // Proof Size summary in bytes: - // Measured: `211` - // Estimated: `3676` - // Minimum execution time: 27_275_000 picoseconds. - Weight::from_parts(27_861_000, 3676) - .saturating_add(T::DbWeight::get().reads(7)) - .saturating_add(T::DbWeight::get().writes(4)) - } - /// Storage: XcmPallet AssetTraps (r:1 w:1) - /// Proof Skipped: XcmPallet AssetTraps (max_values: None, max_size: None, mode: Measured) - pub(crate) fn claim_asset() -> Weight { - // Proof Size summary in bytes: - // Measured: `226` - // Estimated: `3691` - // Minimum execution time: 14_731_000 picoseconds. - Weight::from_parts(15_006_000, 3691) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - pub(crate) fn trap() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_446_000 picoseconds. - Weight::from_parts(2_581_000, 0) - } - /// Storage: XcmPallet VersionNotifyTargets (r:1 w:1) - /// Proof Skipped: XcmPallet VersionNotifyTargets (max_values: None, max_size: None, mode: Measured) - /// Storage: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) - /// Proof Skipped: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) - /// Storage: Dmp DeliveryFeeFactor (r:1 w:0) - /// Proof Skipped: Dmp DeliveryFeeFactor (max_values: None, max_size: None, mode: Measured) - /// Storage: XcmPallet SupportedVersion (r:1 w:0) - /// Proof Skipped: XcmPallet SupportedVersion (max_values: None, max_size: None, mode: Measured) - /// Storage: XcmPallet VersionDiscoveryQueue (r:1 w:1) - /// Proof Skipped: XcmPallet VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: XcmPallet SafeXcmVersion (r:1 w:0) - /// Proof Skipped: XcmPallet SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Dmp DownwardMessageQueues (r:1 w:1) - /// Proof Skipped: Dmp DownwardMessageQueues (max_values: None, max_size: None, mode: Measured) - /// Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) - /// Proof Skipped: Dmp DownwardMessageQueueHeads (max_values: None, max_size: None, mode: Measured) - pub(crate) fn subscribe_version() -> Weight { - // Proof Size summary in bytes: - // Measured: `211` - // Estimated: `3676` - // Minimum execution time: 34_319_000 picoseconds. - Weight::from_parts(34_708_000, 3676) - .saturating_add(T::DbWeight::get().reads(8)) - .saturating_add(T::DbWeight::get().writes(5)) - } - /// Storage: XcmPallet VersionNotifyTargets (r:0 w:1) - /// Proof Skipped: XcmPallet VersionNotifyTargets (max_values: None, max_size: None, mode: Measured) - pub(crate) fn unsubscribe_version() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 4_974_000 picoseconds. - Weight::from_parts(5_155_000, 0) - .saturating_add(T::DbWeight::get().writes(1)) - } - pub(crate) fn burn_asset() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 4_059_000 picoseconds. - Weight::from_parts(4_125_000, 0) - } - pub(crate) fn expect_asset() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_657_000 picoseconds. - Weight::from_parts(2_741_000, 0) - } - pub(crate) fn expect_origin() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_585_000 picoseconds. - Weight::from_parts(2_653_000, 0) - } - pub(crate) fn expect_error() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_552_000 picoseconds. - Weight::from_parts(2_632_000, 0) - } - pub(crate) fn expect_transact_status() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_682_000 picoseconds. - Weight::from_parts(2_763_000, 0) - } - /// Storage: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) - /// Proof Skipped: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) - /// Storage: Dmp DeliveryFeeFactor (r:1 w:0) - /// Proof Skipped: Dmp DeliveryFeeFactor (max_values: None, max_size: None, mode: Measured) - /// Storage: XcmPallet SupportedVersion (r:1 w:0) - /// Proof Skipped: XcmPallet SupportedVersion (max_values: None, max_size: None, mode: Measured) - /// Storage: XcmPallet VersionDiscoveryQueue (r:1 w:1) - /// Proof Skipped: XcmPallet VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: XcmPallet SafeXcmVersion (r:1 w:0) - /// Proof Skipped: XcmPallet SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Dmp DownwardMessageQueues (r:1 w:1) - /// Proof Skipped: Dmp DownwardMessageQueues (max_values: None, max_size: None, mode: Measured) - /// Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) - /// Proof Skipped: Dmp DownwardMessageQueueHeads (max_values: None, max_size: None, mode: Measured) - pub(crate) fn query_pallet() -> Weight { - // Proof Size summary in bytes: - // Measured: `211` - // Estimated: `3676` - // Minimum execution time: 34_316_000 picoseconds. - Weight::from_parts(34_682_000, 3676) - .saturating_add(T::DbWeight::get().reads(7)) - .saturating_add(T::DbWeight::get().writes(4)) - } - pub(crate) fn expect_pallet() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 7_938_000 picoseconds. - Weight::from_parts(8_071_000, 0) - } - /// Storage: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) - /// Proof Skipped: unknown `0x3a696e747261626c6f636b5f656e74726f7079` (r:1 w:1) - /// Storage: Dmp DeliveryFeeFactor (r:1 w:0) - /// Proof Skipped: Dmp DeliveryFeeFactor (max_values: None, max_size: None, mode: Measured) - /// Storage: XcmPallet SupportedVersion (r:1 w:0) - /// Proof Skipped: XcmPallet SupportedVersion (max_values: None, max_size: None, mode: Measured) - /// Storage: XcmPallet VersionDiscoveryQueue (r:1 w:1) - /// Proof Skipped: XcmPallet VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: XcmPallet SafeXcmVersion (r:1 w:0) - /// Proof Skipped: XcmPallet SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Dmp DownwardMessageQueues (r:1 w:1) - /// Proof Skipped: Dmp DownwardMessageQueues (max_values: None, max_size: None, mode: Measured) - /// Storage: Dmp DownwardMessageQueueHeads (r:1 w:1) - /// Proof Skipped: Dmp DownwardMessageQueueHeads (max_values: None, max_size: None, mode: Measured) - pub(crate) fn report_transact_status() -> Weight { - // Proof Size summary in bytes: - // Measured: `211` - // Estimated: `3676` - // Minimum execution time: 28_002_000 picoseconds. - Weight::from_parts(28_184_000, 3676) - .saturating_add(T::DbWeight::get().reads(7)) - .saturating_add(T::DbWeight::get().writes(4)) - } - pub(crate) fn clear_transact_status() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_520_000 picoseconds. - Weight::from_parts(2_617_000, 0) - } - pub(crate) fn set_topic() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_506_000 picoseconds. - Weight::from_parts(2_560_000, 0) - } - pub(crate) fn clear_topic() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_503_000 picoseconds. - Weight::from_parts(2_605_000, 0) - } - pub(crate) fn set_fees_mode() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_511_000 picoseconds. - Weight::from_parts(2_597_000, 0) - } - pub(crate) fn unpaid_execution() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_617_000 picoseconds. - Weight::from_parts(2_715_000, 0) - } -} diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs new file mode 100644 index 0000000000..4e6aebe286 --- /dev/null +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs @@ -0,0 +1,176 @@ + +//! Autogenerated weights for `astar_xcm_benchmarks::fungible::assets` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-10-18, STEPS: `50`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Deepanshu.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain +// shibuya-dev +// --execution=wasm +// --wasm-execution=compiled +// --pallet +// astar_xcm_benchmarks::fungible::assets +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 1 +// --output +// pallets/transfer-weight.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `astar_xcm_benchmarks::fungible::assets`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) + /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) + /// Storage: Assets Asset (r:1 w:1) + /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) + /// Storage: Assets Account (r:1 w:1) + /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: UnifiedAccounts NativeToEvm (r:1 w:0) + /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + pub(crate) fn withdraw_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `688` + // Estimated: `4153` + // Minimum execution time: 116_000_000 picoseconds. + Weight::from_parts(116_000_000, 0) + .saturating_add(Weight::from_parts(0, 4153)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) + /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) + /// Storage: Assets Asset (r:1 w:1) + /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) + /// Storage: Assets Account (r:2 w:2) + /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + pub(crate) fn transfer_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `622` + // Estimated: `6232` + // Minimum execution time: 107_000_000 picoseconds. + Weight::from_parts(107_000_000, 0) + .saturating_add(Weight::from_parts(0, 6232)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) + /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) + /// Storage: Assets Asset (r:1 w:1) + /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) + /// Storage: Assets Account (r:2 w:2) + /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem HostConfiguration (r:1 w:0) + /// Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + pub(crate) fn transfer_reserve_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `836` + // Estimated: `6232` + // Minimum execution time: 151_000_000 picoseconds. + Weight::from_parts(151_000_000, 0) + .saturating_add(Weight::from_parts(0, 6232)) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(5)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn receive_teleported_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) + /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) + /// Storage: Assets Asset (r:1 w:1) + /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) + /// Storage: Assets Account (r:1 w:1) + /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + pub(crate) fn deposit_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `424` + // Estimated: `3889` + // Minimum execution time: 79_000_000 picoseconds. + Weight::from_parts(79_000_000, 0) + .saturating_add(Weight::from_parts(0, 3889)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) + /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) + /// Storage: Assets Asset (r:1 w:1) + /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) + /// Storage: Assets Account (r:1 w:1) + /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem HostConfiguration (r:1 w:0) + /// Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + pub(crate) fn deposit_reserve_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `638` + // Estimated: `4103` + // Minimum execution time: 121_000_000 picoseconds. + Weight::from_parts(121_000_000, 0) + .saturating_add(Weight::from_parts(0, 4103)) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(5)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn initiate_teleport() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn reserve_asset_deposited() -> Weight { + // This instruction is a no-op for PoV (no storage access) + Weight::from_parts(200_000_000 as u64, 0) + } +} diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs new file mode 100644 index 0000000000..73f83102ed --- /dev/null +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs @@ -0,0 +1,177 @@ + +//! Autogenerated weights for `astar_xcm_benchmarks::fungible::assets` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-10-18, STEPS: `50`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Deepanshu.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain +// shibuya-dev +// --execution=wasm +// --wasm-execution=compiled +// --pallet +// astar_xcm_benchmarks::fungible::assets +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 1 +// --output +// pallets/transfer-weight.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `astar_xcm_benchmarks::fungible::assets`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) + /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) + /// Storage: Assets Asset (r:1 w:1) + /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) + /// Storage: Assets Account (r:1 w:1) + /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: UnifiedAccounts NativeToEvm (r:1 w:0) + /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + pub(crate) fn withdraw_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `688` + // Estimated: `4153` + // Minimum execution time: 116_000_000 picoseconds. + Weight::from_parts(116_000_000, 0) + .saturating_add(Weight::from_parts(0, 4153)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) + /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) + /// Storage: Assets Asset (r:1 w:1) + /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) + /// Storage: Assets Account (r:2 w:2) + /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + pub(crate) fn transfer_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `622` + // Estimated: `6232` + // Minimum execution time: 107_000_000 picoseconds. + Weight::from_parts(107_000_000, 0) + .saturating_add(Weight::from_parts(0, 6232)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) + /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) + /// Storage: Assets Asset (r:1 w:1) + /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) + /// Storage: Assets Account (r:2 w:2) + /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem HostConfiguration (r:1 w:0) + /// Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + pub(crate) fn transfer_reserve_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `836` + // Estimated: `6232` + // Minimum execution time: 151_000_000 picoseconds. + Weight::from_parts(151_000_000, 0) + .saturating_add(Weight::from_parts(0, 6232)) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(5)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn receive_teleported_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) + /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) + /// Storage: Assets Asset (r:1 w:1) + /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) + /// Storage: Assets Account (r:1 w:1) + /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + pub(crate) fn deposit_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `424` + // Estimated: `3889` + // Minimum execution time: 79_000_000 picoseconds. + Weight::from_parts(79_000_000, 0) + .saturating_add(Weight::from_parts(0, 3889)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) + /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) + /// Storage: Assets Asset (r:1 w:1) + /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) + /// Storage: Assets Account (r:1 w:1) + /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + /// Storage: System Account (r:1 w:1) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem HostConfiguration (r:1 w:0) + /// Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + pub(crate) fn deposit_reserve_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `638` + // Estimated: `4103` + // Minimum execution time: 121_000_000 picoseconds. + Weight::from_parts(121_000_000, 0) + .saturating_add(Weight::from_parts(0, 4103)) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(5)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn initiate_teleport() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + + pub(crate) fn reserve_asset_deposited() -> Weight { + // This instruction is a no-op for PoV (no storage access) + Weight::from_parts(200_000_000 as u64, 0) + } +} diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs new file mode 100644 index 0000000000..5d8d16350a --- /dev/null +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs @@ -0,0 +1,440 @@ + +//! Autogenerated weights for `astar_xcm_benchmarks::generic` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-10-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Deepanshu`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain +// shibuya-dev +// --execution=wasm +// --wasm-execution=compiled +// --pallet +// astar_xcm_benchmarks::generic +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --output +// pallets/transfer-weight.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `astar_xcm_benchmarks::generic`. +pub struct WeightInfo(PhantomData); +impl WeightInfo { + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem HostConfiguration (r:1 w:0) + /// Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + pub(crate) fn report_holding() -> Weight { + // Proof Size summary in bytes: + // Measured: `214` + // Estimated: `3679` + // Minimum execution time: 313_000_000 picoseconds. + Weight::from_parts(324_000_000, 0) + .saturating_add(Weight::from_parts(0, 3679)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(2)) + } + pub(crate) fn buy_execution() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 42_000_000 picoseconds. + Weight::from_parts(43_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: PolkadotXcm Queries (r:1 w:0) + /// Proof Skipped: PolkadotXcm Queries (max_values: None, max_size: None, mode: Measured) + pub(crate) fn query_response() -> Weight { + // Proof Size summary in bytes: + // Measured: `69` + // Estimated: `3534` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(12_000_000, 0) + .saturating_add(Weight::from_parts(0, 3534)) + .saturating_add(T::DbWeight::get().reads(1)) + } + pub(crate) fn transact() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 11_000_000 picoseconds. + Weight::from_parts(12_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn refund_surplus() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 4_000_000 picoseconds. + Weight::from_parts(4_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn set_error_handler() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn set_appendix() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn clear_error() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn descend_origin() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(4_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn clear_origin() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem HostConfiguration (r:1 w:0) + /// Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + pub(crate) fn report_error() -> Weight { + // Proof Size summary in bytes: + // Measured: `214` + // Estimated: `3679` + // Minimum execution time: 26_000_000 picoseconds. + Weight::from_parts(27_000_000, 0) + .saturating_add(Weight::from_parts(0, 3679)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: PolkadotXcm AssetTraps (r:1 w:1) + /// Proof Skipped: PolkadotXcm AssetTraps (max_values: None, max_size: None, mode: Measured) + pub(crate) fn claim_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `126` + // Estimated: `3591` + // Minimum execution time: 16_000_000 picoseconds. + Weight::from_parts(17_000_000, 0) + .saturating_add(Weight::from_parts(0, 3591)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + pub(crate) fn trap() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionNotifyTargets (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem HostConfiguration (r:1 w:0) + /// Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + pub(crate) fn subscribe_version() -> Weight { + // Proof Size summary in bytes: + // Measured: `111` + // Estimated: `3576` + // Minimum execution time: 29_000_000 picoseconds. + Weight::from_parts(29_000_000, 0) + .saturating_add(Weight::from_parts(0, 3576)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) + /// Proof Skipped: PolkadotXcm VersionNotifyTargets (max_values: None, max_size: None, mode: Measured) + pub(crate) fn unsubscribe_version() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 5_000_000 picoseconds. + Weight::from_parts(5_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem HostConfiguration (r:1 w:0) + /// Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + pub(crate) fn initiate_reserve_withdraw() -> Weight { + // Proof Size summary in bytes: + // Measured: `214` + // Estimated: `3679` + // Minimum execution time: 339_000_000 picoseconds. + Weight::from_parts(340_000_000, 0) + .saturating_add(Weight::from_parts(0, 3679)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(2)) + } + pub(crate) fn burn_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 109_000_000 picoseconds. + Weight::from_parts(110_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn expect_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 19_000_000 picoseconds. + Weight::from_parts(20_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn expect_origin() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn expect_error() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn expect_transact_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem HostConfiguration (r:1 w:0) + /// Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + pub(crate) fn query_pallet() -> Weight { + // Proof Size summary in bytes: + // Measured: `214` + // Estimated: `3679` + // Minimum execution time: 33_000_000 picoseconds. + Weight::from_parts(34_000_000, 0) + .saturating_add(Weight::from_parts(0, 3679)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(2)) + } + pub(crate) fn expect_pallet() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 9_000_000 picoseconds. + Weight::from_parts(9_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured) + /// Storage: PolkadotXcm VersionDiscoveryQueue (r:1 w:1) + /// Proof Skipped: PolkadotXcm VersionDiscoveryQueue (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: PolkadotXcm SafeXcmVersion (r:1 w:0) + /// Proof Skipped: PolkadotXcm SafeXcmVersion (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem HostConfiguration (r:1 w:0) + /// Proof Skipped: ParachainSystem HostConfiguration (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem PendingUpwardMessages (r:1 w:1) + /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) + pub(crate) fn report_transact_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `214` + // Estimated: `3679` + // Minimum execution time: 26_000_000 picoseconds. + Weight::from_parts(27_000_000, 0) + .saturating_add(Weight::from_parts(0, 3679)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(2)) + } + pub(crate) fn clear_transact_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn set_topic() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn clear_topic() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn set_fees_mode() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + pub(crate) fn unpaid_execution() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_000_000 picoseconds. + Weight::from_parts(3_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn exchange_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn export_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn lock_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn unlock_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn note_unlockable() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn request_unlock() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: Benchmark Override (r:0 w:0) + /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) + pub(crate) fn universal_origin() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } +} + +// added here.into() in the worstcase-scenario. +// changed weightlimit to 1 for buy_execution +// what to do for transact? \ No newline at end of file diff --git a/runtime/shibuya/src/weights/xcm/mod.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs similarity index 80% rename from runtime/shibuya/src/weights/xcm/mod.rs rename to runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs index 1715a3fa80..2be67bdd41 100644 --- a/runtime/shibuya/src/weights/xcm/mod.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs @@ -16,8 +16,9 @@ // You should have received a copy of the GNU General Public License // along with Astar. If not, see . -mod pallet_xcm_benchmarks_fungible; -mod pallet_xcm_benchmarks_generic; +mod fungible_assets_benchmarks; +mod fungible_balances_benchmarks; +mod generic_benchmarks; use crate::Runtime; use frame_support::weights::Weight; @@ -29,13 +30,20 @@ use xcm::{ use astar_primitives::xcm::MAX_ASSETS; use core::cmp::min; -use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; -use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; +use fungible_assets_benchmarks::WeightInfo as XcmFungibleAssetsWeight; +use fungible_balances_benchmarks::WeightInfo as XcmFungibleBalancesWeight; +use generic_benchmarks::WeightInfo as XcmGeneric; trait WeighMultiAssets { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; } +impl WeighMultiAssets for MultiAssets { + fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { + weight.saturating_mul(self.inner().into_iter().count() as u64) + } +} + trait WeighMultiAssetsFilter { fn weigh_multi_assets_filter(&self, weight: Weight) -> XCMWeight; } @@ -54,25 +62,25 @@ impl WeighMultiAssetsFilter for MultiAssetFilter { } } -impl WeighMultiAssets for MultiAssets { - fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { - weight.saturating_mul(self.inner().into_iter().count() as u64) - } -} - pub struct ShibuyaXcmWeight(core::marker::PhantomData); impl XcmWeightInfo for ShibuyaXcmWeight { fn withdraw_asset(assets: &MultiAssets) -> XCMWeight { - assets.inner().iter().fold(Weight::zero(), |acc, _asset| { - acc.saturating_add(XcmFungibleWeight::::withdraw_asset()) - }) + assets.weigh_multi_assets( + XcmFungibleBalancesWeight::::withdraw_asset() + .max(XcmFungibleAssetsWeight::::withdraw_asset()), + ) } - // Currently there is no trusted reserve - fn reserve_asset_deposited(_assets: &MultiAssets) -> XCMWeight { - XcmFungibleWeight::::reserve_asset_deposited() + fn reserve_asset_deposited(assets: &MultiAssets) -> XCMWeight { + assets.weigh_multi_assets( + XcmFungibleBalancesWeight::::reserve_asset_deposited() + .max(XcmFungibleAssetsWeight::::reserve_asset_deposited()), + ) } fn receive_teleported_asset(assets: &MultiAssets) -> XCMWeight { - assets.weigh_multi_assets(XcmFungibleWeight::::receive_teleported_asset()) + assets.weigh_multi_assets( + XcmFungibleBalancesWeight::::receive_teleported_asset() + .max(XcmFungibleAssetsWeight::::receive_teleported_asset()), + ) } fn query_response( _query_id: &u64, @@ -83,18 +91,20 @@ impl XcmWeightInfo for ShibuyaXcmWeight { XcmGeneric::::query_response() } fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> XCMWeight { - assets.inner().iter().fold(Weight::zero(), |acc, _asset| { - acc.saturating_add(XcmFungibleWeight::::transfer_asset()) - }) + assets.weigh_multi_assets( + XcmFungibleBalancesWeight::::transfer_asset() + .max(XcmFungibleAssetsWeight::::transfer_asset()), + ) } fn transfer_reserve_asset( assets: &MultiAssets, _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.inner().iter().fold(Weight::zero(), |acc, _asset| { - acc.saturating_add(XcmFungibleWeight::::transfer_reserve_asset()) - }) + assets.weigh_multi_assets( + XcmFungibleBalancesWeight::::transfer_reserve_asset() + .max(XcmFungibleAssetsWeight::::transfer_reserve_asset()), + ) } fn transact( _origin_type: &OriginKind, @@ -129,14 +139,20 @@ impl XcmWeightInfo for ShibuyaXcmWeight { XcmGeneric::::report_error() } fn deposit_asset(assets: &MultiAssetFilter, _dest: &MultiLocation) -> XCMWeight { - assets.weigh_multi_assets_filter(XcmFungibleWeight::::deposit_asset()) + assets.weigh_multi_assets_filter( + XcmFungibleBalancesWeight::::deposit_asset() + .max(XcmFungibleAssetsWeight::::deposit_asset()), + ) } fn deposit_reserve_asset( assets: &MultiAssetFilter, _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - assets.weigh_multi_assets_filter(XcmFungibleWeight::::deposit_reserve_asset()) + assets.weigh_multi_assets_filter( + XcmFungibleBalancesWeight::::deposit_reserve_asset() + .max(XcmFungibleAssetsWeight::::deposit_reserve_asset()), + ) } fn exchange_asset( _give: &MultiAssetFilter, @@ -150,17 +166,19 @@ impl XcmWeightInfo for ShibuyaXcmWeight { _reserve: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { + /// TODO: Clear wrong // This is not correct. initiate reserve withdraw does not to that many db reads // the only thing it does based on number of assets is a take from a local variable //assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) - XcmFungibleWeight::::initiate_reserve_withdraw() + XcmGeneric::::initiate_reserve_withdraw() } fn initiate_teleport( _assets: &MultiAssetFilter, _dest: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - XcmFungibleWeight::::initiate_teleport() + // max weight + XcmFungibleBalancesWeight::::initiate_teleport() } fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight { XcmGeneric::::report_holding() @@ -193,9 +211,12 @@ impl XcmWeightInfo for ShibuyaXcmWeight { XcmGeneric::::unsubscribe_version() } fn burn_asset(assets: &MultiAssets) -> Weight { + //TODO: This should not be multiploed by assets, we are already burning worse case + // assets assets.weigh_multi_assets(XcmGeneric::::burn_asset()) } fn expect_asset(assets: &MultiAssets) -> Weight { + // TODO same here assets.weigh_multi_assets(XcmGeneric::::expect_asset()) } fn expect_origin(_origin: &Option) -> Weight { diff --git a/runtime/shibuya/src/xcm_config.rs b/runtime/shibuya/src/xcm_config.rs index 775bac1c48..4fe7017fd2 100644 --- a/runtime/shibuya/src/xcm_config.rs +++ b/runtime/shibuya/src/xcm_config.rs @@ -35,10 +35,10 @@ use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ConvertedConcreteId, CurrencyAdapter, - EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, IsConcrete, NoChecking, - ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WithComputedOrigin, + EnsureXcmOrigin, FungiblesAdapter, IsConcrete, NoChecking, ParentAsSuperuser, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + UsingComponents, WeightInfoBounds, WithComputedOrigin, }; use xcm_executor::{ traits::{Convert as XcmConvert, JustTry}, @@ -171,12 +171,12 @@ pub type ShibuyaXcmFungibleFeeHandler = XcmFungibleFeeHandler< TreasuryAccountId, >; -pub type Weigher = FixedWeightBounds; -// pub type Weigher = WeightInfoBounds< -// crate::weights::xcm::ShibuyaXcmWeight, -// RuntimeCall, -// MaxInstructions, -// >; +// pub type Weigher = FixedWeightBounds; +pub type Weigher = WeightInfoBounds< + crate::weights::xcm_instruction_benchmarks::ShibuyaXcmWeight, + RuntimeCall, + MaxInstructions, +>; pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { From 1e2a8c45b5b01e7bc2fe9d2053842b9170adb757 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Thu, 19 Oct 2023 13:56:32 +0530 Subject: [PATCH 13/20] add comments --- runtime/shibuya/src/lib.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 7c2af331bb..d374335d8b 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -1946,6 +1946,8 @@ impl_runtime_apis! { Ok(MultiLocation::parent()) } fn worst_case_holding(_depositable_count: u32) -> MultiAssets { + // we can have max of 64 assets in holding so this should be + // a good estimate for worst case const HOLDING_FUNGIBLES: u32 = 62; let fungibles_amount: u128 = 100; let assets = (0..HOLDING_FUNGIBLES).map(|i| { @@ -1983,11 +1985,12 @@ impl_runtime_apis! { // not sure what will be the worst case for Response // either `Assets(MultiAssets)` or `PalletsInfo(BoundedVec)` // in either case, what will be the worst case? - let assets: Vec = vec![MultiAsset { - id: Concrete(MultiLocation::parent()), - fun: Fungible(u128::MAX), - }]; - (0u64, Response::Assets(assets.into())) + // let assets: Vec = vec![MultiAsset { + // id: Concrete(MultiLocation::parent()), + // fun: Fungible(u128::MAX), + // }]; + // (0u64, Response::Assets(assets.into())) + (0u64, Response::Version(Default::default())) } @@ -2063,9 +2066,7 @@ impl_runtime_apis! { /// Give me a fungible asset that your asset transactor is going to accept. fn get_multi_asset() -> MultiAsset { - // send some token to alice for existential deposit - - // create an asset + // create an asset and make it sufficient assert_ok!(pallet_assets::Pallet::::force_create(RuntimeOrigin::root(),parity_scale_codec::Compact(1),sp_runtime::MultiAddress::Id(AccountId32::new([0u8; 32])),true,1)); let location = MultiLocation { parents : 0, interior :X1(GeneralIndex(1)) }; // convert mapping for asset id From 106bb2e78f3dc02caa77726a4297772bcfbc5de6 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Thu, 19 Oct 2023 14:18:43 +0530 Subject: [PATCH 14/20] clippy and license fix --- .../fungible_assets_benchmarks.rs | 17 +++++++++++++++++ .../fungible_balances_benchmarks.rs | 17 +++++++++++++++++ .../generic_benchmarks.rs | 17 +++++++++++++++++ .../weights/xcm_instruction_benchmarks/mod.rs | 17 +++++++++-------- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs index 4e6aebe286..937db8c28a 100644 --- a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs @@ -1,3 +1,20 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . //! Autogenerated weights for `astar_xcm_benchmarks::fungible::assets` //! diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs index 73f83102ed..b8903aff93 100644 --- a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs @@ -1,4 +1,21 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . //! Autogenerated weights for `astar_xcm_benchmarks::fungible::assets` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs index 5d8d16350a..4742fba5c1 100644 --- a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs @@ -1,4 +1,21 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . //! Autogenerated weights for `astar_xcm_benchmarks::generic` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs index 2be67bdd41..9886207aec 100644 --- a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs @@ -159,14 +159,14 @@ impl XcmWeightInfo for ShibuyaXcmWeight { _receive: &MultiAssets, _maximal: &bool, ) -> XCMWeight { - Weight::MAX + XcmGeneric::::exchange_asset() } fn initiate_reserve_withdraw( _assets: &MultiAssetFilter, _reserve: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - /// TODO: Clear wrong + // TODO: Clear wrong // This is not correct. initiate reserve withdraw does not to that many db reads // the only thing it does based on number of assets is a take from a local variable //assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) @@ -179,6 +179,7 @@ impl XcmWeightInfo for ShibuyaXcmWeight { ) -> XCMWeight { // max weight XcmFungibleBalancesWeight::::initiate_teleport() + .max(XcmFungibleAssetsWeight::::initiate_teleport()) } fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight { XcmGeneric::::report_holding() @@ -247,22 +248,22 @@ impl XcmWeightInfo for ShibuyaXcmWeight { XcmGeneric::::clear_transact_status() } fn universal_origin(_: &Junction) -> Weight { - Weight::MAX + XcmGeneric::::universal_origin() } fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight { - Weight::MAX + XcmGeneric::::export_message() } fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { - Weight::MAX + XcmGeneric::::lock_asset() } fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { - Weight::MAX + XcmGeneric::::unlock_asset() } fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight { - Weight::MAX + XcmGeneric::::note_unlockable() } fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight { - Weight::MAX + XcmGeneric::::request_unlock() } fn set_fees_mode(_: &bool) -> Weight { XcmGeneric::::set_fees_mode() From bbcff0bfdeac3014edbd44d48c37593272e24a8f Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Fri, 20 Oct 2023 14:24:06 +0530 Subject: [PATCH 15/20] clean up --- .../src/fungible/assets/benchmarking.rs | 17 ++++++++++++----- .../src/fungible/assets/mock.rs | 13 ------------- .../src/fungible/balances/mock.rs | 2 -- runtime/astar/src/xcm_config.rs | 4 ++-- runtime/shibuya/src/lib.rs | 14 +++++--------- .../weights/xcm_instruction_benchmarks/mod.rs | 3 --- runtime/shibuya/src/xcm_config.rs | 4 ---- runtime/shiden/src/xcm_config.rs | 4 ++-- 8 files changed, 21 insertions(+), 40 deletions(-) diff --git a/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs index 70a92e0a58..85c9182a2e 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs @@ -37,6 +37,12 @@ benchmarks_instance_pallet! { as TryInto >::Error: sp_std::fmt::Debug, + + < T::TransactAsset + as + Inspect + >::Balance : Into + } withdraw_asset { @@ -86,14 +92,12 @@ benchmarks_instance_pallet! { }, ).unwrap(); assert!(T::TransactAsset::balance(&dest_account).is_zero()); + // reducing some assets for Existential deposit if let Fungible(x) = asset.fun { asset.fun = Fungible(x/10) }; - log::trace!( - target: "xcm::process", - "asset is {:?}",asset.clone()); let assets: MultiAssets = vec![ asset.clone() ].into(); log::trace!( target: "xcm::process", @@ -116,13 +120,14 @@ benchmarks_instance_pallet! { target: "xcm::process", "destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + let previous_balance: u128 = T::TransactAsset::balance(&dest_account).into(); }: { executor.bench_process(xcm)?; } verify { log::trace!( target: "xcm::process", "destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); - assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + assert!(T::TransactAsset::balance(&dest_account).into() == 2 * previous_balance); } transfer_reserve_asset { @@ -165,10 +170,12 @@ benchmarks_instance_pallet! { xcm: Xcm::new() }; let xcm = Xcm(vec![instruction]); + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + let previous_balance: u128 = T::TransactAsset::balance(&dest_account).into(); }: { executor.bench_process(xcm)?; } verify { - assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + assert!(T::TransactAsset::balance(&dest_account).into() == 2 * previous_balance); } receive_teleported_asset { diff --git a/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs index 9de8238fb2..6a09dafc24 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs @@ -129,19 +129,6 @@ impl pallet_assets::Config for Test { #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = (); } -// pub struct MatchAnyFungible; -// impl xcm_executor::traits::MatchesFungible for MatchAnyFungible { -// fn matches_fungible(m: &MultiAsset) -> Option { -// use sp_runtime::traits::SaturatedConversion; -// match m { -// MultiAsset { -// fun: Fungible(amount), -// .. -// } => Some((*amount).saturated_into::()), -// _ => None, -// } -// } -// } // Use fungible transactor as the asset transactor. pub type AssetTransactor = xcm_builder::FungiblesAdapter< diff --git a/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs index 76f5f46a7e..0bd3e943b4 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs @@ -126,8 +126,6 @@ pub type AssetTransactor = xcm_builder::CurrencyAdapter< >; parameter_types! { - /// Maximum number of instructions in a single XCM fragment. A sanity check against weight - /// calculations getting too crazy. pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; } diff --git a/runtime/astar/src/xcm_config.rs b/runtime/astar/src/xcm_config.rs index f104062473..5f01ba0bbf 100644 --- a/runtime/astar/src/xcm_config.rs +++ b/runtime/astar/src/xcm_config.rs @@ -136,8 +136,8 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - // For the PoV size, we estimate 64 kB per instruction - which will is once again very conservative. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, astar_primitives::xcm::DEFAULT_PROOF_SIZE); + // For the PoV size, we estimate 4 kB per instruction. This will be changed when we benchmark the instructions. + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 4 * 1024); pub const MaxInstructions: u32 = 100; } diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index d374335d8b..063b96ed9a 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -1982,15 +1982,11 @@ impl_runtime_apis! { type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { - // not sure what will be the worst case for Response - // either `Assets(MultiAssets)` or `PalletsInfo(BoundedVec)` - // in either case, what will be the worst case? - // let assets: Vec = vec![MultiAsset { - // id: Concrete(MultiLocation::parent()), - // fun: Fungible(u128::MAX), - // }]; - // (0u64, Response::Assets(assets.into())) - (0u64, Response::Version(Default::default())) + let assets: Vec = vec![MultiAsset { + id: Concrete(MultiLocation::parent()), + fun: Fungible(u128::MAX), + }]; + (0u64, Response::Assets(assets.into())) } diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs index 9886207aec..7633bf4fb5 100644 --- a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs @@ -212,12 +212,9 @@ impl XcmWeightInfo for ShibuyaXcmWeight { XcmGeneric::::unsubscribe_version() } fn burn_asset(assets: &MultiAssets) -> Weight { - //TODO: This should not be multiploed by assets, we are already burning worse case - // assets assets.weigh_multi_assets(XcmGeneric::::burn_asset()) } fn expect_asset(assets: &MultiAssets) -> Weight { - // TODO same here assets.weigh_multi_assets(XcmGeneric::::expect_asset()) } fn expect_origin(_origin: &Option) -> Weight { diff --git a/runtime/shibuya/src/xcm_config.rs b/runtime/shibuya/src/xcm_config.rs index 4fe7017fd2..2d985fd13d 100644 --- a/runtime/shibuya/src/xcm_config.rs +++ b/runtime/shibuya/src/xcm_config.rs @@ -137,9 +137,6 @@ pub type XcmOriginToTransactDispatchOrigin = ( ); parameter_types! { - // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - // For the PoV size, we estimate 64 kB per instruction - which will is once again very conservative. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, astar_primitives::xcm::DEFAULT_PROOF_SIZE); pub const MaxInstructions: u32 = 100; } @@ -171,7 +168,6 @@ pub type ShibuyaXcmFungibleFeeHandler = XcmFungibleFeeHandler< TreasuryAccountId, >; -// pub type Weigher = FixedWeightBounds; pub type Weigher = WeightInfoBounds< crate::weights::xcm_instruction_benchmarks::ShibuyaXcmWeight, RuntimeCall, diff --git a/runtime/shiden/src/xcm_config.rs b/runtime/shiden/src/xcm_config.rs index 3521d637d7..a38ec8091d 100644 --- a/runtime/shiden/src/xcm_config.rs +++ b/runtime/shiden/src/xcm_config.rs @@ -138,8 +138,8 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - // For the PoV size, we estimate 64 kB per instruction - which will is once again very conservative. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, astar_primitives::xcm::DEFAULT_PROOF_SIZE); + // For the PoV size, we estimate 4 kB per instruction. This will be changed when we benchmark the instructions. + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 4 * 1024); pub const MaxInstructions: u32 = 100; } From ac8d97e8b1f1b9b042716e76281cd764ab520a51 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Fri, 20 Oct 2023 14:42:48 +0530 Subject: [PATCH 16/20] unitweight fix --- primitives/src/xcm/mod.rs | 2 -- runtime/shibuya/src/xcm_config.rs | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/primitives/src/xcm/mod.rs b/primitives/src/xcm/mod.rs index e405db589f..27d2bcfc68 100644 --- a/primitives/src/xcm/mod.rs +++ b/primitives/src/xcm/mod.rs @@ -51,8 +51,6 @@ use pallet_xc_asset_config::{ExecutionPaymentRate, XcAssetLocation}; /// Max assets allowed in holding register pub const MAX_ASSETS: u64 = 64; -/// Default Proof Size for XCM -pub const DEFAULT_PROOF_SIZE: u64 = 64 * 1024; #[cfg(test)] mod tests; diff --git a/runtime/shibuya/src/xcm_config.rs b/runtime/shibuya/src/xcm_config.rs index 2d985fd13d..3df22afd3c 100644 --- a/runtime/shibuya/src/xcm_config.rs +++ b/runtime/shibuya/src/xcm_config.rs @@ -137,6 +137,9 @@ pub type XcmOriginToTransactDispatchOrigin = ( ); parameter_types! { + // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. + // For the PoV size, we estimate 4 kB per instruction. This will be changed when we benchmark the instructions. + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 4 * 1024); pub const MaxInstructions: u32 = 100; } From a4e2bd940b11acf58c9aa97c6f0b4d9ec7fc4cf1 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Fri, 20 Oct 2023 19:52:15 +0530 Subject: [PATCH 17/20] mock config fix --- Cargo.lock | 3 + pallets/astar-xcm-benchmarks/Cargo.toml | 18 +- .../src/fungible/assets/mock.rs | 50 ++-- .../src/fungible/balances/mock.rs | 28 +- .../src/fungible/benchmarking.rs | 253 ------------------ .../astar-xcm-benchmarks/src/generic/mock.rs | 52 ++-- pallets/astar-xcm-benchmarks/src/mock.rs | 11 +- 7 files changed, 97 insertions(+), 318 deletions(-) delete mode 100644 pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs diff --git a/Cargo.lock b/Cargo.lock index 00cca29359..6800652949 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -629,6 +629,7 @@ dependencies = [ name = "astar-xcm-benchmarks" version = "0.1.0" dependencies = [ + "astar-primitives", "frame-benchmarking", "frame-support", "frame-system", @@ -637,12 +638,14 @@ dependencies = [ "pallet-balances", "pallet-xcm", "parity-scale-codec", + "paste", "scale-info", "serde", "sp-core", "sp-io", "sp-runtime", "sp-std", + "sp-tracing", "xcm", "xcm-builder", "xcm-executor", diff --git a/pallets/astar-xcm-benchmarks/Cargo.toml b/pallets/astar-xcm-benchmarks/Cargo.toml index 0c78bc52f8..d97e16ae90 100644 --- a/pallets/astar-xcm-benchmarks/Cargo.toml +++ b/pallets/astar-xcm-benchmarks/Cargo.toml @@ -13,11 +13,12 @@ serde = { workspace = true, optional = true } # Substrate frame-support = { workspace = true, default-features = false } frame-system = { workspace = true } -parity-scale-codec = { workspace = true, features = ["derive"] } -scale-info = { workspace = true, features = ["derive"] } +parity-scale-codec = { workspace = true } +scale-info = { workspace = true } sp-std = { workspace = true } # Polkadot / XCM +astar-primitives = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } xcm = { workspace = true } @@ -31,7 +32,9 @@ frame-benchmarking = { workspace = true } pallet-assets = { workspace = true } pallet-balances = { workspace = true } pallet-xcm = { workspace = true } +paste = { workspace = true } sp-core = { workspace = true } +sp-tracing = { workspace = true } [features] default = ["std"] @@ -46,12 +49,23 @@ std = [ "xcm/std", "sp-io/std", "sp-runtime/std", + "sp-core/std", + "astar-primitives/std", + "scale-info/std", + "astar-primitives/std", + "pallet-balances/std", + "pallet-assets/std", ] runtime-benchmarks = [ "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", "frame-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "frame-support/runtime-benchmarks", + "astar-primitives/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] + +try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs index 6a09dafc24..5feec89f7d 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs @@ -23,25 +23,36 @@ use crate::{fungible::assets as xcm_assets_benchmark, mock::*}; use frame_benchmarking::BenchmarkError; use frame_support::{ parameter_types, - traits::{ConstU32, Everything, Nothing}, + traits::{AsEnsureOriginWithArg, ConstU32, Everything, Nothing}, weights::Weight, }; +use frame_system::{EnsureRoot, EnsureSigned}; +use parity_scale_codec::Compact; use sp_core::H256; -use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, +}; +use sp_std::borrow::Borrow; use xcm::latest::prelude::*; -use xcm_builder::{AllowUnpaidExecutionFrom, ConvertedConcreteId, IsConcrete, MintLocation}; -use xcm_executor::traits::JustTry; +use xcm_builder::{AllowUnpaidExecutionFrom, ConvertedConcreteId, MintLocation}; +use xcm_executor::traits::{Convert, JustTry}; type Block = frame_system::mocking::MockBlock; +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; // For testing the pallet, we construct a mock runtime. frame_support::construct_runtime!( - pub enum Test + pub struct Test + where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - XcmAssetsBenchmark: xcm_assets_benchmark::{Pallet}, - Assets : pallet_balances::{Pallet, Call, Storage, Config, Event}, + System: frame_system, + Balances: pallet_balances, + XcmAssetsBenchmark: xcm_assets_benchmark, + Assets: pallet_assets, } ); @@ -56,13 +67,14 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; type Hash = H256; + type Index = u64; + type Header = Header; + type BlockNumber = u64; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; - type Block = Block; type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type Version = (); @@ -90,10 +102,10 @@ impl pallet_balances::Config for Test { type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); - type RuntimeHoldReason = RuntimeHoldReason; type FreezeIdentifier = (); type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; + type HoldIdentifier = (); } parameter_types! { @@ -103,7 +115,7 @@ parameter_types! { pub const MetadataDepositBase: u64 = 10 * ExistentialDeposit::get(); pub const MetadataDepositPerByte: u64 = 1 * ExistentialDeposit::get(); pub const AssetAccountDeposit: u64 = 1 * ExistentialDeposit::get(); - const AssetsStringLimit: u32 = 50; + pub const AssetsStringLimit: u32 = 50; } @@ -112,8 +124,8 @@ impl pallet_assets::Config for Test { type Balance = u64; type AssetId = u64; type Currency = Balances; - type CreateOrigin = AsEnsureOriginWithArg>; - type ForceOrigin = EnsureRoot; + type CreateOrigin = AsEnsureOriginWithArg>; + type ForceOrigin = EnsureRoot; type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase; type MetadataDepositPerByte = MetadataDepositPerByte; @@ -130,6 +142,9 @@ impl pallet_assets::Config for Test { type BenchmarkHelper = (); } +parameter_types! { + pub const DummyCheckingAccount : u64 = 0; +} // Use fungible transactor as the asset transactor. pub type AssetTransactor = xcm_builder::FungiblesAdapter< Assets, @@ -137,14 +152,14 @@ pub type AssetTransactor = xcm_builder::FungiblesAdapter< AccountIdConverter, u64, xcm_builder::NoChecking, - 0, + DummyCheckingAccount, >; pub struct AssetLocationIdConverter; impl Convert for AssetLocationIdConverter { fn convert_ref(location: impl Borrow) -> Result { if let X1(GeneralIndex(i)) = location.borrow().clone().interior { - Ok(i.into()) + Ok(>::try_into(i).map_err(|_| ())?) } else { Err(()) } @@ -187,7 +202,6 @@ impl xcm_executor::Config for XcmConfig { type UniversalAliases = Nothing; type CallDispatcher = RuntimeCall; type SafeCallFilter = Everything; - type Aliasers = Nothing; } impl crate::Config for Test { diff --git a/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs index 0bd3e943b4..347ebc2eb0 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs @@ -19,7 +19,7 @@ // Copyright (C) Parity Technologies (UK) Ltd. //! A mock runtime for XCM benchmarking. -use crate::{fungible as xcm_balances_benchmark, mock::*}; +use crate::{fungible::balances as xcm_balances_benchmark, mock::*}; use frame_benchmarking::BenchmarkError; use frame_support::{ parameter_types, @@ -27,19 +27,27 @@ use frame_support::{ weights::Weight, }; use sp_core::H256; -use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, +}; use xcm::latest::prelude::*; use xcm_builder::{AllowUnpaidExecutionFrom, MintLocation}; type Block = frame_system::mocking::MockBlock; +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; // For testing the pallet, we construct a mock runtime. frame_support::construct_runtime!( - pub enum Test + pub struct 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}, + System: frame_system, + Balances: pallet_balances, + XcmBalancesBenchmark: xcm_balances_benchmark, } ); @@ -54,13 +62,14 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; type Hash = H256; + type Index = u64; + type Header = Header; + type BlockNumber = u64; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; - type Block = Block; type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type Version = (); @@ -88,10 +97,10 @@ impl pallet_balances::Config for Test { type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); - type RuntimeHoldReason = RuntimeHoldReason; type FreezeIdentifier = (); type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; + type HoldIdentifier = (); } parameter_types! { @@ -155,7 +164,6 @@ impl xcm_executor::Config for XcmConfig { type UniversalAliases = Nothing; type CallDispatcher = RuntimeCall; type SafeCallFilter = Everything; - type Aliasers = Nothing; } impl crate::Config for Test { diff --git a/pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs deleted file mode 100644 index a8b8a8cd55..0000000000 --- a/pallets/astar-xcm-benchmarks/src/fungible/benchmarking.rs +++ /dev/null @@ -1,253 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later - -// Astar 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. - -// Astar 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 Astar. If not, see . - -// Copyright (C) Parity Technologies (UK) Ltd. -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(0); - let asset = T::get_multi_asset(); - - >::deposit_asset( - &asset, - &sender_location, - &XcmContext { - origin: Some(sender_location.clone()), - message_hash: [0; 32], - topic: None, - }, - ).unwrap(); - // check the assets of origin. - assert!(!T::TransactAsset::balance(&sender_account).is_zero()); - - let mut executor = new_executor::(sender_location); - executor.set_holding(worst_case_holding.into()); - let instruction = Instruction::>::WithdrawAsset(vec![asset.clone()].into()); - let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(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, - &XcmContext { - origin: Some(sender_location.clone()), - message_hash: [0; 32], - topic: None, - }, - ).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.bench_process(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, - &XcmContext { - origin: Some(sender_location.clone()), - message_hash: [0; 32], - topic: None, - }, - ).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.bench_process(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 - } - - 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.bench_process(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(1); - - // 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.set_holding(holding.into()); - let instruction = Instruction::>::DepositAsset { - assets: asset.into(), - beneficiary: dest_location, - }; - let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(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(1); - - // 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.set_holding(holding.into()); - let instruction = Instruction::>::DepositReserveAsset { - assets: asset.into(), - dest: dest_location, - xcm: Xcm::new(), - }; - let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(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(0); - - // Add our asset to the holding. - holding.push(asset.clone()); - - // Checked account starts at zero - assert!(T::CheckedAccount::get().map_or(true, |(c, _)| T::TransactAsset::balance(&c).is_zero())); - - let mut executor = new_executor::(Default::default()); - executor.set_holding(holding.into()); - let instruction = Instruction::>::InitiateTeleport { - assets: asset.into(), - dest: T::valid_destination()?, - xcm: Xcm::new(), - }; - let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { - if let Some((checked_account, _)) = T::CheckedAccount::get() { - // teleport checked account should have received some asset. - assert!(!T::TransactAsset::balance(&checked_account).is_zero()); - } - } - - impl_benchmark_test_suite!( - Pallet, - crate::fungible::mock::new_test_ext(), - crate::fungible::mock::Test - ); -} diff --git a/pallets/astar-xcm-benchmarks/src/generic/mock.rs b/pallets/astar-xcm-benchmarks/src/generic/mock.rs index 6edce1f896..aa73c969cc 100644 --- a/pallets/astar-xcm-benchmarks/src/generic/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/generic/mock.rs @@ -20,30 +20,38 @@ //! A mock runtime for XCM benchmarking. use crate::{generic, mock::*, *}; -use codec::Decode; use frame_support::{ match_types, parameter_types, traits::{Everything, OriginTrait}, weights::Weight, }; +use parity_scale_codec::Decode; use sp_core::H256; -use sp_runtime::traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput}; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput}, +}; use xcm_builder::{ test_utils::{ Assets, TestAssetExchanger, TestAssetLocker, TestAssetTrap, TestSubscriptionService, TestUniversalAliases, }, - AliasForeignAccountId32, AllowUnpaidExecutionFrom, + AllowUnpaidExecutionFrom, }; use xcm_executor::traits::ConvertOrigin; -type Block = frame_system::mocking::MockBlock; +type Block = frame_system::mocking::MockBlock; +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; frame_support::construct_runtime!( - pub enum Test + pub struct TestRuntime + where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - XcmGenericBenchmarks: generic::{Pallet}, + System: frame_system, + XcmGenericBenchmarks: generic, } ); @@ -53,19 +61,17 @@ parameter_types! { frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, u64::MAX)); } -impl frame_system::Config for Test { +impl frame_system::Config for TestRuntime { type BaseCallFilter = Everything; type BlockWeights = (); type BlockLength = (); type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; type Hash = H256; type RuntimeCall = RuntimeCall; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; - type Block = Block; type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; type Version = (); @@ -77,6 +83,9 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = frame_support::traits::ConstU32<16>; + type Index = u64; + type Header = Header; + type BlockNumber = u64; } /// The benchmarks in this pallet should never need an asset transactor to begin with. @@ -106,7 +115,6 @@ match_types! { }; } -type Aliasers = AliasForeignAccountId32; pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; @@ -133,10 +141,9 @@ impl xcm_executor::Config for XcmConfig { type UniversalAliases = TestUniversalAliases; type CallDispatcher = RuntimeCall; type SafeCallFilter = Everything; - type Aliasers = Aliasers; } -impl crate::Config for Test { +impl crate::Config for TestRuntime { type XcmConfig = XcmConfig; type AccountIdConverter = AccountIdConverter; fn valid_destination() -> Result { @@ -156,7 +163,7 @@ impl crate::Config for Test { } } -impl generic::Config for Test { +impl generic::Config for TestRuntime { type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { @@ -203,23 +210,6 @@ impl generic::Config for Test { // No MessageExporter in tests Err(BenchmarkError::Skip) } - - fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> { - let origin: MultiLocation = ( - Parachain(1), - AccountId32 { - network: None, - id: [0; 32], - }, - ) - .into(); - let target: MultiLocation = AccountId32 { - network: None, - id: [0; 32], - } - .into(); - Ok((origin, target)) - } } #[cfg(feature = "runtime-benchmarks")] diff --git a/pallets/astar-xcm-benchmarks/src/mock.rs b/pallets/astar-xcm-benchmarks/src/mock.rs index 45170bfc6d..3f783859df 100644 --- a/pallets/astar-xcm-benchmarks/src/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/mock.rs @@ -50,16 +50,19 @@ impl xcm_executor::traits::OnResponse for DevNull { } pub struct AccountIdConverter; -impl xcm_executor::traits::ConvertLocation for AccountIdConverter { - fn convert_location(ml: &MultiLocation) -> Option { +impl xcm_executor::traits::Convert for AccountIdConverter { + fn convert(ml: MultiLocation) -> Result { match ml { MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { id, .. }), - } => Some(::decode(&mut &*id.to_vec()).unwrap()), - _ => None, + } => Ok(::decode(&mut &*id.to_vec()).unwrap()), + _ => Err(ml), } } + fn reverse(acc: u64) -> Result { + Err(acc) + } } parameter_types! { From 1ee6bc40993421e8ed7355aca2a9c585aedc401f Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Sat, 21 Oct 2023 01:23:10 +0530 Subject: [PATCH 18/20] add correct weight --- .../fungible_assets_benchmarks.rs | 84 +++---- .../fungible_balances_benchmarks.rs | 107 ++++----- .../generic_benchmarks.rs | 220 +++++++----------- 3 files changed, 164 insertions(+), 247 deletions(-) diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs index 937db8c28a..dae5969057 100644 --- a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_assets_benchmarks.rs @@ -1,3 +1,4 @@ + // This file is part of Astar. // Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. @@ -16,44 +17,39 @@ // You should have received a copy of the GNU General Public License // along with Astar. If not, see . -//! Autogenerated weights for `astar_xcm_benchmarks::fungible::assets` +//! Autogenerated weights for astar_xcm_benchmarks::fungible::assets //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-10-18, STEPS: `50`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-10-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Deepanshu.local`, CPU: `` +//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 // Executed Command: // ./target/release/astar-collator // benchmark // pallet -// --chain -// shibuya-dev +// --chain=shibuya-dev +// --steps=50 +// --repeat=20 +// --pallet=astar_xcm_benchmarks::fungible::assets +// --extrinsic=* // --execution=wasm // --wasm-execution=compiled -// --pallet -// astar_xcm_benchmarks::fungible::assets -// --extrinsic -// * -// --steps -// 50 -// --repeat -// 1 -// --output -// pallets/transfer-weight.rs +// --heap-pages=4096 +// --output=./benchmark-results/shibuya-dev/xcm_benchmarks_fungible_assets_weights.rs +// --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(missing_docs)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; -/// Weight functions for `astar_xcm_benchmarks::fungible::assets`. +/// Weights for astar_xcm_benchmarks::fungible::assets using the Substrate node and recommended hardware. pub struct WeightInfo(PhantomData); -impl WeightInfo { +impl WeightInfo { /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) /// Storage: Assets Asset (r:1 w:1) @@ -68,11 +64,10 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `688` // Estimated: `4153` - // Minimum execution time: 116_000_000 picoseconds. - Weight::from_parts(116_000_000, 0) - .saturating_add(Weight::from_parts(0, 4153)) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(3)) + // Minimum execution time: 48_407_000 picoseconds. + Weight::from_parts(48_710_000, 4153) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) @@ -84,11 +79,10 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `622` // Estimated: `6232` - // Minimum execution time: 107_000_000 picoseconds. - Weight::from_parts(107_000_000, 0) - .saturating_add(Weight::from_parts(0, 6232)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(3)) + // Minimum execution time: 43_069_000 picoseconds. + Weight::from_parts(44_006_000, 6232) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) @@ -112,11 +106,10 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `836` // Estimated: `6232` - // Minimum execution time: 151_000_000 picoseconds. - Weight::from_parts(151_000_000, 0) - .saturating_add(Weight::from_parts(0, 6232)) - .saturating_add(T::DbWeight::get().reads(10)) - .saturating_add(T::DbWeight::get().writes(5)) + // Minimum execution time: 68_124_000 picoseconds. + Weight::from_parts(68_800_000, 6232) + .saturating_add(T::DbWeight::get().reads(10_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -126,7 +119,6 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) @@ -140,11 +132,10 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `424` // Estimated: `3889` - // Minimum execution time: 79_000_000 picoseconds. - Weight::from_parts(79_000_000, 0) - .saturating_add(Weight::from_parts(0, 3889)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(3)) + // Minimum execution time: 37_158_000 picoseconds. + Weight::from_parts(37_598_000, 3889) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) @@ -170,11 +161,10 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `638` // Estimated: `4103` - // Minimum execution time: 121_000_000 picoseconds. - Weight::from_parts(121_000_000, 0) - .saturating_add(Weight::from_parts(0, 4103)) - .saturating_add(T::DbWeight::get().reads(10)) - .saturating_add(T::DbWeight::get().writes(5)) + // Minimum execution time: 61_240_000 picoseconds. + Weight::from_parts(61_987_000, 4103) + .saturating_add(T::DbWeight::get().reads(10_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -184,9 +174,9 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } - pub(crate) fn reserve_asset_deposited() -> Weight { + + pub(crate) fn reserve_asset_deposited() -> Weight { // This instruction is a no-op for PoV (no storage access) Weight::from_parts(200_000_000 as u64, 0) } diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs index b8903aff93..7369c496ca 100644 --- a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/fungible_balances_benchmarks.rs @@ -54,48 +54,36 @@ use core::marker::PhantomData; /// Weight functions for `astar_xcm_benchmarks::fungible::assets`. pub struct WeightInfo(PhantomData); impl WeightInfo { - /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) - /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) - /// Storage: Assets Asset (r:1 w:1) - /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) - /// Storage: Assets Account (r:1 w:1) - /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) /// Storage: System Account (r:1 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: UnifiedAccounts NativeToEvm (r:1 w:0) /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) pub(crate) fn withdraw_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `688` - // Estimated: `4153` - // Minimum execution time: 116_000_000 picoseconds. - Weight::from_parts(116_000_000, 0) - .saturating_add(Weight::from_parts(0, 4153)) - .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(3)) + // Measured: `182` + // Estimated: `3593` + // Minimum execution time: 29_196_000 picoseconds. + Weight::from_parts(29_523_000, 3593) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) - /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) - /// Storage: Assets Asset (r:1 w:1) - /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) - /// Storage: Assets Account (r:2 w:2) - /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + /// Storage: System Account (r:2 w:2) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: UnifiedAccounts NativeToEvm (r:1 w:0) + /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) pub(crate) fn transfer_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `622` - // Estimated: `6232` - // Minimum execution time: 107_000_000 picoseconds. - Weight::from_parts(107_000_000, 0) - .saturating_add(Weight::from_parts(0, 6232)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(3)) + // Measured: `182` + // Estimated: `6196` + // Minimum execution time: 51_481_000 picoseconds. + Weight::from_parts(52_599_000, 6196) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } - /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) - /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) - /// Storage: Assets Asset (r:1 w:1) - /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) - /// Storage: Assets Account (r:2 w:2) - /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + /// Storage: System Account (r:2 w:2) + /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + /// Storage: UnifiedAccounts NativeToEvm (r:1 w:0) + /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) /// Storage: ParachainInfo ParachainId (r:1 w:0) /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Storage: PolkadotXcm SupportedVersion (r:1 w:0) @@ -110,13 +98,12 @@ impl WeightInfo { /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) pub(crate) fn transfer_reserve_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `836` - // Estimated: `6232` - // Minimum execution time: 151_000_000 picoseconds. - Weight::from_parts(151_000_000, 0) - .saturating_add(Weight::from_parts(0, 6232)) - .saturating_add(T::DbWeight::get().reads(10)) - .saturating_add(T::DbWeight::get().writes(5)) + // Measured: `396` + // Estimated: `6196` + // Minimum execution time: 74_937_000 picoseconds. + Weight::from_parts(75_528_000, 6196) + .saturating_add(T::DbWeight::get().reads(9_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -126,32 +113,18 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) - /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) - /// Storage: Assets Asset (r:1 w:1) - /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) - /// Storage: Assets Account (r:1 w:1) - /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) /// Storage: System Account (r:1 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) pub(crate) fn deposit_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `424` - // Estimated: `3889` - // Minimum execution time: 79_000_000 picoseconds. - Weight::from_parts(79_000_000, 0) - .saturating_add(Weight::from_parts(0, 3889)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(3)) + // Measured: `0` + // Estimated: `3593` + // Minimum execution time: 25_946_000 picoseconds. + Weight::from_parts(26_173_000, 3593) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: XcAssetConfig AssetLocationToId (r:1 w:0) - /// Proof Skipped: XcAssetConfig AssetLocationToId (max_values: None, max_size: None, mode: Measured) - /// Storage: Assets Asset (r:1 w:1) - /// Proof: Assets Asset (max_values: None, max_size: Some(222), added: 2697, mode: MaxEncodedLen) - /// Storage: Assets Account (r:1 w:1) - /// Proof: Assets Account (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) /// Storage: System Account (r:1 w:1) /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) /// Storage: ParachainInfo ParachainId (r:1 w:0) @@ -168,13 +141,12 @@ impl WeightInfo { /// Proof Skipped: ParachainSystem PendingUpwardMessages (max_values: Some(1), max_size: None, mode: Measured) pub(crate) fn deposit_reserve_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `638` - // Estimated: `4103` - // Minimum execution time: 121_000_000 picoseconds. - Weight::from_parts(121_000_000, 0) - .saturating_add(Weight::from_parts(0, 4103)) - .saturating_add(T::DbWeight::get().reads(10)) - .saturating_add(T::DbWeight::get().writes(5)) + // Measured: `214` + // Estimated: `3679` + // Minimum execution time: 51_389_000 picoseconds. + Weight::from_parts(51_915_000, 3679) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -184,9 +156,8 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } - + pub(crate) fn reserve_asset_deposited() -> Weight { // This instruction is a no-op for PoV (no storage access) Weight::from_parts(200_000_000 as u64, 0) diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs index 4742fba5c1..174dd56875 100644 --- a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/generic_benchmarks.rs @@ -16,42 +16,38 @@ // You should have received a copy of the GNU General Public License // along with Astar. If not, see . -//! Autogenerated weights for `astar_xcm_benchmarks::generic` + +//! Autogenerated weights for astar_xcm_benchmarks::generic //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-10-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-10-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Deepanshu`, CPU: `` +//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 // Executed Command: // ./target/release/astar-collator // benchmark // pallet -// --chain -// shibuya-dev +// --chain=shibuya-dev +// --steps=50 +// --repeat=20 +// --pallet=astar_xcm_benchmarks::generic +// --extrinsic=* // --execution=wasm // --wasm-execution=compiled -// --pallet -// astar_xcm_benchmarks::generic -// --extrinsic -// * -// --steps -// 50 -// --repeat -// 20 -// --output -// pallets/transfer-weight.rs +// --heap-pages=4096 +// --output=./benchmark-results/shibuya-dev/xcm_benchmarks_generic_weights.rs +// --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(missing_docs)] -use frame_support::{traits::Get, weights::Weight}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; -/// Weight functions for `astar_xcm_benchmarks::generic`. +/// Weights for astar_xcm_benchmarks::generic using the Substrate node and recommended hardware. pub struct WeightInfo(PhantomData); impl WeightInfo { /// Storage: ParachainInfo ParachainId (r:1 w:0) @@ -70,19 +66,17 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `214` // Estimated: `3679` - // Minimum execution time: 313_000_000 picoseconds. - Weight::from_parts(324_000_000, 0) - .saturating_add(Weight::from_parts(0, 3679)) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(2)) + // Minimum execution time: 367_936_000 picoseconds. + Weight::from_parts(369_906_000, 3679) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } pub(crate) fn buy_execution() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 42_000_000 picoseconds. - Weight::from_parts(43_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 48_101_000 picoseconds. + Weight::from_parts(48_508_000, 0) } /// Storage: PolkadotXcm Queries (r:1 w:0) /// Proof Skipped: PolkadotXcm Queries (max_values: None, max_size: None, mode: Measured) @@ -90,66 +84,58 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `69` // Estimated: `3534` - // Minimum execution time: 12_000_000 picoseconds. - Weight::from_parts(12_000_000, 0) - .saturating_add(Weight::from_parts(0, 3534)) - .saturating_add(T::DbWeight::get().reads(1)) + // Minimum execution time: 11_817_000 picoseconds. + Weight::from_parts(12_036_000, 3534) + .saturating_add(T::DbWeight::get().reads(1_u64)) } pub(crate) fn transact() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 11_000_000 picoseconds. - Weight::from_parts(12_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 11_443_000 picoseconds. + Weight::from_parts(11_718_000, 0) } pub(crate) fn refund_surplus() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 4_000_000 picoseconds. - Weight::from_parts(4_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 3_771_000 picoseconds. + Weight::from_parts(3_878_000, 0) } pub(crate) fn set_error_handler() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_643_000 picoseconds. + Weight::from_parts(2_790_000, 0) } pub(crate) fn set_appendix() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_615_000 picoseconds. + Weight::from_parts(2_686_000, 0) } pub(crate) fn clear_error() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_541_000 picoseconds. + Weight::from_parts(2_678_000, 0) } pub(crate) fn descend_origin() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(4_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 3_485_000 picoseconds. + Weight::from_parts(3_604_000, 0) } pub(crate) fn clear_origin() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_599_000 picoseconds. + Weight::from_parts(2_719_000, 0) } /// Storage: ParachainInfo ParachainId (r:1 w:0) /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) @@ -167,11 +153,10 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `214` // Estimated: `3679` - // Minimum execution time: 26_000_000 picoseconds. - Weight::from_parts(27_000_000, 0) - .saturating_add(Weight::from_parts(0, 3679)) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(2)) + // Minimum execution time: 26_327_000 picoseconds. + Weight::from_parts(26_810_000, 3679) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: PolkadotXcm AssetTraps (r:1 w:1) /// Proof Skipped: PolkadotXcm AssetTraps (max_values: None, max_size: None, mode: Measured) @@ -179,19 +164,17 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `126` // Estimated: `3591` - // Minimum execution time: 16_000_000 picoseconds. - Weight::from_parts(17_000_000, 0) - .saturating_add(Weight::from_parts(0, 3591)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + // Minimum execution time: 15_575_000 picoseconds. + Weight::from_parts(15_829_000, 3591) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } pub(crate) fn trap() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_551_000 picoseconds. + Weight::from_parts(2_648_000, 0) } /// Storage: PolkadotXcm VersionNotifyTargets (r:1 w:1) /// Proof Skipped: PolkadotXcm VersionNotifyTargets (max_values: None, max_size: None, mode: Measured) @@ -209,11 +192,10 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `111` // Estimated: `3576` - // Minimum execution time: 29_000_000 picoseconds. - Weight::from_parts(29_000_000, 0) - .saturating_add(Weight::from_parts(0, 3576)) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(3)) + // Minimum execution time: 26_081_000 picoseconds. + Weight::from_parts(26_533_000, 3576) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } /// Storage: PolkadotXcm VersionNotifyTargets (r:0 w:1) /// Proof Skipped: PolkadotXcm VersionNotifyTargets (max_values: None, max_size: None, mode: Measured) @@ -221,10 +203,9 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_000_000 picoseconds. - Weight::from_parts(5_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) + // Minimum execution time: 4_433_000 picoseconds. + Weight::from_parts(4_546_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: ParachainInfo ParachainId (r:1 w:0) /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) @@ -242,51 +223,45 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `214` // Estimated: `3679` - // Minimum execution time: 339_000_000 picoseconds. - Weight::from_parts(340_000_000, 0) - .saturating_add(Weight::from_parts(0, 3679)) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(2)) + // Minimum execution time: 415_251_000 picoseconds. + Weight::from_parts(417_527_000, 3679) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } pub(crate) fn burn_asset() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 109_000_000 picoseconds. - Weight::from_parts(110_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 118_820_000 picoseconds. + Weight::from_parts(121_105_000, 0) } pub(crate) fn expect_asset() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 19_000_000 picoseconds. - Weight::from_parts(20_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 9_352_000 picoseconds. + Weight::from_parts(9_648_000, 0) } pub(crate) fn expect_origin() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_700_000 picoseconds. + Weight::from_parts(2_789_000, 0) } pub(crate) fn expect_error() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_552_000 picoseconds. + Weight::from_parts(2_654_000, 0) } pub(crate) fn expect_transact_status() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_693_000 picoseconds. + Weight::from_parts(2_822_000, 0) } /// Storage: ParachainInfo ParachainId (r:1 w:0) /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) @@ -304,19 +279,17 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `214` // Estimated: `3679` - // Minimum execution time: 33_000_000 picoseconds. - Weight::from_parts(34_000_000, 0) - .saturating_add(Weight::from_parts(0, 3679)) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(2)) + // Minimum execution time: 31_400_000 picoseconds. + Weight::from_parts(31_951_000, 3679) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } pub(crate) fn expect_pallet() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 9_000_000 picoseconds. - Weight::from_parts(9_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 6_829_000 picoseconds. + Weight::from_parts(6_963_000, 0) } /// Storage: ParachainInfo ParachainId (r:1 w:0) /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) @@ -334,51 +307,45 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `214` // Estimated: `3679` - // Minimum execution time: 26_000_000 picoseconds. - Weight::from_parts(27_000_000, 0) - .saturating_add(Weight::from_parts(0, 3679)) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(2)) + // Minimum execution time: 26_405_000 picoseconds. + Weight::from_parts(27_466_000, 3679) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } pub(crate) fn clear_transact_status() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_569_000 picoseconds. + Weight::from_parts(2_691_000, 0) } pub(crate) fn set_topic() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_542_000 picoseconds. + Weight::from_parts(2_648_000, 0) } pub(crate) fn clear_topic() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_511_000 picoseconds. + Weight::from_parts(2_634_000, 0) } pub(crate) fn set_fees_mode() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_519_000 picoseconds. + Weight::from_parts(2_619_000, 0) } pub(crate) fn unpaid_execution() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_000_000 picoseconds. - Weight::from_parts(3_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Minimum execution time: 2_695_000 picoseconds. + Weight::from_parts(2_828_000, 0) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -388,7 +355,6 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -398,7 +364,6 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -408,7 +373,6 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -418,7 +382,6 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -428,7 +391,6 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -438,7 +400,6 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } /// Storage: Benchmark Override (r:0 w:0) /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) @@ -448,10 +409,5 @@ impl WeightInfo { // Estimated: `0` // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. Weight::from_parts(18_446_744_073_709_551_000, 0) - .saturating_add(Weight::from_parts(0, 0)) } } - -// added here.into() in the worstcase-scenario. -// changed weightlimit to 1 for buy_execution -// what to do for transact? \ No newline at end of file From f4fcec25380db062fe909d6fa135b84266d9f9d7 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Sat, 21 Oct 2023 01:40:18 +0530 Subject: [PATCH 19/20] comments edit --- pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs | 2 +- runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs index 0a56832391..4e1bbe71b9 100644 --- a/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs +++ b/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs @@ -107,7 +107,7 @@ benchmarks! { }: { executor.bench_process(xcm)?; } verify { - // TODO Make the assertion configurable? + // The assert above is enough to show this XCM succeeded } refund_surplus { diff --git a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs index 7633bf4fb5..55fa4dab29 100644 --- a/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs +++ b/runtime/shibuya/src/weights/xcm_instruction_benchmarks/mod.rs @@ -166,10 +166,6 @@ impl XcmWeightInfo for ShibuyaXcmWeight { _reserve: &MultiLocation, _xcm: &Xcm<()>, ) -> XCMWeight { - // TODO: Clear wrong - // This is not correct. initiate reserve withdraw does not to that many db reads - // the only thing it does based on number of assets is a take from a local variable - //assets.weigh_multi_assets(XcmGeneric::::initiate_reserve_withdraw()) XcmGeneric::::initiate_reserve_withdraw() } fn initiate_teleport( From 2908a268351026452f86614a54f214f4cc8b0769 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Wed, 1 Nov 2023 18:22:06 +0530 Subject: [PATCH 20/20] change benchmark to V2 --- Cargo.lock | 1 + pallets/astar-xcm-benchmarks/Cargo.toml | 2 + .../src/fungible/assets/benchmarking.rs | 168 ++++-- .../src/fungible/assets/mock.rs | 67 ++- .../src/fungible/balances/benchmarking.rs | 143 +++-- .../src/fungible/balances/mock.rs | 2 +- .../src/generic/benchmarking.rs | 540 +++++++++++------- .../astar-xcm-benchmarks/src/generic/mock.rs | 16 +- 8 files changed, 604 insertions(+), 335 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6800652949..d7c7b65e46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -636,6 +636,7 @@ dependencies = [ "log", "pallet-assets", "pallet-balances", + "pallet-xc-asset-config", "pallet-xcm", "parity-scale-codec", "paste", diff --git a/pallets/astar-xcm-benchmarks/Cargo.toml b/pallets/astar-xcm-benchmarks/Cargo.toml index d97e16ae90..de5c7a3a63 100644 --- a/pallets/astar-xcm-benchmarks/Cargo.toml +++ b/pallets/astar-xcm-benchmarks/Cargo.toml @@ -31,6 +31,7 @@ frame-benchmarking = { workspace = true } [dev-dependencies] pallet-assets = { workspace = true } pallet-balances = { workspace = true } +pallet-xc-asset-config = { workspace = true } pallet-xcm = { workspace = true } paste = { workspace = true } sp-core = { workspace = true } @@ -55,6 +56,7 @@ std = [ "astar-primitives/std", "pallet-balances/std", "pallet-assets/std", + "pallet-xc-asset-config/std", ] runtime-benchmarks = [ diff --git a/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs index 85c9182a2e..76b4c79d92 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs @@ -19,33 +19,35 @@ // Copyright (C) Parity Technologies (UK) Ltd. use super::*; use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; -use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError, BenchmarkResult}; +use frame_benchmarking::v2::*; use frame_support::traits::fungible::Inspect; use sp_runtime::traits::Zero; use sp_std::{prelude::*, vec}; use xcm::latest::{prelude::*, Weight}; use xcm_executor::traits::{Convert, TransactAsset}; -benchmarks_instance_pallet! { - where_clause { where +#[benchmarks( + where + < < - < - T::TransactAsset - as - Inspect - >::Balance + ::TransactAsset as - TryInto - >::Error: sp_std::fmt::Debug, + Inspect + >::Balance + as + TryInto + >::Error: sp_std::fmt::Debug, - < T::TransactAsset - as - Inspect - >::Balance : Into - - } - - withdraw_asset { + < ::TransactAsset + as + Inspect + >::Balance : Into +)] +mod benchmarks { + use super::*; + + #[benchmark] + fn withdraw_asset() -> Result<(), BenchmarkError> { let (sender_account, sender_location) = account_and_location::(1); let worst_case_holding = T::worst_case_holding(0); let asset = T::get_multi_asset(); @@ -58,7 +60,8 @@ benchmarks_instance_pallet! { message_hash: [0; 32], topic: None, }, - ).unwrap(); + ) + .unwrap(); // check the assets of origin. assert!(!T::TransactAsset::balance(&sender_account).is_zero()); @@ -66,18 +69,23 @@ benchmarks_instance_pallet! { executor.set_holding(worst_case_holding.into()); let instruction = Instruction::>::WithdrawAsset(vec![asset.clone()].into()); let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } // 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()); + assert!(executor + .holding() + .ensure_contains(&vec![asset].into()) + .is_ok()); + Ok(()) } - transfer_asset { + #[benchmark] + fn transfer_asset() -> Result<(), BenchmarkError> { let (sender_account, sender_location) = account_and_location::(1); let mut asset = T::get_multi_asset(); - let assets: MultiAssets = vec![ asset.clone() ].into(); // this xcm doesn't use holding let dest_location = T::valid_destination()?; @@ -90,15 +98,16 @@ benchmarks_instance_pallet! { message_hash: [0; 32], topic: None, }, - ).unwrap(); + ) + .unwrap(); assert!(T::TransactAsset::balance(&dest_account).is_zero()); // reducing some assets for Existential deposit if let Fungible(x) = asset.fun { - asset.fun = Fungible(x/10) + asset.fun = Fungible(x / 10) }; - let assets: MultiAssets = vec![ asset.clone() ].into(); + let assets: MultiAssets = vec![asset.clone()].into(); log::trace!( target: "xcm::process", "assets is {:?}",assets.clone()); @@ -112,26 +121,35 @@ benchmarks_instance_pallet! { message_hash: [0; 32], topic: None, }, - ).unwrap(); + ) + .unwrap(); let mut executor = new_executor::(sender_location); - let instruction = Instruction::TransferAsset { assets, beneficiary: dest_location }; + let instruction = Instruction::TransferAsset { + assets, + beneficiary: dest_location, + }; let xcm = Xcm(vec![instruction]); log::trace!( target: "xcm::process", "destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); assert!(!T::TransactAsset::balance(&dest_account).is_zero()); let previous_balance: u128 = T::TransactAsset::balance(&dest_account).into(); - }: { - executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } + log::trace!( - target: "xcm::process", - "destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); + target: "xcm::process", + "destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); assert!(T::TransactAsset::balance(&dest_account).into() == 2 * previous_balance); + Ok(()) } - transfer_reserve_asset { - let (sender_account, sender_location) = account_and_location::(1); + #[benchmark] + fn transfer_reserve_asset() -> Result<(), BenchmarkError> { + let (_, sender_location) = account_and_location::(1); let dest_location = T::valid_destination()?; let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap(); @@ -144,12 +162,13 @@ benchmarks_instance_pallet! { message_hash: [0; 32], topic: None, }, - ).unwrap(); + ) + .unwrap(); assert!(T::TransactAsset::balance(&dest_account).is_zero()); if let Fungible(x) = asset.fun { - asset.fun = Fungible(x/10) + asset.fun = Fungible(x / 10) }; >::transfer_asset( @@ -161,29 +180,40 @@ benchmarks_instance_pallet! { message_hash: [0; 32], topic: None, }, - ).unwrap(); - let assets: MultiAssets = vec![ asset ].into(); + ) + .unwrap(); + let assets: MultiAssets = vec![asset].into(); let mut executor = new_executor::(sender_location); let instruction = Instruction::TransferReserveAsset { assets, dest: dest_location, - xcm: Xcm::new() + xcm: Xcm::new(), }; let xcm = Xcm(vec![instruction]); assert!(!T::TransactAsset::balance(&dest_account).is_zero()); let previous_balance: u128 = T::TransactAsset::balance(&dest_account).into(); - }: { - executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } + assert!(T::TransactAsset::balance(&dest_account).into() == 2 * previous_balance); + Ok(()) } - receive_teleported_asset { - } : { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + #[benchmark] + fn receive_teleported_asset() -> Result<(), BenchmarkError> { + // need to add an empty block as it is necessary to have either #[block] or #[extrinsic_call] + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) } - deposit_asset { + #[benchmark] + fn deposit_asset() -> Result<(), BenchmarkError> { let asset = T::get_multi_asset(); let mut holding = T::worst_case_holding(1); @@ -202,14 +232,18 @@ benchmarks_instance_pallet! { beneficiary: dest_location, }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } // dest should have received some asset. - assert!(!T::TransactAsset::balance(&dest_account).is_zero()) + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + Ok(()) } - deposit_reserve_asset { + #[benchmark] + fn deposit_reserve_asset() -> Result<(), BenchmarkError> { let asset = T::get_multi_asset(); let mut holding = T::worst_case_holding(1); @@ -229,21 +263,29 @@ benchmarks_instance_pallet! { xcm: Xcm::new(), }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } + // dest should have received some asset. - assert!(!T::TransactAsset::balance(&dest_account).is_zero()) + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + Ok(()) } - initiate_teleport { - }: { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + #[benchmark] + fn initiate_teleport() -> Result<(), BenchmarkError> { + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) } impl_benchmark_test_suite!( Pallet, - crate::fungible::mock::new_test_ext(), - crate::fungible::mock::Test + crate::fungible::assets::mock::new_test_ext(), + crate::fungible::assets::mock::Test ); } diff --git a/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs index 5feec89f7d..842b320382 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/assets/mock.rs @@ -22,13 +22,13 @@ use crate::{fungible::assets as xcm_assets_benchmark, mock::*}; use frame_benchmarking::BenchmarkError; use frame_support::{ - parameter_types, - traits::{AsEnsureOriginWithArg, ConstU32, Everything, Nothing}, + assert_ok, parameter_types, + traits::{tokens::fungible::ItemOf, AsEnsureOriginWithArg, ConstU32, Everything, Nothing}, weights::Weight, }; use frame_system::{EnsureRoot, EnsureSigned}; use parity_scale_codec::Compact; -use sp_core::H256; +use sp_core::{ConstU64, H256}; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, @@ -53,6 +53,7 @@ frame_support::construct_runtime!( Balances: pallet_balances, XcmAssetsBenchmark: xcm_assets_benchmark, Assets: pallet_assets, + XcAssetConfig: pallet_xc_asset_config, } ); @@ -119,6 +120,13 @@ parameter_types! { } +impl pallet_xc_asset_config::Config for Test { + type RuntimeEvent = RuntimeEvent; + type AssetId = u64; + type ManagerOrigin = EnsureRoot; + type WeightInfo = (); +} + impl pallet_assets::Config for Test { type RuntimeEvent = RuntimeEvent; type Balance = u64; @@ -139,7 +147,16 @@ impl pallet_assets::Config for Test { type AssetIdParameter = Compact; type CallbackHandle = (); #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = (); + type BenchmarkHelper = AssetsBenchmarkHelper; +} + +pub struct AssetsBenchmarkHelper; +impl> pallet_assets::BenchmarkHelper + for AssetsBenchmarkHelper +{ + fn create_asset_id_parameter(id: u32) -> AssetIdParameter { + u64::from(id).into() + } } parameter_types! { @@ -223,7 +240,6 @@ impl crate::Config for Test { ) } } - pub type TrustedTeleporters = (xcm_builder::Case,); parameter_types! { @@ -237,29 +253,40 @@ parameter_types! { (Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get()); pub const ReserveConcreteFungible: (MultiAssetFilter, MultiLocation) = (Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get()); + pub const NoCheckingAccount: Option<(::AccountId, MintLocation)> = None; + pub const NoTeleporter: Option<(xcm::latest::MultiLocation, xcm::latest::MultiAsset)> = None; } impl xcm_assets_benchmark::Config for Test { - type TransactAsset = Balances; - type CheckedAccount = CheckingAccount; - type TrustedTeleporter = TrustedTeleporter; + type TransactAsset = ItemOf, u64>; + type CheckedAccount = NoCheckingAccount; + type TrustedTeleporter = NoTeleporter; fn get_multi_asset() -> MultiAsset { - let amount = - >::minimum_balance() as u128; + // create an asset and make it sufficient + assert_ok!(pallet_assets::Pallet::::force_create( + RuntimeOrigin::root(), + parity_scale_codec::Compact(1), + 0_u64, + true, + 1 + )); let location = MultiLocation { - parents: 1, - interior: X2( - Parachain(1000), - AccountId32 { - network: None, - id: [152; 32], - }, - ), + parents: 0, + interior: X1(GeneralIndex(1)), }; + // convert mapping for asset id + assert_ok!( + pallet_xc_asset_config::Pallet::::register_asset_location( + RuntimeOrigin::root(), + Box::new(location.clone().into_versioned()), + 1 + ) + ); + MultiAsset { id: Concrete(location), - fun: Fungible(amount), + fun: Fungible(100_000_000_000u128), } } } @@ -267,7 +294,7 @@ impl xcm_assets_benchmark::Config for Test { #[cfg(feature = "runtime-benchmarks")] pub fn new_test_ext() -> sp_io::TestExternalities { use sp_runtime::BuildStorage; - let t = RuntimeGenesisConfig { + let t = GenesisConfig { ..Default::default() } .build_storage() diff --git a/pallets/astar-xcm-benchmarks/src/fungible/balances/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/fungible/balances/benchmarking.rs index 312b0141fd..464a0169e3 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/balances/benchmarking.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/balances/benchmarking.rs @@ -19,27 +19,30 @@ // Copyright (C) Parity Technologies (UK) Ltd. use super::*; use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; -use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError, BenchmarkResult}; +use frame_benchmarking::v2::*; use frame_support::traits::fungible::Inspect; use sp_runtime::traits::Zero; use sp_std::{prelude::*, vec}; use xcm::latest::{prelude::*, Weight}; use xcm_executor::traits::{Convert, TransactAsset}; -benchmarks_instance_pallet! { - where_clause { where +#[benchmarks( + where + < < - < - T::TransactAsset - as - Inspect - >::Balance + ::TransactAsset as - TryInto - >::Error: sp_std::fmt::Debug, - } - - withdraw_asset { + Inspect + >::Balance + as + TryInto + >::Error: sp_std::fmt::Debug, +)] +mod benchmarks { + use super::*; + + #[benchmark] + fn withdraw_asset() -> Result<(), BenchmarkError> { let (sender_account, sender_location) = account_and_location::(1); let worst_case_holding = T::worst_case_holding(0); let asset = T::get_multi_asset(); @@ -52,7 +55,8 @@ benchmarks_instance_pallet! { message_hash: [0; 32], topic: None, }, - ).unwrap(); + ) + .unwrap(); // check the assets of origin. assert!(!T::TransactAsset::balance(&sender_account).is_zero()); @@ -60,18 +64,24 @@ benchmarks_instance_pallet! { executor.set_holding(worst_case_holding.into()); let instruction = Instruction::>::WithdrawAsset(vec![asset.clone()].into()); let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } // 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()); + assert!(executor + .holding() + .ensure_contains(&vec![asset].into()) + .is_ok()); + Ok(()) } - transfer_asset { + #[benchmark] + fn transfer_asset() -> Result<(), BenchmarkError> { let (sender_account, sender_location) = account_and_location::(1); let asset = T::get_multi_asset(); - let assets: MultiAssets = vec![ asset.clone() ].into(); + let assets: MultiAssets = vec![asset.clone()].into(); // this xcm doesn't use holding let dest_location = T::valid_destination()?; @@ -85,20 +95,29 @@ benchmarks_instance_pallet! { message_hash: [0; 32], topic: None, }, - ).unwrap(); + ) + .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 instruction = Instruction::TransferAsset { + assets, + beneficiary: dest_location, + }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } + assert!(T::TransactAsset::balance(&sender_account).is_zero()); assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + Ok(()) } - transfer_reserve_asset { + #[benchmark] + fn transfer_reserve_asset() -> Result<(), BenchmarkError> { 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(); @@ -112,30 +131,41 @@ benchmarks_instance_pallet! { message_hash: [0; 32], topic: None, }, - ).unwrap(); - let assets: MultiAssets = vec![ asset ].into(); + ) + .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() + xcm: Xcm::new(), }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } + assert!(T::TransactAsset::balance(&sender_account).is_zero()); assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + Ok(()) } - receive_teleported_asset { - } : { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + #[benchmark] + fn receive_teleported_asset() -> Result<(), BenchmarkError> { + // need to add an empty block as it is necessary to have either #[block] or #[extrinsic_call] + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) } - deposit_asset { + #[benchmark] + fn deposit_asset() -> Result<(), BenchmarkError> { let asset = T::get_multi_asset(); let mut holding = T::worst_case_holding(1); @@ -154,14 +184,18 @@ benchmarks_instance_pallet! { beneficiary: dest_location, }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } // dest should have received some asset. - assert!(!T::TransactAsset::balance(&dest_account).is_zero()) + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + Ok(()) } - deposit_reserve_asset { + #[benchmark] + fn deposit_reserve_asset() -> Result<(), BenchmarkError> { let asset = T::get_multi_asset(); let mut holding = T::worst_case_holding(1); @@ -181,21 +215,28 @@ benchmarks_instance_pallet! { xcm: Xcm::new(), }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } + // dest should have received some asset. - assert!(!T::TransactAsset::balance(&dest_account).is_zero()) + assert!(!T::TransactAsset::balance(&dest_account).is_zero()); + Ok(()) } - initiate_teleport { - }: { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + #[benchmark] + fn initiate_teleport() -> Result<(), BenchmarkError> { + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) } - impl_benchmark_test_suite!( Pallet, - crate::fungible::mock::new_test_ext(), - crate::fungible::mock::Test + crate::fungible::balances::mock::new_test_ext(), + crate::fungible::balances::mock::Test ); } diff --git a/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs b/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs index 347ebc2eb0..e8ed442036 100644 --- a/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/fungible/balances/mock.rs @@ -219,7 +219,7 @@ impl xcm_balances_benchmark::Config for Test { #[cfg(feature = "runtime-benchmarks")] pub fn new_test_ext() -> sp_io::TestExternalities { use sp_runtime::BuildStorage; - let t = RuntimeGenesisConfig { + let t = GenesisConfig { ..Default::default() } .build_storage() diff --git a/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs b/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs index 4e1bbe71b9..0fe0a6c4d5 100644 --- a/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs +++ b/pallets/astar-xcm-benchmarks/src/generic/benchmarking.rs @@ -20,7 +20,7 @@ use super::*; use crate::{new_executor, XcmCallOf}; -use frame_benchmarking::{benchmarks, BenchmarkError, BenchmarkResult}; +use frame_benchmarking::v2::*; use frame_support::dispatch::GetDispatchInfo; use parity_scale_codec::Encode; use sp_std::vec; @@ -30,8 +30,12 @@ use xcm::{ }; use xcm_executor::{ExecutorError, FeesMode}; -benchmarks! { - report_holding { +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn report_holding() -> Result<(), BenchmarkError> { let holding = T::worst_case_holding(0); let mut executor = new_executor::(Default::default()); @@ -46,18 +50,18 @@ benchmarks! { // Worst case is looking through all holdings for every asset explicitly. assets: Definite(holding), }; - let xcm = Xcm(vec![instruction]); - } : { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } // The completion of execution above is enough to validate this is completed. + Ok(()) } - // This benchmark does not use any additional orders or instructions. This should be managed - // by the `deep` and `shallow` implementation. - buy_execution { + #[benchmark] + fn buy_execution() -> Result<(), BenchmarkError> { let holding = T::worst_case_holding(0).into(); let mut executor = new_executor::(Default::default()); @@ -67,33 +71,44 @@ benchmarks! { let instruction = Instruction::>::BuyExecution { fees: (fee_asset, 100_000_000_000u128).into(), // should be something inside of holding - weight_limit: WeightLimit::Limited(Weight::from_parts(1u64, 64*1024)), + weight_limit: WeightLimit::Limited(Weight::from_parts(1u64, 64 * 1024)), }; let xcm = Xcm(vec![instruction]); - } : { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } + Ok(()) } - query_response { + #[benchmark] + fn query_response() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); let (query_id, response) = T::worst_case_response(); let max_weight = Weight::MAX; let querier: Option = Some(Here.into()); - let instruction = Instruction::QueryResponse { query_id, response, max_weight, querier }; + let instruction = Instruction::QueryResponse { + query_id, + response, + max_weight, + querier, + }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { - // The assert above is enough to show this XCM succeeded + + #[block] + { + executor.bench_process(xcm)?; + } + Ok(()) } // 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 { + #[benchmark] + fn transact() -> Result<(), BenchmarkError> { let (origin, noop_call) = T::transact_origin_and_runtime_call()?; let mut executor = new_executor::(origin); let double_encoded_noop_call: DoubleEncoded<_> = noop_call.encode().into(); @@ -104,13 +119,17 @@ benchmarks! { call: double_encoded_noop_call, }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } // The assert above is enough to show this XCM succeeded + Ok(()) } - refund_surplus { + #[benchmark] + fn refund_surplus() -> Result<(), BenchmarkError> { let holding = T::worst_case_holding(0).into(); let mut executor = new_executor::(Default::default()); executor.set_holding(holding); @@ -119,53 +138,69 @@ benchmarks! { let instruction = Instruction::>::RefundSurplus; let xcm = Xcm(vec![instruction]); - } : { - let result = executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } + assert_eq!(executor.total_surplus(), &Weight::from_parts(1337, 1337)); assert_eq!(executor.total_refunded(), &Weight::from_parts(1337, 1337)); + Ok(()) } - set_error_handler { + #[benchmark] + fn set_error_handler() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); let instruction = Instruction::>::SetErrorHandler(Xcm(vec![])); let xcm = Xcm(vec![instruction]); - } : { - executor.bench_process(xcm)?; - } verify { + + #[block] + { + executor.bench_process(xcm)?; + } assert_eq!(executor.error_handler(), &Xcm(vec![])); + Ok(()) } - set_appendix { + #[benchmark] + fn set_appendix() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); let appendix = Xcm(vec![]); let instruction = Instruction::>::SetAppendix(appendix); let xcm = Xcm(vec![instruction]); - } : { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } assert_eq!(executor.appendix(), &Xcm(vec![])); + Ok(()) } - clear_error { + #[benchmark] + fn clear_error() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); executor.set_error(Some((5u32, XcmError::Overflow))); let instruction = Instruction::>::ClearError; let xcm = Xcm(vec![instruction]); - } : { - executor.bench_process(xcm)?; - } verify { - assert!(executor.error().is_none()) + #[block] + { + executor.bench_process(xcm)?; + } + assert!(executor.error().is_none()); + Ok(()) } - descend_origin { + #[benchmark] + fn descend_origin() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); let who = X2(OnlyChild, OnlyChild); let instruction = Instruction::DescendOrigin(who.clone()); let xcm = Xcm(vec![instruction]); - } : { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } assert_eq!( executor.origin(), &Some(MultiLocation { @@ -173,19 +208,24 @@ benchmarks! { interior: who, }), ); + Ok(()) } - clear_origin { + #[benchmark] + fn clear_origin() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); let instruction = Instruction::ClearOrigin; let xcm = Xcm(vec![instruction]); - } : { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } assert_eq!(executor.origin(), &None); + Ok(()) } - report_error { + #[benchmark] + fn report_error() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); executor.set_error(Some((0u32, XcmError::Unimplemented))); let query_id = Default::default(); @@ -193,16 +233,21 @@ benchmarks! { let max_weight = Default::default(); let instruction = Instruction::ReportError(QueryResponseInfo { - query_id, destination, max_weight + query_id, + destination, + max_weight, }); let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } // the execution succeeding is all we need to verify this xcm was successful + Ok(()) } - claim_asset { + #[benchmark] + fn claim_asset() -> Result<(), BenchmarkError> { use xcm_executor::traits::DropAssets; let (origin, ticket, assets) = T::claimable_asset()?; @@ -221,44 +266,65 @@ benchmarks! { // Assets should be in the trap now. let mut executor = new_executor::(origin); - let instruction = Instruction::ClaimAsset { assets: assets.clone(), ticket }; + let instruction = Instruction::ClaimAsset { + assets: assets.clone(), + ticket, + }; let xcm = Xcm(vec![instruction]); - } :{ - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } assert!(executor.holding().ensure_contains(&assets).is_ok()); + Ok(()) } - trap { + #[benchmark] + fn trap() -> Result<(), BenchmarkError> { 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.bench_process(xcm); - } verify { - assert!(matches!(_result, Err(ExecutorError { - xcm_error: XcmError::Trap(10), - .. - }))); - } - subscribe_version { + #[block] + { + _result = executor.bench_process(xcm); + } + assert!(matches!( + _result, + Err(ExecutorError { + xcm_error: XcmError::Trap(10), + .. + }) + )); + Ok(()) + } + + #[benchmark] + fn subscribe_version() -> Result<(), BenchmarkError> { 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 instruction = Instruction::SubscribeVersion { + query_id, + max_response_weight, + }; let xcm = Xcm(vec![instruction]); - } : { - executor.bench_process(xcm)?; - } verify { - assert!(::SubscriptionService::is_subscribed(&origin)); + #[block] + { + executor.bench_process(xcm)?; + } + assert!( + ::SubscriptionService::is_subscribed(&origin) + ); + Ok(()) } - unsubscribe_version { + #[benchmark] + fn unsubscribe_version() -> Result<(), BenchmarkError> { use xcm_executor::traits::VersionChangeNotifier; // First we need to subscribe to notifications. let origin = T::subscribe_origin()?; @@ -273,34 +339,48 @@ benchmarks! { message_hash: [0; 32], topic: None, }, - ).map_err(|_| "Could not start subscription")?; - assert!(::SubscriptionService::is_subscribed(&origin)); + ) + .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.bench_process(xcm)?; - } verify { - assert!(!::SubscriptionService::is_subscribed(&origin)); + #[block] + { + executor.bench_process(xcm)?; + } + assert!( + !::SubscriptionService::is_subscribed(&origin) + ); + Ok(()) } - initiate_reserve_withdraw { + #[benchmark] + fn initiate_reserve_withdraw() -> Result<(), BenchmarkError> { let holding = T::worst_case_holding(1); let assets_filter = MultiAssetFilter::Definite(holding.clone()); let reserve = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; let mut executor = new_executor::(Default::default()); executor.set_holding(holding.into()); - let instruction = Instruction::InitiateReserveWithdraw { assets: assets_filter, reserve, xcm: Xcm(vec![]) }; + let instruction = Instruction::InitiateReserveWithdraw { + assets: assets_filter, + reserve, + xcm: Xcm(vec![]), + }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } // 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 + Ok(()) } - burn_asset { + #[benchmark] + fn burn_asset() -> Result<(), BenchmarkError> { let holding = T::worst_case_holding(0); let assets = holding.clone(); @@ -309,13 +389,16 @@ benchmarks! { let instruction = Instruction::BurnAsset(assets.into()); let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } assert!(executor.holding().is_empty()); + Ok(()) } - expect_asset { + #[benchmark] + fn expect_asset() -> Result<(), BenchmarkError> { let holding = T::worst_case_holding(0); let assets = holding.clone(); @@ -324,61 +407,78 @@ benchmarks! { let instruction = Instruction::ExpectAsset(assets.into()); let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } // `execute` completing successfully is as good as we can check. + Ok(()) } - expect_origin { + #[benchmark] + fn expect_origin() -> Result<(), BenchmarkError> { let expected_origin = Parent.into(); let mut executor = new_executor::(Default::default()); let instruction = Instruction::ExpectOrigin(Some(expected_origin)); let xcm = Xcm(vec![instruction]); let mut _result = Ok(()); - }: { - _result = executor.bench_process(xcm); - } verify { - assert!(matches!(_result, Err(ExecutorError { - xcm_error: XcmError::ExpectationFalse, - .. - }))); - } - - expect_error { + #[block] + { + _result = executor.bench_process(xcm); + } + assert!(matches!( + _result, + Err(ExecutorError { + xcm_error: XcmError::ExpectationFalse, + .. + }) + )); + Ok(()) + } + + #[benchmark] + fn expect_error() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); executor.set_error(Some((3u32, XcmError::Overflow))); let instruction = Instruction::ExpectError(None); let xcm = Xcm(vec![instruction]); let mut _result = Ok(()); - }: { - _result = executor.bench_process(xcm); - } verify { - assert!(matches!(_result, Err(ExecutorError { - xcm_error: XcmError::ExpectationFalse, - .. - }))); - } - - expect_transact_status { + #[block] + { + _result = executor.bench_process(xcm); + } + assert!(matches!( + _result, + Err(ExecutorError { + xcm_error: XcmError::ExpectationFalse, + .. + }) + )); + Ok(()) + } + + #[benchmark] + fn expect_transact_status() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); - let worst_error = || -> MaybeErrorCode { - vec![0; MaxDispatchErrorLen::get() as usize].into() - }; + let worst_error = + || -> MaybeErrorCode { vec![0; MaxDispatchErrorLen::get() as usize].into() }; executor.set_transact_status(worst_error()); let instruction = Instruction::ExpectTransactStatus(worst_error()); let xcm = Xcm(vec![instruction]); let mut _result = Ok(()); - }: { - _result = executor.bench_process(xcm); - } verify { + #[block] + { + _result = executor.bench_process(xcm); + } assert!(matches!(_result, Ok(..))); + Ok(()) } - query_pallet { + #[benchmark] + fn query_pallet() -> Result<(), BenchmarkError> { let query_id = Default::default(); let destination = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; let max_weight = Default::default(); @@ -386,16 +486,22 @@ benchmarks! { let instruction = Instruction::QueryPallet { module_name: b"frame_system".to_vec(), - response_info: QueryResponseInfo { destination, query_id, max_weight }, + response_info: QueryResponseInfo { + destination, + query_id, + max_weight, + }, }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { - // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 + #[block] + { + executor.bench_process(xcm)?; + } + Ok(()) } - expect_pallet { + #[benchmark] + fn expect_pallet() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); let instruction = Instruction::ExpectPallet { @@ -406,13 +512,16 @@ benchmarks! { min_crate_minor: 0, }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } // the execution succeeding is all we need to verify this xcm was successful + Ok(()) } - report_transact_status { + #[benchmark] + fn report_transact_status() -> Result<(), BenchmarkError> { let query_id = Default::default(); let destination = T::valid_destination().map_err(|_| BenchmarkError::Skip)?; let max_weight = Default::default(); @@ -426,60 +535,76 @@ benchmarks! { max_weight, }); let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { - // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 + #[block] + { + executor.bench_process(xcm)?; + } + Ok(()) } - clear_transact_status { + #[benchmark] + fn clear_transact_status() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); executor.set_transact_status(b"MyError".to_vec().into()); let instruction = Instruction::ClearTransactStatus; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } assert_eq!(executor.transact_status(), &MaybeErrorCode::Success); + Ok(()) } - set_topic { + #[benchmark] + fn set_topic() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); let instruction = Instruction::SetTopic([1; 32]); let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } assert_eq!(executor.topic(), &Some([1; 32])); + Ok(()) } - clear_topic { + #[benchmark] + fn clear_topic() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); executor.set_topic(Some([2; 32])); let instruction = Instruction::ClearTopic; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } assert_eq!(executor.topic(), &None); + Ok(()) } - set_fees_mode { + #[benchmark] + fn set_fees_mode() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); - executor.set_fees_mode(FeesMode { jit_withdraw: false }); + executor.set_fees_mode(FeesMode { + jit_withdraw: false, + }); let instruction = Instruction::SetFeesMode { jit_withdraw: true }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } verify { + #[block] + { + executor.bench_process(xcm)?; + } assert_eq!(executor.fees_mode(), &FeesMode { jit_withdraw: true }); + Ok(()) } - unpaid_execution { + #[benchmark] + fn unpaid_execution() -> Result<(), BenchmarkError> { let mut executor = new_executor::(Default::default()); executor.set_origin(Some(Here.into())); @@ -489,43 +614,74 @@ benchmarks! { }; let xcm = Xcm(vec![instruction]); - }: { - executor.bench_process(xcm)?; - } - - exchange_asset { - } : { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; - } - - export_message { - } : { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; - } - - lock_asset { - } : { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; - } - - unlock_asset { - } : { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; - } - - note_unlockable { - } : { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; - } - - request_unlock { - } : { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; - } - - universal_origin { - } : { - Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; + #[block] + { + executor.bench_process(xcm)?; + } + Ok(()) + } + + #[benchmark] + fn exchange_asset() -> Result<(), BenchmarkError> { + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) + } + + #[benchmark] + fn export_message() -> Result<(), BenchmarkError> { + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) + } + + #[benchmark] + fn lock_asset() -> Result<(), BenchmarkError> { + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) + } + + #[benchmark] + fn unlock_asset() -> Result<(), BenchmarkError> { + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) + } + + #[benchmark] + fn note_unlockable() -> Result<(), BenchmarkError> { + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) + } + + #[benchmark] + fn request_unlock() -> Result<(), BenchmarkError> { + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) + } + + #[benchmark] + fn universal_origin() -> Result<(), BenchmarkError> { + #[block] + {} + Err(BenchmarkError::Override(BenchmarkResult::from_weight( + Weight::MAX, + ))) } impl_benchmark_test_suite!( diff --git a/pallets/astar-xcm-benchmarks/src/generic/mock.rs b/pallets/astar-xcm-benchmarks/src/generic/mock.rs index aa73c969cc..76a9493373 100644 --- a/pallets/astar-xcm-benchmarks/src/generic/mock.rs +++ b/pallets/astar-xcm-benchmarks/src/generic/mock.rs @@ -40,17 +40,17 @@ use xcm_builder::{ }; use xcm_executor::traits::ConvertOrigin; -type Block = frame_system::mocking::MockBlock; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; frame_support::construct_runtime!( - pub struct TestRuntime + pub struct Test where Block = Block, NodeBlock = Block, UncheckedExtrinsic = UncheckedExtrinsic, { - System: frame_system, + System: frame_system = 10, XcmGenericBenchmarks: generic, } ); @@ -61,7 +61,7 @@ parameter_types! { frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, u64::MAX)); } -impl frame_system::Config for TestRuntime { +impl frame_system::Config for Test { type BaseCallFilter = Everything; type BlockWeights = (); type BlockLength = (); @@ -143,7 +143,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; } -impl crate::Config for TestRuntime { +impl crate::Config for Test { type XcmConfig = XcmConfig; type AccountIdConverter = AccountIdConverter; fn valid_destination() -> Result { @@ -163,7 +163,7 @@ impl crate::Config for TestRuntime { } } -impl generic::Config for TestRuntime { +impl generic::Config for Test { type RuntimeCall = RuntimeCall; fn worst_case_response() -> (u64, Response) { @@ -215,7 +215,7 @@ impl generic::Config for TestRuntime { #[cfg(feature = "runtime-benchmarks")] pub fn new_test_ext() -> sp_io::TestExternalities { use sp_runtime::BuildStorage; - let t = RuntimeGenesisConfig { + let t = GenesisConfig { ..Default::default() } .build_storage()