From cff071bc2446f4e61dad4dd24f01a2184bc857bf Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 22 Jun 2023 17:30:34 +0300 Subject: [PATCH] Renamings (#2226) * StorageProofSize -> StorageSize * Rename benchmarks * StorageSize -> UnverifiedStorageProofParams * Fix clippy * Fix priority boost --- .../src/messages_benchmarking.rs | 16 +- .../src/parachains_benchmarking.rs | 12 +- bridges/modules/messages/src/benchmarking.rs | 32 +-- bridges/modules/messages/src/proofs.rs | 2 +- .../messages/src/tests/messages_generation.rs | 24 +- bridges/modules/messages/src/tests/mock.rs | 16 +- bridges/modules/messages/src/weights.rs | 212 +++++++++--------- bridges/modules/messages/src/weights_ext.rs | 8 +- .../modules/parachains/src/benchmarking.rs | 10 +- bridges/modules/parachains/src/mock.rs | 2 +- bridges/modules/parachains/src/weights.rs | 60 +++-- bridges/modules/xcm-bridge-hub/src/mock.rs | 5 +- bridges/primitives/runtime/src/lib.rs | 2 +- .../primitives/runtime/src/storage_proof.rs | 34 +-- 14 files changed, 219 insertions(+), 216 deletions(-) diff --git a/bridges/bin/runtime-common/src/messages_benchmarking.rs b/bridges/bin/runtime-common/src/messages_benchmarking.rs index b339605554da..f39c9ee74894 100644 --- a/bridges/bin/runtime-common/src/messages_benchmarking.rs +++ b/bridges/bin/runtime-common/src/messages_benchmarking.rs @@ -24,7 +24,7 @@ use bp_messages::{ target_chain::FromBridgedChainMessagesProof, MessagePayload, }; use bp_polkadot_core::parachains::ParaHash; -use bp_runtime::{AccountIdOf, Chain, HashOf, Parachain, StorageProofSize}; +use bp_runtime::{AccountIdOf, Chain, HashOf, Parachain}; use codec::Encode; use frame_support::weights::Weight; use pallet_bridge_messages::{ @@ -44,11 +44,7 @@ fn prepare_inbound_message( params: &MessageProofParams, successful_dispatch_message_generator: impl Fn(usize) -> MessagePayload, ) -> MessagePayload { - // 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, - }; + let expected_size = params.proof_params.db_size.unwrap_or(0) as usize; // if we don't need a correct message, then we may just return some random blob if !params.is_successful_dispatch_expected { @@ -93,7 +89,7 @@ where params.lane, params.message_nonces.clone(), params.outbound_lane_data.clone(), - params.size, + params.proof_params, |_| prepare_inbound_message(¶ms, &message_generator), encode_all_messages, encode_lane_data, @@ -140,7 +136,7 @@ where params.lane, params.message_nonces.clone(), params.outbound_lane_data.clone(), - params.size, + params.proof_params, |_| prepare_inbound_message(¶ms, &message_generator), encode_all_messages, encode_lane_data, @@ -186,7 +182,7 @@ where let (state_root, storage_proof) = prepare_message_delivery_storage_proof::< BridgedChainOf, ThisChainOf, - >(params.lane, params.inbound_lane_data, params.size); + >(params.lane, params.inbound_lane_data, params.proof_params); // update runtime storage let (_, bridged_header_hash) = insert_header_to_grandpa_pallet::(state_root); @@ -217,7 +213,7 @@ where let (state_root, storage_proof) = prepare_message_delivery_storage_proof::< BridgedChainOf, ThisChainOf, - >(params.lane, params.inbound_lane_data, params.size); + >(params.lane, params.inbound_lane_data, params.proof_params); // update runtime storage let (_, bridged_header_hash) = diff --git a/bridges/bin/runtime-common/src/parachains_benchmarking.rs b/bridges/bin/runtime-common/src/parachains_benchmarking.rs index 045653551706..e64b6fc22392 100644 --- a/bridges/bin/runtime-common/src/parachains_benchmarking.rs +++ b/bridges/bin/runtime-common/src/parachains_benchmarking.rs @@ -22,7 +22,7 @@ use crate::messages_benchmarking::insert_header_to_grandpa_pallet; use bp_parachains::parachain_head_storage_key_at_source; use bp_polkadot_core::parachains::{ParaHash, ParaHead, ParaHeadsProof, ParaId}; -use bp_runtime::{grow_storage_value, Chain, StorageProofSize, UnverifiedStorageProof}; +use bp_runtime::{grow_storage_value, Chain, UnverifiedStorageProof, UnverifiedStorageProofParams}; use codec::Encode; use frame_support::{sp_runtime::StateVersion, traits::Get}; use pallet_bridge_grandpa::BridgedChain; @@ -37,7 +37,7 @@ use sp_trie::{LayoutV0, LayoutV1, MemoryDB, TrieConfiguration, TrieDBMutBuilder, pub fn prepare_parachain_heads_proof( parachains: &[ParaId], parachain_head_size: u32, - size: StorageProofSize, + proof_params: UnverifiedStorageProofParams, ) -> (RelayBlockNumber, RelayBlockHash, ParaHeadsProof, Vec<(ParaId, ParaHash)>) where R: pallet_bridge_parachains::Config @@ -50,12 +50,12 @@ where StateVersion::V0 => do_prepare_parachain_heads_proof::>( parachains, parachain_head_size, - size, + proof_params, ), StateVersion::V1 => do_prepare_parachain_heads_proof::>( parachains, parachain_head_size, - size, + proof_params, ), } } @@ -63,7 +63,7 @@ where fn do_prepare_parachain_heads_proof( parachains: &[ParaId], parachain_head_size: u32, - size: StorageProofSize, + proof_params: UnverifiedStorageProofParams, ) -> (RelayBlockNumber, RelayBlockHash, ParaHeadsProof, Vec<(ParaId, ParaHash)>) where R: pallet_bridge_parachains::Config @@ -88,7 +88,7 @@ where let storage_key = parachain_head_storage_key_at_source(R::ParasPalletName::get(), *parachain); let leaf_data = if i == 0 { - grow_storage_value(parachain_head.encode(), size) + grow_storage_value(parachain_head.encode(), &proof_params) } else { parachain_head.encode() }; diff --git a/bridges/modules/messages/src/benchmarking.rs b/bridges/modules/messages/src/benchmarking.rs index 14dcbd7be4d6..fec878f1fc74 100644 --- a/bridges/modules/messages/src/benchmarking.rs +++ b/bridges/modules/messages/src/benchmarking.rs @@ -29,7 +29,7 @@ use bp_messages::{ InboundLaneData, LaneId, LaneState, MessageNonce, OutboundLaneData, UnrewardedRelayer, UnrewardedRelayersState, }; -use bp_runtime::{AccountIdOf, HashOf, StorageProofSize}; +use bp_runtime::{AccountIdOf, HashOf, UnverifiedStorageProofParams}; use codec::Decode; use frame_benchmarking::{account, v2::*}; use frame_support::weights::Weight; @@ -57,7 +57,7 @@ pub struct MessageProofParams { /// return `true` from the `is_message_successfully_dispatched`. pub is_successful_dispatch_expected: bool, /// Proof size requirements. - pub size: StorageProofSize, + pub proof_params: UnverifiedStorageProofParams, } /// Benchmark-specific message delivery proof parameters. @@ -68,7 +68,7 @@ pub struct MessageDeliveryProofParams { /// The proof needs to include this inbound lane data. pub inbound_lane_data: InboundLaneData, /// Proof size requirements. - pub size: StorageProofSize, + pub proof_params: UnverifiedStorageProofParams, } /// Trait that must be implemented by runtime. @@ -215,7 +215,9 @@ mod benchmarks { message_nonces: setup.nonces(), outbound_lane_data: None, is_successful_dispatch_expected: false, - size: StorageProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH), + proof_params: UnverifiedStorageProofParams::from_db_size( + EXPECTED_DEFAULT_MESSAGE_LENGTH, + ), }); #[extrinsic_call] @@ -246,7 +248,9 @@ mod benchmarks { message_nonces: setup.nonces(), outbound_lane_data: None, is_successful_dispatch_expected: false, - size: StorageProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH), + proof_params: UnverifiedStorageProofParams::from_db_size( + EXPECTED_DEFAULT_MESSAGE_LENGTH, + ), }); #[extrinsic_call] @@ -287,7 +291,9 @@ mod benchmarks { latest_generated_nonce: setup.last_nonce(), }), is_successful_dispatch_expected: false, - size: StorageProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH), + proof_params: UnverifiedStorageProofParams::from_db_size( + EXPECTED_DEFAULT_MESSAGE_LENGTH, + ), }); #[extrinsic_call] @@ -311,7 +317,7 @@ mod benchmarks { // * message is dispatched (reminder: dispatch weight should be minimal); // * message requires all heavy checks done by dispatcher. #[benchmark] - fn receive_single_message_n_bytes_proof( + fn receive_single_n_bytes_message_proof( /// Proof size in KB n: Linear<1, { 16 * 1024 }>, ) { @@ -322,7 +328,7 @@ mod benchmarks { message_nonces: setup.nonces(), outbound_lane_data: None, is_successful_dispatch_expected: false, - size: StorageProofSize::Minimal(n), + proof_params: UnverifiedStorageProofParams::from_db_size(n), }); #[extrinsic_call] @@ -368,7 +374,7 @@ mod benchmarks { .collect(), last_confirmed_nonce: 0, }, - size: StorageProofSize::Minimal(0), + proof_params: UnverifiedStorageProofParams::default(), }); #[extrinsic_call] @@ -420,7 +426,7 @@ mod benchmarks { .collect(), last_confirmed_nonce: 0, }, - size: StorageProofSize::Minimal(0), + proof_params: UnverifiedStorageProofParams::default(), }); #[extrinsic_call] @@ -477,7 +483,7 @@ mod benchmarks { .collect(), last_confirmed_nonce: 0, }, - size: StorageProofSize::Minimal(0), + proof_params: UnverifiedStorageProofParams::default(), }); #[extrinsic_call] @@ -511,7 +517,7 @@ mod benchmarks { // * message requires all heavy checks done by dispatcher. // #[benchmark(extra)] #[benchmark] - fn receive_single_message_n_bytes_proof_with_dispatch( + fn receive_single_n_bytes_message_proof_with_dispatch( /// Proof size in KB n: Linear<1, { 16 * 1024 }>, ) { @@ -522,7 +528,7 @@ mod benchmarks { message_nonces: setup.nonces(), outbound_lane_data: None, is_successful_dispatch_expected: true, - size: StorageProofSize::Minimal(n), + proof_params: UnverifiedStorageProofParams::from_db_size(n), }); #[extrinsic_call] diff --git a/bridges/modules/messages/src/proofs.rs b/bridges/modules/messages/src/proofs.rs index db80952b6342..14118d7819ae 100644 --- a/bridges/modules/messages/src/proofs.rs +++ b/bridges/modules/messages/src/proofs.rs @@ -187,7 +187,7 @@ mod tests { test_lane_id(), 1..=nonces_end, outbound_lane_data, - bp_runtime::StorageProofSize::Minimal(0), + bp_runtime::UnverifiedStorageProofParams::default(), generate_dummy_message, encode_message, encode_outbound_lane_data, diff --git a/bridges/modules/messages/src/tests/messages_generation.rs b/bridges/modules/messages/src/tests/messages_generation.rs index 56df19cf8809..5e078e262e0e 100644 --- a/bridges/modules/messages/src/tests/messages_generation.rs +++ b/bridges/modules/messages/src/tests/messages_generation.rs @@ -21,8 +21,8 @@ use bp_messages::{ MessagePayload, OutboundLaneData, }; use bp_runtime::{ - grow_storage_value, AccountIdOf, Chain, HashOf, HasherOf, RangeInclusiveExt, StorageProofSize, - UnverifiedStorageProof, + grow_storage_value, AccountIdOf, Chain, HashOf, HasherOf, RangeInclusiveExt, + UnverifiedStorageProof, UnverifiedStorageProofParams, }; use codec::Encode; use frame_support::sp_runtime::StateVersion; @@ -52,7 +52,7 @@ pub fn prepare_messages_storage_proof, outbound_lane_data: Option, - size: StorageProofSize, + proof_params: UnverifiedStorageProofParams, generate_message: impl Fn(MessageNonce) -> MessagePayload, encode_message: impl Fn(MessageNonce, &MessagePayload) -> Option>, encode_outbound_lane_data: impl Fn(&OutboundLaneData) -> Vec, @@ -71,7 +71,7 @@ where lane, message_nonces, outbound_lane_data, - size, + proof_params, generate_message, encode_message, encode_outbound_lane_data, @@ -86,7 +86,7 @@ where lane, message_nonces, outbound_lane_data, - size, + proof_params, generate_message, encode_message, encode_outbound_lane_data, @@ -100,7 +100,7 @@ where pub fn prepare_message_delivery_storage_proof( lane: LaneId, inbound_lane_data: InboundLaneData>, - size: StorageProofSize, + proof_params: UnverifiedStorageProofParams, ) -> (HashOf, UnverifiedStorageProof) where HashOf: Copy + Default, @@ -110,12 +110,12 @@ where BridgedChain, ThisChain, LayoutV0>, - >(lane, inbound_lane_data, size), + >(lane, inbound_lane_data, proof_params), StateVersion::V1 => do_prepare_message_delivery_storage_proof::< BridgedChain, ThisChain, LayoutV1>, - >(lane, inbound_lane_data, size), + >(lane, inbound_lane_data, proof_params), } } @@ -127,7 +127,7 @@ fn do_prepare_messages_storage_proof, outbound_lane_data: Option, - size: StorageProofSize, + proof_params: UnverifiedStorageProofParams, generate_message: impl Fn(MessageNonce) -> MessagePayload, encode_message: impl Fn(MessageNonce, &MessagePayload) -> Option>, encode_outbound_lane_data: impl Fn(&OutboundLaneData) -> Vec, @@ -152,7 +152,7 @@ where let message_payload = match encode_message(nonce, &generate_message(nonce)) { Some(message_payload) => if i == 0 { - grow_storage_value(message_payload, size) + grow_storage_value(message_payload, &proof_params) } else { message_payload }, @@ -212,7 +212,7 @@ where fn do_prepare_message_delivery_storage_proof( lane: LaneId, inbound_lane_data: InboundLaneData>, - size: StorageProofSize, + proof_params: UnverifiedStorageProofParams, ) -> (HashOf, UnverifiedStorageProof) where L: TrieConfiguration>, @@ -225,7 +225,7 @@ where let mut mdb = MemoryDB::default(); { let mut trie = TrieDBMutBuilder::::new(&mut mdb, &mut root).build(); - let inbound_lane_data = grow_storage_value(inbound_lane_data.encode(), size); + let inbound_lane_data = grow_storage_value(inbound_lane_data.encode(), &proof_params); trie.insert(&storage_key, &inbound_lane_data) .map_err(|_| "TrieMut::insert has failed") .expect("TrieMut::insert should not fail in benchmarks"); diff --git a/bridges/modules/messages/src/tests/mock.rs b/bridges/modules/messages/src/tests/mock.rs index 14f7943434f5..38e5df68bdc0 100644 --- a/bridges/modules/messages/src/tests/mock.rs +++ b/bridges/modules/messages/src/tests/mock.rs @@ -38,7 +38,9 @@ use bp_messages::{ ChainWithMessages, DeliveredMessages, InboundLaneData, LaneId, LaneState, Message, MessageKey, MessageNonce, OutboundLaneData, UnrewardedRelayer, UnrewardedRelayersState, }; -use bp_runtime::{messages::MessageDispatchResult, Chain, ChainId, Size, StorageProofSize}; +use bp_runtime::{ + messages::MessageDispatchResult, Chain, ChainId, Size, UnverifiedStorageProofParams, +}; use codec::{Decode, Encode}; use frame_support::{ derive_impl, parameter_types, @@ -488,7 +490,7 @@ pub fn prepare_messages_proof( lane, nonces_start..=nonces_end, outbound_lane_data, - StorageProofSize::Minimal(0), + UnverifiedStorageProofParams::default(), |nonce| messages[(nonce - nonces_start) as usize].payload.clone(), encode_all_messages, encode_lane_data, @@ -522,10 +524,12 @@ pub fn prepare_messages_delivery_proof( inbound_lane_data: InboundLaneData, ) -> FromBridgedChainMessagesDeliveryProof { // first - let's generate storage proof - let (storage_root, storage_proof) = prepare_message_delivery_storage_proof::< - BridgedChain, - ThisChain, - >(lane, inbound_lane_data, StorageProofSize::Minimal(0)); + let (storage_root, storage_proof) = + prepare_message_delivery_storage_proof::( + lane, + inbound_lane_data, + UnverifiedStorageProofParams::default(), + ); // let's now insert bridged chain header into the storage let bridged_header_hash = Default::default(); diff --git a/bridges/modules/messages/src/weights.rs b/bridges/modules/messages/src/weights.rs index 6c77fe19d9c4..72a06599b165 100644 --- a/bridges/modules/messages/src/weights.rs +++ b/bridges/modules/messages/src/weights.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for pallet_bridge_messages //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-06-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-06-22, 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` +//! HOSTNAME: `serban-ROG-Zephyrus`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -53,11 +53,11 @@ pub trait WeightInfo { fn receive_single_message_proof() -> Weight; fn receive_n_messages_proof(n: u32) -> Weight; fn receive_single_message_proof_with_outbound_lane_state() -> Weight; - fn receive_single_message_n_bytes_proof(n: u32) -> Weight; + fn receive_single_n_bytes_message_proof(n: u32) -> Weight; 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_n_bytes_proof_with_dispatch(n: u32) -> Weight; + fn receive_single_n_bytes_message_proof_with_dispatch(n: u32) -> Weight; } /// Weights for `pallet_bridge_messages` that are generated using one of the Bridge testnets. @@ -81,10 +81,10 @@ impl WeightInfo for BridgeWeight { /// 51655, mode: MaxEncodedLen) fn receive_single_message_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `490` - // Estimated: `52645` - // Minimum execution time: 46_942 nanoseconds. - Weight::from_parts(49_198_000, 52645) + // Measured: `653` + // Estimated: `52673` + // Minimum execution time: 38_724 nanoseconds. + Weight::from_parts(40_650_000, 52673) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -100,20 +100,20 @@ impl WeightInfo for BridgeWeight { /// /// Storage: BridgeRialtoMessages InboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: - /// 51655, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49208), added: + /// 51683, mode: MaxEncodedLen) /// /// The range of component `n` is `[1, 1004]`. /// /// The range of component `n` is `[1, 1004]`. fn receive_n_messages_proof(n: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `490` - // Estimated: `52645` - // Minimum execution time: 47_880 nanoseconds. - Weight::from_parts(49_410_000, 52645) - // Standard Error: 62_811 - .saturating_add(Weight::from_parts(11_128_145, 0).saturating_mul(n.into())) + // Measured: `653` + // Estimated: `52673` + // Minimum execution time: 39_354 nanoseconds. + Weight::from_parts(29_708_543, 52673) + // Standard Error: 1_185 + .saturating_add(Weight::from_parts(7_648_787, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -133,10 +133,10 @@ impl WeightInfo for BridgeWeight { /// 51655, mode: MaxEncodedLen) fn receive_single_message_proof_with_outbound_lane_state() -> Weight { // Proof Size summary in bytes: - // Measured: `490` - // Estimated: `52645` - // Minimum execution time: 56_275 nanoseconds. - Weight::from_parts(58_324_000, 52645) + // Measured: `653` + // Estimated: `52673` + // Minimum execution time: 45_578 nanoseconds. + Weight::from_parts(47_161_000, 52673) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -156,14 +156,14 @@ impl WeightInfo for BridgeWeight { /// 51655, mode: MaxEncodedLen) /// /// The range of component `n` is `[1, 16384]`. - fn receive_single_message_n_bytes_proof(n: u32) -> Weight { + fn receive_single_n_bytes_message_proof(n: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `490` - // Estimated: `52645` - // Minimum execution time: 47_796 nanoseconds. - Weight::from_parts(51_176_451, 52645) + // Measured: `653` + // Estimated: `52673` + // Minimum execution time: 38_702 nanoseconds. + Weight::from_parts(41_040_143, 52673) // Standard Error: 5 - .saturating_add(Weight::from_parts(1_303, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(1_174, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -184,19 +184,19 @@ impl WeightInfo for BridgeWeight { /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(93), added: 2568, /// mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundMessages (r:0 w:1) /// - /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65568), - /// added: 68043, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65596), + /// added: 68071, mode: MaxEncodedLen) fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: - // Measured: `515` - // Estimated: `3530` - // Minimum execution time: 43_987 nanoseconds. - Weight::from_parts(46_149_000, 3530) + // Measured: `701` + // Estimated: `3558` + // Minimum execution time: 37_197 nanoseconds. + Weight::from_parts(38_371_000, 3558) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -217,19 +217,19 @@ impl WeightInfo for BridgeWeight { /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(93), added: 2568, /// mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundMessages (r:0 w:2) /// - /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65568), - /// added: 68043, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65596), + /// added: 68071, mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: - // Measured: `532` - // Estimated: `3530` - // Minimum execution time: 44_871 nanoseconds. - Weight::from_parts(46_068_000, 3530) + // Measured: `701` + // Estimated: `3558` + // Minimum execution time: 38_684 nanoseconds. + Weight::from_parts(39_929_000, 3558) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -250,19 +250,19 @@ impl WeightInfo for BridgeWeight { /// /// Storage: BridgeRelayers RelayerRewards (r:2 w:2) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(93), added: 2568, /// mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundMessages (r:0 w:2) /// - /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65568), - /// added: 68043, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65596), + /// added: 68071, mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: - // Measured: `532` - // Estimated: `6070` - // Minimum execution time: 48_361 nanoseconds. - Weight::from_parts(49_654_000, 6070) + // Measured: `701` + // Estimated: `6126` + // Minimum execution time: 41_363 nanoseconds. + Weight::from_parts(42_621_000, 6126) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -282,14 +282,14 @@ impl WeightInfo for BridgeWeight { /// 51655, mode: MaxEncodedLen) /// /// The range of component `n` is `[1, 16384]`. - fn receive_single_message_n_bytes_proof_with_dispatch(n: u32) -> Weight { + fn receive_single_n_bytes_message_proof_with_dispatch(n: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `490` - // Estimated: `52645` - // Minimum execution time: 47_017 nanoseconds. - Weight::from_parts(48_876_000, 52645) - // Standard Error: 686 - .saturating_add(Weight::from_parts(498_597, 0).saturating_mul(n.into())) + // Measured: `653` + // Estimated: `52673` + // Minimum execution time: 38_925 nanoseconds. + Weight::from_parts(39_617_000, 52673) + // Standard Error: 612 + .saturating_add(Weight::from_parts(372_813, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -313,10 +313,10 @@ impl WeightInfo for () { /// 51655, mode: MaxEncodedLen) fn receive_single_message_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `490` - // Estimated: `52645` - // Minimum execution time: 46_942 nanoseconds. - Weight::from_parts(49_198_000, 52645) + // Measured: `653` + // Estimated: `52673` + // Minimum execution time: 38_724 nanoseconds. + Weight::from_parts(40_650_000, 52673) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -332,20 +332,20 @@ impl WeightInfo for () { /// /// Storage: BridgeRialtoMessages InboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: - /// 51655, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49208), added: + /// 51683, mode: MaxEncodedLen) /// /// The range of component `n` is `[1, 1004]`. /// /// The range of component `n` is `[1, 1004]`. fn receive_n_messages_proof(n: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `490` - // Estimated: `52645` - // Minimum execution time: 47_880 nanoseconds. - Weight::from_parts(49_410_000, 52645) - // Standard Error: 62_811 - .saturating_add(Weight::from_parts(11_128_145, 0).saturating_mul(n.into())) + // Measured: `653` + // Estimated: `52673` + // Minimum execution time: 39_354 nanoseconds. + Weight::from_parts(29_708_543, 52673) + // Standard Error: 1_185 + .saturating_add(Weight::from_parts(7_648_787, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -365,10 +365,10 @@ impl WeightInfo for () { /// 51655, mode: MaxEncodedLen) fn receive_single_message_proof_with_outbound_lane_state() -> Weight { // Proof Size summary in bytes: - // Measured: `490` - // Estimated: `52645` - // Minimum execution time: 56_275 nanoseconds. - Weight::from_parts(58_324_000, 52645) + // Measured: `653` + // Estimated: `52673` + // Minimum execution time: 45_578 nanoseconds. + Weight::from_parts(47_161_000, 52673) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -384,20 +384,20 @@ impl WeightInfo for () { /// /// Storage: BridgeUnknownMessages InboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49180), added: - /// 51655, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages InboundLanes (max_values: None, max_size: Some(49208), added: + /// 51683, mode: MaxEncodedLen) /// /// The range of component `n` is `[1, 16384]`. /// /// The range of component `n` is `[1, 16384]`. - fn receive_single_message_n_bytes_proof(n: u32) -> Weight { + fn receive_single_n_bytes_message_proof(n: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `490` - // Estimated: `52645` - // Minimum execution time: 47_796 nanoseconds. - Weight::from_parts(51_176_451, 52645) + // Measured: `653` + // Estimated: `52673` + // Minimum execution time: 38_702 nanoseconds. + Weight::from_parts(41_040_143, 52673) // Standard Error: 5 - .saturating_add(Weight::from_parts(1_303, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(1_174, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -418,19 +418,19 @@ impl WeightInfo for () { /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(93), added: 2568, /// mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundMessages (r:0 w:1) /// - /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65568), - /// added: 68043, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65596), + /// added: 68071, mode: MaxEncodedLen) fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: - // Measured: `515` - // Estimated: `3530` - // Minimum execution time: 43_987 nanoseconds. - Weight::from_parts(46_149_000, 3530) + // Measured: `701` + // Estimated: `3558` + // Minimum execution time: 37_197 nanoseconds. + Weight::from_parts(38_371_000, 3558) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -451,19 +451,19 @@ impl WeightInfo for () { /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(93), added: 2568, /// mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundMessages (r:0 w:2) /// - /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65568), - /// added: 68043, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65596), + /// added: 68071, mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: - // Measured: `532` - // Estimated: `3530` - // Minimum execution time: 44_871 nanoseconds. - Weight::from_parts(46_068_000, 3530) + // Measured: `701` + // Estimated: `3558` + // Minimum execution time: 38_684 nanoseconds. + Weight::from_parts(39_929_000, 3558) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -484,19 +484,19 @@ impl WeightInfo for () { /// /// Storage: BridgeRelayers RelayerRewards (r:2 w:2) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(93), added: 2568, /// mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundMessages (r:0 w:2) /// - /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65568), - /// added: 68043, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(65596), + /// added: 68071, mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: - // Measured: `532` - // Estimated: `6070` - // Minimum execution time: 48_361 nanoseconds. - Weight::from_parts(49_654_000, 6070) + // Measured: `701` + // Estimated: `6126` + // Minimum execution time: 41_363 nanoseconds. + Weight::from_parts(42_621_000, 6126) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -516,14 +516,14 @@ impl WeightInfo for () { /// 51655, mode: MaxEncodedLen) /// /// The range of component `n` is `[1, 16384]`. - fn receive_single_message_n_bytes_proof_with_dispatch(n: u32) -> Weight { + fn receive_single_n_bytes_message_proof_with_dispatch(n: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `490` - // Estimated: `52645` - // Minimum execution time: 47_017 nanoseconds. - Weight::from_parts(48_876_000, 52645) - // Standard Error: 686 - .saturating_add(Weight::from_parts(498_597, 0).saturating_mul(n.into())) + // Measured: `653` + // Estimated: `52673` + // Minimum execution time: 38_925 nanoseconds. + Weight::from_parts(39_617_000, 52673) + // Standard Error: 612 + .saturating_add(Weight::from_parts(372_813, 0).saturating_mul(n.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 0e0450ed1fb6..7711e212efb0 100644 --- a/bridges/modules/messages/src/weights_ext.rs +++ b/bridges/modules/messages/src/weights_ext.rs @@ -411,8 +411,8 @@ pub trait WeightInfoExt: WeightInfo { /// is less than that cost). fn storage_proof_size_overhead(proof_size: u32) -> Weight { let proof_size_in_bytes = proof_size; - let byte_weight = Self::receive_single_message_n_bytes_proof(2) - - Self::receive_single_message_n_bytes_proof(1); + let byte_weight = Self::receive_single_n_bytes_message_proof(2) - + Self::receive_single_n_bytes_message_proof(1); proof_size_in_bytes * byte_weight } @@ -425,8 +425,8 @@ pub trait WeightInfoExt: WeightInfo { /// details. fn message_dispatch_weight(message_size: u32) -> Weight { let message_size_in_bytes = message_size; - Self::receive_single_message_n_bytes_proof_with_dispatch(message_size_in_bytes) - .saturating_sub(Self::receive_single_message_n_bytes_proof(message_size_in_bytes)) + Self::receive_single_n_bytes_message_proof_with_dispatch(message_size_in_bytes) + .saturating_sub(Self::receive_single_n_bytes_message_proof(message_size_in_bytes)) } } diff --git a/bridges/modules/parachains/src/benchmarking.rs b/bridges/modules/parachains/src/benchmarking.rs index 27e06a12a1d9..92ece6d688cb 100644 --- a/bridges/modules/parachains/src/benchmarking.rs +++ b/bridges/modules/parachains/src/benchmarking.rs @@ -22,7 +22,7 @@ use crate::{ }; use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId}; -use bp_runtime::StorageProofSize; +use bp_runtime::UnverifiedStorageProofParams; use frame_benchmarking::{account, benchmarks_instance_pallet}; use frame_system::RawOrigin; use sp_std::prelude::*; @@ -38,7 +38,7 @@ pub trait Config: crate::Config { fn prepare_parachain_heads_proof( parachains: &[ParaId], parachain_head_size: u32, - proof_size: StorageProofSize, + proof_params: UnverifiedStorageProofParams, ) -> (RelayBlockNumber, RelayBlockHash, ParaHeadsProof, Vec<(ParaId, ParaHash)>); } @@ -68,7 +68,7 @@ benchmarks_instance_pallet! { let (relay_block_number, relay_block_hash, parachain_heads_proof, parachains_heads) = T::prepare_parachain_heads_proof( ¶chains, DEFAULT_PARACHAIN_HEAD_SIZE, - StorageProofSize::Minimal(0), + UnverifiedStorageProofParams::default(), ); let at_relay_block = (relay_block_number, relay_block_hash); }: submit_parachain_heads(RawOrigin::Signed(sender), at_relay_block, parachains_heads, parachain_heads_proof) @@ -85,7 +85,7 @@ benchmarks_instance_pallet! { let (relay_block_number, relay_block_hash, parachain_heads_proof, parachains_heads) = T::prepare_parachain_heads_proof( ¶chains, DEFAULT_PARACHAIN_HEAD_SIZE, - StorageProofSize::HasLargeLeaf(1024), + UnverifiedStorageProofParams::from_db_size(1024), ); let at_relay_block = (relay_block_number, relay_block_hash); }: submit_parachain_heads(RawOrigin::Signed(sender), at_relay_block, parachains_heads, parachain_heads_proof) @@ -102,7 +102,7 @@ benchmarks_instance_pallet! { let (relay_block_number, relay_block_hash, parachain_heads_proof, parachains_heads) = T::prepare_parachain_heads_proof( ¶chains, DEFAULT_PARACHAIN_HEAD_SIZE, - StorageProofSize::HasLargeLeaf(16 * 1024), + UnverifiedStorageProofParams::from_db_size(16 * 1024), ); let at_relay_block = (relay_block_number, relay_block_hash); }: submit_parachain_heads(RawOrigin::Signed(sender), at_relay_block, parachains_heads, parachain_heads_proof) diff --git a/bridges/modules/parachains/src/mock.rs b/bridges/modules/parachains/src/mock.rs index d5fdf37e36fd..746b65c435c3 100644 --- a/bridges/modules/parachains/src/mock.rs +++ b/bridges/modules/parachains/src/mock.rs @@ -230,7 +230,7 @@ impl pallet_bridge_parachains::benchmarking::Config<()> for TestRuntime { fn prepare_parachain_heads_proof( parachains: &[ParaId], _parachain_head_size: u32, - _proof_size: bp_runtime::StorageProofSize, + _proof_params: bp_runtime::UnverifiedStorageProofParams, ) -> ( crate::RelayBlockNumber, crate::RelayBlockHash, diff --git a/bridges/modules/parachains/src/weights.rs b/bridges/modules/parachains/src/weights.rs index abddc8768947..1f92b7ff763c 100644 --- a/bridges/modules/parachains/src/weights.rs +++ b/bridges/modules/parachains/src/weights.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for pallet_bridge_parachains //! //! 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-06-22, 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` +//! HOSTNAME: `serban-ROG-Zephyrus`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -86,14 +86,12 @@ impl WeightInfo for BridgeWeight { /// Some(196), added: 1681, mode: MaxEncodedLen) /// /// The range of component `p` is `[1, 2]`. - fn submit_parachain_heads_with_n_parachains(p: u32) -> Weight { + fn submit_parachain_heads_with_n_parachains(_p: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `366` - // Estimated: `4648` - // Minimum execution time: 36_701 nanoseconds. - Weight::from_parts(38_597_828, 4648) - // Standard Error: 190_859 - .saturating_add(Weight::from_parts(60_685, 0).saturating_mul(p.into())) + // Measured: `302` + // Estimated: `3038` + // Minimum execution time: 30_211 nanoseconds. + Weight::from_parts(32_633_893, 3038) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -123,10 +121,10 @@ impl WeightInfo for BridgeWeight { /// Some(196), added: 1681, mode: MaxEncodedLen) fn submit_parachain_heads_with_1kb_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `366` - // Estimated: `4648` - // Minimum execution time: 38_189 nanoseconds. - Weight::from_parts(39_252_000, 4648) + // Measured: `302` + // Estimated: `3038` + // Minimum execution time: 30_830 nanoseconds. + Weight::from_parts(31_801_000, 3038) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -156,10 +154,10 @@ impl WeightInfo for BridgeWeight { /// Some(196), added: 1681, mode: MaxEncodedLen) fn submit_parachain_heads_with_16kb_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `366` - // Estimated: `4648` - // Minimum execution time: 62_868 nanoseconds. - Weight::from_parts(63_581_000, 4648) + // Measured: `302` + // Estimated: `3038` + // Minimum execution time: 44_736 nanoseconds. + Weight::from_parts(45_296_000, 3038) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -193,14 +191,12 @@ impl WeightInfo for () { /// Some(196), added: 1681, mode: MaxEncodedLen) /// /// The range of component `p` is `[1, 2]`. - fn submit_parachain_heads_with_n_parachains(p: u32) -> Weight { + fn submit_parachain_heads_with_n_parachains(_p: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `366` - // Estimated: `4648` - // Minimum execution time: 36_701 nanoseconds. - Weight::from_parts(38_597_828, 4648) - // Standard Error: 190_859 - .saturating_add(Weight::from_parts(60_685, 0).saturating_mul(p.into())) + // Measured: `302` + // Estimated: `3038` + // Minimum execution time: 30_211 nanoseconds. + Weight::from_parts(32_633_893, 3038) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -230,10 +226,10 @@ impl WeightInfo for () { /// Some(196), added: 1681, mode: MaxEncodedLen) fn submit_parachain_heads_with_1kb_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `366` - // Estimated: `4648` - // Minimum execution time: 38_189 nanoseconds. - Weight::from_parts(39_252_000, 4648) + // Measured: `302` + // Estimated: `3038` + // Minimum execution time: 30_830 nanoseconds. + Weight::from_parts(31_801_000, 3038) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -263,10 +259,10 @@ impl WeightInfo for () { /// Some(196), added: 1681, mode: MaxEncodedLen) fn submit_parachain_heads_with_16kb_proof() -> Weight { // Proof Size summary in bytes: - // Measured: `366` - // Estimated: `4648` - // Minimum execution time: 62_868 nanoseconds. - Weight::from_parts(63_581_000, 4648) + // Measured: `302` + // Estimated: `3038` + // Minimum execution time: 44_736 nanoseconds. + Weight::from_parts(45_296_000, 3038) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } diff --git a/bridges/modules/xcm-bridge-hub/src/mock.rs b/bridges/modules/xcm-bridge-hub/src/mock.rs index b9af95c27cb6..6f6e9f9f846d 100644 --- a/bridges/modules/xcm-bridge-hub/src/mock.rs +++ b/bridges/modules/xcm-bridge-hub/src/mock.rs @@ -109,7 +109,7 @@ impl pallet_bridge_messages::WeightInfo for TestMessagesWeights { fn receive_single_message_proof_with_outbound_lane_state() -> Weight { Weight::zero() } - fn receive_single_message_n_bytes_proof(_: u32) -> Weight { + fn receive_single_n_bytes_message_proof(_: u32) -> Weight { Weight::zero() } fn receive_delivery_proof_for_single_message() -> Weight { @@ -121,8 +121,7 @@ impl pallet_bridge_messages::WeightInfo for TestMessagesWeights { fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { Weight::zero() } - - fn receive_single_message_n_bytes_proof_with_dispatch(_: u32) -> Weight { + fn receive_single_n_bytes_message_proof_with_dispatch(_: u32) -> Weight { Weight::zero() } } diff --git a/bridges/primitives/runtime/src/lib.rs b/bridges/primitives/runtime/src/lib.rs index 4b5a24b38078..1c7e153dc6a5 100644 --- a/bridges/primitives/runtime/src/lib.rs +++ b/bridges/primitives/runtime/src/lib.rs @@ -41,7 +41,7 @@ pub use chain::{ pub use frame_support::storage::storage_prefix as storage_value_final_key; use num_traits::{CheckedAdd, CheckedSub, One, SaturatingAdd, Zero}; #[cfg(feature = "test-helpers")] -pub use storage_proof::{grow_storage_proof, grow_storage_value, StorageProofSize}; +pub use storage_proof::{grow_storage_proof, grow_storage_value, UnverifiedStorageProofParams}; pub use storage_proof::{StorageProofError, UnverifiedStorageProof, VerifiedStorageProof}; pub use storage_types::BoundedStorageValue; diff --git a/bridges/primitives/runtime/src/storage_proof.rs b/bridges/primitives/runtime/src/storage_proof.rs index 4ca38abf209e..f1505e692ef5 100644 --- a/bridges/primitives/runtime/src/storage_proof.rs +++ b/bridges/primitives/runtime/src/storage_proof.rs @@ -254,29 +254,31 @@ impl VerifiedStorageProof { } } -/// Storage proof size requirements. +/// Storage values size requirements. /// /// This is currently used by benchmarks when generating storage proofs. #[cfg(feature = "test-helpers")] -#[derive(Clone, Copy, Debug)] -pub enum StorageProofSize { - /// The storage proof is expected to be minimal. If value size may be changed, then it is - /// expected to have given size. - Minimal(u32), - /// The storage proof is expected to have at least given size and grow by increasing value that - /// is stored in the trie. - HasLargeLeaf(u32), +#[derive(Clone, Copy, Debug, Default)] +pub struct UnverifiedStorageProofParams { + #[allow(missing_docs)] + pub db_size: Option, +} + +#[cfg(feature = "test-helpers")] +impl UnverifiedStorageProofParams { + #[allow(missing_docs)] + pub fn from_db_size(db_size: u32) -> Self { + Self { db_size: Some(db_size) } + } } /// Add extra data to the storage value so that it'll be of given size. #[cfg(feature = "test-helpers")] -pub fn grow_storage_value(mut value: Vec, size: StorageProofSize) -> Vec { - match size { - StorageProofSize::Minimal(_) => (), - StorageProofSize::HasLargeLeaf(size) if size as usize > value.len() => { - value.extend(sp_std::iter::repeat(42u8).take(size as usize - value.len())); - }, - StorageProofSize::HasLargeLeaf(_) => (), +pub fn grow_storage_value(mut value: Vec, params: &UnverifiedStorageProofParams) -> Vec { + if let Some(db_size) = params.db_size { + if db_size as usize > value.len() { + value.extend(sp_std::iter::repeat(42u8).take(db_size as usize - value.len())); + } } value }