From e7606b710adcb6e716f696f98e432fb94e112c90 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 9 Feb 2023 15:41:44 +0300 Subject: [PATCH 1/3] more tests for message pallet weights --- modules/messages/src/weights.rs | 299 ++++++++++++---------------- modules/messages/src/weights_ext.rs | 123 ++++++++++++ 2 files changed, 249 insertions(+), 173 deletions(-) diff --git a/modules/messages/src/weights.rs b/modules/messages/src/weights.rs index 0e258508885..7547d46ea6f 100644 --- a/modules/messages/src/weights.rs +++ b/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-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-09, 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 @@ -42,10 +42,7 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; /// Weight functions needed for pallet_bridge_messages. @@ -67,215 +64,193 @@ pub struct BridgeWeight(PhantomData); impl WeightInfo for BridgeWeight { /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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: `55198` - // Minimum execution time: 47_968 nanoseconds. - Weight::from_parts(48_937_000, 55198) + // Estimated: `54703` + // Minimum execution time: 47_692 nanoseconds. + Weight::from_parts(48_625_000, 54703) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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: `55198` - // Minimum execution time: 63_831 nanoseconds. - Weight::from_parts(85_093_000, 55198) + // Estimated: `54703` + // Minimum execution time: 59_215 nanoseconds. + Weight::from_parts(60_489_000, 54703) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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: `55198` - // Minimum execution time: 53_775 nanoseconds. - Weight::from_parts(55_113_000, 55198) + // Estimated: `54703` + // Minimum execution time: 52_559 nanoseconds. + Weight::from_parts(53_382_000, 54703) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// 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) + /// Proof: BridgeRialtoMessages 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: `618` - // Estimated: `54695` - // Minimum execution time: 54_314 nanoseconds. - Weight::from_parts(55_804_000, 54695) + // Estimated: `54200` + // Minimum execution time: 52_855 nanoseconds. + Weight::from_parts(54_270_000, 54200) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// 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) + /// Proof: BridgeRialtoMessages 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: `618` - // Estimated: `54695` - // Minimum execution time: 103_050 nanoseconds. - Weight::from_parts(106_715_000, 54695) + // Estimated: `54200` + // Minimum execution time: 104_513 nanoseconds. + Weight::from_parts(107_747_000, 54200) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: - /// 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, - /// mode: MaxEncodedLen) + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: // Measured: `579` - // Estimated: `8094` - // Minimum execution time: 42_111 nanoseconds. - Weight::from_parts(43_168_000, 8094) + // Estimated: `7599` + // Minimum execution time: 40_366 nanoseconds. + Weight::from_parts(41_383_000, 7599) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: - /// 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, - /// mode: MaxEncodedLen) + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `8094` - // Minimum execution time: 40_094 nanoseconds. - Weight::from_parts(41_140_000, 8094) + // Estimated: `7599` + // Minimum execution time: 39_494 nanoseconds. + Weight::from_parts(41_752_000, 7599) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: - /// 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:2 w:2) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, - /// mode: MaxEncodedLen) + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `10629` - // Minimum execution time: 42_498 nanoseconds. - Weight::from_parts(43_494_000, 10629) + // Estimated: `10134` + // Minimum execution time: 41_827 nanoseconds. + Weight::from_parts(42_862_000, 10134) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -285,215 +260,193 @@ impl WeightInfo for BridgeWeight { impl WeightInfo for () { /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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: `55198` - // Minimum execution time: 47_968 nanoseconds. - Weight::from_parts(48_937_000, 55198) + // Estimated: `54703` + // Minimum execution time: 47_692 nanoseconds. + Weight::from_parts(48_625_000, 54703) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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: `55198` - // Minimum execution time: 63_831 nanoseconds. - Weight::from_parts(85_093_000, 55198) + // Estimated: `54703` + // Minimum execution time: 59_215 nanoseconds. + Weight::from_parts(60_489_000, 54703) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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: `55198` - // Minimum execution time: 53_775 nanoseconds. - Weight::from_parts(55_113_000, 55198) + // Estimated: `54703` + // Minimum execution time: 52_559 nanoseconds. + Weight::from_parts(53_382_000, 54703) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// 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) + /// Proof: BridgeRialtoMessages 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: `618` - // Estimated: `54695` - // Minimum execution time: 54_314 nanoseconds. - Weight::from_parts(55_804_000, 54695) + // Estimated: `54200` + // Minimum execution time: 52_855 nanoseconds. + Weight::from_parts(54_270_000, 54200) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// 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) + /// Proof: BridgeRialtoMessages 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: `618` - // Estimated: `54695` - // Minimum execution time: 103_050 nanoseconds. - Weight::from_parts(106_715_000, 54695) + // Estimated: `54200` + // Minimum execution time: 104_513 nanoseconds. + Weight::from_parts(107_747_000, 54200) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: - /// 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, - /// mode: MaxEncodedLen) + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: // Measured: `579` - // Estimated: `8094` - // Minimum execution time: 42_111 nanoseconds. - Weight::from_parts(43_168_000, 8094) + // Estimated: `7599` + // Minimum execution time: 40_366 nanoseconds. + Weight::from_parts(41_383_000, 7599) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: - /// 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, - /// mode: MaxEncodedLen) + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `8094` - // Minimum execution time: 40_094 nanoseconds. - Weight::from_parts(41_140_000, 8094) + // Estimated: `7599` + // Minimum execution time: 39_494 nanoseconds. + Weight::from_parts(41_752_000, 7599) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), - /// added: 497, mode: MaxEncodedLen) + /// 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: None, max_size: Some(68), added: - /// 2543, mode: MaxEncodedLen) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: - /// 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:2 w:2) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, - /// mode: MaxEncodedLen) + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) + /// fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: // Measured: `596` - // Estimated: `10629` - // Minimum execution time: 42_498 nanoseconds. - Weight::from_parts(43_494_000, 10629) + // Estimated: `10134` + // Minimum execution time: 41_827 nanoseconds. + Weight::from_parts(42_862_000, 10134) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } diff --git a/modules/messages/src/weights_ext.rs b/modules/messages/src/weights_ext.rs index c764f5b8f65..cc2b5fbac84 100644 --- a/modules/messages/src/weights_ext.rs +++ b/modules/messages/src/weights_ext.rs @@ -234,6 +234,7 @@ pub trait WeightInfoExt: WeightInfo { /// Returns weight that needs to be accounted when receiving confirmations for given a number of /// messages with delivery confirmation transaction (`receive_messages_delivery_proof`). fn receive_messages_delivery_proof_messages_overhead(messages: MessageNonce) -> Weight { +// TODO: this would return 0. Is it used correctly? let weight_of_two_messages = Self::receive_delivery_proof_for_two_messages_by_single_relayer(); let weight_of_single_message = Self::receive_delivery_proof_for_single_message(); @@ -282,3 +283,125 @@ impl WeightInfoExt for crate::weights::BridgeWeight EXTRA_STORAGE_PROOF_SIZE } } + +#[cfg(test)] +mod tests { + use crate::{mock::TestRuntime, weights::BridgeWeight}; + use super::*; + + type Weights = BridgeWeight; + + // TODO: maybe move this to `ensure_weights_are_correct`? + + fn ensure_weight_components_are_not_zero(weight: Weight) { + assert_ne!(weight.ref_time(), 0); + assert_ne!(weight.proof_size(), 0); + } + + fn ensure_ref_time_lesser(weight1: Weight, weight2: Weight, msg: &str) { + assert!( + weight1.ref_time() < weight2.ref_time(), + "{msg}: {} must be less than {}", + weight1.ref_time(), + weight2.ref_time(), + ); + } + + fn ensure_proof_size_is_the_same(weight1: Weight, weight2: Weight, msg: &str) { + assert_eq!( + weight1.proof_size(), + weight2.proof_size(), + "{msg}: {} must be equal to {}", + weight1.proof_size(), + weight2.proof_size(), + ); + } + + #[test] + fn messages_proof_size_does_not_affect_proof_size() { + let dispatch_weight = Weight::zero(); + let weight_when_proof_size_is_8k = Weights::receive_messages_proof_weight( + &PreComputedSize(8 * 1024), + 1, + dispatch_weight, + ); + let weight_when_proof_size_is_16k = Weights::receive_messages_proof_weight( + &PreComputedSize(16 * 1024), + 1, + dispatch_weight, + ); + + ensure_weight_components_are_not_zero(weight_when_proof_size_is_8k); + ensure_weight_components_are_not_zero(weight_when_proof_size_is_16k); + ensure_proof_size_is_the_same( + weight_when_proof_size_is_8k, + weight_when_proof_size_is_16k, + "Messages proof size does not affect values that we read from our storage", + ); + ensure_ref_time_lesser( + weight_when_proof_size_is_8k, + weight_when_proof_size_is_16k, + "Larger message proofs mean more hashing and iterations => computation time", + ); + } + + #[test] + fn messages_count_does_not_affect_proof_size() { + let messages_proof_size = PreComputedSize(8 * 1024); + let dispatch_weight = Weight::zero(); + let weight_of_one_incoming_message = Weights::receive_messages_proof_weight( + &messages_proof_size, + 1, + dispatch_weight, + ); + let weight_of_two_incoming_messages = Weights::receive_messages_proof_weight( + &messages_proof_size, + 2, + dispatch_weight, + ); + + ensure_weight_components_are_not_zero(weight_of_one_incoming_message); + ensure_weight_components_are_not_zero(weight_of_two_incoming_messages); + ensure_proof_size_is_the_same( + weight_of_one_incoming_message, + weight_of_two_incoming_messages, + "Number of same-lane incoming messages does not affect values that we read from our storage", + ); + ensure_ref_time_lesser( + weight_of_one_incoming_message, + weight_of_two_incoming_messages, + "More incoming messages mean more computation overhead", + ); + } + + #[test] + fn messages_delivery_proof_size_does_not_affect_proof_size() { + let relayers_state = UnrewardedRelayersState { + unrewarded_relayer_entries: 1, + messages_in_oldest_entry: 1, + total_messages: 1, + last_delivered_nonce: 1, + }; + let weight_when_proof_size_is_8k = Weights::receive_messages_delivery_proof_weight( + &PreComputedSize(8 * 1024), + &relayers_state, + ); + let weight_when_proof_size_is_16k = Weights::receive_messages_delivery_proof_weight( + &PreComputedSize(16 * 1024), + &relayers_state, + ); + + ensure_weight_components_are_not_zero(weight_when_proof_size_is_8k); + ensure_weight_components_are_not_zero(weight_when_proof_size_is_16k); + ensure_proof_size_is_the_same( + weight_when_proof_size_is_8k, + weight_when_proof_size_is_16k, + "Messages delivery proof size does not affect values that we read from our storage", + ); + ensure_ref_time_lesser( + weight_when_proof_size_is_8k, + weight_when_proof_size_is_16k, + "Larger messages delivery proofs mean more hashing and iterations => computation time", + ); + } +} From 1395d9c04ca7e7704822ff2bf49803a9c9c1d061 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Fri, 10 Feb 2023 12:34:12 +0300 Subject: [PATCH 2/3] move tests to ensure_weights_are_correct --- modules/messages/src/weights.rs | 201 +++++++++++-------- modules/messages/src/weights_ext.rs | 293 ++++++++++++++++------------ 2 files changed, 296 insertions(+), 198 deletions(-) diff --git a/modules/messages/src/weights.rs b/modules/messages/src/weights.rs index 7547d46ea6f..f6fe3d3fac6 100644 --- a/modules/messages/src/weights.rs +++ b/modules/messages/src/weights.rs @@ -42,7 +42,10 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame_support::{ + traits::Get, + weights::{constants::RocksDbWeight, Weight}, +}; use sp_std::marker::PhantomData; /// Weight functions needed for pallet_bridge_messages. @@ -64,20 +67,23 @@ pub struct BridgeWeight(PhantomData); impl WeightInfo for BridgeWeight { /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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) - /// + /// 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` @@ -89,20 +95,23 @@ impl WeightInfo for BridgeWeight { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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) - /// + /// 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` @@ -114,20 +123,23 @@ impl WeightInfo for BridgeWeight { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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) - /// + /// 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` @@ -139,16 +151,18 @@ impl WeightInfo for BridgeWeight { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// 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) - /// + /// Proof: BridgeRialtoMessages 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: `618` @@ -160,16 +174,18 @@ impl WeightInfo for BridgeWeight { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// 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) - /// + /// Proof: BridgeRialtoMessages 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: `618` @@ -181,20 +197,23 @@ impl WeightInfo for BridgeWeight { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), + /// added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: + /// 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// mode: MaxEncodedLen) fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: // Measured: `579` @@ -206,20 +225,23 @@ impl WeightInfo for BridgeWeight { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), + /// added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: + /// 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: // Measured: `596` @@ -231,20 +253,23 @@ impl WeightInfo for BridgeWeight { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), + /// added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: + /// 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:2 w:2) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: // Measured: `596` @@ -260,20 +285,23 @@ impl WeightInfo for BridgeWeight { impl WeightInfo for () { /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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) - /// + /// 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` @@ -285,20 +313,23 @@ impl WeightInfo for () { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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) - /// + /// 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` @@ -310,20 +341,23 @@ impl WeightInfo for () { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// 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) + /// 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) - /// + /// 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` @@ -335,16 +369,18 @@ impl WeightInfo for () { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// 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) - /// + /// Proof: BridgeRialtoMessages 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: `618` @@ -356,16 +392,18 @@ impl WeightInfo for () { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// 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) - /// + /// Proof: BridgeRialtoMessages 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: `618` @@ -377,20 +415,23 @@ impl WeightInfo for () { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), + /// added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: + /// 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// mode: MaxEncodedLen) fn receive_delivery_proof_for_single_message() -> Weight { // Proof Size summary in bytes: // Measured: `579` @@ -402,20 +443,23 @@ impl WeightInfo for () { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), + /// added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: + /// 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:1 w:1) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { // Proof Size summary in bytes: // Measured: `596` @@ -427,20 +471,23 @@ impl WeightInfo for () { } /// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0) /// - /// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen) + /// 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) + /// Proof: BridgeRialtoGrandpa ImportedHeaders (max_values: Some(14400), max_size: Some(68), + /// added: 2048, mode: MaxEncodedLen) /// /// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1) /// - /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen) + /// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added: + /// 2519, mode: MaxEncodedLen) /// /// Storage: BridgeRelayers RelayerRewards (r:2 w:2) /// - /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) - /// + /// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(60), added: 2535, + /// mode: MaxEncodedLen) fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { // Proof Size summary in bytes: // Measured: `596` diff --git a/modules/messages/src/weights_ext.rs b/modules/messages/src/weights_ext.rs index cc2b5fbac84..1e0a69d4edf 100644 --- a/modules/messages/src/weights_ext.rs +++ b/modules/messages/src/weights_ext.rs @@ -36,21 +36,42 @@ pub const EXTRA_STORAGE_PROOF_SIZE: u32 = 1024; /// Ensure that weights from `WeightInfoExt` implementation are looking correct. pub fn ensure_weights_are_correct() { + // all component of weight formulae, except the transaction overhead (*_overhead) and + // the unrewarded relayers overhead, must have: + // + // - non-zero `ref_time`, because they add computation time to the call; + // + // - zero `proof_size`, because the `proof_size` is benchmarked using `MaxEncodedLen` approach + // and there are no components that cause additional db reads + // verify `receive_messages_proof` weight components - assert_ne!(W::receive_messages_proof_overhead(), Weight::zero()); - assert_ne!(W::receive_messages_proof_messages_overhead(1), Weight::zero()); - assert_ne!(W::receive_messages_proof_outbound_lane_state_overhead(), Weight::zero()); - assert_ne!(W::storage_proof_size_overhead(1), Weight::zero()); + assert_ne!(W::receive_messages_proof_overhead().ref_time(), 0); + assert_ne!(W::receive_messages_proof_overhead().proof_size(), 0); + assert_ne!(W::receive_messages_proof_messages_overhead(1).ref_time(), 0); + assert_eq!(W::receive_messages_proof_messages_overhead(1).proof_size(), 0); + assert_ne!(W::receive_messages_proof_outbound_lane_state_overhead().ref_time(), 0); + assert_eq!(W::receive_messages_proof_outbound_lane_state_overhead().proof_size(), 0); + assert_ne!(W::storage_proof_size_overhead(1).ref_time(), 0); + assert_eq!(W::storage_proof_size_overhead(1).proof_size(), 0); // verify `receive_messages_delivery_proof` weight components - assert_ne!(W::receive_messages_delivery_proof_overhead(), Weight::zero()); - assert_ne!(W::storage_proof_size_overhead(1), Weight::zero()); + assert_ne!(W::receive_messages_delivery_proof_overhead().ref_time(), 0); + assert_ne!(W::receive_messages_delivery_proof_overhead().proof_size(), 0); + assert_ne!(W::receive_messages_delivery_proof_messages_overhead(1).ref_time(), 0); + assert_eq!(W::receive_messages_delivery_proof_messages_overhead(1).proof_size(), 0); + assert_ne!(W::receive_messages_delivery_proof_relayers_overhead(1).ref_time(), 0); + // W::receive_messages_delivery_proof_relayers_overhead(1).proof_size() is an exception + // it may or may not cause additional db reads, so proof size may vary + assert_ne!(W::storage_proof_size_overhead(1).ref_time(), 0); + assert_eq!(W::storage_proof_size_overhead(1).proof_size(), 0); // verify `receive_message_proof` weight let receive_messages_proof_weight = W::receive_messages_proof_weight(&PreComputedSize(1), 10, Weight::zero()); assert_ne!(receive_messages_proof_weight.ref_time(), 0); assert_ne!(receive_messages_proof_weight.proof_size(), 0); + messages_proof_size_does_not_affect_proof_size::(); + messages_count_does_not_affect_proof_size::(); // verify `receive_message_proof` weight let receive_messages_delivery_proof_weight = W::receive_messages_delivery_proof_weight( @@ -59,6 +80,8 @@ pub fn ensure_weights_are_correct() { ); assert_ne!(receive_messages_delivery_proof_weight.ref_time(), 0); assert_ne!(receive_messages_delivery_proof_weight.proof_size(), 0); + messages_delivery_proof_size_does_not_affect_proof_size::(); + total_messages_in_delivery_proof_does_not_affect_proof_size::(); } /// Ensure that we're able to receive maximal (by-size and by-weight) message from other chain. @@ -122,6 +145,146 @@ pub fn ensure_able_to_receive_confirmation( ); } +/// Panics if `proof_size` of message delivery call depends on the message proof size. +fn messages_proof_size_does_not_affect_proof_size() { + let dispatch_weight = Weight::zero(); + let weight_when_proof_size_is_8k = + W::receive_messages_proof_weight(&PreComputedSize(8 * 1024), 1, dispatch_weight); + let weight_when_proof_size_is_16k = + W::receive_messages_proof_weight(&PreComputedSize(16 * 1024), 1, dispatch_weight); + + ensure_weight_components_are_not_zero(weight_when_proof_size_is_8k); + ensure_weight_components_are_not_zero(weight_when_proof_size_is_16k); + ensure_proof_size_is_the_same( + weight_when_proof_size_is_8k, + weight_when_proof_size_is_16k, + "Messages proof size does not affect values that we read from our storage", + ); + ensure_ref_time_lte( + weight_when_proof_size_is_8k, + weight_when_proof_size_is_16k, + "Larger message proofs mean more hashing and iterations => computation time", + ); +} + +/// Panics if `proof_size` of message delivery call depends on the messages count. +/// +/// In practice, it will depend on the messages count, because most probably every +/// message will read something from db during dispatch. But this must be accounted +/// by the `dispatch_weight`. +fn messages_count_does_not_affect_proof_size() { + let messages_proof_size = PreComputedSize(8 * 1024); + let dispatch_weight = Weight::zero(); + let weight_of_one_incoming_message = + W::receive_messages_proof_weight(&messages_proof_size, 1, dispatch_weight); + let weight_of_two_incoming_messages = + W::receive_messages_proof_weight(&messages_proof_size, 2, dispatch_weight); + + ensure_weight_components_are_not_zero(weight_of_one_incoming_message); + ensure_weight_components_are_not_zero(weight_of_two_incoming_messages); + ensure_proof_size_is_the_same( + weight_of_one_incoming_message, + weight_of_two_incoming_messages, + "Number of same-lane incoming messages does not affect values that we read from our storage", + ); + ensure_ref_time_lte( + weight_of_one_incoming_message, + weight_of_two_incoming_messages, + "More incoming messages mean more computation overhead", + ); +} + +/// Panics if `proof_size` of delivery confirmation call depends on the delivery proof size. +fn messages_delivery_proof_size_does_not_affect_proof_size() { + let relayers_state = UnrewardedRelayersState { + unrewarded_relayer_entries: 1, + messages_in_oldest_entry: 1, + total_messages: 1, + last_delivered_nonce: 1, + }; + let weight_when_proof_size_is_8k = + W::receive_messages_delivery_proof_weight(&PreComputedSize(8 * 1024), &relayers_state); + let weight_when_proof_size_is_16k = + W::receive_messages_delivery_proof_weight(&PreComputedSize(16 * 1024), &relayers_state); + + ensure_weight_components_are_not_zero(weight_when_proof_size_is_8k); + ensure_weight_components_are_not_zero(weight_when_proof_size_is_16k); + ensure_proof_size_is_the_same( + weight_when_proof_size_is_8k, + weight_when_proof_size_is_16k, + "Messages delivery proof size does not affect values that we read from our storage", + ); + ensure_ref_time_lte( + weight_when_proof_size_is_8k, + weight_when_proof_size_is_16k, + "Larger messages delivery proofs mean more hashing and iterations => computation time", + ); +} + +/// Panics if `proof_size` of delivery confirmation call depends on the number of confirmed +/// messages. +fn total_messages_in_delivery_proof_does_not_affect_proof_size() { + let proof_size = PreComputedSize(8 * 1024); + let weight_when_1k_messages_confirmed = W::receive_messages_delivery_proof_weight( + &proof_size, + &UnrewardedRelayersState { + unrewarded_relayer_entries: 1, + messages_in_oldest_entry: 1, + total_messages: 1024, + last_delivered_nonce: 1, + }, + ); + let weight_when_2k_messages_confirmed = W::receive_messages_delivery_proof_weight( + &proof_size, + &UnrewardedRelayersState { + unrewarded_relayer_entries: 1, + messages_in_oldest_entry: 1, + total_messages: 2048, + last_delivered_nonce: 1, + }, + ); + + ensure_weight_components_are_not_zero(weight_when_1k_messages_confirmed); + ensure_weight_components_are_not_zero(weight_when_2k_messages_confirmed); + ensure_proof_size_is_the_same( + weight_when_1k_messages_confirmed, + weight_when_2k_messages_confirmed, + "More messages in delivery proof does not affect values that we read from our storage", + ); + ensure_ref_time_lte( + weight_when_1k_messages_confirmed, + weight_when_2k_messages_confirmed, + "More messages in delivery proof means more iterations => computation time", + ); +} + +/// Panics if either Weight' `proof_size` or `ref_time` are zero. +fn ensure_weight_components_are_not_zero(weight: Weight) { + assert_ne!(weight.ref_time(), 0); + assert_ne!(weight.proof_size(), 0); +} + +/// Panics if `ref_time` of `weight1` is larger than `ref_time` of `weight2`. +fn ensure_ref_time_lte(weight1: Weight, weight2: Weight, msg: &str) { + assert!( + weight1.ref_time() <= weight2.ref_time(), + "{msg}: {} must be less than {}", + weight1.ref_time(), + weight2.ref_time(), + ); +} + +/// Panics if `proof_size` of `weight1` is not equal to `proof_size` of `weight2`. +fn ensure_proof_size_is_the_same(weight1: Weight, weight2: Weight, msg: &str) { + assert_eq!( + weight1.proof_size(), + weight2.proof_size(), + "{msg}: {} must be equal to {}", + weight1.proof_size(), + weight2.proof_size(), + ); +} + /// Extended weight info. pub trait WeightInfoExt: WeightInfo { /// Size of proof that is already included in the single message delivery weight. @@ -234,7 +397,6 @@ pub trait WeightInfoExt: WeightInfo { /// Returns weight that needs to be accounted when receiving confirmations for given a number of /// messages with delivery confirmation transaction (`receive_messages_delivery_proof`). fn receive_messages_delivery_proof_messages_overhead(messages: MessageNonce) -> Weight { -// TODO: this would return 0. Is it used correctly? let weight_of_two_messages = Self::receive_delivery_proof_for_two_messages_by_single_relayer(); let weight_of_single_message = Self::receive_delivery_proof_for_single_message(); @@ -286,122 +448,11 @@ impl WeightInfoExt for crate::weights::BridgeWeight #[cfg(test)] mod tests { - use crate::{mock::TestRuntime, weights::BridgeWeight}; use super::*; - - type Weights = BridgeWeight; - - // TODO: maybe move this to `ensure_weights_are_correct`? - - fn ensure_weight_components_are_not_zero(weight: Weight) { - assert_ne!(weight.ref_time(), 0); - assert_ne!(weight.proof_size(), 0); - } - - fn ensure_ref_time_lesser(weight1: Weight, weight2: Weight, msg: &str) { - assert!( - weight1.ref_time() < weight2.ref_time(), - "{msg}: {} must be less than {}", - weight1.ref_time(), - weight2.ref_time(), - ); - } - - fn ensure_proof_size_is_the_same(weight1: Weight, weight2: Weight, msg: &str) { - assert_eq!( - weight1.proof_size(), - weight2.proof_size(), - "{msg}: {} must be equal to {}", - weight1.proof_size(), - weight2.proof_size(), - ); - } - - #[test] - fn messages_proof_size_does_not_affect_proof_size() { - let dispatch_weight = Weight::zero(); - let weight_when_proof_size_is_8k = Weights::receive_messages_proof_weight( - &PreComputedSize(8 * 1024), - 1, - dispatch_weight, - ); - let weight_when_proof_size_is_16k = Weights::receive_messages_proof_weight( - &PreComputedSize(16 * 1024), - 1, - dispatch_weight, - ); - - ensure_weight_components_are_not_zero(weight_when_proof_size_is_8k); - ensure_weight_components_are_not_zero(weight_when_proof_size_is_16k); - ensure_proof_size_is_the_same( - weight_when_proof_size_is_8k, - weight_when_proof_size_is_16k, - "Messages proof size does not affect values that we read from our storage", - ); - ensure_ref_time_lesser( - weight_when_proof_size_is_8k, - weight_when_proof_size_is_16k, - "Larger message proofs mean more hashing and iterations => computation time", - ); - } - - #[test] - fn messages_count_does_not_affect_proof_size() { - let messages_proof_size = PreComputedSize(8 * 1024); - let dispatch_weight = Weight::zero(); - let weight_of_one_incoming_message = Weights::receive_messages_proof_weight( - &messages_proof_size, - 1, - dispatch_weight, - ); - let weight_of_two_incoming_messages = Weights::receive_messages_proof_weight( - &messages_proof_size, - 2, - dispatch_weight, - ); - - ensure_weight_components_are_not_zero(weight_of_one_incoming_message); - ensure_weight_components_are_not_zero(weight_of_two_incoming_messages); - ensure_proof_size_is_the_same( - weight_of_one_incoming_message, - weight_of_two_incoming_messages, - "Number of same-lane incoming messages does not affect values that we read from our storage", - ); - ensure_ref_time_lesser( - weight_of_one_incoming_message, - weight_of_two_incoming_messages, - "More incoming messages mean more computation overhead", - ); - } + use crate::{mock::TestRuntime, weights::BridgeWeight}; #[test] - fn messages_delivery_proof_size_does_not_affect_proof_size() { - let relayers_state = UnrewardedRelayersState { - unrewarded_relayer_entries: 1, - messages_in_oldest_entry: 1, - total_messages: 1, - last_delivered_nonce: 1, - }; - let weight_when_proof_size_is_8k = Weights::receive_messages_delivery_proof_weight( - &PreComputedSize(8 * 1024), - &relayers_state, - ); - let weight_when_proof_size_is_16k = Weights::receive_messages_delivery_proof_weight( - &PreComputedSize(16 * 1024), - &relayers_state, - ); - - ensure_weight_components_are_not_zero(weight_when_proof_size_is_8k); - ensure_weight_components_are_not_zero(weight_when_proof_size_is_16k); - ensure_proof_size_is_the_same( - weight_when_proof_size_is_8k, - weight_when_proof_size_is_16k, - "Messages delivery proof size does not affect values that we read from our storage", - ); - ensure_ref_time_lesser( - weight_when_proof_size_is_8k, - weight_when_proof_size_is_16k, - "Larger messages delivery proofs mean more hashing and iterations => computation time", - ); + fn ensure_default_weights_are_correct() { + ensure_weights_are_correct::>(); } } From 05dbbdad9838ca8d9a79ae4792c93cb54151a1ad Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 13 Feb 2023 11:36:57 +0300 Subject: [PATCH 3/3] removed extra tests --- modules/messages/src/mock.rs | 5 ++- modules/messages/src/weights.rs | 66 ++++++++++++++--------------- modules/messages/src/weights_ext.rs | 51 +++++----------------- 3 files changed, 47 insertions(+), 75 deletions(-) diff --git a/modules/messages/src/mock.rs b/modules/messages/src/mock.rs index bd10de09c7f..084262c7905 100644 --- a/modules/messages/src/mock.rs +++ b/modules/messages/src/mock.rs @@ -34,7 +34,7 @@ use codec::{Decode, Encode}; use frame_support::{ parameter_types, traits::ConstU64, - weights::{RuntimeDbWeight, Weight}, + weights::{constants::RocksDbWeight, Weight}, }; use scale_info::TypeInfo; use sp_core::H256; @@ -92,9 +92,10 @@ parameter_types! { pub const MaximumBlockWeight: Weight = Weight::from_ref_time(1024); pub const MaximumBlockLength: u32 = 2 * 1024; pub const AvailableBlockRatio: Perbill = Perbill::one(); - pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1, write: 2 }; } +pub type DbWeight = RocksDbWeight; + impl frame_system::Config for TestRuntime { type RuntimeOrigin = RuntimeOrigin; type Index = u64; diff --git a/modules/messages/src/weights.rs b/modules/messages/src/weights.rs index f6fe3d3fac6..10750aabcd3 100644 --- a/modules/messages/src/weights.rs +++ b/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-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-02-13, 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: 47_692 nanoseconds. - Weight::from_parts(48_625_000, 54703) + // Minimum execution time: 76_449 nanoseconds. + Weight::from_parts(127_110_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: 59_215 nanoseconds. - Weight::from_parts(60_489_000, 54703) + // Minimum execution time: 102_297 nanoseconds. + Weight::from_parts(108_619_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: 52_559 nanoseconds. - Weight::from_parts(53_382_000, 54703) + // Minimum execution time: 84_911 nanoseconds. + Weight::from_parts(87_518_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: 52_855 nanoseconds. - Weight::from_parts(54_270_000, 54200) + // Minimum execution time: 79_805 nanoseconds. + Weight::from_parts(84_148_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: 104_513 nanoseconds. - Weight::from_parts(107_747_000, 54200) + // Minimum execution time: 141_515 nanoseconds. + Weight::from_parts(150_421_000, 54200) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -218,8 +218,8 @@ impl WeightInfo for BridgeWeight { // Proof Size summary in bytes: // Measured: `579` // Estimated: `7599` - // Minimum execution time: 40_366 nanoseconds. - Weight::from_parts(41_383_000, 7599) + // Minimum execution time: 54_740 nanoseconds. + Weight::from_parts(56_637_000, 7599) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -246,8 +246,8 @@ impl WeightInfo for BridgeWeight { // Proof Size summary in bytes: // Measured: `596` // Estimated: `7599` - // Minimum execution time: 39_494 nanoseconds. - Weight::from_parts(41_752_000, 7599) + // Minimum execution time: 54_583 nanoseconds. + Weight::from_parts(56_205_000, 7599) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -274,8 +274,8 @@ impl WeightInfo for BridgeWeight { // Proof Size summary in bytes: // Measured: `596` // Estimated: `10134` - // Minimum execution time: 41_827 nanoseconds. - Weight::from_parts(42_862_000, 10134) + // Minimum execution time: 59_426 nanoseconds. + Weight::from_parts(61_911_000, 10134) .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: 47_692 nanoseconds. - Weight::from_parts(48_625_000, 54703) + // Minimum execution time: 76_449 nanoseconds. + Weight::from_parts(127_110_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: 59_215 nanoseconds. - Weight::from_parts(60_489_000, 54703) + // Minimum execution time: 102_297 nanoseconds. + Weight::from_parts(108_619_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: 52_559 nanoseconds. - Weight::from_parts(53_382_000, 54703) + // Minimum execution time: 84_911 nanoseconds. + Weight::from_parts(87_518_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: 52_855 nanoseconds. - Weight::from_parts(54_270_000, 54200) + // Minimum execution time: 79_805 nanoseconds. + Weight::from_parts(84_148_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: 104_513 nanoseconds. - Weight::from_parts(107_747_000, 54200) + // Minimum execution time: 141_515 nanoseconds. + Weight::from_parts(150_421_000, 54200) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -436,8 +436,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `579` // Estimated: `7599` - // Minimum execution time: 40_366 nanoseconds. - Weight::from_parts(41_383_000, 7599) + // Minimum execution time: 54_740 nanoseconds. + Weight::from_parts(56_637_000, 7599) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -464,8 +464,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `596` // Estimated: `7599` - // Minimum execution time: 39_494 nanoseconds. - Weight::from_parts(41_752_000, 7599) + // Minimum execution time: 54_583 nanoseconds. + Weight::from_parts(56_205_000, 7599) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -492,8 +492,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `596` // Estimated: `10134` - // Minimum execution time: 41_827 nanoseconds. - Weight::from_parts(42_862_000, 10134) + // Minimum execution time: 59_426 nanoseconds. + Weight::from_parts(61_911_000, 10134) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } diff --git a/modules/messages/src/weights_ext.rs b/modules/messages/src/weights_ext.rs index 1e0a69d4edf..5598706b5db 100644 --- a/modules/messages/src/weights_ext.rs +++ b/modules/messages/src/weights_ext.rs @@ -36,20 +36,20 @@ pub const EXTRA_STORAGE_PROOF_SIZE: u32 = 1024; /// Ensure that weights from `WeightInfoExt` implementation are looking correct. pub fn ensure_weights_are_correct() { - // all component of weight formulae, except the transaction overhead (*_overhead) and - // the unrewarded relayers overhead, must have: - // - // - non-zero `ref_time`, because they add computation time to the call; - // - // - zero `proof_size`, because the `proof_size` is benchmarked using `MaxEncodedLen` approach - // and there are no components that cause additional db reads + // all components of weight formulae must have zero `proof_size`, because the `proof_size` is + // benchmarked using `MaxEncodedLen` approach and there are no components that cause additional + // db reads // verify `receive_messages_proof` weight components assert_ne!(W::receive_messages_proof_overhead().ref_time(), 0); assert_ne!(W::receive_messages_proof_overhead().proof_size(), 0); - assert_ne!(W::receive_messages_proof_messages_overhead(1).ref_time(), 0); + // W::receive_messages_proof_messages_overhead(1).ref_time() may be zero because: + // the message processing code (`InboundLane::receive_message`) is minimal and may not be + // accounted by our benchmarks assert_eq!(W::receive_messages_proof_messages_overhead(1).proof_size(), 0); - assert_ne!(W::receive_messages_proof_outbound_lane_state_overhead().ref_time(), 0); + // W::receive_messages_proof_outbound_lane_state_overhead().ref_time() may be zero because: + // the outbound lane state processing code (`InboundLane::receive_state_update`) is minimal and + // may not be accounted by our benchmarks assert_eq!(W::receive_messages_proof_outbound_lane_state_overhead().proof_size(), 0); assert_ne!(W::storage_proof_size_overhead(1).ref_time(), 0); assert_eq!(W::storage_proof_size_overhead(1).proof_size(), 0); @@ -57,7 +57,8 @@ pub fn ensure_weights_are_correct() { // verify `receive_messages_delivery_proof` weight components assert_ne!(W::receive_messages_delivery_proof_overhead().ref_time(), 0); assert_ne!(W::receive_messages_delivery_proof_overhead().proof_size(), 0); - assert_ne!(W::receive_messages_delivery_proof_messages_overhead(1).ref_time(), 0); + // W::receive_messages_delivery_proof_messages_overhead(1).ref_time() may be zero because: + // there's no code that iterates over confirmed messages in confirmation transaction assert_eq!(W::receive_messages_delivery_proof_messages_overhead(1).proof_size(), 0); assert_ne!(W::receive_messages_delivery_proof_relayers_overhead(1).ref_time(), 0); // W::receive_messages_delivery_proof_relayers_overhead(1).proof_size() is an exception @@ -160,11 +161,6 @@ fn messages_proof_size_does_not_affect_proof_size() { weight_when_proof_size_is_16k, "Messages proof size does not affect values that we read from our storage", ); - ensure_ref_time_lte( - weight_when_proof_size_is_8k, - weight_when_proof_size_is_16k, - "Larger message proofs mean more hashing and iterations => computation time", - ); } /// Panics if `proof_size` of message delivery call depends on the messages count. @@ -187,11 +183,6 @@ fn messages_count_does_not_affect_proof_size() { weight_of_two_incoming_messages, "Number of same-lane incoming messages does not affect values that we read from our storage", ); - ensure_ref_time_lte( - weight_of_one_incoming_message, - weight_of_two_incoming_messages, - "More incoming messages mean more computation overhead", - ); } /// Panics if `proof_size` of delivery confirmation call depends on the delivery proof size. @@ -214,11 +205,6 @@ fn messages_delivery_proof_size_does_not_affect_proof_size() { weight_when_proof_size_is_16k, "Messages delivery proof size does not affect values that we read from our storage", ); - ensure_ref_time_lte( - weight_when_proof_size_is_8k, - weight_when_proof_size_is_16k, - "Larger messages delivery proofs mean more hashing and iterations => computation time", - ); } /// Panics if `proof_size` of delivery confirmation call depends on the number of confirmed @@ -251,11 +237,6 @@ fn total_messages_in_delivery_proof_does_not_affect_proof_size weight_when_2k_messages_confirmed, "More messages in delivery proof does not affect values that we read from our storage", ); - ensure_ref_time_lte( - weight_when_1k_messages_confirmed, - weight_when_2k_messages_confirmed, - "More messages in delivery proof means more iterations => computation time", - ); } /// Panics if either Weight' `proof_size` or `ref_time` are zero. @@ -264,16 +245,6 @@ fn ensure_weight_components_are_not_zero(weight: Weight) { assert_ne!(weight.proof_size(), 0); } -/// Panics if `ref_time` of `weight1` is larger than `ref_time` of `weight2`. -fn ensure_ref_time_lte(weight1: Weight, weight2: Weight, msg: &str) { - assert!( - weight1.ref_time() <= weight2.ref_time(), - "{msg}: {} must be less than {}", - weight1.ref_time(), - weight2.ref_time(), - ); -} - /// Panics if `proof_size` of `weight1` is not equal to `proof_size` of `weight2`. fn ensure_proof_size_is_the_same(weight1: Weight, weight2: Weight, msg: &str) { assert_eq!(