Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Add message lane weights tests
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Jan 12, 2023
1 parent 88816e0 commit e1c0efb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
34 changes: 32 additions & 2 deletions bridges/bin/runtime-common/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
//! Most of the tests in this module assume that the bridge is using standard (see `crate::messages`
//! module for details) configuration.
use crate::messages::MessageBridge;
use crate::{messages, messages::MessageBridge};

use bp_messages::MessageNonce;
use bp_messages::{InboundLaneData, MessageNonce};
use bp_runtime::{Chain, ChainId};
use codec::Encode;
use frame_support::{storage::generator::StorageValue, traits::Get};
Expand Down Expand Up @@ -289,3 +289,33 @@ where
assert_bridge_messages_pallet_constants::<R, MI>(params.messages_pallet_constants);
assert_bridge_pallet_names::<B, R, GI, MI>(params.pallet_names);
}

/// Check that the message lane weights are correct.
pub fn check_message_lane_weights<C: Chain, T: frame_system::Config>(
bridged_chain_extra_storage_proof_size: u32,
this_chain_max_unrewarded_relayers: MessageNonce,
this_chain_max_unconfirmed_messages: MessageNonce,
) {
type Weights<T> = pallet_bridge_messages::weights::BridgeWeight<T>;

pallet_bridge_messages::ensure_weights_are_correct::<Weights<T>>();

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>>(
C::max_extrinsic_size(),
C::max_extrinsic_weight(),
max_incoming_message_proof_size,
messages::target::maximal_incoming_message_dispatch_weight(C::max_extrinsic_weight()),
);

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>>(
C::max_extrinsic_size(),
C::max_extrinsic_weight(),
max_incoming_inbound_lane_data_proof_size,
this_chain_max_unrewarded_relayers,
this_chain_max_unconfirmed_messages,
);
}
4 changes: 2 additions & 2 deletions bridges/primitives/chain-bridge-hub-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub use bp_bridge_hub_rococo::{
AccountId, AccountInfoStorageMapKeyProvider, AccountPublic, AccountSigner, Address, Balance,
BlockLength, BlockNumber, BlockWeights, Hash, Hasher, Hashing, Header, Index, Nonce,
SS58Prefix, Signature, SignedBlock, SignedExtensions, UncheckedExtrinsic, WeightToFee,
MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
TX_EXTRA_BYTES,
EXTRA_STORAGE_PROOF_SIZE, MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, TX_EXTRA_BYTES,
};
use bp_messages::*;
use bp_runtime::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,21 @@ mod tests {
use bridge_runtime_common::{
assert_complete_bridge_types,
integrity::{
assert_complete_bridge_constants, AssertBridgeMessagesPalletConstants,
AssertBridgePalletNames, AssertChainConstants, AssertCompleteBridgeConstants,
assert_complete_bridge_constants, check_message_lane_weights,
AssertBridgeMessagesPalletConstants, AssertBridgePalletNames, AssertChainConstants,
AssertCompleteBridgeConstants,
},
};

#[test]
fn ensure_bridge_hub_rococo_message_lane_weights_are_correct() {
check_message_lane_weights::<bp_bridge_hub_rococo::BridgeHubRococo, Runtime>(
bp_bridge_hub_wococo::EXTRA_STORAGE_PROOF_SIZE,
bp_bridge_hub_rococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
bp_bridge_hub_rococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
);
}

#[test]
fn ensure_bridge_integrity() {
assert_complete_bridge_types!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,21 @@ mod tests {
use bridge_runtime_common::{
assert_complete_bridge_types,
integrity::{
assert_complete_bridge_constants, AssertBridgeMessagesPalletConstants,
AssertBridgePalletNames, AssertChainConstants, AssertCompleteBridgeConstants,
assert_complete_bridge_constants, check_message_lane_weights,
AssertBridgeMessagesPalletConstants, AssertBridgePalletNames, AssertChainConstants,
AssertCompleteBridgeConstants,
},
};

#[test]
fn ensure_bridge_hub_wococo_message_lane_weights_are_correct() {
check_message_lane_weights::<bp_bridge_hub_wococo::BridgeHubWococo, Runtime>(
bp_bridge_hub_rococo::EXTRA_STORAGE_PROOF_SIZE,
bp_bridge_hub_wococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
bp_bridge_hub_wococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
);
}

#[test]
fn ensure_bridge_integrity() {
assert_complete_bridge_types!(
Expand Down

0 comments on commit e1c0efb

Please sign in to comment.