diff --git a/Cargo.lock b/Cargo.lock index db33c59f803c..301aca8a8d55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23882,7 +23882,6 @@ dependencies = [ "rbtag", "relay-substrate-client", "relay-utils", - "rustc-hex", "scale-info", "sp-consensus-grandpa", "sp-core 28.0.0", diff --git a/bridges/relays/lib-substrate-relay/Cargo.toml b/bridges/relays/lib-substrate-relay/Cargo.toml index 89115cfeee92..b0f93e5b5485 100644 --- a/bridges/relays/lib-substrate-relay/Cargo.toml +++ b/bridges/relays/lib-substrate-relay/Cargo.toml @@ -22,7 +22,6 @@ num-traits = { workspace = true, default-features = true } rbtag = { workspace = true } structopt = { workspace = true } strum = { features = ["derive"], workspace = true, default-features = true } -rustc-hex = { workspace = true } thiserror = { workspace = true } # Bridge dependencies diff --git a/bridges/relays/lib-substrate-relay/src/cli/bridge.rs b/bridges/relays/lib-substrate-relay/src/cli/bridge.rs index 2e15562f6c2e..9467813f86cc 100644 --- a/bridges/relays/lib-substrate-relay/src/cli/bridge.rs +++ b/bridges/relays/lib-substrate-relay/src/cli/bridge.rs @@ -23,12 +23,9 @@ use crate::{ parachains::SubstrateParachainsPipeline, }; use bp_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber}; -use codec::{Codec, EncodeLike}; -use messages_relay::Labeled; use relay_substrate_client::{ Chain, ChainWithRuntimeVersion, ChainWithTransactions, Parachain, RelayChain, }; -use std::fmt::Debug; /// Minimal bridge representation that can be used from the CLI. /// It connects a source chain to a target chain. @@ -102,22 +99,7 @@ where /// Bridge representation that can be used from the CLI for relaying messages. pub trait MessagesCliBridge: CliBridgeBase { /// The Source -> Destination messages synchronization pipeline. - type MessagesLane: SubstrateMessageLane< - SourceChain = Self::Source, - TargetChain = Self::Target, - LaneId = Self::LaneId, - >; - /// Lane identifier type. - type LaneId: Clone - + Copy - + Debug - + Codec - + EncodeLike - + Send - + Sync - + Labeled - + TryFrom> - + Default; + type MessagesLane: SubstrateMessageLane; /// Optional messages delivery transaction limits that the messages relay is going /// to use. If it returns `None`, limits are estimated using `TransactionPayment` API @@ -128,4 +110,5 @@ pub trait MessagesCliBridge: CliBridgeBase { } /// An alias for lane identifier type. -pub type MessagesLaneIdOf = ::LaneId; +pub type MessagesLaneIdOf = + <::MessagesLane as SubstrateMessageLane>::LaneId; diff --git a/bridges/relays/lib-substrate-relay/src/cli/relay_headers_and_messages/mod.rs b/bridges/relays/lib-substrate-relay/src/cli/relay_headers_and_messages/mod.rs index e875c53a2e7e..b9b68916e25e 100644 --- a/bridges/relays/lib-substrate-relay/src/cli/relay_headers_and_messages/mod.rs +++ b/bridges/relays/lib-substrate-relay/src/cli/relay_headers_and_messages/mod.rs @@ -31,7 +31,6 @@ pub mod relay_to_relay; pub mod relay_to_parachain; use async_trait::async_trait; -use codec::{Codec, EncodeLike}; use std::{fmt::Debug, marker::PhantomData, sync::Arc}; use structopt::StructOpt; @@ -47,7 +46,6 @@ use crate::{ HeadersToRelay, TaggedAccount, TransactionParams, }; use bp_runtime::BalanceOf; -use messages_relay::Labeled; use relay_substrate_client::{ AccountIdOf, AccountKeyPairOf, Chain, ChainWithBalances, ChainWithMessages, ChainWithRuntimeVersion, ChainWithTransactions, @@ -239,20 +237,9 @@ where + ChainWithRuntimeVersion; /// Left to Right bridge. - type L2R: MessagesCliBridge; + type L2R: MessagesCliBridge; /// Right to Left bridge - type R2L: MessagesCliBridge; - /// Lane identifier type. - type LaneId: Clone - + Copy - + Debug - + Codec - + EncodeLike - + Send - + Sync - + Labeled - + TryFrom> - + Default; + type R2L: MessagesCliBridge; /// Construct new bridge. fn new(params: ::Params) -> anyhow::Result; @@ -303,7 +290,7 @@ where self.mut_base().start_on_demand_headers_relayers().await?; // add balance-related metrics - let lanes: Vec = self + let lanes_l2r: Vec> = self .base() .common() .shared @@ -312,28 +299,46 @@ where .cloned() .map(HexLaneId::try_convert) .collect::, HexLaneId>>() - .expect(""); + .map_err(|e| { + anyhow::format_err!("Conversion failed for L2R lanes with error: {:?}!", e) + })?; + let lanes_r2l: Vec> = self + .base() + .common() + .shared + .lane + .iter() + .cloned() + .map(HexLaneId::try_convert) + .collect::, HexLaneId>>() + .map_err(|e| { + anyhow::format_err!("Conversion failed for R2L lanes with error: {:?}!", e) + })?; { let common = self.mut_base().mut_common(); crate::messages::metrics::add_relay_balances_metrics::< _, Self::Right, MessagesLaneIdOf, - >(common.left.client.clone(), &common.metrics_params, &common.left.accounts, &lanes) + >(common.left.client.clone(), &common.metrics_params, &common.left.accounts, &lanes_l2r) .await?; crate::messages::metrics::add_relay_balances_metrics::< _, Self::Left, MessagesLaneIdOf, >( - common.right.client.clone(), &common.metrics_params, &common.right.accounts, &lanes + common.right.client.clone(), + &common.metrics_params, + &common.right.accounts, + &lanes_r2l, ) .await?; } // Need 2x capacity since we consider both directions for each lane - let mut message_relays = Vec::with_capacity(lanes.len() * 2); - for lane in lanes { + let mut message_relays = + Vec::with_capacity(lanes_l2r.len().saturating_add(lanes_r2l.len()) * 2); + for lane in lanes_l2r { let left_to_right_messages = crate::messages::run::<::MessagesLane, _, _>( self.left_to_right().messages_relay_params( @@ -346,7 +351,8 @@ where .map_err(|e| anyhow::format_err!("{}", e)) .boxed(); message_relays.push(left_to_right_messages); - + } + for lane in lanes_r2l { let right_to_left_messages = crate::messages::run::<::MessagesLane, _, _>( self.right_to_left().messages_relay_params(