diff --git a/bridges/bin/runtime-common/src/messages_benchmarking.rs b/bridges/bin/runtime-common/src/messages_benchmarking.rs index 028172e7ab4..5d0ab6df71f 100644 --- a/bridges/bin/runtime-common/src/messages_benchmarking.rs +++ b/bridges/bin/runtime-common/src/messages_benchmarking.rs @@ -21,7 +21,8 @@ use crate::{ messages::{ - source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, + source::FromBridgedChainMessagesDeliveryProof, + target::FromBridgedChainMessagesProof, AccountIdOf, BridgedChain, HashOf, HasherOf, MessageBridge, ThisChain, }, messages_generation::{ @@ -40,6 +41,39 @@ use pallet_bridge_messages::benchmarking::{MessageDeliveryProofParams, MessagePr use sp_runtime::traits::{Header, Zero}; use sp_std::prelude::*; use sp_trie::{trie_types::TrieDBMutBuilderV1, LayoutV1, MemoryDB, TrieMut}; +use xcm::v3::prelude::*; + +/// Prepare inbound bridge message according to given message proof parameters. +fn prepare_inbound_message( + params: &MessageProofParams, + destination: InteriorMultiLocation, +) -> Vec { + // we only care about **this** message size when message proof needs to be `Minimal` + let expected_size = match params.size { + StorageProofSize::Minimal(size) => size as usize, + _ => 0, + }; + + // if we don't need a correct message, then we may just return some random blob + if !params.is_successful_dispatch_expected { + return vec![0u8; expected_size] + } + + // else let's prepare successful message. For XCM bridge hubs, it is the message that + // will be pushed further to some XCM queue (XCMP/UMP) + let location = xcm::VersionedInteriorMultiLocation::V3(destination); + let location_encoded_size = location.encoded_size(); + + // we don't need to be super-precise with `expected_size` here + let xcm_size = expected_size.saturating_sub(location_encoded_size); + let xcm = xcm::VersionedXcm::<()>::V3(vec![Instruction::ClearOrigin; xcm_size].into()); + + // this is the `BridgeMessage` from polkadot xcm builder, but it has no constructor + // or public fields, so just tuple + // (double encoding, because `.encode()` is called on original Xcm BLOB when it is pushed + // to the storage) + (location, xcm).encode().encode() +} /// Prepare proof of messages for the `receive_messages_proof` call. /// @@ -51,6 +85,7 @@ use sp_trie::{trie_types::TrieDBMutBuilderV1, LayoutV1, MemoryDB, TrieMut}; /// function. pub fn prepare_message_proof_from_grandpa_chain( params: MessageProofParams, + message_destination: InteriorMultiLocation, ) -> (FromBridgedChainMessagesProof>>, Weight) where R: pallet_bridge_grandpa::Config>>, @@ -61,12 +96,9 @@ where let (state_root, storage_proof) = prepare_messages_storage_proof::( params.lane, params.message_nonces.clone(), - params.outbound_lane_data, + params.outbound_lane_data.clone(), params.size, - match params.size { - StorageProofSize::Minimal(ref size) => vec![0u8; *size as _], - _ => vec![], - }, + prepare_inbound_message(¶ms, message_destination), encode_all_messages, encode_lane_data, ); @@ -82,7 +114,7 @@ where nonces_start: *params.message_nonces.start(), nonces_end: *params.message_nonces.end(), }, - Weight::zero(), + Weight::MAX / 1000, ) } @@ -96,6 +128,7 @@ where /// `prepare_message_proof_from_grandpa_chain` function. pub fn prepare_message_proof_from_parachain( params: MessageProofParams, + message_destination: InteriorMultiLocation, ) -> (FromBridgedChainMessagesProof>>, Weight) where R: pallet_bridge_parachains::Config, @@ -107,12 +140,9 @@ where let (state_root, storage_proof) = prepare_messages_storage_proof::( params.lane, params.message_nonces.clone(), - params.outbound_lane_data, + params.outbound_lane_data.clone(), params.size, - match params.size { - StorageProofSize::Minimal(ref size) => vec![0u8; *size as _], - _ => vec![], - }, + prepare_inbound_message(¶ms, message_destination), encode_all_messages, encode_lane_data, ); @@ -129,7 +159,7 @@ where nonces_start: *params.message_nonces.start(), nonces_end: *params.message_nonces.end(), }, - Weight::zero(), + Weight::MAX / 1000, ) } diff --git a/bridges/bin/runtime-common/src/messages_xcm_extension.rs b/bridges/bin/runtime-common/src/messages_xcm_extension.rs index 7163d8a5357..353f777d6ca 100644 --- a/bridges/bin/runtime-common/src/messages_xcm_extension.rs +++ b/bridges/bin/runtime-common/src/messages_xcm_extension.rs @@ -28,8 +28,10 @@ use bp_messages::{ }; use bp_runtime::{messages::MessageDispatchResult, AccountIdOf, Chain}; use codec::{Decode, Encode}; -use frame_support::{dispatch::Weight, traits::Get, CloneNoBound, EqNoBound, PartialEqNoBound}; +use frame_support::{dispatch::Weight, CloneNoBound, EqNoBound, PartialEqNoBound}; +use pallet_bridge_messages::WeightInfoExt as MessagesPalletWeights; use scale_info::TypeInfo; +use sp_runtime::SaturatedConversion; use xcm_builder::{DispatchBlob, DispatchBlobError, HaulBlob, HaulBlobError}; /// Plain "XCM" payload, which we transfer through bridge @@ -44,38 +46,36 @@ pub enum XcmBlobMessageDispatchResult { } /// [`XcmBlobMessageDispatch`] is responsible for dispatching received messages -pub struct XcmBlobMessageDispatch< - SourceBridgeHubChain, - TargetBridgeHubChain, - DispatchBlob, - DispatchBlobWeigher, -> { +pub struct XcmBlobMessageDispatch +{ _marker: sp_std::marker::PhantomData<( SourceBridgeHubChain, TargetBridgeHubChain, DispatchBlob, - DispatchBlobWeigher, + Weights, )>, } impl< + 'a, SourceBridgeHubChain: Chain, TargetBridgeHubChain: Chain, BlobDispatcher: DispatchBlob, - DispatchBlobWeigher: Get, + Weights: MessagesPalletWeights, > MessageDispatch> - for XcmBlobMessageDispatch< - SourceBridgeHubChain, - TargetBridgeHubChain, - BlobDispatcher, - DispatchBlobWeigher, - > + for XcmBlobMessageDispatch { type DispatchPayload = XcmAsPlainPayload; type DispatchLevelResult = XcmBlobMessageDispatchResult; - fn dispatch_weight(_message: &mut DispatchMessage) -> Weight { - DispatchBlobWeigher::get() + fn dispatch_weight(message: &mut DispatchMessage) -> Weight { + match message.data.payload { + Ok(ref payload) => { + let payload_size = payload.encoded_size().saturated_into(); + Weights::message_dispatch_weight(payload_size) + }, + Err(_) => Weight::zero(), + } } fn dispatch( @@ -92,7 +92,6 @@ impl< message.key.nonce ); return MessageDispatchResult { - // TODO:check-parameter - setup uspent_weight? https://github.com/paritytech/polkadot/issues/6629 unspent_weight: Weight::zero(), dispatch_level_result: XcmBlobMessageDispatchResult::InvalidPayload, } @@ -128,11 +127,7 @@ impl< XcmBlobMessageDispatchResult::NotDispatched(e) }, }; - MessageDispatchResult { - // TODO:check-parameter - setup uspent_weight? https://github.com/paritytech/polkadot/issues/6629 - unspent_weight: Weight::zero(), - dispatch_level_result, - } + MessageDispatchResult { unspent_weight: Weight::zero(), dispatch_level_result } } } @@ -159,23 +154,24 @@ impl> HaulBlo { fn haul_blob(blob: sp_std::prelude::Vec) -> Result<(), HaulBlobError> { let lane = H::xcm_lane(); - let result = H::MessageSender::send_message(H::message_sender_origin(), lane, blob); - let result = result - .map(|artifacts| (lane, artifacts.nonce).using_encoded(sp_io::hashing::blake2_256)); - match &result { - Ok(result) => log::info!( - target: crate::LOG_TARGET_BRIDGE_DISPATCH, - "haul_blob result - ok: {:?} on lane: {:?}", - result, - lane - ), - Err(error) => log::error!( - target: crate::LOG_TARGET_BRIDGE_DISPATCH, - "haul_blob result - error: {:?} on lane: {:?}", - error, - lane - ), - }; - result.map(|_| ()).map_err(|_| HaulBlobError::Transport("MessageSenderError")) + H::MessageSender::send_message(H::message_sender_origin(), lane, blob) + .map(|artifacts| (lane, artifacts.nonce).using_encoded(sp_io::hashing::blake2_256)) + .map(|result| { + log::info!( + target: crate::LOG_TARGET_BRIDGE_DISPATCH, + "haul_blob result - ok: {:?} on lane: {:?}", + result, + lane + ) + }) + .map_err(|error| { + log::error!( + target: crate::LOG_TARGET_BRIDGE_DISPATCH, + "haul_blob result - error: {:?} on lane: {:?}", + error, + lane + ); + HaulBlobError::Transport("MessageSenderError") + }) } } diff --git a/bridges/modules/messages/src/benchmarking.rs b/bridges/modules/messages/src/benchmarking.rs index 955dd3da2c5..bc9c1f75257 100644 --- a/bridges/modules/messages/src/benchmarking.rs +++ b/bridges/modules/messages/src/benchmarking.rs @@ -48,6 +48,11 @@ pub struct MessageProofParams { pub message_nonces: RangeInclusive, /// If `Some`, the proof needs to include this outbound lane data. pub outbound_lane_data: Option, + /// If `true`, the caller expects that the proof will contain correct messages that will + /// be successfully dispatched. This is only called from the "optional" + /// `receive_single_message_proof_with_dispatch` benchmark. If you don't need it, just + /// return `true` from the `is_message_successfully_dispatched`. + pub is_successful_dispatch_expected: bool, /// Proof size requirements. pub size: StorageProofSize, } @@ -95,32 +100,25 @@ pub trait Config: crate::Config { params: MessageDeliveryProofParams, ) -> >::MessagesDeliveryProof; - /// Returns true if message has been dispatched (either successfully or not). - /// - /// We assume that messages have near-zero dispatch weight, so most of times it - /// is hard to determine whether messages has been dispatched or not. For example, - /// XCM message can be a call that leaves entry in `frame_system::Events` vector, - /// but not all XCM messages do that and we don't want to include weight of this - /// action to the base weight of message delivery. Hence, the default `true` return - /// value. - fn is_message_dispatched(_nonce: MessageNonce) -> bool { + /// Returns true if message has been successfully dispatched or not. + fn is_message_successfully_dispatched(_nonce: MessageNonce) -> bool { true } + /// Returns true if given relayer has been rewarded for some of its actions. fn is_relayer_rewarded(relayer: &Self::AccountId) -> bool; } benchmarks_instance_pallet! { // - // Benchmarks that are used directly by the runtime. + // Benchmarks that are used directly by the runtime calls weight formulae. // // Benchmark `receive_messages_proof` extrinsic with single minimal-weight message and following conditions: // * proof does not include outbound lane state proof; // * inbound lane already has state, so it needs to be read and decoded; - // * message is successfully dispatched; - // * message requires all heavy checks done by dispatcher; - // * message dispatch fee is paid at target (this) chain. + // * message is dispatched (reminder: dispatch weight should be minimal); + // * message requires all heavy checks done by dispatcher. // // This is base benchmark for all other message delivery benchmarks. receive_single_message_proof { @@ -135,6 +133,7 @@ benchmarks_instance_pallet! { lane: T::bench_lane_id(), message_nonces: 21..=21, outbound_lane_data: None, + is_successful_dispatch_expected: false, size: StorageProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH), }); }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight) @@ -143,15 +142,13 @@ benchmarks_instance_pallet! { crate::InboundLanes::::get(&T::bench_lane_id()).last_delivered_nonce(), 21, ); - assert!(T::is_message_dispatched(21)); } // Benchmark `receive_messages_proof` extrinsic with two minimal-weight messages and following conditions: // * proof does not include outbound lane state proof; // * inbound lane already has state, so it needs to be read and decoded; - // * message is successfully dispatched; - // * message requires all heavy checks done by dispatcher; - // * message dispatch fee is paid at target (this) chain. + // * message is dispatched (reminder: dispatch weight should be minimal); + // * message requires all heavy checks done by dispatcher. // // The weight of single message delivery could be approximated as // `weight(receive_two_messages_proof) - weight(receive_single_message_proof)`. @@ -169,6 +166,7 @@ benchmarks_instance_pallet! { lane: T::bench_lane_id(), message_nonces: 21..=22, outbound_lane_data: None, + is_successful_dispatch_expected: false, size: StorageProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH), }); }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 2, dispatch_weight) @@ -177,15 +175,13 @@ benchmarks_instance_pallet! { crate::InboundLanes::::get(&T::bench_lane_id()).last_delivered_nonce(), 22, ); - assert!(T::is_message_dispatched(22)); } // Benchmark `receive_messages_proof` extrinsic with single minimal-weight message and following conditions: // * proof includes outbound lane state proof; // * inbound lane already has state, so it needs to be read and decoded; - // * message is successfully dispatched; - // * message requires all heavy checks done by dispatcher; - // * message dispatch fee is paid at target (this) chain. + // * message is successfully dispatched (reminder: dispatch weight should be minimal); + // * message requires all heavy checks done by dispatcher. // // The weight of outbound lane state delivery would be // `weight(receive_single_message_proof_with_outbound_lane_state) - weight(receive_single_message_proof)`. @@ -207,6 +203,7 @@ benchmarks_instance_pallet! { latest_received_nonce: 20, latest_generated_nonce: 21, }), + is_successful_dispatch_expected: false, size: StorageProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH), }); }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight) @@ -214,14 +211,13 @@ benchmarks_instance_pallet! { let lane_state = crate::InboundLanes::::get(&T::bench_lane_id()); assert_eq!(lane_state.last_delivered_nonce(), 21); assert_eq!(lane_state.last_confirmed_nonce, 20); - assert!(T::is_message_dispatched(21)); } // Benchmark `receive_messages_proof` extrinsic with single minimal-weight message and following conditions: - // * the proof has many redundand trie nodes with total size of approximately 1KB; + // * the proof has large leaf with total size of approximately 1KB; // * proof does not include outbound lane state proof; // * inbound lane already has state, so it needs to be read and decoded; - // * message is successfully dispatched; + // * message is dispatched (reminder: dispatch weight should be minimal); // * message requires all heavy checks done by dispatcher. // // With single KB of messages proof, the weight of the call is increased (roughly) by @@ -238,6 +234,7 @@ benchmarks_instance_pallet! { lane: T::bench_lane_id(), message_nonces: 21..=21, outbound_lane_data: None, + is_successful_dispatch_expected: false, size: StorageProofSize::HasLargeLeaf(1024), }); }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight) @@ -246,14 +243,13 @@ benchmarks_instance_pallet! { crate::InboundLanes::::get(&T::bench_lane_id()).last_delivered_nonce(), 21, ); - assert!(T::is_message_dispatched(21)); } // Benchmark `receive_messages_proof` extrinsic with single minimal-weight message and following conditions: - // * the proof has many redundand trie nodes with total size of approximately 16KB; + // * the proof has large leaf with total size of approximately 16KB; // * proof does not include outbound lane state proof; // * inbound lane already has state, so it needs to be read and decoded; - // * message is successfully dispatched; + // * message is dispatched (reminder: dispatch weight should be minimal); // * message requires all heavy checks done by dispatcher. // // Size of proof grows because it contains extra trie nodes in it. @@ -272,6 +268,7 @@ benchmarks_instance_pallet! { lane: T::bench_lane_id(), message_nonces: 21..=21, outbound_lane_data: None, + is_successful_dispatch_expected: false, size: StorageProofSize::HasLargeLeaf(16 * 1024), }); }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight) @@ -280,7 +277,6 @@ benchmarks_instance_pallet! { crate::InboundLanes::::get(&T::bench_lane_id()).last_delivered_nonce(), 21, ); - assert!(T::is_message_dispatched(21)); } // Benchmark `receive_messages_delivery_proof` extrinsic with following conditions: @@ -400,6 +396,47 @@ benchmarks_instance_pallet! { assert!(T::is_relayer_rewarded(&relayer1_id)); assert!(T::is_relayer_rewarded(&relayer2_id)); } + + // + // Benchmarks that the runtime developers may use for proper pallet configuration. + // + + // This benchmark is optional and may be used when runtime developer need a way to compute + // message dispatch weight. In this case, he needs to provide messages that can go the whole + // dispatch + // + // Benchmark `receive_messages_proof` extrinsic with single message and following conditions: + // + // * proof does not include outbound lane state proof; + // * inbound lane already has state, so it needs to be read and decoded; + // * message is **SUCCESSFULLY** dispatched; + // * message requires all heavy checks done by dispatcher. + receive_single_message_proof_with_dispatch { + // maybe dispatch weight relies on the message size too? + let i in EXPECTED_DEFAULT_MESSAGE_LENGTH .. EXPECTED_DEFAULT_MESSAGE_LENGTH * 16; + + let relayer_id_on_source = T::bridged_relayer_id(); + let relayer_id_on_target = account("relayer", 0, SEED); + T::endow_account(&relayer_id_on_target); + + // mark messages 1..=20 as delivered + receive_messages::(20); + + let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams { + lane: T::bench_lane_id(), + message_nonces: 21..=21, + outbound_lane_data: None, + is_successful_dispatch_expected: true, + size: StorageProofSize::Minimal(i), + }); + }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight) + verify { + assert_eq!( + crate::InboundLanes::::get(&T::bench_lane_id()).last_delivered_nonce(), + 21, + ); + assert!(T::is_message_successfully_dispatched(21)); + } } fn send_regular_message, I: 'static>() { diff --git a/bridges/modules/messages/src/weights.rs b/bridges/modules/messages/src/weights.rs index 4b2e5b48ee2..baaef317241 100644 --- a/bridges/modules/messages/src/weights.rs +++ b/bridges/modules/messages/src/weights.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for RialtoMessages //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `covid`, CPU: `11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 @@ -58,6 +58,7 @@ pub trait WeightInfo { fn receive_delivery_proof_for_single_message() -> Weight; fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight; fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight; + fn receive_single_message_proof_with_dispatch(i: u32) -> Weight; } /// Weights for `RialtoMessages` that are generated using one of the Bridge testnets. @@ -79,19 +80,14 @@ impl WeightInfo for BridgeWeight { /// /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: /// 51655, mode: MaxEncodedLen) - /// - /// Storage: Balances TotalIssuance (r:1 w:1) - /// - /// Proof: Balances TotalIssuance (max_values: Some(1), max_size: Some(8), added: 503, mode: - /// MaxEncodedLen) fn receive_single_message_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `693` - // Estimated: `54703` - // Minimum execution time: 48_058 nanoseconds. - Weight::from_parts(50_422_000, 54703) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Measured: `618` + // Estimated: `57170` + // Minimum execution time: 52_321 nanoseconds. + Weight::from_parts(54_478_000, 57170) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// @@ -107,19 +103,14 @@ impl WeightInfo for BridgeWeight { /// /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: /// 51655, mode: MaxEncodedLen) - /// - /// Storage: Balances TotalIssuance (r:1 w:1) - /// - /// Proof: Balances TotalIssuance (max_values: Some(1), max_size: Some(8), added: 503, mode: - /// MaxEncodedLen) fn receive_two_messages_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `693` - // Estimated: `54703` - // Minimum execution time: 59_371 nanoseconds. - Weight::from_parts(61_726_000, 54703) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Measured: `618` + // Estimated: `57170` + // Minimum execution time: 64_597 nanoseconds. + Weight::from_parts(69_267_000, 57170) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// @@ -135,19 +126,14 @@ impl WeightInfo for BridgeWeight { /// /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: /// 51655, mode: MaxEncodedLen) - /// - /// Storage: Balances TotalIssuance (r:1 w:1) - /// - /// Proof: Balances TotalIssuance (max_values: Some(1), max_size: Some(8), added: 503, mode: - /// MaxEncodedLen) fn receive_single_message_proof_with_outbound_lane_state() -> Weight { // Proof Size summary in bytes: - // Measured: `693` - // Estimated: `54703` - // Minimum execution time: 53_398 nanoseconds. - Weight::from_parts(54_351_000, 54703) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Measured: `618` + // Estimated: `57170` + // Minimum execution time: 64_079 nanoseconds. + Weight::from_parts(65_905_000, 57170) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// @@ -166,9 +152,9 @@ impl WeightInfo for BridgeWeight { fn receive_single_message_proof_1_kb() -> Weight { // Proof Size summary in bytes: // Measured: `618` - // Estimated: `54200` - // Minimum execution time: 50_064 nanoseconds. - Weight::from_parts(51_306_000, 54200) + // Estimated: `57170` + // Minimum execution time: 50_588 nanoseconds. + Weight::from_parts(53_544_000, 57170) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -189,9 +175,9 @@ impl WeightInfo for BridgeWeight { fn receive_single_message_proof_16_kb() -> Weight { // Proof Size summary in bytes: // Measured: `618` - // Estimated: `54200` - // Minimum execution time: 75_403 nanoseconds. - Weight::from_parts(77_006_000, 54200) + // Estimated: `57170` + // Minimum execution time: 78_269 nanoseconds. + Weight::from_parts(81_748_000, 57170) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -217,9 +203,9 @@ impl WeightInfo for BridgeWeight { fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: // Measured: `579` - // Estimated: `5624` - // Minimum execution time: 41_670 nanoseconds. - Weight::from_parts(42_863_000, 5624) + // Estimated: `9584` + // Minimum execution time: 45_786 nanoseconds. + Weight::from_parts(47_382_000, 9584) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -245,9 +231,9 @@ impl WeightInfo for BridgeWeight { fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `5624` - // Minimum execution time: 40_928 nanoseconds. - Weight::from_parts(42_165_000, 5624) + // Estimated: `9584` + // Minimum execution time: 44_544 nanoseconds. + Weight::from_parts(45_451_000, 9584) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -273,12 +259,39 @@ impl WeightInfo for BridgeWeight { fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `8164` - // Minimum execution time: 44_022 nanoseconds. - Weight::from_parts(44_657_000, 8164) + // Estimated: `12124` + // Minimum execution time: 47_344 nanoseconds. + Weight::from_parts(48_311_000, 12124) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } + /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) + /// + /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), + /// added: 497, mode: MaxEncodedLen) + /// + /// Storage: BridgeRialtoGrandpa ImportedHeaders (r:1 w:0) + /// + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), + /// added: 2048, mode: MaxEncodedLen) + /// + /// Storage: BridgeRialtoMessages InboundLanes (r:1 w:1) + /// + /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: + /// 51655, mode: MaxEncodedLen) + /// + /// The range of component `i` is `[128, 2048]`. + fn receive_single_message_proof_with_dispatch(i: u32) -> Weight { + // Proof Size summary in bytes: + // Measured: `618` + // Estimated: `57170` + // Minimum execution time: 52_385 nanoseconds. + Weight::from_parts(54_919_468, 57170) + // Standard Error: 108 + .saturating_add(Weight::from_parts(3_286, 0).saturating_mul(i.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } // For backwards compatibility and tests @@ -297,19 +310,14 @@ impl WeightInfo for () { /// /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: /// 51655, mode: MaxEncodedLen) - /// - /// Storage: Balances TotalIssuance (r:1 w:1) - /// - /// Proof: Balances TotalIssuance (max_values: Some(1), max_size: Some(8), added: 503, mode: - /// MaxEncodedLen) fn receive_single_message_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `693` - // Estimated: `54703` - // Minimum execution time: 48_058 nanoseconds. - Weight::from_parts(50_422_000, 54703) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + // Measured: `618` + // Estimated: `57170` + // Minimum execution time: 52_321 nanoseconds. + Weight::from_parts(54_478_000, 57170) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// @@ -325,19 +333,14 @@ impl WeightInfo for () { /// /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: /// 51655, mode: MaxEncodedLen) - /// - /// Storage: Balances TotalIssuance (r:1 w:1) - /// - /// Proof: Balances TotalIssuance (max_values: Some(1), max_size: Some(8), added: 503, mode: - /// MaxEncodedLen) fn receive_two_messages_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `693` - // Estimated: `54703` - // Minimum execution time: 59_371 nanoseconds. - Weight::from_parts(61_726_000, 54703) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + // Measured: `618` + // Estimated: `57170` + // Minimum execution time: 64_597 nanoseconds. + Weight::from_parts(69_267_000, 57170) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// @@ -353,19 +356,14 @@ impl WeightInfo for () { /// /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: /// 51655, mode: MaxEncodedLen) - /// - /// Storage: Balances TotalIssuance (r:1 w:1) - /// - /// Proof: Balances TotalIssuance (max_values: Some(1), max_size: Some(8), added: 503, mode: - /// MaxEncodedLen) fn receive_single_message_proof_with_outbound_lane_state() -> Weight { // Proof Size summary in bytes: - // Measured: `693` - // Estimated: `54703` - // Minimum execution time: 53_398 nanoseconds. - Weight::from_parts(54_351_000, 54703) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + // Measured: `618` + // Estimated: `57170` + // Minimum execution time: 64_079 nanoseconds. + Weight::from_parts(65_905_000, 57170) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// @@ -384,9 +382,9 @@ impl WeightInfo for () { fn receive_single_message_proof_1_kb() -> Weight { // Proof Size summary in bytes: // Measured: `618` - // Estimated: `54200` - // Minimum execution time: 50_064 nanoseconds. - Weight::from_parts(51_306_000, 54200) + // Estimated: `57170` + // Minimum execution time: 50_588 nanoseconds. + Weight::from_parts(53_544_000, 57170) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -407,9 +405,9 @@ impl WeightInfo for () { fn receive_single_message_proof_16_kb() -> Weight { // Proof Size summary in bytes: // Measured: `618` - // Estimated: `54200` - // Minimum execution time: 75_403 nanoseconds. - Weight::from_parts(77_006_000, 54200) + // Estimated: `57170` + // Minimum execution time: 78_269 nanoseconds. + Weight::from_parts(81_748_000, 57170) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -435,9 +433,9 @@ impl WeightInfo for () { fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: // Measured: `579` - // Estimated: `5624` - // Minimum execution time: 41_670 nanoseconds. - Weight::from_parts(42_863_000, 5624) + // Estimated: `9584` + // Minimum execution time: 45_786 nanoseconds. + Weight::from_parts(47_382_000, 9584) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -463,9 +461,9 @@ impl WeightInfo for () { fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `5624` - // Minimum execution time: 40_928 nanoseconds. - Weight::from_parts(42_165_000, 5624) + // Estimated: `9584` + // Minimum execution time: 44_544 nanoseconds. + Weight::from_parts(45_451_000, 9584) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -491,10 +489,37 @@ impl WeightInfo for () { fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `8164` - // Minimum execution time: 44_022 nanoseconds. - Weight::from_parts(44_657_000, 8164) + // Estimated: `12124` + // Minimum execution time: 47_344 nanoseconds. + Weight::from_parts(48_311_000, 12124) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } + /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) + /// + /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), + /// added: 497, mode: MaxEncodedLen) + /// + /// Storage: BridgeRialtoGrandpa ImportedHeaders (r:1 w:0) + /// + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), + /// added: 2048, mode: MaxEncodedLen) + /// + /// Storage: BridgeRialtoMessages InboundLanes (r:1 w:1) + /// + /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: + /// 51655, mode: MaxEncodedLen) + /// + /// The range of component `i` is `[128, 2048]`. + fn receive_single_message_proof_with_dispatch(i: u32) -> Weight { + // Proof Size summary in bytes: + // Measured: `618` + // Estimated: `57170` + // Minimum execution time: 52_385 nanoseconds. + Weight::from_parts(54_919_468, 57170) + // Standard Error: 108 + .saturating_add(Weight::from_parts(3_286, 0).saturating_mul(i.into())) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } } diff --git a/bridges/modules/messages/src/weights_ext.rs b/bridges/modules/messages/src/weights_ext.rs index 5598706b5db..090c03390ba 100644 --- a/bridges/modules/messages/src/weights_ext.rs +++ b/bridges/modules/messages/src/weights_ext.rs @@ -403,6 +403,21 @@ pub trait WeightInfoExt: WeightInfo { (15 * 1024); proof_size_in_bytes * byte_weight } + + // Functions that may be used by runtime developers. + + /// Returns dispatch weight of message of given size. + /// + /// This function would return correct value only if your runtime is configured to run + /// `receive_single_message_proof_with_dispatch` benchmark. See its requirements for + /// details. + fn message_dispatch_weight(message_size: u32) -> Weight { + // There may be a tiny overweight/underweight here, because we don't account how message + // size affects all steps before dispatch. But the effect should be small enough and we + // may ignore it. + Self::receive_single_message_proof_with_dispatch(message_size) + .saturating_sub(Self::receive_single_message_proof()) + } } impl WeightInfoExt for () { diff --git a/pallets/parachain-system/src/lib.rs b/pallets/parachain-system/src/lib.rs index 97c6cfe368d..42f4eaa2cad 100644 --- a/pallets/parachain-system/src/lib.rs +++ b/pallets/parachain-system/src/lib.rs @@ -1042,6 +1042,30 @@ impl Pallet { pub fn set_custom_validation_head_data(head_data: Vec) { CustomValidationHeadData::::put(head_data); } + + /// Open HRMP channel for using it in benchmarks. + /// + /// The caller assumes that the pallet will accept regular outbound message to the sibling + /// `target_parachain` after this call. No other assumptions are made. + #[cfg(feature = "runtime-benchmarks")] + pub fn open_outbound_hrmp_channel_for_benchmarks(target_parachain: ParaId) { + RelevantMessagingState::::put(MessagingStateSnapshot { + dmq_mqc_head: Default::default(), + relay_dispatch_queue_size: Default::default(), + ingress_channels: Default::default(), + egress_channels: vec![( + target_parachain, + cumulus_primitives_core::AbridgedHrmpChannel { + max_capacity: 10, + max_total_size: 10_000_000_u32, + max_message_size: 10_000_000_u32, + msg_count: 5, + total_size: 5_000_000_u32, + mqc_head: None, + }, + )], + }) + } } pub struct ParachainSetCode(sp_std::marker::PhantomData); diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 7e32cdcf585..8188899088a 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -174,6 +174,7 @@ runtime-benchmarks = [ "pallet-bridge-relayers/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-utility/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index fb95c47b76c..f94a54251e7 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -80,7 +80,7 @@ use crate::{ WithBridgeHubRococoMessageBridge, }, constants::fee::WeightToFee, - xcm_config::{XcmRouter, XcmRouterWeigher}, + xcm_config::XcmRouter, }; use bridge_runtime_common::{ messages::{source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter}, @@ -486,7 +486,7 @@ impl pallet_bridge_messages::Config for Run bp_bridge_hub_wococo::BridgeHubWococo, bp_bridge_hub_rococo::BridgeHubRococo, OnBridgeHubRococoBlobDispatcher, - XcmRouterWeigher, + Self::WeightInfo, >; } @@ -523,7 +523,7 @@ impl pallet_bridge_messages::Config for Run bp_bridge_hub_rococo::BridgeHubRococo, bp_bridge_hub_wococo::BridgeHubWococo, OnBridgeHubWococoBlobDispatcher, - XcmRouterWeigher, + Self::WeightInfo, >; } @@ -994,11 +994,14 @@ impl_runtime_apis! { fn prepare_message_proof( params: MessageProofParams, ) -> (bridge_hub_rococo_config::FromWococoBridgeHubMessagesProof, Weight) { + use cumulus_primitives_core::XcmpMessageSource; + assert!(XcmpQueue::take_outbound_messages(usize::MAX).is_empty()); + ParachainSystem::open_outbound_hrmp_channel_for_benchmarks(42.into()); prepare_message_proof_from_parachain::< Runtime, BridgeGrandpaWococoInstance, bridge_hub_rococo_config::WithBridgeHubWococoMessageBridge, - >(params) + >(params, X2(GlobalConsensus(Rococo), Parachain(42))) } fn prepare_message_delivery_proof( @@ -1010,6 +1013,11 @@ impl_runtime_apis! { bridge_hub_rococo_config::WithBridgeHubWococoMessageBridge, >(params) } + + fn is_message_successfully_dispatched(_nonce: bp_messages::MessageNonce) -> bool { + use cumulus_primitives_core::XcmpMessageSource; + !XcmpQueue::take_outbound_messages(usize::MAX).is_empty() + } } impl BridgeMessagesConfig for Runtime { @@ -1030,11 +1038,14 @@ impl_runtime_apis! { fn prepare_message_proof( params: MessageProofParams, ) -> (bridge_hub_wococo_config::FromRococoBridgeHubMessagesProof, Weight) { + use cumulus_primitives_core::XcmpMessageSource; + assert!(XcmpQueue::take_outbound_messages(usize::MAX).is_empty()); + ParachainSystem::open_outbound_hrmp_channel_for_benchmarks(42.into()); prepare_message_proof_from_parachain::< Runtime, BridgeGrandpaRococoInstance, bridge_hub_wococo_config::WithBridgeHubRococoMessageBridge, - >(params) + >(params, X2(GlobalConsensus(Wococo), Parachain(42))) } fn prepare_message_delivery_proof( @@ -1046,6 +1057,11 @@ impl_runtime_apis! { bridge_hub_wococo_config::WithBridgeHubRococoMessageBridge, >(params) } + + fn is_message_successfully_dispatched(_nonce: bp_messages::MessageNonce) -> bool { + use cumulus_primitives_core::XcmpMessageSource; + !XcmpQueue::take_outbound_messages(usize::MAX).is_empty() + } } use bridge_runtime_common::parachains_benchmarking::prepare_parachain_heads_proof; diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_messages_bridge_messages_bench_runtime_with_bridge_hub_rococo_messages_instance.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_messages_bridge_messages_bench_runtime_with_bridge_hub_rococo_messages_instance.rs index 14f7e85227b..7f61b0d6a11 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_messages_bridge_messages_bench_runtime_with_bridge_hub_rococo_messages_instance.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_messages_bridge_messages_bench_runtime_with_bridge_hub_rococo_messages_instance.rs @@ -17,25 +17,24 @@ //! Autogenerated weights for `pallet_bridge_messages` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-15, STEPS: `50`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bkontur-ThinkPad-P14s-Gen-2i`, CPU: `11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz` +//! HOSTNAME: `covid`, CPU: `11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bridge-hub-rococo-dev"), DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot-parachain +// target/debug/polkadot-parachain // benchmark // pallet // --steps=50 -// --repeat=2 +// --repeat=20 // --extrinsic=* // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --json-file=./bench.json -// --header=./file_header.txt -// --chain=bridge-hub-rococo-dev // --pallet=pallet_bridge_messages +// --chain=bridge-hub-rococo-dev +// --header=./file_header.txt // --output=./parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights #![cfg_attr(rustfmt, rustfmt_skip)] @@ -58,10 +57,10 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn receive_single_message_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `430` + // Measured: `367` // Estimated: `57797` - // Minimum execution time: 43_647_000 picoseconds. - Weight::from_parts(78_914_000, 0) + // Minimum execution time: 1_052_304_000 picoseconds. + Weight::from_parts(1_067_318_000, 0) .saturating_add(Weight::from_parts(0, 57797)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) @@ -76,10 +75,10 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn receive_two_messages_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `430` + // Measured: `367` // Estimated: `57797` - // Minimum execution time: 62_322_000 picoseconds. - Weight::from_parts(75_283_000, 0) + // Minimum execution time: 1_358_159_000 picoseconds. + Weight::from_parts(1_371_112_000, 0) .saturating_add(Weight::from_parts(0, 57797)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) @@ -94,10 +93,10 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn receive_single_message_proof_with_outbound_lane_state() -> Weight { // Proof Size summary in bytes: - // Measured: `430` + // Measured: `367` // Estimated: `57797` - // Minimum execution time: 47_917_000 picoseconds. - Weight::from_parts(53_246_000, 0) + // Minimum execution time: 1_248_139_000 picoseconds. + Weight::from_parts(1_262_958_000, 0) .saturating_add(Weight::from_parts(0, 57797)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) @@ -110,10 +109,10 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: BridgeRococoMessages InboundLanes (max_values: None, max_size: Some(49180), added: 51655, mode: MaxEncodedLen) fn receive_single_message_proof_1_kb() -> Weight { // Proof Size summary in bytes: - // Measured: `398` + // Measured: `335` // Estimated: `56308` - // Minimum execution time: 42_265_000 picoseconds. - Weight::from_parts(50_221_000, 0) + // Minimum execution time: 1_006_936_000 picoseconds. + Weight::from_parts(1_017_299_000, 0) .saturating_add(Weight::from_parts(0, 56308)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -126,10 +125,10 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: BridgeRococoMessages InboundLanes (max_values: None, max_size: Some(49180), added: 51655, mode: MaxEncodedLen) fn receive_single_message_proof_16_kb() -> Weight { // Proof Size summary in bytes: - // Measured: `398` + // Measured: `335` // Estimated: `56308` - // Minimum execution time: 70_236_000 picoseconds. - Weight::from_parts(107_444_000, 0) + // Minimum execution time: 1_734_842_000 picoseconds. + Weight::from_parts(1_750_451_000, 0) .saturating_add(Weight::from_parts(0, 56308)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -146,11 +145,11 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: - // Measured: `370` - // Estimated: `12565` - // Minimum execution time: 34_072_000 picoseconds. - Weight::from_parts(54_240_000, 0) - .saturating_add(Weight::from_parts(0, 12565)) + // Measured: `339` + // Estimated: `12534` + // Minimum execution time: 983_917_000 picoseconds. + Weight::from_parts(991_532_000, 0) + .saturating_add(Weight::from_parts(0, 12534)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -166,11 +165,11 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: - // Measured: `370` - // Estimated: `12565` - // Minimum execution time: 34_013_000 picoseconds. - Weight::from_parts(50_732_000, 0) - .saturating_add(Weight::from_parts(0, 12565)) + // Measured: `339` + // Estimated: `12534` + // Minimum execution time: 983_370_000 picoseconds. + Weight::from_parts(992_178_000, 0) + .saturating_add(Weight::from_parts(0, 12534)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -186,12 +185,46 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: - // Measured: `370` - // Estimated: `15113` - // Minimum execution time: 36_242_000 picoseconds. - Weight::from_parts(57_344_000, 0) - .saturating_add(Weight::from_parts(0, 15113)) + // Measured: `339` + // Estimated: `15082` + // Minimum execution time: 1_118_509_000 picoseconds. + Weight::from_parts(1_136_181_000, 0) + .saturating_add(Weight::from_parts(0, 15082)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) } + /// Storage: BridgeRococoMessages PalletOperatingMode (r:1 w:0) + /// Proof: BridgeRococoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// Storage: BridgeRococoParachain ImportedParaHeads (r:1 w:0) + /// Proof: BridgeRococoParachain ImportedParaHeads (max_values: Some(64), max_size: Some(196), added: 1186, mode: MaxEncodedLen) + /// Storage: BridgeRococoMessages InboundLanes (r:1 w:1) + /// Proof: BridgeRococoMessages InboundLanes (max_values: None, max_size: Some(49180), added: 51655, 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 RelevantMessagingState (r:1 w:0) + /// Proof Skipped: ParachainSystem RelevantMessagingState (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: XcmpQueue OutboundXcmpStatus (r:1 w:1) + /// Proof Skipped: XcmpQueue OutboundXcmpStatus (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: XcmpQueue OutboundXcmpMessages (r:0 w:1) + /// Proof Skipped: XcmpQueue OutboundXcmpMessages (max_values: None, max_size: None, mode: Measured) + /// The range of component `i` is `[128, 2048]`. + /// The range of component `i` is `[128, 2048]`. + fn receive_single_message_proof_with_dispatch(i: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `635` + // Estimated: `71012` + // Minimum execution time: 1_887_056_000 picoseconds. + Weight::from_parts(1_896_414_726, 0) + .saturating_add(Weight::from_parts(0, 71012)) + // Standard Error: 2_462 + .saturating_add(Weight::from_parts(557_738, 0).saturating_mul(i.into())) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(4)) + } } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_messages_bridge_messages_bench_runtime_with_bridge_hub_wococo_messages_instance.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_messages_bridge_messages_bench_runtime_with_bridge_hub_wococo_messages_instance.rs index 23d74f6feb7..811e483a779 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_messages_bridge_messages_bench_runtime_with_bridge_hub_wococo_messages_instance.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_messages_bridge_messages_bench_runtime_with_bridge_hub_wococo_messages_instance.rs @@ -17,25 +17,24 @@ //! Autogenerated weights for `pallet_bridge_messages` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-15, STEPS: `50`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bkontur-ThinkPad-P14s-Gen-2i`, CPU: `11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz` +//! HOSTNAME: `covid`, CPU: `11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bridge-hub-rococo-dev"), DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot-parachain +// target/debug/polkadot-parachain // benchmark // pallet // --steps=50 -// --repeat=2 +// --repeat=20 // --extrinsic=* // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --json-file=./bench.json -// --header=./file_header.txt -// --chain=bridge-hub-rococo-dev // --pallet=pallet_bridge_messages +// --chain=bridge-hub-rococo-dev +// --header=./file_header.txt // --output=./parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights #![cfg_attr(rustfmt, rustfmt_skip)] @@ -58,10 +57,10 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn receive_single_message_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `467` + // Measured: `404` // Estimated: `57797` - // Minimum execution time: 46_035_000 picoseconds. - Weight::from_parts(87_082_000, 0) + // Minimum execution time: 1_063_700_000 picoseconds. + Weight::from_parts(1_073_859_000, 0) .saturating_add(Weight::from_parts(0, 57797)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) @@ -76,10 +75,10 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn receive_two_messages_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `467` + // Measured: `404` // Estimated: `57797` - // Minimum execution time: 69_379_000 picoseconds. - Weight::from_parts(80_326_000, 0) + // Minimum execution time: 1_363_828_000 picoseconds. + Weight::from_parts(1_383_808_000, 0) .saturating_add(Weight::from_parts(0, 57797)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) @@ -94,10 +93,10 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) fn receive_single_message_proof_with_outbound_lane_state() -> Weight { // Proof Size summary in bytes: - // Measured: `467` + // Measured: `404` // Estimated: `57797` - // Minimum execution time: 51_877_000 picoseconds. - Weight::from_parts(61_053_000, 0) + // Minimum execution time: 1_258_314_000 picoseconds. + Weight::from_parts(1_276_600_000, 0) .saturating_add(Weight::from_parts(0, 57797)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) @@ -110,10 +109,10 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: BridgeWococoMessages InboundLanes (max_values: None, max_size: Some(49180), added: 51655, mode: MaxEncodedLen) fn receive_single_message_proof_1_kb() -> Weight { // Proof Size summary in bytes: - // Measured: `435` + // Measured: `372` // Estimated: `56308` - // Minimum execution time: 44_882_000 picoseconds. - Weight::from_parts(53_124_000, 0) + // Minimum execution time: 1_019_420_000 picoseconds. + Weight::from_parts(1_031_056_000, 0) .saturating_add(Weight::from_parts(0, 56308)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -126,10 +125,10 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: BridgeWococoMessages InboundLanes (max_values: None, max_size: Some(49180), added: 51655, mode: MaxEncodedLen) fn receive_single_message_proof_16_kb() -> Weight { // Proof Size summary in bytes: - // Measured: `435` + // Measured: `372` // Estimated: `56308` - // Minimum execution time: 74_426_000 picoseconds. - Weight::from_parts(111_901_000, 0) + // Minimum execution time: 1_745_271_000 picoseconds. + Weight::from_parts(1_759_460_000, 0) .saturating_add(Weight::from_parts(0, 56308)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -146,11 +145,11 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: - // Measured: `407` - // Estimated: `12602` - // Minimum execution time: 35_466_000 picoseconds. - Weight::from_parts(59_081_000, 0) - .saturating_add(Weight::from_parts(0, 12602)) + // Measured: `376` + // Estimated: `12571` + // Minimum execution time: 993_132_000 picoseconds. + Weight::from_parts(1_005_111_000, 0) + .saturating_add(Weight::from_parts(0, 12571)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -166,11 +165,11 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: - // Measured: `407` - // Estimated: `12602` - // Minimum execution time: 35_889_000 picoseconds. - Weight::from_parts(48_281_000, 0) - .saturating_add(Weight::from_parts(0, 12602)) + // Measured: `376` + // Estimated: `12571` + // Minimum execution time: 995_201_000 picoseconds. + Weight::from_parts(1_003_630_000, 0) + .saturating_add(Weight::from_parts(0, 12571)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -186,12 +185,46 @@ impl pallet_bridge_messages::WeightInfo for WeightInfo< /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: - // Measured: `407` - // Estimated: `15150` - // Minimum execution time: 37_430_000 picoseconds. - Weight::from_parts(54_994_000, 0) - .saturating_add(Weight::from_parts(0, 15150)) + // Measured: `376` + // Estimated: `15119` + // Minimum execution time: 1_126_518_000 picoseconds. + Weight::from_parts(1_143_524_000, 0) + .saturating_add(Weight::from_parts(0, 15119)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) } + /// Storage: BridgeWococoMessages PalletOperatingMode (r:1 w:0) + /// Proof: BridgeWococoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// Storage: BridgeWococoParachain ImportedParaHeads (r:1 w:0) + /// Proof: BridgeWococoParachain ImportedParaHeads (max_values: Some(64), max_size: Some(196), added: 1186, mode: MaxEncodedLen) + /// Storage: BridgeWococoMessages InboundLanes (r:1 w:1) + /// Proof: BridgeWococoMessages InboundLanes (max_values: None, max_size: Some(49180), added: 51655, 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 RelevantMessagingState (r:1 w:0) + /// Proof Skipped: ParachainSystem RelevantMessagingState (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: XcmpQueue OutboundXcmpStatus (r:1 w:1) + /// Proof Skipped: XcmpQueue OutboundXcmpStatus (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: XcmpQueue OutboundXcmpMessages (r:0 w:1) + /// Proof Skipped: XcmpQueue OutboundXcmpMessages (max_values: None, max_size: None, mode: Measured) + /// The range of component `i` is `[128, 2048]`. + /// The range of component `i` is `[128, 2048]`. + fn receive_single_message_proof_with_dispatch(i: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `672` + // Estimated: `71234` + // Minimum execution time: 1_893_906_000 picoseconds. + Weight::from_parts(1_907_046_615, 0) + .saturating_add(Weight::from_parts(0, 71234)) + // Standard Error: 2_494 + .saturating_add(Weight::from_parts(561_329, 0).saturating_mul(i.into())) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(4)) + } } diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index bae5aea0a84..571e2075cb8 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -26,7 +26,6 @@ use crate::{ use frame_support::{ match_types, parameter_types, traits::{ConstU32, Contains, Everything, Nothing}, - weights::Weight, }; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; @@ -45,7 +44,6 @@ use xcm_executor::{ XcmExecutor, }; -use crate::weights::RocksDbWeight; use parachains_common::xcm_config::{ ConcreteNativeAssetFrom, DenyReserveTransferToRelayChain, DenyThenTry, }; @@ -264,25 +262,6 @@ pub type XcmRouter = ( XcmpQueue, ); -/// Simple weigher for xcm dispatch: -/// -/// `ParentAsUmp` does `>::append(` means one write -/// `XcmpQueue` does: -/// - `wrap_version` - 1 read -/// - `send_fragment`: -/// - `get_channel_max` - 1 read -/// - `>::get()` - 1 read -/// - `>::mutate(` - 1 write -/// or -/// - `>::insert(` - 1 write -/// - `>::put - 1 write` - 1 write -pub struct XcmRouterWeigher; -impl Get for XcmRouterWeigher { - fn get() -> Weight { - RocksDbWeight::get().reads_writes(1, 2) - } -} - #[cfg(feature = "runtime-benchmarks")] parameter_types! { pub ReachableDest: Option = Some(Parent.into());