diff --git a/Cargo.lock b/Cargo.lock index 42cf68cef9e..9d1b0b71d7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,6 +982,7 @@ dependencies = [ "rococo-runtime-constants", "scale-info", "serde", + "serial_test", "smallvec", "sp-api", "sp-block-builder", @@ -995,6 +996,7 @@ dependencies = [ "sp-std", "sp-transaction-pool", "sp-version", + "static_assertions", "substrate-wasm-builder", "xcm", "xcm-builder", @@ -2753,6 +2755,17 @@ dependencies = [ "syn", ] +[[package]] +name = "dashmap" +version = "5.2.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "4c8858831f7781322e539ea39e72449c46b059638250c14344fec8d0aa6e539c" +dependencies = [ + "cfg-if", + "num_cpus", + "parking_lot 0.12.1", +] + [[package]] name = "data-encoding" version = "2.3.2" @@ -5909,11 +5922,11 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.0" +version = "1.15.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi 0.2.6", "libc", ] @@ -11508,6 +11521,32 @@ dependencies = [ "serde", ] +[[package]] +name = "serial_test" +version = "0.9.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "92761393ee4dc3ff8f4af487bd58f4307c9329bbedea02cac0089ad9c411e153" +dependencies = [ + "dashmap", + "futures", + "lazy_static", + "log", + "parking_lot 0.12.1", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "0.9.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "4b6f5d1c3087fb119617cff2966fe3808a80e5eb59a8c1601d5994d66f4346a5" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sha-1" version = "0.8.2" diff --git a/bridges/bin/runtime-common/src/integrity.rs b/bridges/bin/runtime-common/src/integrity.rs index 11c6cb90a83..51fb50df7e1 100644 --- a/bridges/bin/runtime-common/src/integrity.rs +++ b/bridges/bin/runtime-common/src/integrity.rs @@ -90,7 +90,6 @@ macro_rules! assert_bridge_messages_pallet_types( assert_type_eq_all!(<$r as MessagesConfig<$i>>::OutboundPayload, FromThisChainMessagePayload); - assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundPayload, FromBridgedChainMessagePayload>>); assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundRelayer, AccountIdOf>); assert_type_eq_all!(<$r as MessagesConfig<$i>>::TargetHeaderChain, TargetHeaderChainAdapter<$bridge>); diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 4fc2cb1b445..f6c42988383 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -86,7 +86,10 @@ pallet-bridge-relayers = { path = "../../../../bridges/modules/relayers", defaul bridge-runtime-common = { path = "../../../../bridges/bin/runtime-common", default-features = false } [dev-dependencies] +serial_test = "0.9.0" +static_assertions = "1.1" bridge-hub-test-utils = { path = "../test-utils"} +bridge-runtime-common = { path = "../../../../bridges/bin/runtime-common", features = ["integrity-test"] } [features] default = [ diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs index 3f85f457b62..cdaaa8bb49e 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs @@ -16,20 +16,13 @@ use crate::{ BridgeParachainWococoInstance, ParachainInfo, Runtime, WithBridgeHubWococoMessagesInstance, - XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter, XcmRouter, -}; -use bp_messages::{ - source_chain::TargetHeaderChain, - target_chain::{ProvedMessages, SourceHeaderChain}, - InboundLaneData, LaneId, Message, MessageNonce, + XcmBlobHauler, XcmBlobHaulerAdapter, XcmRouter, }; +use bp_messages::{LaneId, MessageNonce}; use bp_runtime::ChainId; use bridge_runtime_common::{ messages, - messages::{ - target::FromBridgedChainMessagesProof, MessageBridge, ThisChainWithMessages, - UnderlyingChainProvider, - }, + messages::{MessageBridge, ThisChainWithMessages, UnderlyingChainProvider}, }; use frame_support::{parameter_types, RuntimeDebug}; use xcm::{ @@ -110,37 +103,6 @@ impl UnderlyingChainProvider for BridgeHubWococo { type Chain = bp_bridge_hub_wococo::BridgeHubWococo; } -impl SourceHeaderChain for BridgeHubWococo { - type Error = &'static str; - type MessagesProof = FromBridgedChainMessagesProof; - - fn verify_messages_proof( - proof: Self::MessagesProof, - messages_count: u32, - ) -> Result, Self::Error> { - bridge_runtime_common::messages::target::verify_messages_proof::< - WithBridgeHubWococoMessageBridge, - >(proof, messages_count) - .map_err(Into::into) - } -} - -impl TargetHeaderChain for BridgeHubWococo { - type Error = &'static str; - type MessagesDeliveryProof = - messages::source::FromBridgedChainMessagesDeliveryProof; - - fn verify_message(payload: &XcmAsPlainPayload) -> Result<(), Self::Error> { - messages::source::verify_chain_message::(payload) - } - - fn verify_messages_delivery_proof( - proof: Self::MessagesDeliveryProof, - ) -> Result<(LaneId, InboundLaneData), Self::Error> { - messages::source::verify_messages_delivery_proof::(proof) - } -} - impl messages::BridgedChainWithMessages for BridgeHubWococo { fn verify_dispatch_weight(_message_payload: &[u8]) -> bool { true @@ -172,3 +134,65 @@ impl ThisChainWithMessages for BridgeHubRococo { MessageNonce::MAX / 2 } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::BridgeGrandpaWococoInstance; + use bridge_runtime_common::{ + assert_complete_bridge_types, + integrity::{ + 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_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!( + runtime: Runtime, + with_bridged_chain_grandpa_instance: BridgeGrandpaWococoInstance, + with_bridged_chain_messages_instance: WithBridgeHubWococoMessagesInstance, + bridge: WithBridgeHubWococoMessageBridge, + this_chain: bp_rococo::Rococo, + bridged_chain: bp_wococo::Wococo, + ); + + assert_complete_bridge_constants::< + Runtime, + BridgeGrandpaWococoInstance, + WithBridgeHubWococoMessagesInstance, + WithBridgeHubWococoMessageBridge, + bp_rococo::Rococo, + >(AssertCompleteBridgeConstants { + this_chain_constants: AssertChainConstants { + block_length: bp_bridge_hub_rococo::BlockLength::get(), + block_weights: bp_bridge_hub_rococo::BlockWeights::get(), + }, + messages_pallet_constants: AssertBridgeMessagesPalletConstants { + max_unrewarded_relayers_in_bridged_confirmation_tx: + bp_bridge_hub_wococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, + max_unconfirmed_messages_in_bridged_confirmation_tx: + bp_bridge_hub_wococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, + bridged_chain_id: bp_runtime::BRIDGE_HUB_WOCOCO_CHAIN_ID, + }, + pallet_names: AssertBridgePalletNames { + with_this_chain_messages_pallet_name: + bp_bridge_hub_rococo::WITH_BRIDGE_HUB_ROCOCO_MESSAGES_PALLET_NAME, + with_bridged_chain_grandpa_pallet_name: bp_wococo::WITH_WOCOCO_GRANDPA_PALLET_NAME, + with_bridged_chain_messages_pallet_name: + bp_bridge_hub_wococo::WITH_BRIDGE_HUB_WOCOCO_MESSAGES_PALLET_NAME, + }, + }); + } +} diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs index 798c8267517..93b85dde9ed 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs @@ -16,20 +16,13 @@ use crate::{ BridgeParachainRococoInstance, ParachainInfo, Runtime, WithBridgeHubRococoMessagesInstance, - XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter, XcmRouter, -}; -use bp_messages::{ - source_chain::TargetHeaderChain, - target_chain::{ProvedMessages, SourceHeaderChain}, - InboundLaneData, LaneId, Message, MessageNonce, + XcmBlobHauler, XcmBlobHaulerAdapter, XcmRouter, }; +use bp_messages::{LaneId, MessageNonce}; use bp_runtime::ChainId; use bridge_runtime_common::{ messages, - messages::{ - target::FromBridgedChainMessagesProof, MessageBridge, ThisChainWithMessages, - UnderlyingChainProvider, - }, + messages::{MessageBridge, ThisChainWithMessages, UnderlyingChainProvider}, }; use frame_support::{parameter_types, RuntimeDebug}; use xcm::{ @@ -110,37 +103,6 @@ impl UnderlyingChainProvider for BridgeHubRococo { type Chain = bp_bridge_hub_rococo::BridgeHubRococo; } -impl SourceHeaderChain for BridgeHubRococo { - type Error = &'static str; - type MessagesProof = FromBridgedChainMessagesProof; - - fn verify_messages_proof( - proof: Self::MessagesProof, - messages_count: u32, - ) -> Result, Self::Error> { - bridge_runtime_common::messages::target::verify_messages_proof::< - WithBridgeHubRococoMessageBridge, - >(proof, messages_count) - .map_err(Into::into) - } -} - -impl TargetHeaderChain for BridgeHubRococo { - type Error = &'static str; - type MessagesDeliveryProof = - messages::source::FromBridgedChainMessagesDeliveryProof; - - fn verify_message(payload: &XcmAsPlainPayload) -> Result<(), Self::Error> { - messages::source::verify_chain_message::(payload) - } - - fn verify_messages_delivery_proof( - proof: Self::MessagesDeliveryProof, - ) -> Result<(LaneId, InboundLaneData), Self::Error> { - messages::source::verify_messages_delivery_proof::(proof) - } -} - impl messages::BridgedChainWithMessages for BridgeHubRococo { fn verify_dispatch_weight(_message_payload: &[u8]) -> bool { true @@ -172,3 +134,65 @@ impl ThisChainWithMessages for BridgeHubWococo { MessageNonce::MAX / 2 } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::BridgeGrandpaRococoInstance; + use bridge_runtime_common::{ + assert_complete_bridge_types, + integrity::{ + 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_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!( + runtime: Runtime, + with_bridged_chain_grandpa_instance: BridgeGrandpaRococoInstance, + with_bridged_chain_messages_instance: WithBridgeHubRococoMessagesInstance, + bridge: WithBridgeHubRococoMessageBridge, + this_chain: bp_wococo::Wococo, + bridged_chain: bp_rococo::Rococo, + ); + + assert_complete_bridge_constants::< + Runtime, + BridgeGrandpaRococoInstance, + WithBridgeHubRococoMessagesInstance, + WithBridgeHubRococoMessageBridge, + bp_wococo::Wococo, + >(AssertCompleteBridgeConstants { + this_chain_constants: AssertChainConstants { + block_length: bp_bridge_hub_wococo::BlockLength::get(), + block_weights: bp_bridge_hub_wococo::BlockWeights::get(), + }, + messages_pallet_constants: AssertBridgeMessagesPalletConstants { + max_unrewarded_relayers_in_bridged_confirmation_tx: + bp_bridge_hub_rococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, + max_unconfirmed_messages_in_bridged_confirmation_tx: + bp_bridge_hub_rococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, + bridged_chain_id: bp_runtime::BRIDGE_HUB_ROCOCO_CHAIN_ID, + }, + pallet_names: AssertBridgePalletNames { + with_this_chain_messages_pallet_name: + bp_bridge_hub_wococo::WITH_BRIDGE_HUB_WOCOCO_MESSAGES_PALLET_NAME, + with_bridged_chain_grandpa_pallet_name: bp_rococo::WITH_ROCOCO_GRANDPA_PALLET_NAME, + with_bridged_chain_messages_pallet_name: + bp_bridge_hub_rococo::WITH_BRIDGE_HUB_ROCOCO_MESSAGES_PALLET_NAME, + }, + }); + } +} diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index d18f25b4e19..6fd79614ba0 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -73,10 +73,14 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use crate::{ - bridge_hub_rococo_config::OnBridgeHubRococoBlobDispatcher, - bridge_hub_wococo_config::OnBridgeHubWococoBlobDispatcher, constants::fee::WeightToFee, + bridge_hub_rococo_config::{OnBridgeHubRococoBlobDispatcher, WithBridgeHubWococoMessageBridge}, + bridge_hub_wococo_config::{OnBridgeHubWococoBlobDispatcher, WithBridgeHubRococoMessageBridge}, + constants::fee::WeightToFee, xcm_config::XcmRouter, }; +use bridge_runtime_common::messages::{ + source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, +}; use parachains_common::{ opaque, AccountId, Balance, BlockNumber, Hash, Header, Index, Signature, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, @@ -469,12 +473,12 @@ impl pallet_bridge_messages::Config for Run // TODO:check-parameter - check delivery type DeliveryPayments = (); - type TargetHeaderChain = bridge_hub_rococo_config::BridgeHubWococo; + type TargetHeaderChain = TargetHeaderChainAdapter; type LaneMessageVerifier = bridge_hub_rococo_config::ToBridgeHubWococoMessageVerifier; // TODO:check-parameter - check delivery type DeliveryConfirmationPayments = (); - type SourceHeaderChain = bridge_hub_rococo_config::BridgeHubWococo; + type SourceHeaderChain = SourceHeaderChainAdapter; type MessageDispatch = XcmBlobMessageDispatch< bp_bridge_hub_wococo::BridgeHubWococo, bp_bridge_hub_rococo::BridgeHubRococo, @@ -503,12 +507,12 @@ impl pallet_bridge_messages::Config for Run // TODO:check-parameter - check delivery type DeliveryPayments = (); - type TargetHeaderChain = bridge_hub_wococo_config::BridgeHubRococo; + type TargetHeaderChain = TargetHeaderChainAdapter; type LaneMessageVerifier = bridge_hub_wococo_config::ToBridgeHubRococoMessageVerifier; // TODO:check-parameter - check delivery type DeliveryConfirmationPayments = (); - type SourceHeaderChain = bridge_hub_wococo_config::BridgeHubRococo; + type SourceHeaderChain = SourceHeaderChainAdapter; type MessageDispatch = XcmBlobMessageDispatch< bp_bridge_hub_rococo::BridgeHubRococo, bp_bridge_hub_wococo::BridgeHubWococo, @@ -972,3 +976,41 @@ cumulus_pallet_parachain_system::register_validate_block! { BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, CheckInherents = CheckInherents, } + +#[cfg(test)] +mod tests { + use super::*; + use bridge_runtime_common::integrity::check_additional_signed; + use codec::Encode; + use sp_runtime::generic::Era; + + #[test] + fn ensure_signed_extension_definition_is_correct() { + let payload: SignedExtra = ( + frame_system::CheckNonZeroSender::new(), + frame_system::CheckSpecVersion::new(), + frame_system::CheckTxVersion::new(), + frame_system::CheckGenesis::new(), + frame_system::CheckEra::from(Era::Immortal), + frame_system::CheckNonce::from(10), + frame_system::CheckWeight::new(), + pallet_transaction_payment::ChargeTransactionPayment::from(10), + BridgeRejectObsoleteHeadersAndMessages {}, + ); + + let bhr_indirect_payload = bp_bridge_hub_rococo::SignedExtension::new( + ((), (), (), (), Era::Immortal, 10.into(), (), 10.into(), ()), + None, + ); + assert_eq!(payload.encode(), bhr_indirect_payload.encode()); + + let bhw_indirect_payload = bp_bridge_hub_wococo::SignedExtension::new( + ((), (), (), (), Era::Immortal, 10.into(), (), 10.into(), ()), + None, + ); + assert_eq!(payload.encode(), bhw_indirect_payload.encode()); + + check_additional_signed::(); + check_additional_signed::(); + } +}