Skip to content

Commit bcc6c89

Browse files
svyatonikbkontur
authored andcommitted
Moved FromBridgedChainMessagesProof to bp-messages (#2170)
* moved FromBridgedChainMessagesProof to bp-messages * fmt
1 parent bf7b275 commit bcc6c89

File tree

8 files changed

+57
-54
lines changed

8 files changed

+57
-54
lines changed

bridges/bin/runtime-common/src/extensions/refund_relayer_extension.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,6 @@ where
935935
pub(crate) mod tests {
936936
use super::*;
937937
use crate::{
938-
messages::{
939-
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
940-
},
941938
messages_call_ext::{
942939
BaseMessagesProofInfo, ReceiveMessagesDeliveryProofInfo, ReceiveMessagesProofInfo,
943940
UnrewardedRelayerOccupation,
@@ -946,8 +943,10 @@ pub(crate) mod tests {
946943
};
947944
use bp_header_chain::StoredHeaderDataBuilder;
948945
use bp_messages::{
949-
DeliveredMessages, InboundLaneData, MessageNonce, MessagesOperatingMode, OutboundLaneData,
950-
UnrewardedRelayer, UnrewardedRelayersState,
946+
source_chain::FromBridgedChainMessagesDeliveryProof,
947+
target_chain::FromBridgedChainMessagesProof, DeliveredMessages, InboundLaneData,
948+
MessageNonce, MessagesOperatingMode, OutboundLaneData, UnrewardedRelayer,
949+
UnrewardedRelayersState,
951950
};
952951
use bp_parachains::{BestParaHeadHash, ParaInfo};
953952
use bp_polkadot_core::parachains::{ParaHeadsProof, ParaId};

bridges/bin/runtime-common/src/messages.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@
2323
use bp_header_chain::HeaderChain;
2424
use bp_messages::{
2525
source_chain::{FromBridgedChainMessagesDeliveryProof, TargetHeaderChain},
26-
target_chain::{ProvedLaneMessages, ProvedMessages, SourceHeaderChain},
26+
target_chain::{
27+
FromBridgedChainMessagesProof, ProvedLaneMessages, ProvedMessages, SourceHeaderChain,
28+
},
2729
InboundLaneData, LaneId, Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData,
2830
VerificationError,
2931
};
3032
pub use bp_runtime::{
3133
Chain, RangeInclusiveExt, RawStorageProof, Size, TrustedVecDb, UnderlyingChainOf,
3234
UnderlyingChainProvider, UntrustedVecDb,
3335
};
34-
use codec::{Decode, Encode};
3536
use frame_support::{traits::Get, weights::Weight};
36-
use scale_info::TypeInfo;
37-
use sp_runtime::RuntimeDebug;
3837
use sp_std::{marker::PhantomData, vec::Vec};
3938

4039
/// Bidirectional message bridge.
@@ -190,32 +189,6 @@ pub mod target {
190189
/// Decoded Bridged -> This message payload.
191190
pub type FromBridgedChainMessagePayload = crate::messages_xcm_extension::XcmAsPlainPayload;
192191

193-
/// Messages proof from bridged chain:
194-
///
195-
/// - hash of finalized header;
196-
/// - storage proof of messages and (optionally) outbound lane state;
197-
/// - lane id;
198-
/// - nonces (inclusive range) of messages which are included in this proof.
199-
#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
200-
pub struct FromBridgedChainMessagesProof<BridgedHeaderHash> {
201-
/// Hash of the finalized bridged header the proof is for.
202-
pub bridged_header_hash: BridgedHeaderHash,
203-
/// The proved storage containing the messages being delivered.
204-
pub storage: UntrustedVecDb,
205-
/// Messages in this proof are sent over this lane.
206-
pub lane: LaneId,
207-
/// Nonce of the first message being delivered.
208-
pub nonces_start: MessageNonce,
209-
/// Nonce of the last message being delivered.
210-
pub nonces_end: MessageNonce,
211-
}
212-
213-
impl<BridgedHeaderHash> Size for FromBridgedChainMessagesProof<BridgedHeaderHash> {
214-
fn size(&self) -> u32 {
215-
self.storage.size()
216-
}
217-
}
218-
219192
/// Return maximal dispatch weight of the message we're able to receive.
220193
pub fn maximal_incoming_message_dispatch_weight(maximal_extrinsic_weight: Weight) -> Weight {
221194
maximal_extrinsic_weight / 2
@@ -342,7 +315,7 @@ pub mod target {
342315
/// The `BridgeMessagesCall` used by a chain.
343316
pub type BridgeMessagesCallOf<C> = bp_messages::BridgeMessagesCall<
344317
bp_runtime::AccountIdOf<C>,
345-
target::FromBridgedChainMessagesProof<bp_runtime::HashOf<C>>,
318+
FromBridgedChainMessagesProof<bp_runtime::HashOf<C>>,
346319
bp_messages::source_chain::FromBridgedChainMessagesDeliveryProof<bp_runtime::HashOf<C>>,
347320
>;
348321

@@ -400,7 +373,7 @@ mod tests {
400373
encode_outbound_lane_data: impl Fn(&OutboundLaneData) -> Vec<u8>,
401374
add_duplicate_key: bool,
402375
add_unused_key: bool,
403-
test: impl Fn(target::FromBridgedChainMessagesProof<H256>) -> R,
376+
test: impl Fn(FromBridgedChainMessagesProof<H256>) -> R,
404377
) -> R {
405378
let (state_root, storage) = prepare_messages_storage_proof::<OnThisChainBridge>(
406379
TEST_LANE_ID,
@@ -432,7 +405,7 @@ mod tests {
432405
bridged_header_hash,
433406
bridged_header.build(),
434407
);
435-
test(target::FromBridgedChainMessagesProof {
408+
test(FromBridgedChainMessagesProof {
436409
bridged_header_hash,
437410
storage,
438411
lane: TEST_LANE_ID,

bridges/bin/runtime-common/src/messages_benchmarking.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
#![cfg(feature = "runtime-benchmarks")]
2121

2222
use crate::{
23-
messages::{
24-
target::FromBridgedChainMessagesProof, AccountIdOf, BridgedChain, HashOf, MessageBridge,
25-
ThisChain,
26-
},
23+
messages::{AccountIdOf, BridgedChain, HashOf, MessageBridge, ThisChain},
2724
messages_generation::{
2825
encode_all_messages, encode_lane_data, prepare_message_delivery_storage_proof,
2926
prepare_messages_storage_proof,
3027
},
3128
};
3229

33-
use bp_messages::{source_chain::FromBridgedChainMessagesDeliveryProof, MessagePayload};
30+
use bp_messages::{
31+
source_chain::FromBridgedChainMessagesDeliveryProof,
32+
target_chain::FromBridgedChainMessagesProof, MessagePayload,
33+
};
3434
use bp_polkadot_core::parachains::ParaHash;
3535
use bp_runtime::{Chain, Parachain, StorageProofSize, UnderlyingChainOf};
3636
use codec::Encode;

bridges/bin/runtime-common/src/messages_call_ext.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
//! Signed extension for the `pallet-bridge-messages` that is able to reject obsolete
1818
//! (and some other invalid) transactions.
1919
20-
use crate::messages::target::FromBridgedChainMessagesProof;
2120
use bp_messages::{
22-
source_chain::FromBridgedChainMessagesDeliveryProof, target_chain::MessageDispatch,
21+
source_chain::FromBridgedChainMessagesDeliveryProof,
22+
target_chain::{FromBridgedChainMessagesProof, MessageDispatch},
2323
InboundLaneData, LaneId, MessageNonce,
2424
};
2525
use bp_runtime::OwnedBridgeModule;
@@ -359,15 +359,15 @@ fn unrewarded_relayers_occupation<T: Config<I>, I: 'static>(
359359
mod tests {
360360
use super::*;
361361
use crate::{
362-
messages::target::FromBridgedChainMessagesProof,
363362
messages_call_ext::MessagesCallSubType,
364363
mock::{
365364
DummyMessageDispatch, MaxUnconfirmedMessagesAtInboundLane,
366365
MaxUnrewardedRelayerEntriesAtInboundLane, TestRuntime, ThisChainRuntimeCall,
367366
},
368367
};
369368
use bp_messages::{
370-
source_chain::FromBridgedChainMessagesDeliveryProof, DeliveredMessages, UnrewardedRelayer,
369+
source_chain::FromBridgedChainMessagesDeliveryProof,
370+
target_chain::FromBridgedChainMessagesProof, DeliveredMessages, UnrewardedRelayer,
371371
UnrewardedRelayersState,
372372
};
373373
use sp_std::ops::RangeInclusive;

bridges/bin/runtime-common/src/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::messages::{
2323
FromThisChainMaximalOutboundPayloadSize, FromThisChainMessagePayload,
2424
TargetHeaderChainAdapter,
2525
},
26-
target::{FromBridgedChainMessagePayload, SourceHeaderChainAdapter},
26+
target::SourceHeaderChainAdapter,
2727
BridgedChainWithMessages, HashOf, MessageBridge, ThisChainWithMessages,
2828
};
2929

@@ -210,7 +210,7 @@ impl pallet_bridge_messages::Config for TestRuntime {
210210
type MaximalOutboundPayloadSize = FromThisChainMaximalOutboundPayloadSize<OnThisChainBridge>;
211211
type OutboundPayload = FromThisChainMessagePayload;
212212

213-
type InboundPayload = FromBridgedChainMessagePayload;
213+
type InboundPayload = Vec<u8>;
214214
type InboundRelayer = BridgedChainAccountId;
215215
type DeliveryPayments = ();
216216

bridges/primitives/messages/src/target_chain.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,45 @@ use crate::{
2020
LaneId, Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData, VerificationError,
2121
};
2222

23-
use bp_runtime::{messages::MessageDispatchResult, Size};
23+
use bp_runtime::{messages::MessageDispatchResult, Size, UntrustedVecDb};
2424
use codec::{Decode, Encode, Error as CodecError};
2525
use frame_support::{weights::Weight, Parameter};
2626
use scale_info::TypeInfo;
2727
use sp_core::RuntimeDebug;
2828
use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, marker::PhantomData, prelude::*};
2929

30+
/// Messages proof from bridged chain.
31+
///
32+
/// It contains everything required to prove that bridged (source) chain has
33+
/// sent us some messages:
34+
///
35+
/// - hash of finalized header;
36+
///
37+
/// - storage proof of messages and (optionally) outbound lane state;
38+
///
39+
/// - lane id;
40+
///
41+
/// - nonces (inclusive range) of messages which are included in this proof.
42+
#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
43+
pub struct FromBridgedChainMessagesProof<BridgedHeaderHash> {
44+
/// Hash of the finalized bridged header the proof is for.
45+
pub bridged_header_hash: BridgedHeaderHash,
46+
/// The proved storage containing the messages being delivered.
47+
pub storage: UntrustedVecDb,
48+
/// Messages in this proof are sent over this lane.
49+
pub lane: LaneId,
50+
/// Nonce of the first message being delivered.
51+
pub nonces_start: MessageNonce,
52+
/// Nonce of the last message being delivered.
53+
pub nonces_end: MessageNonce,
54+
}
55+
56+
impl<BridgedHeaderHash> Size for FromBridgedChainMessagesProof<BridgedHeaderHash> {
57+
fn size(&self) -> u32 {
58+
self.storage.size()
59+
}
60+
}
61+
3062
/// Proved messages from the source chain.
3163
pub type ProvedMessages<Message> = BTreeMap<LaneId, ProvedLaneMessages<Message>>;
3264

bridges/relays/lib-substrate-relay/src/messages_lane.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ use crate::{
2525

2626
use async_std::sync::Arc;
2727
use bp_messages::{
28-
source_chain::FromBridgedChainMessagesDeliveryProof, ChainWithMessages as _, LaneId,
29-
MessageNonce,
28+
source_chain::FromBridgedChainMessagesDeliveryProof,
29+
target_chain::FromBridgedChainMessagesProof, ChainWithMessages as _, LaneId, MessageNonce,
3030
};
3131
use bp_runtime::{
3232
AccountIdOf, Chain as _, EncodedOrDecodedCall, HeaderIdOf, TransactionEra, WeightExtraOps,
3333
};
34-
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
3534
use codec::Encode;
3635
use frame_support::{dispatch::GetDispatchInfo, weights::Weight};
3736
use messages_relay::{message_lane::MessageLane, message_lane_loop::BatchTransaction};

bridges/relays/lib-substrate-relay/src/messages_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ use async_std::sync::Arc;
3232
use async_trait::async_trait;
3333
use bp_messages::{
3434
storage_keys::{operating_mode_key, outbound_lane_data_key},
35+
target_chain::FromBridgedChainMessagesProof,
3536
ChainWithMessages as _, InboundMessageDetails, LaneId, MessageNonce, MessagePayload,
3637
MessagesOperatingMode, OutboundLaneData, OutboundMessageDetails,
3738
};
3839
use bp_runtime::{
3940
BasicOperatingMode, HasherOf, HeaderIdProvider, RangeInclusiveExt, UntrustedVecDb,
4041
};
41-
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
4242
use codec::Encode;
4343
use frame_support::weights::Weight;
4444
use messages_relay::{

0 commit comments

Comments
 (0)