diff --git a/Cargo.lock b/Cargo.lock index f9ecad6935ee4..2c302ca26bd25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -378,9 +378,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "anstyle-parse" @@ -3260,9 +3260,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.13" +version = "4.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fbb260a053428790f3de475e304ff84cdbc4face759ea7a3e64c1edd938a7fc" +checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae" dependencies = [ "clap_builder", "clap_derive", @@ -3270,9 +3270,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.13" +version = "4.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64b17d7ea74e9f833c7dbf2cbe4fb12ff26783eda4782a8975b72f895c9b4d99" +checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9" dependencies = [ "anstream", "anstyle", @@ -3292,9 +3292,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" dependencies = [ "heck 0.5.0", "proc-macro2 1.0.95", @@ -3304,9 +3304,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.0" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "cmd_lib" @@ -7462,9 +7462,9 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "glob-match" @@ -25362,12 +25362,12 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.3.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +checksum = "60b8cb979cb11c32ce1603f8137b22262a9d131aaa5c37b5678025f22b8becd0" dependencies = [ - "rustix 0.38.42", - "windows-sys 0.48.0", + "rustix 1.0.8", + "windows-sys 0.60.2", ] [[package]] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 6c598a77160b9..a2454575371a8 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -100,8 +100,9 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; #[cfg(feature = "runtime-benchmarks")] use xcm::latest::prelude::{ - Asset, Assets as XcmAssets, Fungible, Here, InteriorLocation, Junction, Junction::*, Location, - NetworkId, NonFungible, ParentThen, Response, WeightLimit, XCM_VERSION, + Asset, Assets as XcmAssets, Fungible, Here, Instruction, InteriorLocation, Junction, + Junction::*, Location, NetworkId, NonFungible, ParentThen, Response, WeightLimit, Xcm, + XCM_VERSION, }; use xcm::{ latest::prelude::{AssetId, BodyId}, @@ -2016,6 +2017,10 @@ impl_runtime_apis! { Location::new(1, [Parachain(1001), AccountId32 { id: [111u8; 32], network: None }]), )) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index a9a7eb2196e0d..8cafe486d2a82 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -120,8 +120,9 @@ use frame_support::traits::PalletInfoAccess; #[cfg(feature = "runtime-benchmarks")] use xcm::latest::prelude::{ - Asset, Assets as XcmAssets, Fungible, Here, InteriorLocation, Junction, Junction::*, Location, - NetworkId, NonFungible, ParentThen, Response, WeightLimit, XCM_VERSION, + Asset, Assets as XcmAssets, Fungible, Here, Instruction, InteriorLocation, Junction, + Junction::*, Location, NetworkId, NonFungible, ParentThen, Response, WeightLimit, Xcm, + XCM_VERSION, }; use xcm_runtime_apis::{ @@ -2562,6 +2563,29 @@ pallet_revive::impl_runtime_apis_plus_revive!( Location::new(1, [Parachain(1001), AccountId32 { id: [111u8; 32], network: None }]), )) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + use xcm::latest::prelude::{ClearOrigin, SetAppendix, SetTopic}; + + let nested_limit = xcm_executor::RECURSION_LIMIT as usize - 2; + + // Within the recursion limit, this is fine. + let mut set_topic = Xcm(vec![SetTopic([42; 32])]); + for _ in 0..nested_limit { + set_topic = Xcm(vec![SetAppendix(set_topic)]); + } + let set_topics = Xcm(vec![SetAppendix(set_topic); nested_limit]); + + // Exceed the recursion limit, this will be rejected. + let mut clear_origin = Xcm(vec![SetAppendix(Xcm(vec![ClearOrigin]))]); + for _ in 0..=nested_limit { + clear_origin = Xcm(vec![SetAppendix(clear_origin)]); + } + + let xcm = Xcm(vec![SetAppendix(set_topics), SetAppendix(clear_origin)]); + + Ok(xcm) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/xcm/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/xcm/mod.rs index 27532ac431e7a..d2cbf1f43a0cf 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/xcm/mod.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/xcm/mod.rs @@ -17,8 +17,8 @@ mod pallet_xcm_benchmarks_fungible; mod pallet_xcm_benchmarks_generic; use crate::{ - xcm_config::{ERC20TransferGasLimit, MaxAssetsIntoHolding}, - Runtime, + xcm_config::{ERC20TransferGasLimit, MaxAssetsIntoHolding, MaxInstructions}, + Runtime, RuntimeCall, }; use alloc::vec::Vec; use assets_common::IsLocalAccountKey20; @@ -30,6 +30,8 @@ use xcm::{ latest::{prelude::*, AssetTransferFilter}, DoubleEncoded, }; +use xcm_builder::WeightInfoBounds; +use xcm_executor::traits::WeightBounds; trait WeighAssets { fn weigh_assets(&self, weight: Weight) -> Weight; @@ -303,3 +305,26 @@ impl XcmWeightInfo for AssetHubWestendXcmWeight { XcmGeneric::::execute_with_origin() } } + +pub struct AssetHubWestendXcmWeightInfoBounds; +impl WeightBounds for AssetHubWestendXcmWeightInfoBounds { + fn weight( + message: &mut Xcm, + weight_limit: Weight, + ) -> Result { + WeightInfoBounds::, RuntimeCall, MaxInstructions>::weight( + message, + weight_limit, + ) + } + + fn instr_weight(instruction: &mut Instruction) -> Result { + WeightInfoBounds::, RuntimeCall, MaxInstructions>::instr_weight( + instruction, + ) + } + + fn barrier_check_weight() -> Option { + Some(XcmGeneric::::barrier_check()) + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index 04ed54ad8f48b..94dd7836d46d8 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -16,9 +16,9 @@ //! Autogenerated weights for `pallet_xcm_benchmarks::generic` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2025-07-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2025-09-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `601cc0634d73`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `919088bef400`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -68,8 +68,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `2632` // Estimated: `6196` - // Minimum execution time: 128_179_000 picoseconds. - Weight::from_parts(132_827_000, 6196) + // Minimum execution time: 142_020_000 picoseconds. + Weight::from_parts(146_016_000, 6196) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -79,8 +79,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3593` - // Minimum execution time: 6_735_000 picoseconds. - Weight::from_parts(7_064_000, 3593) + // Minimum execution time: 7_378_000 picoseconds. + Weight::from_parts(7_747_000, 3593) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -90,8 +90,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3593` - // Minimum execution time: 6_580_000 picoseconds. - Weight::from_parts(7_050_000, 3593) + // Minimum execution time: 7_249_000 picoseconds. + Weight::from_parts(7_695_000, 3593) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -99,8 +99,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 773_000 picoseconds. - Weight::from_parts(829_000, 0) + // Minimum execution time: 874_000 picoseconds. + Weight::from_parts(950_000, 0) } // Storage: `PolkadotXcm::Queries` (r:1 w:0) // Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -108,51 +108,51 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3465` - // Minimum execution time: 6_112_000 picoseconds. - Weight::from_parts(6_358_000, 3465) + // Minimum execution time: 6_185_000 picoseconds. + Weight::from_parts(6_600_000, 3465) .saturating_add(T::DbWeight::get().reads(1)) } pub fn transact() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_002_000 picoseconds. - Weight::from_parts(8_377_000, 0) + // Minimum execution time: 8_070_000 picoseconds. + Weight::from_parts(8_583_000, 0) } pub fn refund_surplus() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_344_000 picoseconds. - Weight::from_parts(1_497_000, 0) + // Minimum execution time: 1_506_000 picoseconds. + Weight::from_parts(1_617_000, 0) } pub fn set_error_handler() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 786_000 picoseconds. - Weight::from_parts(840_000, 0) + // Minimum execution time: 768_000 picoseconds. + Weight::from_parts(859_000, 0) } pub fn set_appendix() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 737_000 picoseconds. - Weight::from_parts(805_000, 0) + // Minimum execution time: 851_000 picoseconds. + Weight::from_parts(899_000, 0) } pub fn clear_error() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 745_000 picoseconds. - Weight::from_parts(810_000, 0) + // Minimum execution time: 818_000 picoseconds. + Weight::from_parts(880_000, 0) } pub fn descend_origin() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 774_000 picoseconds. - Weight::from_parts(828_000, 0) + // Minimum execution time: 868_000 picoseconds. + Weight::from_parts(934_000, 0) } // Storage: `Benchmark::Override` (r:0 w:0) // Proof: `Benchmark::Override` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -167,8 +167,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 739_000 picoseconds. - Weight::from_parts(822_000, 0) + // Minimum execution time: 803_000 picoseconds. + Weight::from_parts(906_000, 0) } // Storage: `ParachainInfo::ParachainId` (r:1 w:0) // Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) @@ -188,8 +188,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `2632` // Estimated: `6196` - // Minimum execution time: 91_221_000 picoseconds. - Weight::from_parts(93_944_000, 6196) + // Minimum execution time: 99_920_000 picoseconds. + Weight::from_parts(103_610_000, 6196) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -199,8 +199,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `23` // Estimated: `3488` - // Minimum execution time: 9_795_000 picoseconds. - Weight::from_parts(10_091_000, 3488) + // Minimum execution time: 10_347_000 picoseconds. + Weight::from_parts(10_840_000, 3488) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -208,8 +208,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_599_000 picoseconds. - Weight::from_parts(3_920_000, 0) + // Minimum execution time: 3_932_000 picoseconds. + Weight::from_parts(4_112_000, 0) } // Storage: `PolkadotXcm::VersionNotifyTargets` (r:1 w:1) // Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -227,8 +227,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `378` // Estimated: `3843` - // Minimum execution time: 36_969_000 picoseconds. - Weight::from_parts(37_920_000, 3843) + // Minimum execution time: 38_093_000 picoseconds. + Weight::from_parts(39_724_000, 3843) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -238,44 +238,44 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_401_000 picoseconds. - Weight::from_parts(3_642_000, 0) + // Minimum execution time: 3_635_000 picoseconds. + Weight::from_parts(4_004_000, 0) .saturating_add(T::DbWeight::get().writes(1)) } pub fn burn_asset() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 23_275_000 picoseconds. - Weight::from_parts(23_612_000, 0) + // Minimum execution time: 24_147_000 picoseconds. + Weight::from_parts(24_428_000, 0) } pub fn expect_asset() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_950_000 picoseconds. - Weight::from_parts(6_129_000, 0) + // Minimum execution time: 6_252_000 picoseconds. + Weight::from_parts(6_425_000, 0) } pub fn expect_origin() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_589_000 picoseconds. - Weight::from_parts(3_806_000, 0) + // Minimum execution time: 3_807_000 picoseconds. + Weight::from_parts(4_064_000, 0) } pub fn expect_error() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_648_000 picoseconds. - Weight::from_parts(3_844_000, 0) + // Minimum execution time: 3_948_000 picoseconds. + Weight::from_parts(4_104_000, 0) } pub fn expect_transact_status() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 917_000 picoseconds. - Weight::from_parts(975_000, 0) + // Minimum execution time: 971_000 picoseconds. + Weight::from_parts(1_042_000, 0) } // Storage: `ParachainInfo::ParachainId` (r:1 w:0) // Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) @@ -295,8 +295,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `2632` // Estimated: `6196` - // Minimum execution time: 100_417_000 picoseconds. - Weight::from_parts(102_884_000, 6196) + // Minimum execution time: 109_118_000 picoseconds. + Weight::from_parts(113_440_000, 6196) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -304,8 +304,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_030_000 picoseconds. - Weight::from_parts(8_265_000, 0) + // Minimum execution time: 9_429_000 picoseconds. + Weight::from_parts(9_765_000, 0) } // Storage: `ParachainInfo::ParachainId` (r:1 w:0) // Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) @@ -325,8 +325,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `2632` // Estimated: `6196` - // Minimum execution time: 91_164_000 picoseconds. - Weight::from_parts(93_992_000, 6196) + // Minimum execution time: 98_366_000 picoseconds. + Weight::from_parts(102_857_000, 6196) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -334,22 +334,22 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 780_000 picoseconds. - Weight::from_parts(842_000, 0) + // Minimum execution time: 839_000 picoseconds. + Weight::from_parts(902_000, 0) } pub fn set_topic() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 707_000 picoseconds. - Weight::from_parts(768_000, 0) + // Minimum execution time: 847_000 picoseconds. + Weight::from_parts(919_000, 0) } pub fn clear_topic() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 711_000 picoseconds. - Weight::from_parts(775_000, 0) + // Minimum execution time: 819_000 picoseconds. + Weight::from_parts(876_000, 0) } // Storage: `System::Account` (r:1 w:1) // Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) @@ -363,8 +363,8 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `1244` // Estimated: `4273` - // Minimum execution time: 93_724_000 picoseconds. - Weight::from_parts(96_332_000, 4273) + // Minimum execution time: 101_215_000 picoseconds. + Weight::from_parts(105_533_000, 4273) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -374,29 +374,39 @@ impl WeightInfo { // Proof Size summary in bytes: // Measured: `136` // Estimated: `1489` - // Minimum execution time: 5_567_000 picoseconds. - Weight::from_parts(5_841_000, 1489) + // Minimum execution time: 5_677_000 picoseconds. + Weight::from_parts(6_009_000, 1489) .saturating_add(T::DbWeight::get().reads(1)) } pub fn set_fees_mode() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 713_000 picoseconds. - Weight::from_parts(779_000, 0) + // Minimum execution time: 820_000 picoseconds. + Weight::from_parts(888_000, 0) } pub fn unpaid_execution() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 728_000 picoseconds. - Weight::from_parts(783_000, 0) + // Minimum execution time: 863_000 picoseconds. + Weight::from_parts(923_000, 0) } pub fn alias_origin() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 777_000 picoseconds. - Weight::from_parts(859_000, 0) + // Minimum execution time: 863_000 picoseconds. + Weight::from_parts(930_000, 0) + } + // Storage: `PolkadotXcm::ShouldRecordXcm` (r:1 w:0) + // Proof: `PolkadotXcm::ShouldRecordXcm` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + pub fn barrier_check() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `1485` + // Minimum execution time: 25_422_000 picoseconds. + Weight::from_parts(25_803_000, 1485) + .saturating_add(T::DbWeight::get().reads(1)) } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 84f7dcdf9c054..22715e81fb47b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -559,11 +559,7 @@ impl pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Everything; type XcmReserveTransferFilter = Everything; - type Weigher = WeightInfoBounds< - crate::weights::xcm::AssetHubWestendXcmWeight, - RuntimeCall, - MaxInstructions, - >; + type Weigher = crate::weights::xcm::AssetHubWestendXcmWeightInfoBounds; type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 545473565810b..f0421baf4a928 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -1324,6 +1324,10 @@ impl_runtime_apis! { fn alias_origin() -> Result<(Location, Location), BenchmarkError> { Err(BenchmarkError::Skip) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 88f49f47949c6..756835730bfdd 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -1270,6 +1270,10 @@ impl_runtime_apis! { let target = Location::new(1, [Parachain(1000), AccountId32 { id: [128u8; 32], network: None }]); Ok((origin, target)) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index a4983f96e55fb..698333318fcbf 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -1311,6 +1311,10 @@ impl_runtime_apis! { let target = Location::new(1, [Parachain(1000), AccountId32 { id: [128u8; 32], network: None }]); Ok((origin, target)) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index dedf3532c7877..454bf19328aa3 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -1143,6 +1143,10 @@ impl_runtime_apis! { fn alias_origin() -> Result<(Location, Location), BenchmarkError> { Err(BenchmarkError::Skip) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 53fae462c0ed0..c6f2e3a429754 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -1169,6 +1169,10 @@ impl_runtime_apis! { let target = Location::new(1, [Parachain(1000), AccountId32 { id: [128u8; 32], network: None }]); Ok((origin, target)) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 5be85498ab439..12ee4d132a0c2 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -1075,6 +1075,10 @@ impl_runtime_apis! { fn alias_origin() -> Result<(Location, Location), BenchmarkError> { Err(BenchmarkError::Skip) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index f08f2db83fd01..a529ec48b6dc8 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -1102,6 +1102,10 @@ impl_runtime_apis! { let target = Location::new(1, [Parachain(1000), AccountId32 { id: [128u8; 32], network: None }]); Ok((origin, target)) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 586b989075ce1..bd751157d74f0 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2683,6 +2683,10 @@ sp_api::impl_runtime_apis! { // The XCM executor of Rococo doesn't have a configured `Aliasers` Err(BenchmarkError::Skip) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } let mut whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 2215212ad478f..a93a22c7791db 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -3071,6 +3071,10 @@ sp_api::impl_runtime_apis! { let target = Location::new(0, [Parachain(1000), AccountId32 { id: [128u8; 32], network: None }]); Ok((origin, target)) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs index aefbada7429dd..c6ca06cd8720c 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs @@ -16,7 +16,7 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -use crate::{account_and_location, new_executor, EnsureDelivery, XcmCallOf}; +use crate::{account_and_location, new_executor, EnsureDelivery, ExecuteXcmOf, XcmCallOf}; use alloc::{vec, vec::Vec}; use codec::Encode; use frame_benchmarking::v2::*; @@ -961,6 +961,28 @@ mod benchmarks { Ok(()) } + #[benchmark] + fn barrier_check() -> Result<(), BenchmarkError> { + use xcm::latest::{prelude::Outcome, Error::Barrier}; + + let xcm = T::worst_case_for_not_passing_barrier().map_err(|_| BenchmarkError::Skip)?; + let mut executor = ExecuteXcmOf::::new(Location::default(), XcmHash::default()); + + #[block] + { + executor.execute(xcm.into())?; + } + + assert!(matches!( + executor.outcome(), + Some(Outcome::Incomplete { + used: _, + error: InstructionError { index: 0, error: Barrier } + }) + )); + Ok(()) + } + impl_benchmark_test_suite!( Pallet, crate::generic::mock::new_test_ext(), diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index 6368ca0e9c3f5..f51a384d362ad 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -20,7 +20,7 @@ use crate::{generic, mock::*, *}; use codec::Decode; use frame_support::{ derive_impl, parameter_types, - traits::{Contains, Everything, OriginTrait}, + traits::{Contains, Everything, OriginTrait, ProcessMessageError}, }; use sp_runtime::traits::TrailingZeroInput; use xcm_builder::{ @@ -28,10 +28,10 @@ use xcm_builder::{ AssetsInHolding, TestAssetExchanger, TestAssetLocker, TestAssetTrap, TestSubscriptionService, TestUniversalAliases, }, - AliasForeignAccountId32, AllowUnpaidExecutionFrom, EnsureDecodableXcm, - FrameTransactionalProcessor, + AliasForeignAccountId32, AllowUnpaidExecutionFrom, DenyRecursively, DenyThenTry, + EnsureDecodableXcm, FrameTransactionalProcessor, }; -use xcm_executor::traits::ConvertOrigin; +use xcm_executor::traits::{ConvertOrigin, DenyExecution, Properties}; type Block = frame_system::mocking::MockBlock; @@ -78,6 +78,18 @@ impl Contains for OnlyParachains { } } +pub struct DenyNothing; +impl DenyExecution for DenyNothing { + fn deny_execution( + _origin: &Location, + _instructions: &mut [Instruction], + _max_weight: Weight, + _properties: &mut Properties, + ) -> Result<(), ProcessMessageError> { + Ok(()) + } +} + type Aliasers = AliasForeignAccountId32; pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { @@ -89,7 +101,7 @@ impl xcm_executor::Config for XcmConfig { type IsReserve = AllAssetLocationsPass; type IsTeleporter = (); type UniversalLocation = UniversalLocation; - type Barrier = AllowUnpaidExecutionFrom; + type Barrier = DenyThenTry, AllowUnpaidExecutionFrom>; type Weigher = xcm_builder::FixedWeightBounds; type Trader = xcm_builder::FixedRateOfFungible; type ResponseHandler = DevNull; @@ -193,6 +205,29 @@ impl generic::Config for Test { let target: Location = AccountId32 { network: None, id: [0; 32] }.into(); Ok((origin, target)) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + use xcm::latest::prelude::{ClearOrigin, SetAppendix, SetTopic}; + + let nested_limit = xcm_executor::RECURSION_LIMIT as usize - 2; + + // Within the recursion limit, this is fine. + let mut set_topic = Xcm(vec![SetTopic([42; 32])]); + for _ in 0..nested_limit { + set_topic = Xcm(vec![SetAppendix(set_topic)]); + } + let set_topics = Xcm(vec![SetAppendix(set_topic); nested_limit]); + + // Exceed the recursion limit, this will be rejected. + let mut clear_origin = Xcm(vec![SetAppendix(Xcm(vec![ClearOrigin]))]); + for _ in 0..=nested_limit { + clear_origin = Xcm(vec![SetAppendix(clear_origin)]); + } + + let xcm = Xcm(vec![SetAppendix(set_topics), SetAppendix(clear_origin)]); + + Ok(xcm) + } } #[cfg(feature = "runtime-benchmarks")] diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs index d7471b02368fa..854efa537c4f8 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs @@ -27,7 +27,8 @@ pub mod pallet { use frame_support::{dispatch::GetDispatchInfo, pallet_prelude::Encode}; use sp_runtime::traits::Dispatchable; use xcm::latest::{ - Asset, Assets, InteriorLocation, Junction, Location, NetworkId, Response, WeightLimit, + Asset, Assets, Instruction, InteriorLocation, Junction, Location, NetworkId, Response, + WeightLimit, Xcm, }; #[pallet::config] @@ -97,6 +98,14 @@ pub mod pallet { /// If set to `Err`, benchmarks which rely on a universal alias will be skipped. fn alias_origin() -> Result<(Location, Location), BenchmarkError>; + /// An XCM used to exercise the barrier logic in benchmarks. + /// + /// This represents a call used to benchmark the cost of barrier evaluation in rejection + /// cases. + /// + /// If set to `Err`, benchmarks which rely on a barrier check will be skipped. + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError>; + /// Returns a valid pallet info for `ExpectPallet` or `QueryPallet` benchmark. /// /// By default returns `frame_system::Pallet` info with expected pallet index `0`. diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs index 5f8482bdcb8cf..6811e19b886fd 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/lib.rs @@ -68,6 +68,32 @@ pub type AssetTransactorOf = <::XcmConfig as XcmConfig>::AssetTr /// The call type of executor's config. Should eventually resolve to the same overarching call type. pub type XcmCallOf = <::XcmConfig as XcmConfig>::RuntimeCall; +/// The wrapper for executing XCMs in benchmarks, storing the execution outcome. +pub struct ExecuteXcmOf { + _config: core::marker::PhantomData, + origin: Location, + id: XcmHash, + outcome: Option, +} + +impl ExecuteXcmOf { + pub fn new(origin: impl Into, id: XcmHash) -> Self { + Self { _config: core::marker::PhantomData, origin: origin.into(), id, outcome: None } + } + + pub fn execute(&mut self, xcm: Xcm>) -> Result<(), BenchmarkError> { + let message = + ExecutorOf::::prepare(xcm, Weight::MAX).map_err(|_| BenchmarkError::Skip)?; + self.outcome = + Some(ExecutorOf::::execute(self.origin.clone(), message, &mut self.id, Weight::MAX)); + Ok(()) + } + + pub fn outcome(&self) -> &Option { + &self.outcome + } +} + pub fn generate_holding_assets(max_assets: u32) -> Assets { let fungibles_amount: u128 = 100; let holding_fungibles = max_assets / 2; diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index b4efab9349a4b..2369a82a1e735 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -283,10 +283,12 @@ impl ExecuteXcm for XcmExecutor { /// Return the maximum amount of weight that an attempted execution of this instruction could /// consume. fn instr_weight(instruction: &mut Instruction) -> Result; + + /// Return the weight consumed by a barrier check for an XCM, or None if not applicable. + fn barrier_check_weight() -> Option { + None + } } /// Charge for weight in order to execute XCM. diff --git a/prdoc/pr_9808.prdoc b/prdoc/pr_9808.prdoc new file mode 100644 index 0000000000000..2c822819b0c7c --- /dev/null +++ b/prdoc/pr_9808.prdoc @@ -0,0 +1,35 @@ +title: Benchmark Barrier for Accurate Weighting on Early Rejection +doc: +- audience: Runtime Dev + description: This PR improves the weight accounting for XCMs that are rejected early by `Barrier`. +crates: +- name: asset-hub-rococo-runtime + bump: patch +- name: asset-hub-westend-runtime + bump: patch +- name: bridge-hub-rococo-runtime + bump: patch +- name: bridge-hub-westend-runtime + bump: patch +- name: collectives-westend-runtime + bump: patch +- name: coretime-rococo-runtime + bump: patch +- name: coretime-westend-runtime + bump: patch +- name: people-rococo-runtime + bump: patch +- name: people-westend-runtime + bump: patch +- name: rococo-runtime + bump: patch +- name: pallet-staking-async-parachain-runtime + bump: none +- name: pallet-staking-async-rc-runtime + bump: none +- name: pallet-xcm-benchmarks + bump: major +- name: staging-xcm-executor + bump: major +- name: westend-runtime + bump: patch \ No newline at end of file diff --git a/substrate/frame/staking-async/runtimes/parachain/src/lib.rs b/substrate/frame/staking-async/runtimes/parachain/src/lib.rs index d587ef148e925..511f7041db67c 100644 --- a/substrate/frame/staking-async/runtimes/parachain/src/lib.rs +++ b/substrate/frame/staking-async/runtimes/parachain/src/lib.rs @@ -109,8 +109,8 @@ use frame_support::traits::PalletInfoAccess; #[cfg(feature = "runtime-benchmarks")] use xcm::latest::prelude::{ - Asset, Assets as XcmAssets, Fungible, Here, InteriorLocation, Junction, Junction::*, Location, - NetworkId, NonFungible, Parent, ParentThen, Response, XCM_VERSION, + Asset, Assets as XcmAssets, Fungible, Here, Instruction, InteriorLocation, Junction, + Junction::*, Location, NetworkId, NonFungible, Parent, ParentThen, Response, Xcm, XCM_VERSION, }; use xcm_runtime_apis::{ @@ -2133,6 +2133,10 @@ impl_runtime_apis! { Location::new(1, [Parachain(1001), AccountId32 { id: [111u8; 32], network: None }]), )) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/substrate/frame/staking-async/runtimes/rc/src/lib.rs b/substrate/frame/staking-async/runtimes/rc/src/lib.rs index c7136f81e8338..bf93e02fbe187 100644 --- a/substrate/frame/staking-async/runtimes/rc/src/lib.rs +++ b/substrate/frame/staking-async/runtimes/rc/src/lib.rs @@ -2956,6 +2956,10 @@ sp_api::impl_runtime_apis! { let target = Location::new(0, [Parachain(1000), AccountId32 { id: [128u8; 32], network: None }]); Ok((origin, target)) } + + fn worst_case_for_not_passing_barrier() -> Result>, BenchmarkError> { + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::;