Add weight of refund extension post_dispatch to the weights of messages pallet (#2089)

* add weight of refund extension post_dispatch to the weights of messages pallet

* fixed tests and removed TODO

* verify runtime overhead weight in integrity tests

* add integrity tests to rialto-parachain runtime

* refactor weights a bit

* refund ext is disabled for Rialto <> Millau bridge

* Update bin/runtime-common/src/integrity.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>

* Update bin/runtime-common/src/integrity.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>

* Update modules/relayers/src/weights_ext.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>

---------

Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
Svyatoslav Nikolsky
2023-05-02 14:55:07 +03:00
committed by Bastian Köcher
parent b03c584e31
commit 49d11e9ce5
12 changed files with 308 additions and 30 deletions
+1 -1
View File
@@ -599,7 +599,7 @@ generate_bridge_reject_obsolete_headers_and_messages! {
bp_runtime::generate_static_str_provider!(BridgeRefundRialtoPara2000Lane0Msgs);
/// Signed extension that refunds relayers that are delivering messages from the Rialto parachain.
pub type PriorityBoostPerMessage = ConstU64<699_683_285>;
pub type PriorityBoostPerMessage = ConstU64<324_316_715>;
pub type BridgeRefundRialtoParachainMessages = RefundBridgedParachainMessages<
Runtime,
RefundableParachain<WithRialtoParachainsInstance, RialtoParachainId>,
@@ -26,6 +26,7 @@ use bridge_runtime_common::{
messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter},
};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
use pallet_bridge_relayers::WeightInfoExt as _;
use xcm::latest::prelude::*;
use xcm_builder::HaulBlobExporter;
@@ -139,6 +140,14 @@ impl pallet_bridge_messages::WeightInfoExt for crate::weights::RialtoMessagesWei
fn expected_extra_storage_proof_size() -> u32 {
bp_rialto::EXTRA_STORAGE_PROOF_SIZE
}
fn receive_messages_proof_overhead_from_runtime() -> Weight {
pallet_bridge_relayers::weights::BridgeWeight::<Runtime>::receive_messages_proof_overhead_from_runtime()
}
fn receive_messages_delivery_proof_overhead_from_runtime() -> Weight {
pallet_bridge_relayers::weights::BridgeWeight::<Runtime>::receive_messages_delivery_proof_overhead_from_runtime()
}
}
#[cfg(test)]
@@ -161,6 +170,7 @@ mod tests {
bp_rialto::EXTRA_STORAGE_PROOF_SIZE,
bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
false,
);
}
@@ -28,6 +28,7 @@ use bridge_runtime_common::{
messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter},
};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
use pallet_bridge_relayers::WeightInfoExt as _;
use xcm::latest::prelude::*;
use xcm_builder::HaulBlobExporter;
@@ -142,6 +143,14 @@ impl pallet_bridge_messages::WeightInfoExt
fn expected_extra_storage_proof_size() -> u32 {
bp_rialto_parachain::EXTRA_STORAGE_PROOF_SIZE
}
fn receive_messages_proof_overhead_from_runtime() -> Weight {
pallet_bridge_relayers::weights::BridgeWeight::<Runtime>::receive_messages_proof_overhead_from_runtime()
}
fn receive_messages_delivery_proof_overhead_from_runtime() -> Weight {
pallet_bridge_relayers::weights::BridgeWeight::<Runtime>::receive_messages_delivery_proof_overhead_from_runtime()
}
}
#[cfg(test)]
@@ -167,6 +176,7 @@ mod tests {
bp_rialto_parachain::EXTRA_STORAGE_PROOF_SIZE,
bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
true,
);
}
@@ -154,6 +154,7 @@ mod tests {
bp_millau::EXTRA_STORAGE_PROOF_SIZE,
bp_rialto_parachain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
bp_rialto_parachain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
false,
);
}
@@ -154,6 +154,7 @@ mod tests {
bp_millau::EXTRA_STORAGE_PROOF_SIZE,
bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
false,
);
}
+29 -3
View File
@@ -24,8 +24,9 @@ use crate::{messages, messages::MessageBridge};
use bp_messages::{InboundLaneData, MessageNonce};
use bp_runtime::{Chain, ChainId};
use codec::Encode;
use frame_support::{storage::generator::StorageValue, traits::Get};
use frame_support::{storage::generator::StorageValue, traits::Get, weights::Weight};
use frame_system::limits;
use pallet_bridge_messages::WeightInfoExt as _;
use sp_runtime::traits::SignedExtension;
/// Macro that ensures that the runtime configuration and chain primitives crate are sharing
@@ -289,15 +290,25 @@ where
}
/// Check that the message lane weights are correct.
pub fn check_message_lane_weights<C: Chain, T: frame_system::Config>(
pub fn check_message_lane_weights<
C: Chain,
T: frame_system::Config + pallet_bridge_messages::Config,
>(
bridged_chain_extra_storage_proof_size: u32,
this_chain_max_unrewarded_relayers: MessageNonce,
this_chain_max_unconfirmed_messages: MessageNonce,
// whether `RefundBridgedParachainMessages` extension is deployed at runtime and is used for
// refunding this bridge transactions?
//
// in other words: pass true for all known production chains
runtime_includes_refund_extension: bool,
) {
type Weights<T> = pallet_bridge_messages::weights::BridgeWeight<T>;
type Weights<T> = <T as pallet_bridge_messages::Config>::WeightInfo;
// check basic weight assumptions
pallet_bridge_messages::ensure_weights_are_correct::<Weights<T>>();
// check that weights allow us to receive messages
let max_incoming_message_proof_size = bridged_chain_extra_storage_proof_size
.saturating_add(messages::target::maximal_incoming_message_size(C::max_extrinsic_size()));
pallet_bridge_messages::ensure_able_to_receive_message::<Weights<T>>(
@@ -307,6 +318,7 @@ pub fn check_message_lane_weights<C: Chain, T: frame_system::Config>(
messages::target::maximal_incoming_message_dispatch_weight(C::max_extrinsic_weight()),
);
// check that weights allow us to receive delivery confirmations
let max_incoming_inbound_lane_data_proof_size =
InboundLaneData::<()>::encoded_size_hint_u32(this_chain_max_unrewarded_relayers as _);
pallet_bridge_messages::ensure_able_to_receive_confirmation::<Weights<T>>(
@@ -316,6 +328,20 @@ pub fn check_message_lane_weights<C: Chain, T: frame_system::Config>(
this_chain_max_unrewarded_relayers,
this_chain_max_unconfirmed_messages,
);
// check that extra weights of delivery/confirmation transactions include the weight
// of `RefundBridgedParachainMessages` operations. This signed extension assumes the worst case
// (i.e. slashing if delivery transaction was invalid) and refunds some weight if
// assumption was wrong (i.e. if we did refund instead of slashing). This check
// ensures the extension will not refund weight when it doesn't need to (i.e. if pallet
// weights do not account weights of refund extension).
if runtime_includes_refund_extension {
assert_ne!(Weights::<T>::receive_messages_proof_overhead_from_runtime(), Weight::zero());
assert_ne!(
Weights::<T>::receive_messages_delivery_proof_overhead_from_runtime(),
Weight::zero()
);
}
}
/// Check that the `AdditionalSigned` type of a wrapped runtime is the same as the one of the
@@ -40,7 +40,9 @@ use pallet_bridge_parachains::{
BoundedBridgeGrandpaConfig, CallSubType as ParachainsCallSubType, Config as ParachainsConfig,
RelayBlockNumber, SubmitParachainHeadsHelper, SubmitParachainHeadsInfo,
};
use pallet_bridge_relayers::{Config as RelayersConfig, Pallet as RelayersPallet};
use pallet_bridge_relayers::{
Config as RelayersConfig, Pallet as RelayersPallet, WeightInfoExt as _,
};
use pallet_transaction_payment::{Config as TransactionPaymentConfig, OnChargeTransaction};
use pallet_utility::{Call as UtilityCall, Config as UtilityConfig, Pallet as UtilityPallet};
use scale_info::TypeInfo;
@@ -445,11 +447,19 @@ where
// decrease post-dispatch weight/size using extra weight/size that we know now
let post_info_len = len.saturating_sub(extra_size as usize);
let mut post_info = *post_info;
post_info.actual_weight =
Some(post_info.actual_weight.unwrap_or(info.weight).saturating_sub(extra_weight));
let mut post_info_weight =
post_info.actual_weight.unwrap_or(info.weight).saturating_sub(extra_weight);
// let's also replace the weight of slashing relayer with the weight of rewarding relayer
if call_info.is_receive_messages_proof_call() {
post_info_weight = post_info_weight.saturating_sub(
<Runtime as RelayersConfig>::WeightInfo::extra_weight_of_successful_receive_messages_proof_call(),
);
}
// compute the relayer refund
let mut post_info = *post_info;
post_info.actual_weight = Some(post_info_weight);
let refund = Refund::compute_refund(info, &post_info, post_info_len, tip);
// we can finally reward relayer
@@ -1052,7 +1062,20 @@ mod tests {
assert_eq!(post_dispatch_result, Ok(()));
}
fn expected_reward() -> ThisChainBalance {
fn expected_delivery_reward() -> ThisChainBalance {
let mut post_dispatch_info = post_dispatch_info();
let extra_weight = <TestRuntime as RelayersConfig>::WeightInfo::extra_weight_of_successful_receive_messages_proof_call();
post_dispatch_info.actual_weight =
Some(dispatch_info().weight.saturating_sub(extra_weight));
pallet_transaction_payment::Pallet::<TestRuntime>::compute_actual_fee(
1024,
&dispatch_info(),
&post_dispatch_info,
Zero::zero(),
)
}
fn expected_confirmation_reward() -> ThisChainBalance {
pallet_transaction_payment::Pallet::<TestRuntime>::compute_actual_fee(
1024,
&dispatch_info(),
@@ -1449,7 +1472,7 @@ mod tests {
// without any size/weight refund: we expect regular reward
let pre_dispatch_data = all_finality_pre_dispatch_data();
let regular_reward = expected_reward();
let regular_reward = expected_delivery_reward();
run_post_dispatch(Some(pre_dispatch_data), Ok(()));
assert_eq!(
RelayersPallet::<TestRuntime>::relayer_reward(
@@ -1496,7 +1519,7 @@ mod tests {
relayer_account_at_this_chain(),
MsgProofsRewardsAccount::get()
),
Some(expected_reward()),
Some(expected_delivery_reward()),
);
run_post_dispatch(Some(all_finality_confirmation_pre_dispatch_data()), Ok(()));
@@ -1505,7 +1528,7 @@ mod tests {
relayer_account_at_this_chain(),
MsgDeliveryProofsRewardsAccount::get()
),
Some(expected_reward()),
Some(expected_confirmation_reward()),
);
});
}
@@ -1521,7 +1544,7 @@ mod tests {
relayer_account_at_this_chain(),
MsgProofsRewardsAccount::get()
),
Some(expected_reward()),
Some(expected_delivery_reward()),
);
run_post_dispatch(Some(parachain_finality_confirmation_pre_dispatch_data()), Ok(()));
@@ -1530,7 +1553,7 @@ mod tests {
relayer_account_at_this_chain(),
MsgDeliveryProofsRewardsAccount::get()
),
Some(expected_reward()),
Some(expected_confirmation_reward()),
);
});
}
@@ -1546,7 +1569,7 @@ mod tests {
relayer_account_at_this_chain(),
MsgProofsRewardsAccount::get()
),
Some(expected_reward()),
Some(expected_delivery_reward()),
);
run_post_dispatch(Some(confirmation_pre_dispatch_data()), Ok(()));
@@ -1555,7 +1578,7 @@ mod tests {
relayer_account_at_this_chain(),
MsgDeliveryProofsRewardsAccount::get()
),
Some(expected_reward()),
Some(expected_confirmation_reward()),
);
});
}
@@ -266,6 +266,27 @@ pub trait WeightInfoExt: WeightInfo {
/// this value, we're going to charge relayer for that.
fn expected_extra_storage_proof_size() -> u32;
// Our configuration assumes that the runtime has special signed extensions used to:
//
// 1) reject obsolete delivery and confirmation transactions;
//
// 2) refund transaction cost to relayer and register his rewards.
//
// The checks in (1) are trivial, so its computation weight may be ignored. And we only touch
// storage values that are read during the call. So we may ignore the weight of this check.
//
// However, during (2) we read and update storage values of other pallets
// (`pallet-bridge-relayers` and balances/assets pallet). So we need to add this weight to the
// weight of our call. Hence two following methods.
/// Extra weight that is added to the `receive_messages_proof` call weight by signed extensions
/// that are declared at runtime level.
fn receive_messages_proof_overhead_from_runtime() -> Weight;
/// Extra weight that is added to the `receive_messages_delivery_proof` call weight by signed
/// extensions that are declared at runtime level.
fn receive_messages_delivery_proof_overhead_from_runtime() -> Weight;
// Functions that are directly mapped to extrinsics weights.
/// Weight of message delivery extrinsic.
@@ -276,6 +297,8 @@ pub trait WeightInfoExt: WeightInfo {
) -> Weight {
// basic components of extrinsic weight
let transaction_overhead = Self::receive_messages_proof_overhead();
let transaction_overhead_from_runtime =
Self::receive_messages_proof_overhead_from_runtime();
let outbound_state_delivery_weight =
Self::receive_messages_proof_outbound_lane_state_overhead();
let messages_delivery_weight =
@@ -292,6 +315,7 @@ pub trait WeightInfoExt: WeightInfo {
);
transaction_overhead
.saturating_add(transaction_overhead_from_runtime)
.saturating_add(outbound_state_delivery_weight)
.saturating_add(messages_delivery_weight)
.saturating_add(messages_dispatch_weight)
@@ -305,6 +329,8 @@ pub trait WeightInfoExt: WeightInfo {
) -> Weight {
// basic components of extrinsic weight
let transaction_overhead = Self::receive_messages_delivery_proof_overhead();
let transaction_overhead_from_runtime =
Self::receive_messages_delivery_proof_overhead_from_runtime();
let messages_overhead =
Self::receive_messages_delivery_proof_messages_overhead(relayers_state.total_messages);
let relayers_overhead = Self::receive_messages_delivery_proof_relayers_overhead(
@@ -319,6 +345,7 @@ pub trait WeightInfoExt: WeightInfo {
);
transaction_overhead
.saturating_add(transaction_overhead_from_runtime)
.saturating_add(messages_overhead)
.saturating_add(relayers_overhead)
.saturating_add(proof_size_overhead)
@@ -424,12 +451,28 @@ impl WeightInfoExt for () {
fn expected_extra_storage_proof_size() -> u32 {
EXTRA_STORAGE_PROOF_SIZE
}
fn receive_messages_proof_overhead_from_runtime() -> Weight {
Weight::zero()
}
fn receive_messages_delivery_proof_overhead_from_runtime() -> Weight {
Weight::zero()
}
}
impl<T: frame_system::Config> WeightInfoExt for crate::weights::BridgeWeight<T> {
fn expected_extra_storage_proof_size() -> u32 {
EXTRA_STORAGE_PROOF_SIZE
}
fn receive_messages_proof_overhead_from_runtime() -> Weight {
Weight::zero()
}
fn receive_messages_delivery_proof_overhead_from_runtime() -> Weight {
Weight::zero()
}
}
#[cfg(test)]
@@ -88,5 +88,44 @@ benchmarks! {
assert!(!crate::Pallet::<T>::is_registration_active(&relayer));
}
// Benchmark `slash_and_deregister` method of the pallet. We are adding this weight to
// the weight of message delivery call if `RefundBridgedParachainMessages` signed extension
// is deployed at runtime level.
slash_and_deregister {
// prepare and register relayer account
let relayer: T::AccountId = whitelisted_caller();
let valid_till = frame_system::Pallet::<T>::block_number()
.saturating_add(crate::Pallet::<T>::required_registration_lease())
.saturating_add(One::one())
.saturating_add(One::one());
T::deposit_account(relayer.clone(), crate::Pallet::<T>::required_stake());
crate::Pallet::<T>::register(RawOrigin::Signed(relayer.clone()).into(), valid_till).unwrap();
// create slash destination account
let lane = LaneId([0, 0, 0, 0]);
let slash_destination = RewardsAccountParams::new(lane, *b"test", RewardsAccountOwner::ThisChain);
T::prepare_rewards_account(slash_destination.clone(), Zero::zero());
}: {
crate::Pallet::<T>::slash_and_deregister(&relayer, slash_destination)
}
verify {
assert!(!crate::Pallet::<T>::is_registration_active(&relayer));
}
// Benchmark `register_relayer_reward` method of the pallet. We are adding this weight to
// the weight of message delivery call if `RefundBridgedParachainMessages` signed extension
// is deployed at runtime level.
register_relayer_reward {
let lane = LaneId([0, 0, 0, 0]);
let relayer: T::AccountId = whitelisted_caller();
let account_params =
RewardsAccountParams::new(lane, *b"test", RewardsAccountOwner::ThisChain);
}: {
crate::Pallet::<T>::register_relayer_reward(account_params.clone(), &relayer, One::one());
}
verify {
assert_eq!(RelayerRewards::<T>::get(relayer, &account_params), Some(One::one()));
}
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::TestRuntime)
}
+3 -1
View File
@@ -33,12 +33,14 @@ pub use pallet::*;
pub use payment_adapter::DeliveryConfirmationPaymentsAdapter;
pub use stake_adapter::StakeAndSlashNamed;
pub use weights::WeightInfo;
pub use weights_ext::WeightInfoExt;
pub mod benchmarking;
mod mock;
mod payment_adapter;
mod stake_adapter;
mod weights_ext;
pub mod weights;
@@ -66,7 +68,7 @@ pub mod pallet {
/// Stake and slash scheme.
type StakeAndSlash: StakeAndSlash<Self::AccountId, Self::BlockNumber, Self::Reward>;
/// Pallet call weights.
type WeightInfo: WeightInfo;
type WeightInfo: WeightInfoExt;
}
#[pallet::pallet]
+87 -13
View File
@@ -17,7 +17,7 @@
//! Autogenerated weights for pallet_bridge_relayers
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-04-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-04-28, 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
@@ -53,6 +53,8 @@ pub trait WeightInfo {
fn claim_rewards() -> Weight;
fn register() -> Weight;
fn deregister() -> Weight;
fn slash_and_deregister() -> Weight;
fn register_relayer_reward() -> Weight;
}
/// Weights for `pallet_bridge_relayers` that are generated using one of the Bridge testnets.
@@ -78,8 +80,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
// Proof Size summary in bytes:
// Measured: `294`
// Estimated: `8592`
// Minimum execution time: 75_307 nanoseconds.
Weight::from_parts(76_564_000, 8592)
// Minimum execution time: 77_614 nanoseconds.
Weight::from_parts(79_987_000, 8592)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
@@ -96,8 +98,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
// Proof Size summary in bytes:
// Measured: `87`
// Estimated: `7843`
// Minimum execution time: 38_270 nanoseconds.
Weight::from_parts(39_191_000, 7843)
// Minimum execution time: 39_590 nanoseconds.
Weight::from_parts(40_546_000, 7843)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
@@ -114,11 +116,47 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
// Proof Size summary in bytes:
// Measured: `264`
// Estimated: `7843`
// Minimum execution time: 43_028 nanoseconds.
Weight::from_parts(44_098_000, 7843)
// Minimum execution time: 43_332 nanoseconds.
Weight::from_parts(45_087_000, 7843)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: BridgeRelayers RegisteredRelayers (r:1 w:1)
///
/// Proof: BridgeRelayers RegisteredRelayers (max_values: None, max_size: Some(64), added: 2539,
/// mode: MaxEncodedLen)
///
/// Storage: Balances Reserves (r:1 w:1)
///
/// Proof: Balances Reserves (max_values: None, max_size: Some(849), added: 3324, mode:
/// MaxEncodedLen)
///
/// Storage: System Account (r:1 w:1)
///
/// Proof: System Account (max_values: None, max_size: Some(104), added: 2579, mode:
/// MaxEncodedLen)
fn slash_and_deregister() -> Weight {
// Proof Size summary in bytes:
// Measured: `380`
// Estimated: `11412`
// Minimum execution time: 42_358 nanoseconds.
Weight::from_parts(43_539_000, 11412)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
///
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540,
/// mode: MaxEncodedLen)
fn register_relayer_reward() -> Weight {
// Proof Size summary in bytes:
// Measured: `12`
// Estimated: `3530`
// Minimum execution time: 6_338 nanoseconds.
Weight::from_parts(6_526_000, 3530)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}
// For backwards compatibility and tests
@@ -141,8 +179,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `294`
// Estimated: `8592`
// Minimum execution time: 75_307 nanoseconds.
Weight::from_parts(76_564_000, 8592)
// Minimum execution time: 77_614 nanoseconds.
Weight::from_parts(79_987_000, 8592)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
@@ -159,8 +197,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `87`
// Estimated: `7843`
// Minimum execution time: 38_270 nanoseconds.
Weight::from_parts(39_191_000, 7843)
// Minimum execution time: 39_590 nanoseconds.
Weight::from_parts(40_546_000, 7843)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
@@ -177,9 +215,45 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `264`
// Estimated: `7843`
// Minimum execution time: 43_028 nanoseconds.
Weight::from_parts(44_098_000, 7843)
// Minimum execution time: 43_332 nanoseconds.
Weight::from_parts(45_087_000, 7843)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
/// Storage: BridgeRelayers RegisteredRelayers (r:1 w:1)
///
/// Proof: BridgeRelayers RegisteredRelayers (max_values: None, max_size: Some(64), added: 2539,
/// mode: MaxEncodedLen)
///
/// Storage: Balances Reserves (r:1 w:1)
///
/// Proof: Balances Reserves (max_values: None, max_size: Some(849), added: 3324, mode:
/// MaxEncodedLen)
///
/// Storage: System Account (r:1 w:1)
///
/// Proof: System Account (max_values: None, max_size: Some(104), added: 2579, mode:
/// MaxEncodedLen)
fn slash_and_deregister() -> Weight {
// Proof Size summary in bytes:
// Measured: `380`
// Estimated: `11412`
// Minimum execution time: 42_358 nanoseconds.
Weight::from_parts(43_539_000, 11412)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(3_u64))
}
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
///
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540,
/// mode: MaxEncodedLen)
fn register_relayer_reward() -> Weight {
// Proof Size summary in bytes:
// Measured: `12`
// Estimated: `3530`
// Minimum execution time: 6_338 nanoseconds.
Weight::from_parts(6_526_000, 3530)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}
@@ -0,0 +1,49 @@
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Parity Bridges Common.
// Parity Bridges Common is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Bridges Common is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
//! Weight-related utilities.
use crate::weights::WeightInfo;
use frame_support::pallet_prelude::Weight;
/// Extended weight info.
pub trait WeightInfoExt: WeightInfo {
/// Returns weight, that needs to be added to the pre-dispatch weight of message delivery call,
/// if `RefundBridgedParachainMessages` signed extension is deployed at runtime level.
fn receive_messages_proof_overhead_from_runtime() -> Weight {
Self::slash_and_deregister().max(Self::register_relayer_reward())
}
/// Returns weight, that needs to be added to the pre-dispatch weight of message delivery
/// confirmation call, if `RefundBridgedParachainMessages` signed extension is deployed at
/// runtime level.
fn receive_messages_delivery_proof_overhead_from_runtime() -> Weight {
Self::register_relayer_reward()
}
/// Returns weight that we need to deduct from the message delivery call weight that has
/// completed successfully.
///
/// Usually, the weight of `slash_and_deregister` is larger than the weight of the
/// `register_relayer_reward`. So if relayer has been rewarded, we want to deduct the difference
/// to get the actual post-dispatch weight.
fn extra_weight_of_successful_receive_messages_proof_call() -> Weight {
Self::slash_and_deregister().saturating_sub(Self::register_relayer_reward())
}
}
impl<T: WeightInfo> WeightInfoExt for T {}