From 45ac3825731afe99e3110a54159c7f1be348a730 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 12 Jan 2023 15:05:26 +0200 Subject: [PATCH 1/3] Define method for checking message lane weights --- bin/millau/runtime/src/rialto_messages.rs | 33 ++++------------------- bin/rialto/runtime/src/millau_messages.rs | 32 ++++------------------ bin/runtime-common/src/integrity.rs | 33 +++++++++++++++++++++-- 3 files changed, 41 insertions(+), 57 deletions(-) diff --git a/bin/millau/runtime/src/rialto_messages.rs b/bin/millau/runtime/src/rialto_messages.rs index 0d80cdd7b1a..ac203a2f6dd 100644 --- a/bin/millau/runtime/src/rialto_messages.rs +++ b/bin/millau/runtime/src/rialto_messages.rs @@ -163,42 +163,19 @@ mod tests { use super::*; use crate::{Runtime, WithRialtoMessagesInstance}; - use bp_runtime::Chain; 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, }, - messages, }; #[test] fn ensure_millau_message_lane_weights_are_correct() { - type Weights = pallet_bridge_messages::weights::BridgeWeight; - - pallet_bridge_messages::ensure_weights_are_correct::(); - - let max_incoming_message_proof_size = bp_rialto::EXTRA_STORAGE_PROOF_SIZE.saturating_add( - messages::target::maximal_incoming_message_size(bp_millau::Millau::max_extrinsic_size()), - ); - pallet_bridge_messages::ensure_able_to_receive_message::( - bp_millau::Millau::max_extrinsic_size(), - bp_millau::Millau::max_extrinsic_weight(), - max_incoming_message_proof_size, - messages::target::maximal_incoming_message_dispatch_weight( - bp_millau::Millau::max_extrinsic_weight(), - ), - ); - - let max_incoming_inbound_lane_data_proof_size = - bp_messages::InboundLaneData::<()>::encoded_size_hint_u32( - bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX as _, - ); - pallet_bridge_messages::ensure_able_to_receive_confirmation::( - bp_millau::Millau::max_extrinsic_size(), - bp_millau::Millau::max_extrinsic_weight(), - max_incoming_inbound_lane_data_proof_size, + check_message_lane_weights::( + bp_rialto::EXTRA_STORAGE_PROOF_SIZE, bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, ); diff --git a/bin/rialto/runtime/src/millau_messages.rs b/bin/rialto/runtime/src/millau_messages.rs index b2e55ccfa02..90a63a733c3 100644 --- a/bin/rialto/runtime/src/millau_messages.rs +++ b/bin/rialto/runtime/src/millau_messages.rs @@ -162,41 +162,19 @@ impl SourceHeaderChain for Millau { mod tests { use super::*; use crate::{MillauGrandpaInstance, Runtime, WithMillauMessagesInstance}; - use bp_runtime::Chain; 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_rialto_message_lane_weights_are_correct() { - type Weights = pallet_bridge_messages::weights::BridgeWeight; - - pallet_bridge_messages::ensure_weights_are_correct::(); - - let max_incoming_message_proof_size = bp_millau::EXTRA_STORAGE_PROOF_SIZE.saturating_add( - messages::target::maximal_incoming_message_size(bp_rialto::Rialto::max_extrinsic_size()), - ); - pallet_bridge_messages::ensure_able_to_receive_message::( - bp_rialto::Rialto::max_extrinsic_size(), - bp_rialto::Rialto::max_extrinsic_weight(), - max_incoming_message_proof_size, - messages::target::maximal_incoming_message_dispatch_weight( - bp_rialto::Rialto::max_extrinsic_weight(), - ), - ); - - let max_incoming_inbound_lane_data_proof_size = - bp_messages::InboundLaneData::<()>::encoded_size_hint_u32( - bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX as _, - ); - pallet_bridge_messages::ensure_able_to_receive_confirmation::( - bp_rialto::Rialto::max_extrinsic_size(), - bp_rialto::Rialto::max_extrinsic_weight(), - max_incoming_inbound_lane_data_proof_size, + check_message_lane_weights::( + bp_millau::EXTRA_STORAGE_PROOF_SIZE, bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, ); diff --git a/bin/runtime-common/src/integrity.rs b/bin/runtime-common/src/integrity.rs index 4c69a29b821..150478e7f1b 100644 --- a/bin/runtime-common/src/integrity.rs +++ b/bin/runtime-common/src/integrity.rs @@ -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}; @@ -289,3 +289,32 @@ where assert_bridge_messages_pallet_constants::(params.messages_pallet_constants); assert_bridge_pallet_names::(params.pallet_names); } + +pub fn check_message_lane_weights( + extra_storage_proof_size: u32, + max_unrewarded_relayers: MessageNonce, + max_unconfirmed_messages: MessageNonce, +) { + type Weights = pallet_bridge_messages::weights::BridgeWeight; + + pallet_bridge_messages::ensure_weights_are_correct::>(); + + let max_incoming_message_proof_size = extra_storage_proof_size + .saturating_add(messages::target::maximal_incoming_message_size(C::max_extrinsic_size())); + pallet_bridge_messages::ensure_able_to_receive_message::>( + 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(max_unrewarded_relayers as _); + pallet_bridge_messages::ensure_able_to_receive_confirmation::>( + C::max_extrinsic_size(), + C::max_extrinsic_weight(), + max_incoming_inbound_lane_data_proof_size, + max_unrewarded_relayers, + max_unconfirmed_messages, + ); +} From b9634cb3eb6fb677963723fac1c2424edcf17dd8 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 12 Jan 2023 15:11:46 +0200 Subject: [PATCH 2/3] Docs for public function --- bin/runtime-common/src/integrity.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/runtime-common/src/integrity.rs b/bin/runtime-common/src/integrity.rs index 150478e7f1b..211134ff6e2 100644 --- a/bin/runtime-common/src/integrity.rs +++ b/bin/runtime-common/src/integrity.rs @@ -290,6 +290,7 @@ where assert_bridge_pallet_names::(params.pallet_names); } +/// Check that the message lane weights are correct. pub fn check_message_lane_weights( extra_storage_proof_size: u32, max_unrewarded_relayers: MessageNonce, From fddf1004327b8808a256331b125b47b761e51cbf Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 12 Jan 2023 15:14:10 +0200 Subject: [PATCH 3/3] Renamings --- bin/runtime-common/src/integrity.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/runtime-common/src/integrity.rs b/bin/runtime-common/src/integrity.rs index 211134ff6e2..9c4553ad136 100644 --- a/bin/runtime-common/src/integrity.rs +++ b/bin/runtime-common/src/integrity.rs @@ -292,15 +292,15 @@ where /// Check that the message lane weights are correct. pub fn check_message_lane_weights( - extra_storage_proof_size: u32, - max_unrewarded_relayers: MessageNonce, - max_unconfirmed_messages: MessageNonce, + bridged_chain_extra_storage_proof_size: u32, + this_chain_max_unrewarded_relayers: MessageNonce, + this_chain_max_unconfirmed_messages: MessageNonce, ) { type Weights = pallet_bridge_messages::weights::BridgeWeight; pallet_bridge_messages::ensure_weights_are_correct::>(); - let max_incoming_message_proof_size = extra_storage_proof_size + 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::>( C::max_extrinsic_size(), @@ -310,12 +310,12 @@ pub fn check_message_lane_weights( ); let max_incoming_inbound_lane_data_proof_size = - InboundLaneData::<()>::encoded_size_hint_u32(max_unrewarded_relayers as _); + InboundLaneData::<()>::encoded_size_hint_u32(this_chain_max_unrewarded_relayers as _); pallet_bridge_messages::ensure_able_to_receive_confirmation::>( C::max_extrinsic_size(), C::max_extrinsic_weight(), max_incoming_inbound_lane_data_proof_size, - max_unrewarded_relayers, - max_unconfirmed_messages, + this_chain_max_unrewarded_relayers, + this_chain_max_unconfirmed_messages, ); }