diff --git a/bridges/bin/runtime-common/src/messages.rs b/bridges/bin/runtime-common/src/messages.rs index b86ab45fdeeaf..efc3de7ecb833 100644 --- a/bridges/bin/runtime-common/src/messages.rs +++ b/bridges/bin/runtime-common/src/messages.rs @@ -22,7 +22,7 @@ use bp_header_chain::HeaderChain; use bp_messages::{ - source_chain::TargetHeaderChain, + source_chain::{FromBridgedChainMessagesDeliveryProof, TargetHeaderChain}, target_chain::{ProvedLaneMessages, ProvedMessages, SourceHeaderChain}, InboundLaneData, LaneId, Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData, VerificationError, @@ -90,32 +90,6 @@ pub mod source { } } - /// Messages delivery proof from bridged chain: - /// - /// - hash of finalized header; - /// - storage proof of inbound lane state; - /// - lane id. - #[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] - pub struct FromBridgedChainMessagesDeliveryProof { - /// Hash of the bridge header the proof is for. - pub bridged_header_hash: BridgedHeaderHash, - /// Storage trie proof generated for [`Self::bridged_header_hash`]. - pub storage_proof: RawStorageProof, - /// Lane id of which messages were delivered and the proof is for. - pub lane: LaneId, - } - - impl Size for FromBridgedChainMessagesDeliveryProof { - fn size(&self) -> u32 { - u32::try_from( - self.storage_proof - .iter() - .fold(0usize, |sum, node| sum.saturating_add(node.len())), - ) - .unwrap_or(u32::MAX) - } - } - /// 'Parsed' message delivery proof - inbound lane id and its state. pub type ParsedMessagesDeliveryProofFromBridgedChain = (LaneId, InboundLaneData>>); @@ -369,7 +343,7 @@ pub mod target { pub type BridgeMessagesCallOf = bp_messages::BridgeMessagesCall< bp_runtime::AccountIdOf, target::FromBridgedChainMessagesProof>, - source::FromBridgedChainMessagesDeliveryProof>, + bp_messages::source_chain::FromBridgedChainMessagesDeliveryProof>, >; #[cfg(test)] diff --git a/bridges/bin/runtime-common/src/messages_benchmarking.rs b/bridges/bin/runtime-common/src/messages_benchmarking.rs index 5d92e9e68711e..c630386339c70 100644 --- a/bridges/bin/runtime-common/src/messages_benchmarking.rs +++ b/bridges/bin/runtime-common/src/messages_benchmarking.rs @@ -21,8 +21,8 @@ use crate::{ messages::{ - source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, - AccountIdOf, BridgedChain, HashOf, MessageBridge, ThisChain, + target::FromBridgedChainMessagesProof, AccountIdOf, BridgedChain, HashOf, MessageBridge, + ThisChain, }, messages_generation::{ encode_all_messages, encode_lane_data, prepare_message_delivery_storage_proof, @@ -30,7 +30,7 @@ use crate::{ }, }; -use bp_messages::MessagePayload; +use bp_messages::{source_chain::FromBridgedChainMessagesDeliveryProof, 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 a29e9b80a50d0..c16c4ca40f3a9 100644 --- a/bridges/bin/runtime-common/src/messages_call_ext.rs +++ b/bridges/bin/runtime-common/src/messages_call_ext.rs @@ -17,10 +17,11 @@ //! Signed extension for the `pallet-bridge-messages` that is able to reject obsolete //! (and some other invalid) transactions. -use crate::messages::{ - source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, +use crate::messages::target::FromBridgedChainMessagesProof; +use bp_messages::{ + source_chain::FromBridgedChainMessagesDeliveryProof, target_chain::MessageDispatch, + InboundLaneData, LaneId, MessageNonce, }; -use bp_messages::{target_chain::MessageDispatch, InboundLaneData, LaneId, MessageNonce}; use bp_runtime::OwnedBridgeModule; use frame_support::{ dispatch::CallableCallFor, @@ -358,16 +359,17 @@ fn unrewarded_relayers_occupation, I: 'static>( mod tests { use super::*; use crate::{ - messages::{ - source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, - }, + messages::target::FromBridgedChainMessagesProof, messages_call_ext::MessagesCallSubType, mock::{ DummyMessageDispatch, MaxUnconfirmedMessagesAtInboundLane, MaxUnrewardedRelayerEntriesAtInboundLane, TestRuntime, ThisChainRuntimeCall, }, }; - use bp_messages::{DeliveredMessages, UnrewardedRelayer, UnrewardedRelayersState}; + use bp_messages::{ + source_chain::FromBridgedChainMessagesDeliveryProof, DeliveredMessages, UnrewardedRelayer, + UnrewardedRelayersState, + }; use sp_std::ops::RangeInclusive; fn fill_unrewarded_relayers() { diff --git a/bridges/primitives/messages/src/source_chain.rs b/bridges/primitives/messages/src/source_chain.rs index f4aefd9735583..eb2e14159abcf 100644 --- a/bridges/primitives/messages/src/source_chain.rs +++ b/bridges/primitives/messages/src/source_chain.rs @@ -16,11 +16,12 @@ //! Primitives of messages module, that are used on the source chain. -use crate::{InboundLaneData, LaneId, MessageNonce, VerificationError}; +use crate::{InboundLaneData, LaneId, MessageNonce, UnrewardedRelayer, VerificationError}; -use crate::UnrewardedRelayer; -use bp_runtime::Size; +use bp_runtime::{RawStorageProof, Size}; +use codec::{Decode, Encode}; use frame_support::Parameter; +use scale_info::TypeInfo; use sp_core::RuntimeDebug; use sp_std::{ collections::{btree_map::BTreeMap, vec_deque::VecDeque}, @@ -28,6 +29,37 @@ use sp_std::{ ops::RangeInclusive, }; +/// Messages delivery proof from the bridged chain. +/// +/// It contains everything required to prove that our (this chain) messages have been +/// delivered to the bridged (target) chain: +/// +/// - hash of finalized header; +/// +/// - storage proof of the inbound lane state; +/// +/// - lane id. +#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)] +pub struct FromBridgedChainMessagesDeliveryProof { + /// Hash of the bridge header the proof is for. + pub bridged_header_hash: BridgedHeaderHash, + /// Storage trie proof generated for [`Self::bridged_header_hash`]. + pub storage_proof: RawStorageProof, + /// Lane id of which messages were delivered and the proof is for. + pub lane: LaneId, +} + +impl Size for FromBridgedChainMessagesDeliveryProof { + fn size(&self) -> u32 { + u32::try_from( + self.storage_proof + .iter() + .fold(0usize, |sum, node| sum.saturating_add(node.len())), + ) + .unwrap_or(u32::MAX) + } +} + /// Number of messages, delivered by relayers. pub type RelayersRewards = BTreeMap; diff --git a/bridges/relays/lib-substrate-relay/src/messages_lane.rs b/bridges/relays/lib-substrate-relay/src/messages_lane.rs index 909fa6b148a25..f34cc446939d0 100644 --- a/bridges/relays/lib-substrate-relay/src/messages_lane.rs +++ b/bridges/relays/lib-substrate-relay/src/messages_lane.rs @@ -24,13 +24,14 @@ use crate::{ }; use async_std::sync::Arc; -use bp_messages::{ChainWithMessages as _, LaneId, MessageNonce}; +use bp_messages::{ + source_chain::FromBridgedChainMessagesDeliveryProof, ChainWithMessages as _, LaneId, + MessageNonce, +}; use bp_runtime::{ AccountIdOf, Chain as _, EncodedOrDecodedCall, HeaderIdOf, TransactionEra, WeightExtraOps, }; -use bridge_runtime_common::messages::{ - source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, -}; +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_target.rs b/bridges/relays/lib-substrate-relay/src/messages_target.rs index e1c7645eac683..c8dab7fe90b94 100644 --- a/bridges/relays/lib-substrate-relay/src/messages_target.rs +++ b/bridges/relays/lib-substrate-relay/src/messages_target.rs @@ -33,10 +33,9 @@ use crate::{ use async_std::sync::Arc; use async_trait::async_trait; use bp_messages::{ - storage_keys::inbound_lane_data_key, ChainWithMessages as _, InboundLaneData, LaneId, - MessageNonce, UnrewardedRelayersState, + source_chain::FromBridgedChainMessagesDeliveryProof, storage_keys::inbound_lane_data_key, + ChainWithMessages as _, InboundLaneData, LaneId, MessageNonce, UnrewardedRelayersState, }; -use bridge_runtime_common::messages::source::FromBridgedChainMessagesDeliveryProof; use messages_relay::{ message_lane::{MessageLane, SourceHeaderIdOf, TargetHeaderIdOf}, message_lane_loop::{NoncesSubmitArtifacts, TargetClient, TargetClientState},