From f3bdab68422f1aaae1d64cb3a756e2caade3c75f Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Wed, 1 Mar 2023 15:42:04 +0300 Subject: [PATCH] Fix benchmarks (#1919) * fixed benchmarks broken by rejecting storage proofs with excessive trie nodes and justifications with extra prevotes * update weights * fmt * accidental paste * revert changes to millau runtime (separate PR) * revert comment change --- .../src/messages_benchmarking.rs | 7 +- .../runtime-common/src/messages_generation.rs | 52 ++++------ .../src/parachains_benchmarking.rs | 13 ++- bridges/modules/grandpa/src/benchmarking.rs | 13 ++- bridges/modules/grandpa/src/weights.rs | 34 +++---- bridges/modules/messages/src/benchmarking.rs | 4 +- bridges/modules/messages/src/weights.rs | 90 +++++++++--------- .../modules/parachains/src/benchmarking.rs | 4 +- bridges/modules/parachains/src/weights.rs | 94 +++++++++---------- bridges/modules/relayers/src/weights.rs | 12 +-- .../primitives/runtime/src/storage_proof.rs | 9 +- 11 files changed, 159 insertions(+), 173 deletions(-) diff --git a/bridges/bin/runtime-common/src/messages_benchmarking.rs b/bridges/bin/runtime-common/src/messages_benchmarking.rs index 1588c77633e23..028172e7ab42f 100644 --- a/bridges/bin/runtime-common/src/messages_benchmarking.rs +++ b/bridges/bin/runtime-common/src/messages_benchmarking.rs @@ -25,7 +25,7 @@ use crate::{ AccountIdOf, BridgedChain, HashOf, HasherOf, MessageBridge, ThisChain, }, messages_generation::{ - encode_all_messages, encode_lane_data, grow_trie, prepare_messages_storage_proof, + encode_all_messages, encode_lane_data, grow_trie_leaf_value, prepare_messages_storage_proof, }, }; @@ -204,11 +204,12 @@ where { let mut trie = TrieDBMutBuilderV1::>>::new(&mut mdb, &mut root).build(); - trie.insert(&storage_key, ¶ms.inbound_lane_data.encode()) + let inbound_lane_data = + grow_trie_leaf_value(params.inbound_lane_data.encode(), params.size); + trie.insert(&storage_key, &inbound_lane_data) .map_err(|_| "TrieMut::insert has failed") .expect("TrieMut::insert should not fail in benchmarks"); } - root = grow_trie(root, &mut mdb, params.size); // generate storage proof to be delivered to This chain let storage_proof = record_all_trie_keys::>>, _>(&mdb, &root) diff --git a/bridges/bin/runtime-common/src/messages_generation.rs b/bridges/bin/runtime-common/src/messages_generation.rs index aec97c2280047..29a869a5c871a 100644 --- a/bridges/bin/runtime-common/src/messages_generation.rs +++ b/bridges/bin/runtime-common/src/messages_generation.rs @@ -25,7 +25,6 @@ use bp_messages::{ }; use bp_runtime::{record_all_trie_keys, RawStorageProof, StorageProofSize}; use codec::Encode; -use sp_core::Hasher; use sp_std::{ops::RangeInclusive, prelude::*}; use sp_trie::{trie_types::TrieDBMutBuilderV1, LayoutV1, MemoryDB, TrieMut}; @@ -65,10 +64,15 @@ where TrieDBMutBuilderV1::>>::new(&mut mdb, &mut root).build(); // insert messages - for nonce in message_nonces { + for (i, nonce) in message_nonces.into_iter().enumerate() { let message_key = MessageKey { lane_id: lane, nonce }; let message_payload = match encode_message(nonce, &message_payload) { - Some(message_payload) => message_payload, + Some(message_payload) => + if i == 0 { + grow_trie_leaf_value(message_payload, size) + } else { + message_payload + }, None => continue, }; let storage_key = storage_keys::message_key( @@ -94,46 +98,22 @@ where storage_keys.push(storage_key); } } - root = grow_trie(root, &mut mdb, size); // generate storage proof to be delivered to This chain let storage_proof = record_all_trie_keys::>>, _>(&mdb, &root) .map_err(|_| "record_all_trie_keys has failed") .expect("record_all_trie_keys should not fail in benchmarks"); - (root, storage_proof) } -/// Populate trie with dummy keys+values until trie has at least given size. -pub fn grow_trie( - mut root: H::Out, - mdb: &mut MemoryDB, - trie_size: StorageProofSize, -) -> H::Out { - let (iterations, leaf_size, minimal_trie_size) = match trie_size { - StorageProofSize::Minimal(_) => return root, - StorageProofSize::HasLargeLeaf(size) => (1, size, size), - StorageProofSize::HasExtraNodes(size) => (8, 1, size), - }; - - let mut key_index = 0; - loop { - // generate storage proof to be delivered to This chain - let storage_proof = record_all_trie_keys::, _>(mdb, &root) - .map_err(|_| "record_all_trie_keys has failed") - .expect("record_all_trie_keys should not fail in benchmarks"); - let size: usize = storage_proof.iter().map(|n| n.len()).sum(); - if size > minimal_trie_size as _ { - return root - } - - let mut trie = TrieDBMutBuilderV1::::from_existing(mdb, &mut root).build(); - for _ in 0..iterations { - trie.insert(&key_index.encode(), &vec![42u8; leaf_size as _]) - .map_err(|_| "TrieMut::insert has failed") - .expect("TrieMut::insert should not fail in benchmarks"); - key_index += 1; - } - trie.commit(); +/// Add extra data to the trie leaf value so that it'll be of given size. +pub fn grow_trie_leaf_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(_) => (), } + value } diff --git a/bridges/bin/runtime-common/src/parachains_benchmarking.rs b/bridges/bin/runtime-common/src/parachains_benchmarking.rs index e549e4f79b9f3..aad53673c3ad3 100644 --- a/bridges/bin/runtime-common/src/parachains_benchmarking.rs +++ b/bridges/bin/runtime-common/src/parachains_benchmarking.rs @@ -19,7 +19,8 @@ #![cfg(feature = "runtime-benchmarks")] use crate::{ - messages_benchmarking::insert_header_to_grandpa_pallet, messages_generation::grow_trie, + messages_benchmarking::insert_header_to_grandpa_pallet, + messages_generation::grow_trie_leaf_value, }; use bp_parachains::parachain_head_storage_key_at_source; @@ -59,17 +60,21 @@ where TrieDBMutBuilderV1::::new(&mut mdb, &mut state_root).build(); // insert parachain heads - for parachain in parachains { + for (i, parachain) in parachains.into_iter().enumerate() { let storage_key = parachain_head_storage_key_at_source(R::ParasPalletName::get(), *parachain); - trie.insert(&storage_key.0, ¶chain_head.encode()) + let leaf_data = if i == 0 { + grow_trie_leaf_value(parachain_head.encode(), size) + } else { + parachain_head.encode() + }; + trie.insert(&storage_key.0, &leaf_data) .map_err(|_| "TrieMut::insert has failed") .expect("TrieMut::insert should not fail in benchmarks"); storage_keys.push(storage_key); parachain_heads.push((*parachain, parachain_head.hash())) } } - state_root = grow_trie(state_root, &mut mdb, size); // generate heads storage proof let proof = record_all_trie_keys::, _>(&mdb, &state_root) diff --git a/bridges/modules/grandpa/src/benchmarking.rs b/bridges/modules/grandpa/src/benchmarking.rs index 337943bee4edc..f79deb7e7527c 100644 --- a/bridges/modules/grandpa/src/benchmarking.rs +++ b/bridges/modules/grandpa/src/benchmarking.rs @@ -41,6 +41,7 @@ use crate::*; +use bp_header_chain::justification::required_justification_precommits; use bp_runtime::BasicOperatingMode; use bp_test_utils::{ accounts, make_justification_for_header, JustificationGeneratorParams, TEST_GRANDPA_ROUND, @@ -66,13 +67,14 @@ const MAX_VOTE_ANCESTRIES_RANGE_END: u32 = MAX_VOTE_ANCESTRIES_RANGE_BEGIN + MAX_VOTE_ANCESTRIES_RANGE_BEGIN; // the same with validators - if there are too much validators, let's run benchmarks on subrange -fn validator_set_range_end, I: 'static>() -> u32 { +fn precommits_range_end, I: 'static>() -> u32 { let max_bridged_authorities = T::BridgedChain::MAX_AUTHORITIES_COUNT; if max_bridged_authorities > 128 { sp_std::cmp::max(128, max_bridged_authorities / 5) } else { max_bridged_authorities - } + }; + required_justification_precommits(max_bridged_authorities) } /// Prepare header and its justification to submit using `submit_finality_proof`. @@ -80,7 +82,10 @@ fn prepare_benchmark_data, I: 'static>( precommits: u32, ancestors: u32, ) -> (BridgedHeader, GrandpaJustification>) { - let authority_list = accounts(precommits as u16) + // going from precommits to total authorities count + let total_authorities_count = (3 * precommits - 1) / 2; + + let authority_list = accounts(total_authorities_count as u16) .iter() .map(|id| (AuthorityId::from(*id), 1)) .collect::>(); @@ -114,7 +119,7 @@ benchmarks_instance_pallet! { // This is the "gold standard" benchmark for this extrinsic, and it's what should be used to // annotate the weight in the pallet. submit_finality_proof { - let p in 1 .. validator_set_range_end::(); + let p in 1 .. precommits_range_end::(); let v in MAX_VOTE_ANCESTRIES_RANGE_BEGIN..MAX_VOTE_ANCESTRIES_RANGE_END; let caller: T::AccountId = whitelisted_caller(); let (header, justification) = prepare_benchmark_data::(p, v); diff --git a/bridges/modules/grandpa/src/weights.rs b/bridges/modules/grandpa/src/weights.rs index 44b4ebd37fbaf..8896674c0112f 100644 --- a/bridges/modules/grandpa/src/weights.rs +++ b/bridges/modules/grandpa/src/weights.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for pallet_bridge_grandpa //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-01, 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 @@ -93,19 +93,19 @@ impl WeightInfo for BridgeWeight { /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), /// added: 2048, mode: MaxEncodedLen) /// - /// The range of component `p` is `[1, 5]`. + /// The range of component `p` is `[1, 4]`. /// /// The range of component `v` is `[50, 100]`. fn submit_finality_proof(p: u32, v: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `416 + p * (40 ±0)` + // Measured: `394 + p * (60 ±0)` // Estimated: `4745` - // Minimum execution time: 221_703 nanoseconds. - Weight::from_parts(39_358_497, 4745) - // Standard Error: 85_573 - .saturating_add(Weight::from_ref_time(40_593_280).saturating_mul(p.into())) - // Standard Error: 7_808 - .saturating_add(Weight::from_ref_time(1_529_400).saturating_mul(v.into())) + // Minimum execution time: 221_810 nanoseconds. + Weight::from_parts(33_157_392, 4745) + // Standard Error: 109_045 + .saturating_add(Weight::from_ref_time(41_100_656).saturating_mul(p.into())) + // Standard Error: 7_754 + .saturating_add(Weight::from_ref_time(1_534_466).saturating_mul(v.into())) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -148,19 +148,19 @@ impl WeightInfo for () { /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), /// added: 2048, mode: MaxEncodedLen) /// - /// The range of component `p` is `[1, 5]`. + /// The range of component `p` is `[1, 4]`. /// /// The range of component `v` is `[50, 100]`. fn submit_finality_proof(p: u32, v: u32) -> Weight { // Proof Size summary in bytes: - // Measured: `416 + p * (40 ±0)` + // Measured: `394 + p * (60 ±0)` // Estimated: `4745` - // Minimum execution time: 221_703 nanoseconds. - Weight::from_parts(39_358_497, 4745) - // Standard Error: 85_573 - .saturating_add(Weight::from_ref_time(40_593_280).saturating_mul(p.into())) - // Standard Error: 7_808 - .saturating_add(Weight::from_ref_time(1_529_400).saturating_mul(v.into())) + // Minimum execution time: 221_810 nanoseconds. + Weight::from_parts(33_157_392, 4745) + // Standard Error: 109_045 + .saturating_add(Weight::from_ref_time(41_100_656).saturating_mul(p.into())) + // Standard Error: 7_754 + .saturating_add(Weight::from_ref_time(1_534_466).saturating_mul(v.into())) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } diff --git a/bridges/modules/messages/src/benchmarking.rs b/bridges/modules/messages/src/benchmarking.rs index a89cb3a8ef038..955dd3da2c57b 100644 --- a/bridges/modules/messages/src/benchmarking.rs +++ b/bridges/modules/messages/src/benchmarking.rs @@ -238,7 +238,7 @@ benchmarks_instance_pallet! { lane: T::bench_lane_id(), message_nonces: 21..=21, outbound_lane_data: None, - size: StorageProofSize::HasExtraNodes(1024), + size: StorageProofSize::HasLargeLeaf(1024), }); }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight) verify { @@ -272,7 +272,7 @@ benchmarks_instance_pallet! { lane: T::bench_lane_id(), message_nonces: 21..=21, outbound_lane_data: None, - size: StorageProofSize::HasExtraNodes(16 * 1024), + size: StorageProofSize::HasLargeLeaf(16 * 1024), }); }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight) verify { diff --git a/bridges/modules/messages/src/weights.rs b/bridges/modules/messages/src/weights.rs index f18285f3dfee4..8a85c8e6b2d25 100644 --- a/bridges/modules/messages/src/weights.rs +++ b/bridges/modules/messages/src/weights.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for pallet_bridge_messages //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-13, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-01, 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 @@ -88,8 +88,8 @@ impl WeightInfo for BridgeWeight { // Proof Size summary in bytes: // Measured: `693` // Estimated: `54703` - // Minimum execution time: 50_655 nanoseconds. - Weight::from_parts(60_502_000, 54703) + // Minimum execution time: 48_426 nanoseconds. + Weight::from_parts(50_113_000, 54703) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -116,8 +116,8 @@ impl WeightInfo for BridgeWeight { // Proof Size summary in bytes: // Measured: `693` // Estimated: `54703` - // Minimum execution time: 58_861 nanoseconds. - Weight::from_parts(60_288_000, 54703) + // Minimum execution time: 59_739 nanoseconds. + Weight::from_parts(61_704_000, 54703) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -144,8 +144,8 @@ impl WeightInfo for BridgeWeight { // Proof Size summary in bytes: // Measured: `693` // Estimated: `54703` - // Minimum execution time: 53_459 nanoseconds. - Weight::from_parts(54_577_000, 54703) + // Minimum execution time: 53_760 nanoseconds. + Weight::from_parts(55_645_000, 54703) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -167,8 +167,8 @@ impl WeightInfo for BridgeWeight { // Proof Size summary in bytes: // Measured: `618` // Estimated: `54200` - // Minimum execution time: 54_011 nanoseconds. - Weight::from_parts(55_573_000, 54200) + // Minimum execution time: 49_582 nanoseconds. + Weight::from_parts(51_250_000, 54200) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -190,8 +190,8 @@ impl WeightInfo for BridgeWeight { // Proof Size summary in bytes: // Measured: `618` // Estimated: `54200` - // Minimum execution time: 105_856 nanoseconds. - Weight::from_parts(109_112_000, 54200) + // Minimum execution time: 76_418 nanoseconds. + Weight::from_parts(77_877_000, 54200) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -212,14 +212,14 @@ impl WeightInfo for BridgeWeight { /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, /// mode: MaxEncodedLen) fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: // Measured: `579` - // Estimated: `5619` - // Minimum execution time: 40_894 nanoseconds. - Weight::from_parts(41_766_000, 5619) + // Estimated: `5624` + // Minimum execution time: 41_795 nanoseconds. + Weight::from_parts(43_683_000, 5624) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -240,14 +240,14 @@ impl WeightInfo for BridgeWeight { /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, /// mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `5619` - // Minimum execution time: 39_996 nanoseconds. - Weight::from_parts(41_452_000, 5619) + // Estimated: `5624` + // Minimum execution time: 39_946 nanoseconds. + Weight::from_parts(41_509_000, 5624) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -268,14 +268,14 @@ impl WeightInfo for BridgeWeight { /// /// Storage: BridgeRelayers RelayerRewards (r:2 w:2) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, /// mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `8154` - // Minimum execution time: 42_281 nanoseconds. - Weight::from_parts(43_593_000, 8154) + // Estimated: `8164` + // Minimum execution time: 42_882 nanoseconds. + Weight::from_parts(44_367_000, 8164) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -306,8 +306,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `693` // Estimated: `54703` - // Minimum execution time: 50_655 nanoseconds. - Weight::from_parts(60_502_000, 54703) + // Minimum execution time: 48_426 nanoseconds. + Weight::from_parts(50_113_000, 54703) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -334,8 +334,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `693` // Estimated: `54703` - // Minimum execution time: 58_861 nanoseconds. - Weight::from_parts(60_288_000, 54703) + // Minimum execution time: 59_739 nanoseconds. + Weight::from_parts(61_704_000, 54703) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -362,8 +362,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `693` // Estimated: `54703` - // Minimum execution time: 53_459 nanoseconds. - Weight::from_parts(54_577_000, 54703) + // Minimum execution time: 53_760 nanoseconds. + Weight::from_parts(55_645_000, 54703) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -385,8 +385,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `618` // Estimated: `54200` - // Minimum execution time: 54_011 nanoseconds. - Weight::from_parts(55_573_000, 54200) + // Minimum execution time: 49_582 nanoseconds. + Weight::from_parts(51_250_000, 54200) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -408,8 +408,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `618` // Estimated: `54200` - // Minimum execution time: 105_856 nanoseconds. - Weight::from_parts(109_112_000, 54200) + // Minimum execution time: 76_418 nanoseconds. + Weight::from_parts(77_877_000, 54200) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -430,14 +430,14 @@ impl WeightInfo for () { /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, /// mode: MaxEncodedLen) fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: // Measured: `579` - // Estimated: `5619` - // Minimum execution time: 40_894 nanoseconds. - Weight::from_parts(41_766_000, 5619) + // Estimated: `5624` + // Minimum execution time: 41_795 nanoseconds. + Weight::from_parts(43_683_000, 5624) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -458,14 +458,14 @@ impl WeightInfo for () { /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, /// mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `5619` - // Minimum execution time: 39_996 nanoseconds. - Weight::from_parts(41_452_000, 5619) + // Estimated: `5624` + // Minimum execution time: 39_946 nanoseconds. + Weight::from_parts(41_509_000, 5624) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -486,14 +486,14 @@ impl WeightInfo for () { /// /// Storage: BridgeRelayers RelayerRewards (r:2 w:2) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, /// mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `8154` - // Minimum execution time: 42_281 nanoseconds. - Weight::from_parts(43_593_000, 8154) + // Estimated: `8164` + // Minimum execution time: 42_882 nanoseconds. + Weight::from_parts(44_367_000, 8164) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } diff --git a/bridges/modules/parachains/src/benchmarking.rs b/bridges/modules/parachains/src/benchmarking.rs index b156b724afeb3..83cfba0b8c6b0 100644 --- a/bridges/modules/parachains/src/benchmarking.rs +++ b/bridges/modules/parachains/src/benchmarking.rs @@ -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::HasExtraNodes(1024), + StorageProofSize::HasLargeLeaf(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::HasExtraNodes(16 * 1024), + StorageProofSize::HasLargeLeaf(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/weights.rs b/bridges/modules/parachains/src/weights.rs index 5ee1e4d36212f..cce2febcf4f0a 100644 --- a/bridges/modules/parachains/src/weights.rs +++ b/bridges/modules/parachains/src/weights.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for pallet_bridge_parachains //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-01, 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 @@ -77,23 +77,21 @@ impl WeightInfo for BridgeWeight { /// /// Storage: BridgeRialtoParachains ImportedParaHashes (r:1 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(14400), max_size: - /// Some(64), added: 2044, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(1024), max_size: + /// Some(64), added: 1549, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoParachains ImportedParaHeads (r:0 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(14400), max_size: - /// Some(196), added: 2176, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(1024), max_size: + /// 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: `5143` - // Minimum execution time: 35_160 nanoseconds. - Weight::from_parts(36_951_585, 5143) - // Standard Error: 336_932 - .saturating_add(Weight::from_ref_time(407_557).saturating_mul(p.into())) + // Estimated: `4648` + // Minimum execution time: 36_567 nanoseconds. + Weight::from_parts(38_887_022, 4648) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -114,19 +112,19 @@ impl WeightInfo for BridgeWeight { /// /// Storage: BridgeRialtoParachains ImportedParaHashes (r:1 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(14400), max_size: - /// Some(64), added: 2044, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(1024), max_size: + /// Some(64), added: 1549, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoParachains ImportedParaHeads (r:0 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(14400), max_size: - /// Some(196), added: 2176, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(1024), max_size: + /// Some(196), added: 1681, mode: MaxEncodedLen) fn submit_parachain_heads_with_1kb_proof() -> Weight { // Proof Size summary in bytes: // Measured: `366` - // Estimated: `5143` - // Minimum execution time: 42_276 nanoseconds. - Weight::from_parts(43_525_000, 5143) + // Estimated: `4648` + // Minimum execution time: 37_910 nanoseconds. + Weight::from_parts(38_967_000, 4648) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -147,19 +145,19 @@ impl WeightInfo for BridgeWeight { /// /// Storage: BridgeRialtoParachains ImportedParaHashes (r:1 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(14400), max_size: - /// Some(64), added: 2044, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(1024), max_size: + /// Some(64), added: 1549, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoParachains ImportedParaHeads (r:0 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(14400), max_size: - /// Some(196), added: 2176, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(1024), max_size: + /// Some(196), added: 1681, mode: MaxEncodedLen) fn submit_parachain_heads_with_16kb_proof() -> Weight { // Proof Size summary in bytes: // Measured: `366` - // Estimated: `5143` - // Minimum execution time: 85_824 nanoseconds. - Weight::from_parts(87_335_000, 5143) + // Estimated: `4648` + // Minimum execution time: 62_823 nanoseconds. + Weight::from_parts(64_658_000, 4648) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -184,23 +182,21 @@ impl WeightInfo for () { /// /// Storage: BridgeRialtoParachains ImportedParaHashes (r:1 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(14400), max_size: - /// Some(64), added: 2044, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(1024), max_size: + /// Some(64), added: 1549, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoParachains ImportedParaHeads (r:0 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(14400), max_size: - /// Some(196), added: 2176, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(1024), max_size: + /// 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: `5143` - // Minimum execution time: 35_160 nanoseconds. - Weight::from_parts(36_951_585, 5143) - // Standard Error: 336_932 - .saturating_add(Weight::from_ref_time(407_557).saturating_mul(p.into())) + // Estimated: `4648` + // Minimum execution time: 36_567 nanoseconds. + Weight::from_parts(38_887_022, 4648) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -221,19 +217,19 @@ impl WeightInfo for () { /// /// Storage: BridgeRialtoParachains ImportedParaHashes (r:1 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(14400), max_size: - /// Some(64), added: 2044, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(1024), max_size: + /// Some(64), added: 1549, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoParachains ImportedParaHeads (r:0 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(14400), max_size: - /// Some(196), added: 2176, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(1024), max_size: + /// Some(196), added: 1681, mode: MaxEncodedLen) fn submit_parachain_heads_with_1kb_proof() -> Weight { // Proof Size summary in bytes: // Measured: `366` - // Estimated: `5143` - // Minimum execution time: 42_276 nanoseconds. - Weight::from_parts(43_525_000, 5143) + // Estimated: `4648` + // Minimum execution time: 37_910 nanoseconds. + Weight::from_parts(38_967_000, 4648) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -254,19 +250,19 @@ impl WeightInfo for () { /// /// Storage: BridgeRialtoParachains ImportedParaHashes (r:1 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(14400), max_size: - /// Some(64), added: 2044, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHashes (max_values: Some(1024), max_size: + /// Some(64), added: 1549, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoParachains ImportedParaHeads (r:0 w:1) /// - /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(14400), max_size: - /// Some(196), added: 2176, mode: MaxEncodedLen) + /// Proof: BridgeRialtoParachains ImportedParaHeads (max_values: Some(1024), max_size: + /// Some(196), added: 1681, mode: MaxEncodedLen) fn submit_parachain_heads_with_16kb_proof() -> Weight { // Proof Size summary in bytes: // Measured: `366` - // Estimated: `5143` - // Minimum execution time: 85_824 nanoseconds. - Weight::from_parts(87_335_000, 5143) + // Estimated: `4648` + // Minimum execution time: 62_823 nanoseconds. + Weight::from_parts(64_658_000, 4648) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } diff --git a/bridges/modules/relayers/src/weights.rs b/bridges/modules/relayers/src/weights.rs index 572935f63025e..5b6a70854e149 100644 --- a/bridges/modules/relayers/src/weights.rs +++ b/bridges/modules/relayers/src/weights.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for pallet_bridge_relayers //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-27, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-03-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `serban-ROG-Zephyrus`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H` +//! 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 // Executed Command: @@ -71,8 +71,8 @@ impl WeightInfo for BridgeWeight { // Proof Size summary in bytes: // Measured: `275` // Estimated: `5111` - // Minimum execution time: 43_031 nanoseconds. - Weight::from_parts(44_527_000, 5111) + // Minimum execution time: 48_688 nanoseconds. + Weight::from_parts(50_457_000, 5111) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -93,8 +93,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `275` // Estimated: `5111` - // Minimum execution time: 43_031 nanoseconds. - Weight::from_parts(44_527_000, 5111) + // Minimum execution time: 48_688 nanoseconds. + Weight::from_parts(50_457_000, 5111) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } diff --git a/bridges/primitives/runtime/src/storage_proof.rs b/bridges/primitives/runtime/src/storage_proof.rs index 133a51ce6e7f5..aa9c3088fa42f 100644 --- a/bridges/primitives/runtime/src/storage_proof.rs +++ b/bridges/primitives/runtime/src/storage_proof.rs @@ -16,7 +16,7 @@ //! Logic for checking Substrate storage proofs. -use codec::{Decode, Encode}; +use codec::Decode; use hash_db::{HashDB, Hasher, EMPTY_PREFIX}; use sp_runtime::RuntimeDebug; use sp_std::{boxed::Box, collections::btree_set::BTreeSet, vec::Vec}; @@ -36,9 +36,6 @@ pub enum ProofSize { /// The proof is expected to be minimal. If value size may be changed, then it is expected to /// have given size. Minimal(u32), - /// The proof is expected to have at least given size and grow by increasing number of trie - /// nodes included in the proof. - HasExtraNodes(u32), /// The proof is expected to have at least given size and grow by increasing value that is /// stored in the trie. HasLargeLeaf(u32), @@ -46,7 +43,8 @@ pub enum ProofSize { /// This struct is used to read storage values from a subset of a Merklized database. The "proof" /// is a subset of the nodes in the Merkle structure of the database, so that it provides -/// authentication against a known Merkle root as well as the values in the database themselves. +/// authentication against a known Merkle root as well as the values in the +/// database themselves. pub struct StorageProofChecker where H: Hasher, @@ -157,6 +155,7 @@ impl From for &'static str { /// NOTE: This should only be used for **testing**. #[cfg(feature = "std")] pub fn craft_valid_storage_proof() -> (sp_core::H256, RawStorageProof) { + use codec::Encode; use sp_state_machine::{backend::Backend, prove_read, InMemoryBackend}; let state_version = sp_runtime::StateVersion::default();