diff --git a/bridges/bin/runtime-common/src/extensions/refund_relayer_extension.rs b/bridges/bin/runtime-common/src/extensions/refund_relayer_extension.rs index aab3280a3493..252bb202649b 100644 --- a/bridges/bin/runtime-common/src/extensions/refund_relayer_extension.rs +++ b/bridges/bin/runtime-common/src/extensions/refund_relayer_extension.rs @@ -935,9 +935,6 @@ where pub(crate) mod tests { use super::*; use crate::{ - messages::{ - source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, - }, messages_call_ext::{ BaseMessagesProofInfo, ReceiveMessagesDeliveryProofInfo, ReceiveMessagesProofInfo, UnrewardedRelayerOccupation, @@ -946,8 +943,10 @@ pub(crate) mod tests { }; use bp_header_chain::StoredHeaderDataBuilder; use bp_messages::{ - DeliveredMessages, InboundLaneData, MessageNonce, MessagesOperatingMode, OutboundLaneData, - UnrewardedRelayer, UnrewardedRelayersState, + source_chain::FromBridgedChainMessagesDeliveryProof, + target_chain::FromBridgedChainMessagesProof, DeliveredMessages, InboundLaneData, + MessageNonce, MessagesOperatingMode, OutboundLaneData, UnrewardedRelayer, + UnrewardedRelayersState, }; use bp_parachains::{BestParaHeadHash, ParaInfo}; use bp_polkadot_core::parachains::{ParaHeadsProof, ParaId}; diff --git a/bridges/bin/runtime-common/src/messages.rs b/bridges/bin/runtime-common/src/messages.rs index efc3de7ecb83..9f71d542937e 100644 --- a/bridges/bin/runtime-common/src/messages.rs +++ b/bridges/bin/runtime-common/src/messages.rs @@ -23,7 +23,9 @@ use bp_header_chain::HeaderChain; use bp_messages::{ source_chain::{FromBridgedChainMessagesDeliveryProof, TargetHeaderChain}, - target_chain::{ProvedLaneMessages, ProvedMessages, SourceHeaderChain}, + target_chain::{ + FromBridgedChainMessagesProof, ProvedLaneMessages, ProvedMessages, SourceHeaderChain, + }, InboundLaneData, LaneId, Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData, VerificationError, }; @@ -31,10 +33,7 @@ pub use bp_runtime::{ Chain, RangeInclusiveExt, RawStorageProof, Size, TrustedVecDb, UnderlyingChainOf, UnderlyingChainProvider, UntrustedVecDb, }; -use codec::{Decode, Encode}; use frame_support::{traits::Get, weights::Weight}; -use scale_info::TypeInfo; -use sp_runtime::RuntimeDebug; use sp_std::{marker::PhantomData, vec::Vec}; /// Bidirectional message bridge. @@ -190,32 +189,6 @@ pub mod target { /// Decoded Bridged -> This message payload. pub type FromBridgedChainMessagePayload = crate::messages_xcm_extension::XcmAsPlainPayload; - /// Messages proof from bridged chain: - /// - /// - hash of finalized header; - /// - storage proof of messages and (optionally) outbound lane state; - /// - lane id; - /// - nonces (inclusive range) of messages which are included in this proof. - #[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] - pub struct FromBridgedChainMessagesProof { - /// Hash of the finalized bridged header the proof is for. - pub bridged_header_hash: BridgedHeaderHash, - /// The proved storage containing the messages being delivered. - pub storage: UntrustedVecDb, - /// Messages in this proof are sent over this lane. - pub lane: LaneId, - /// Nonce of the first message being delivered. - pub nonces_start: MessageNonce, - /// Nonce of the last message being delivered. - pub nonces_end: MessageNonce, - } - - impl Size for FromBridgedChainMessagesProof { - fn size(&self) -> u32 { - self.storage.size() - } - } - /// Return maximal dispatch weight of the message we're able to receive. pub fn maximal_incoming_message_dispatch_weight(maximal_extrinsic_weight: Weight) -> Weight { maximal_extrinsic_weight / 2 @@ -342,7 +315,7 @@ pub mod target { /// The `BridgeMessagesCall` used by a chain. pub type BridgeMessagesCallOf = bp_messages::BridgeMessagesCall< bp_runtime::AccountIdOf, - target::FromBridgedChainMessagesProof>, + FromBridgedChainMessagesProof>, bp_messages::source_chain::FromBridgedChainMessagesDeliveryProof>, >; @@ -400,7 +373,7 @@ mod tests { encode_outbound_lane_data: impl Fn(&OutboundLaneData) -> Vec, add_duplicate_key: bool, add_unused_key: bool, - test: impl Fn(target::FromBridgedChainMessagesProof) -> R, + test: impl Fn(FromBridgedChainMessagesProof) -> R, ) -> R { let (state_root, storage) = prepare_messages_storage_proof::( TEST_LANE_ID, @@ -432,7 +405,7 @@ mod tests { bridged_header_hash, bridged_header.build(), ); - test(target::FromBridgedChainMessagesProof { + test(FromBridgedChainMessagesProof { bridged_header_hash, storage, lane: TEST_LANE_ID, diff --git a/bridges/bin/runtime-common/src/messages_benchmarking.rs b/bridges/bin/runtime-common/src/messages_benchmarking.rs index b28c47cac7ad..30614a21b9eb 100644 --- a/bridges/bin/runtime-common/src/messages_benchmarking.rs +++ b/bridges/bin/runtime-common/src/messages_benchmarking.rs @@ -20,17 +20,17 @@ #![cfg(feature = "runtime-benchmarks")] use crate::{ - messages::{ - target::FromBridgedChainMessagesProof, AccountIdOf, BridgedChain, HashOf, MessageBridge, - ThisChain, - }, + messages::{AccountIdOf, BridgedChain, HashOf, MessageBridge, ThisChain}, messages_generation::{ encode_all_messages, encode_lane_data, prepare_message_delivery_storage_proof, prepare_messages_storage_proof, }, }; -use bp_messages::{source_chain::FromBridgedChainMessagesDeliveryProof, MessagePayload}; +use bp_messages::{ + source_chain::FromBridgedChainMessagesDeliveryProof, + target_chain::FromBridgedChainMessagesProof, MessagePayload, +}; use bp_polkadot_core::parachains::ParaHash; use bp_runtime::{Chain, Parachain, StorageProofSize, UnderlyingChainOf}; use codec::Encode; diff --git a/bridges/bin/runtime-common/src/messages_call_ext.rs b/bridges/bin/runtime-common/src/messages_call_ext.rs index c16c4ca40f3a..aacf3190b78b 100644 --- a/bridges/bin/runtime-common/src/messages_call_ext.rs +++ b/bridges/bin/runtime-common/src/messages_call_ext.rs @@ -17,9 +17,9 @@ //! Signed extension for the `pallet-bridge-messages` that is able to reject obsolete //! (and some other invalid) transactions. -use crate::messages::target::FromBridgedChainMessagesProof; use bp_messages::{ - source_chain::FromBridgedChainMessagesDeliveryProof, target_chain::MessageDispatch, + source_chain::FromBridgedChainMessagesDeliveryProof, + target_chain::{FromBridgedChainMessagesProof, MessageDispatch}, InboundLaneData, LaneId, MessageNonce, }; use bp_runtime::OwnedBridgeModule; @@ -359,7 +359,6 @@ fn unrewarded_relayers_occupation, I: 'static>( mod tests { use super::*; use crate::{ - messages::target::FromBridgedChainMessagesProof, messages_call_ext::MessagesCallSubType, mock::{ DummyMessageDispatch, MaxUnconfirmedMessagesAtInboundLane, @@ -367,7 +366,8 @@ mod tests { }, }; use bp_messages::{ - source_chain::FromBridgedChainMessagesDeliveryProof, DeliveredMessages, UnrewardedRelayer, + source_chain::FromBridgedChainMessagesDeliveryProof, + target_chain::FromBridgedChainMessagesProof, DeliveredMessages, UnrewardedRelayer, UnrewardedRelayersState, }; use sp_std::ops::RangeInclusive; diff --git a/bridges/bin/runtime-common/src/mock.rs b/bridges/bin/runtime-common/src/mock.rs index 4d759a411686..b07efd3e8796 100644 --- a/bridges/bin/runtime-common/src/mock.rs +++ b/bridges/bin/runtime-common/src/mock.rs @@ -23,7 +23,7 @@ use crate::messages::{ FromThisChainMaximalOutboundPayloadSize, FromThisChainMessagePayload, TargetHeaderChainAdapter, }, - target::{FromBridgedChainMessagePayload, SourceHeaderChainAdapter}, + target::SourceHeaderChainAdapter, BridgedChainWithMessages, HashOf, MessageBridge, ThisChainWithMessages, }; @@ -210,7 +210,7 @@ impl pallet_bridge_messages::Config for TestRuntime { type MaximalOutboundPayloadSize = FromThisChainMaximalOutboundPayloadSize; type OutboundPayload = FromThisChainMessagePayload; - type InboundPayload = FromBridgedChainMessagePayload; + type InboundPayload = Vec; type InboundRelayer = BridgedChainAccountId; type DeliveryPayments = (); diff --git a/bridges/primitives/messages/src/target_chain.rs b/bridges/primitives/messages/src/target_chain.rs index 388ce16ccdc0..1178f4e44ce7 100644 --- a/bridges/primitives/messages/src/target_chain.rs +++ b/bridges/primitives/messages/src/target_chain.rs @@ -20,13 +20,45 @@ use crate::{ LaneId, Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData, VerificationError, }; -use bp_runtime::{messages::MessageDispatchResult, Size}; +use bp_runtime::{messages::MessageDispatchResult, Size, UntrustedVecDb}; use codec::{Decode, Encode, Error as CodecError}; use frame_support::{weights::Weight, Parameter}; use scale_info::TypeInfo; use sp_core::RuntimeDebug; use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, marker::PhantomData, prelude::*}; +/// Messages proof from bridged chain. +/// +/// It contains everything required to prove that bridged (source) chain has +/// sent us some messages: +/// +/// - hash of finalized header; +/// +/// - storage proof of messages and (optionally) outbound lane state; +/// +/// - lane id; +/// +/// - nonces (inclusive range) of messages which are included in this proof. +#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] +pub struct FromBridgedChainMessagesProof { + /// Hash of the finalized bridged header the proof is for. + pub bridged_header_hash: BridgedHeaderHash, + /// The proved storage containing the messages being delivered. + pub storage: UntrustedVecDb, + /// Messages in this proof are sent over this lane. + pub lane: LaneId, + /// Nonce of the first message being delivered. + pub nonces_start: MessageNonce, + /// Nonce of the last message being delivered. + pub nonces_end: MessageNonce, +} + +impl Size for FromBridgedChainMessagesProof { + fn size(&self) -> u32 { + self.storage.size() + } +} + /// Proved messages from the source chain. pub type ProvedMessages = BTreeMap>; diff --git a/bridges/relays/lib-substrate-relay/src/messages_lane.rs b/bridges/relays/lib-substrate-relay/src/messages_lane.rs index d02c55b818f4..c6b56508f81d 100644 --- a/bridges/relays/lib-substrate-relay/src/messages_lane.rs +++ b/bridges/relays/lib-substrate-relay/src/messages_lane.rs @@ -25,13 +25,12 @@ use crate::{ use async_std::sync::Arc; use bp_messages::{ - source_chain::FromBridgedChainMessagesDeliveryProof, ChainWithMessages as _, LaneId, - MessageNonce, + source_chain::FromBridgedChainMessagesDeliveryProof, + target_chain::FromBridgedChainMessagesProof, ChainWithMessages as _, LaneId, MessageNonce, }; use bp_runtime::{ AccountIdOf, Chain as _, EncodedOrDecodedCall, HeaderIdOf, TransactionEra, WeightExtraOps, }; -use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof; use codec::Encode; use frame_support::{dispatch::GetDispatchInfo, weights::Weight}; use messages_relay::{message_lane::MessageLane, message_lane_loop::BatchTransaction}; diff --git a/bridges/relays/lib-substrate-relay/src/messages_source.rs b/bridges/relays/lib-substrate-relay/src/messages_source.rs index b8f51cd5c932..8c2faf9fedaa 100644 --- a/bridges/relays/lib-substrate-relay/src/messages_source.rs +++ b/bridges/relays/lib-substrate-relay/src/messages_source.rs @@ -32,13 +32,13 @@ use async_std::sync::Arc; use async_trait::async_trait; use bp_messages::{ storage_keys::{operating_mode_key, outbound_lane_data_key}, + target_chain::FromBridgedChainMessagesProof, ChainWithMessages as _, InboundMessageDetails, LaneId, MessageNonce, MessagePayload, MessagesOperatingMode, OutboundLaneData, OutboundMessageDetails, }; use bp_runtime::{ BasicOperatingMode, HasherOf, HeaderIdProvider, RangeInclusiveExt, UntrustedVecDb, }; -use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof; use codec::Encode; use frame_support::weights::Weight; use messages_relay::{