Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 11 commits into from
May 2, 2023
Prev Previous commit
Next Next commit
verify runtime overhead weight in integrity tests
  • Loading branch information
svyatonik committed May 1, 2023
commit 54cb3caba3bd004c9c12f12f52ff96a5c3ae45eb
32 changes: 29 additions & 3 deletions bin/runtime-common/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>>(
Expand All @@ -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>>(
Expand All @@ -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 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). If pallet weights
// do not account weights of refund extension, the extension will do refund when it
// doesn't need to.
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
Expand Down