Skip to content

Commit

Permalink
Separate folder for messages in relay lib (#2173)
Browse files Browse the repository at this point in the history
* moved message files to separate folder

* ...and fix paths in code

* fmt

rebase nit
  • Loading branch information
svyatonik authored and bkontur committed Jun 5, 2024
1 parent e4db138 commit a773338
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bridges/relays/lib-substrate-relay/src/cli/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::{
equivocation::SubstrateEquivocationDetectionPipeline,
finality::SubstrateFinalitySyncPipeline,
messages_lane::{MessagesRelayLimits, SubstrateMessageLane},
messages::{MessagesRelayLimits, SubstrateMessageLane},
parachains::SubstrateParachainsPipeline,
};
use pallet_bridge_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use futures::{FutureExt, TryFutureExt};

use crate::{
cli::{bridge::MessagesCliBridge, DefaultClient, HexLaneId, PrometheusParams},
messages_lane::{MessagesRelayLimits, MessagesRelayParams},
messages::{MessagesRelayLimits, MessagesRelayParams},
on_demand::OnDemandRelay,
HeadersToRelay, TaggedAccount, TransactionParams,
};
Expand Down Expand Up @@ -298,14 +298,14 @@ where
.collect::<Vec<_>>();
{
let common = self.mut_base().mut_common();
crate::messages_metrics::add_relay_balances_metrics::<_, Self::Right>(
crate::messages::metrics::add_relay_balances_metrics::<_, Self::Right>(
common.left.client.clone(),
&common.metrics_params,
&common.left.accounts,
&lanes,
)
.await?;
crate::messages_metrics::add_relay_balances_metrics::<_, Self::Left>(
crate::messages::metrics::add_relay_balances_metrics::<_, Self::Left>(
common.right.client.clone(),
&common.metrics_params,
&common.right.accounts,
Expand All @@ -318,7 +318,7 @@ where
let mut message_relays = Vec::with_capacity(lanes.len() * 2);
for lane in lanes {
let left_to_right_messages =
crate::messages_lane::run::<<Self::L2R as MessagesCliBridge>::MessagesLane, _, _>(
crate::messages::run::<<Self::L2R as MessagesCliBridge>::MessagesLane, _, _>(
self.left_to_right().messages_relay_params(
left_to_right_on_demand_headers.clone(),
right_to_left_on_demand_headers.clone(),
Expand All @@ -331,7 +331,7 @@ where
message_relays.push(left_to_right_messages);

let right_to_left_messages =
crate::messages_lane::run::<<Self::R2L as MessagesCliBridge>::MessagesLane, _, _>(
crate::messages::run::<<Self::R2L as MessagesCliBridge>::MessagesLane, _, _>(
self.right_to_left().messages_relay_params(
right_to_left_on_demand_headers.clone(),
left_to_right_on_demand_headers.clone(),
Expand Down
6 changes: 3 additions & 3 deletions bridges/relays/lib-substrate-relay/src/cli/relay_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use crate::{
cli::{bridge::*, chain_schema::*, HexLaneId, PrometheusParams},
messages_lane::MessagesRelayParams,
messages::MessagesRelayParams,
TransactionParams,
};

Expand Down Expand Up @@ -117,7 +117,7 @@ where
let target_sign = data.target_sign.to_keypair::<Self::Target>()?;
let target_transactions_mortality = data.target_sign.transactions_mortality()?;

crate::messages_lane::run::<Self::MessagesLane, _, _>(MessagesRelayParams {
crate::messages::run::<Self::MessagesLane, _, _>(MessagesRelayParams {
source_client,
source_transaction_params: TransactionParams {
signer: source_sign,
Expand Down Expand Up @@ -161,7 +161,7 @@ where
})?
.id();

crate::messages_lane::relay_messages_range::<Self::MessagesLane>(
crate::messages::relay_messages_range::<Self::MessagesLane>(
source_client,
target_client,
TransactionParams { signer: source_sign, mortality: source_transactions_mortality },
Expand Down
5 changes: 1 addition & 4 deletions bridges/relays/lib-substrate-relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ pub mod equivocation;
pub mod error;
pub mod finality;
pub mod finality_base;
pub mod messages_lane;
pub mod messages_metrics;
pub mod messages_source;
pub mod messages_target;
pub mod messages;
pub mod on_demand;
pub mod parachains;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
//! Tools for supporting message lanes between two Substrate-based chains.

use crate::{
messages_source::{SubstrateMessagesProof, SubstrateMessagesSource},
messages_target::{SubstrateMessagesDeliveryProof, SubstrateMessagesTarget},
messages::{
source::{SubstrateMessagesProof, SubstrateMessagesSource},
target::{SubstrateMessagesDeliveryProof, SubstrateMessagesTarget},
},
on_demand::OnDemandRelay,
BatchCallBuilder, BatchCallBuilderConstructor, TransactionParams,
};
Expand Down Expand Up @@ -48,6 +50,10 @@ use sp_core::Pair;
use sp_runtime::traits::Zero;
use std::{fmt::Debug, marker::PhantomData, ops::RangeInclusive};

pub mod metrics;
pub mod source;
pub mod target;

/// Substrate -> Substrate messages synchronization pipeline.
pub trait SubstrateMessageLane: 'static + Clone + Debug + Send + Sync {
/// Messages of this chain are relayed to the `TargetChain`.
Expand Down Expand Up @@ -432,21 +438,21 @@ macro_rules! generate_receive_message_proof_call_builder {
($pipeline:ident, $mocked_builder:ident, $bridge_messages:path, $receive_messages_proof:path) => {
pub struct $mocked_builder;

impl $crate::messages_lane::ReceiveMessagesProofCallBuilder<$pipeline>
impl $crate::messages::ReceiveMessagesProofCallBuilder<$pipeline>
for $mocked_builder
{
fn build_receive_messages_proof_call(
relayer_id_at_source: relay_substrate_client::AccountIdOf<
<$pipeline as $crate::messages_lane::SubstrateMessageLane>::SourceChain
<$pipeline as $crate::messages::SubstrateMessageLane>::SourceChain
>,
proof: $crate::messages_source::SubstrateMessagesProof<
<$pipeline as $crate::messages_lane::SubstrateMessageLane>::SourceChain
proof: $crate::messages::source::SubstrateMessagesProof<
<$pipeline as $crate::messages::SubstrateMessageLane>::SourceChain
>,
messages_count: u32,
dispatch_weight: bp_messages::Weight,
_trace_call: bool,
) -> relay_substrate_client::CallOf<
<$pipeline as $crate::messages_lane::SubstrateMessageLane>::TargetChain
<$pipeline as $crate::messages::SubstrateMessageLane>::TargetChain
> {
bp_runtime::paste::item! {
$bridge_messages($receive_messages_proof {
Expand Down Expand Up @@ -528,16 +534,16 @@ macro_rules! generate_receive_message_delivery_proof_call_builder {
($pipeline:ident, $mocked_builder:ident, $bridge_messages:path, $receive_messages_delivery_proof:path) => {
pub struct $mocked_builder;

impl $crate::messages_lane::ReceiveMessagesDeliveryProofCallBuilder<$pipeline>
impl $crate::messages::ReceiveMessagesDeliveryProofCallBuilder<$pipeline>
for $mocked_builder
{
fn build_receive_messages_delivery_proof_call(
proof: $crate::messages_target::SubstrateMessagesDeliveryProof<
<$pipeline as $crate::messages_lane::SubstrateMessageLane>::TargetChain
proof: $crate::messages::target::SubstrateMessagesDeliveryProof<
<$pipeline as $crate::messages::SubstrateMessageLane>::TargetChain
>,
_trace_call: bool,
) -> relay_substrate_client::CallOf<
<$pipeline as $crate::messages_lane::SubstrateMessageLane>::SourceChain
<$pipeline as $crate::messages::SubstrateMessageLane>::SourceChain
> {
bp_runtime::paste::item! {
$bridge_messages($receive_messages_delivery_proof {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use crate::{
finality_base::best_synced_header_id,
messages_lane::{
messages::{
BatchProofTransaction, MessageLaneAdapter, ReceiveMessagesDeliveryProofCallBuilder,
SubstrateMessageLane,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
//! `<BridgedName>` chain.

use crate::{
messages_lane::{
messages::{
source::{
ensure_messages_pallet_active, read_client_state_from_both_chains,
SubstrateMessagesProof,
},
BatchProofTransaction, MessageLaneAdapter, ReceiveMessagesProofCallBuilder,
SubstrateMessageLane,
},
messages_source::{
ensure_messages_pallet_active, read_client_state_from_both_chains, SubstrateMessagesProof,
},
on_demand::OnDemandRelay,
TransactionParams,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! On-demand Substrate -> Substrate parachain finality relay.

use crate::{
messages_source::best_finalized_peer_header_at_self,
messages::source::best_finalized_peer_header_at_self,
on_demand::OnDemandRelay,
parachains::{
source::ParachainsSource, target::ParachainsTarget, ParachainsPipelineAdapter,
Expand Down Expand Up @@ -681,7 +681,7 @@ impl<'a, P: SubstrateParachainsPipeline, SourceRelayClnt, TargetClnt>
async fn best_finalized_relay_block_at_target(
&self,
) -> Result<HeaderIdOf<P::SourceRelayChain>, SubstrateError> {
Ok(crate::messages_source::read_client_state::<P::TargetChain, P::SourceRelayChain>(
Ok(crate::messages::source::read_client_state::<P::TargetChain, P::SourceRelayChain>(
&self.0.target_client,
)
.await?
Expand Down

0 comments on commit a773338

Please sign in to comment.