Skip to content

Commit

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

* spelling

* fix benchmarks compilation
  • Loading branch information
svyatonik authored and bkontur committed May 10, 2024
1 parent 3553587 commit b62af6e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 48 deletions.
30 changes: 2 additions & 28 deletions bridges/bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<BridgedHeaderHash> {
/// 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<BridgedHeaderHash> Size for FromBridgedChainMessagesDeliveryProof<BridgedHeaderHash> {
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<B> =
(LaneId, InboundLaneData<AccountIdOf<ThisChain<B>>>);
Expand Down Expand Up @@ -369,7 +343,7 @@ pub mod target {
pub type BridgeMessagesCallOf<C> = bp_messages::BridgeMessagesCall<
bp_runtime::AccountIdOf<C>,
target::FromBridgedChainMessagesProof<bp_runtime::HashOf<C>>,
source::FromBridgedChainMessagesDeliveryProof<bp_runtime::HashOf<C>>,
bp_messages::source_chain::FromBridgedChainMessagesDeliveryProof<bp_runtime::HashOf<C>>,
>;

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions bridges/bin/runtime-common/src/messages_benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

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,
prepare_messages_storage_proof,
},
};

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;
Expand Down
16 changes: 9 additions & 7 deletions bridges/bin/runtime-common/src/messages_call_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -358,16 +359,17 @@ fn unrewarded_relayers_occupation<T: Config<I>, 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() {
Expand Down
38 changes: 35 additions & 3 deletions bridges/primitives/messages/src/source_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,50 @@

//! 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},
fmt::Debug,
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<BridgedHeaderHash> {
/// 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<BridgedHeaderHash> Size for FromBridgedChainMessagesDeliveryProof<BridgedHeaderHash> {
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<AccountId> = BTreeMap<AccountId, MessageNonce>;

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

0 comments on commit b62af6e

Please sign in to comment.