Skip to content

Commit

Permalink
Moved FromBridgedChainMessagesProof to bp-messages (#2170)
Browse files Browse the repository at this point in the history
* moved FromBridgedChainMessagesProof to bp-messages

* fmt
  • Loading branch information
svyatonik authored and bkontur committed May 15, 2024
1 parent e45e792 commit e9ad8a5
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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};
Expand Down
39 changes: 6 additions & 33 deletions bridges/bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@
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,
};
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.
Expand Down Expand Up @@ -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<BridgedHeaderHash> {
/// 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<BridgedHeaderHash> Size for FromBridgedChainMessagesProof<BridgedHeaderHash> {
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
Expand Down Expand Up @@ -342,7 +315,7 @@ pub mod target {
/// The `BridgeMessagesCall` used by a chain.
pub type BridgeMessagesCallOf<C> = bp_messages::BridgeMessagesCall<
bp_runtime::AccountIdOf<C>,
target::FromBridgedChainMessagesProof<bp_runtime::HashOf<C>>,
FromBridgedChainMessagesProof<bp_runtime::HashOf<C>>,
bp_messages::source_chain::FromBridgedChainMessagesDeliveryProof<bp_runtime::HashOf<C>>,
>;

Expand Down Expand Up @@ -400,7 +373,7 @@ mod tests {
encode_outbound_lane_data: impl Fn(&OutboundLaneData) -> Vec<u8>,
add_duplicate_key: bool,
add_unused_key: bool,
test: impl Fn(target::FromBridgedChainMessagesProof<H256>) -> R,
test: impl Fn(FromBridgedChainMessagesProof<H256>) -> R,
) -> R {
let (state_root, storage) = prepare_messages_storage_proof::<OnThisChainBridge>(
TEST_LANE_ID,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions bridges/bin/runtime-common/src/messages_benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions bridges/bin/runtime-common/src/messages_call_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -359,15 +359,15 @@ fn unrewarded_relayers_occupation<T: Config<I>, I: 'static>(
mod tests {
use super::*;
use crate::{
messages::target::FromBridgedChainMessagesProof,
messages_call_ext::MessagesCallSubType,
mock::{
DummyMessageDispatch, MaxUnconfirmedMessagesAtInboundLane,
MaxUnrewardedRelayerEntriesAtInboundLane, TestRuntime, ThisChainRuntimeCall,
},
};
use bp_messages::{
source_chain::FromBridgedChainMessagesDeliveryProof, DeliveredMessages, UnrewardedRelayer,
source_chain::FromBridgedChainMessagesDeliveryProof,
target_chain::FromBridgedChainMessagesProof, DeliveredMessages, UnrewardedRelayer,
UnrewardedRelayersState,
};
use sp_std::ops::RangeInclusive;
Expand Down
4 changes: 2 additions & 2 deletions bridges/bin/runtime-common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::messages::{
FromThisChainMaximalOutboundPayloadSize, FromThisChainMessagePayload,
TargetHeaderChainAdapter,
},
target::{FromBridgedChainMessagePayload, SourceHeaderChainAdapter},
target::SourceHeaderChainAdapter,
BridgedChainWithMessages, HashOf, MessageBridge, ThisChainWithMessages,
};

Expand Down Expand Up @@ -210,7 +210,7 @@ impl pallet_bridge_messages::Config for TestRuntime {
type MaximalOutboundPayloadSize = FromThisChainMaximalOutboundPayloadSize<OnThisChainBridge>;
type OutboundPayload = FromThisChainMessagePayload;

type InboundPayload = FromBridgedChainMessagePayload;
type InboundPayload = Vec<u8>;
type InboundRelayer = BridgedChainAccountId;
type DeliveryPayments = ();

Expand Down
34 changes: 33 additions & 1 deletion bridges/primitives/messages/src/target_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BridgedHeaderHash> {
/// 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<BridgedHeaderHash> Size for FromBridgedChainMessagesProof<BridgedHeaderHash> {
fn size(&self) -> u32 {
self.storage.size()
}
}

/// Proved messages from the source chain.
pub type ProvedMessages<Message> = BTreeMap<LaneId, ProvedLaneMessages<Message>>;

Expand Down
5 changes: 2 additions & 3 deletions bridges/relays/lib-substrate-relay/src/messages_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion bridges/relays/lib-substrate-relay/src/messages_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down

0 comments on commit e9ad8a5

Please sign in to comment.