Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
888b09f
Add relayer strategy
fewensa Nov 2, 2021
48cd7dc
Add default relayer strategy
fewensa Nov 2, 2021
6da9a7c
default relayer strategy
fewensa Nov 3, 2021
35c29b4
expose relayer strategy
fewensa Nov 3, 2021
7eebf88
fix compile
fewensa Nov 3, 2021
3fa5e5c
fix compile
fewensa Nov 3, 2021
366afe2
docs
fewensa Nov 3, 2021
6d5ea56
Merge branch 'master' of https://github.com/paritytech/parity-bridges…
fewensa Nov 3, 2021
6b2573d
Rename Relayer to Relay, keep RelayerDecide
fewensa Nov 3, 2021
fda40eb
split `DefaultRelayerStrategy` into `AltruisticRelayerStrategy` and `…
fewensa Nov 4, 2021
25ba640
Remove relayer mode
fewensa Nov 4, 2021
6a416b5
Remove unused import
fewensa Nov 4, 2021
ff1e315
Rename `RelayerStrategy` to `RelayStrategy`
fewensa Nov 4, 2021
8451a3b
Add missing docs
fewensa Nov 4, 2021
2b16327
clippy
fewensa Nov 4, 2021
9818a69
clippy
fewensa Nov 4, 2021
5c9c452
clippy
fewensa Nov 4, 2021
7ac4640
clippy
fewensa Nov 4, 2021
994861e
Revert `relayer_mode` and add `MixStrategy`
fewensa Nov 4, 2021
82addf2
Add `EnforcementStrategy`
fewensa Nov 4, 2021
845ac79
fix bug and simplify relay strategy
fewensa Nov 4, 2021
60256e9
Update message_lane_loop.rs
fewensa Nov 5, 2021
c1f3372
Update messages_target.rs
fewensa Nov 5, 2021
f07637d
clippy
fewensa Nov 8, 2021
05bfce3
clippy
fewensa Nov 8, 2021
8b4ae56
clippy
fewensa Nov 8, 2021
5243b85
clippy
fewensa Nov 8, 2021
996dc73
clippy
fewensa Nov 8, 2021
7b5a843
clippy
fewensa Nov 8, 2021
d4d6178
clippy
fewensa Nov 9, 2021
46dbc16
fix test
fewensa Nov 9, 2021
eaa4a1f
fix test
fewensa Nov 9, 2021
ded45f0
test
fewensa Nov 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions relays/bin-substrate/src/chains/kusama_messages_to_polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_core::{Bytes, Pair};
use bp_messages::MessageNonce;
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
use frame_support::weights::Weight;
use messages_relay::message_lane::MessageLane;
use messages_relay::{message_lane::MessageLane, relayer_strategy::DefaultRelayerStrategy};
use relay_kusama_client::{
HeaderId as KusamaHeaderId, Kusama, SigningParams as KusamaSigningParams,
};
Expand All @@ -45,8 +45,13 @@ use substrate_relay_helper::{
};

/// Kusama-to-Polkadot message lane.
pub type MessageLaneKusamaMessagesToPolkadot =
SubstrateMessageLaneToSubstrate<Kusama, KusamaSigningParams, Polkadot, PolkadotSigningParams>;
pub type MessageLaneKusamaMessagesToPolkadot = SubstrateMessageLaneToSubstrate<
Kusama,
KusamaSigningParams,
Polkadot,
PolkadotSigningParams,
DefaultRelayerStrategy,
>;

#[derive(Clone)]
pub struct KusamaMessagesToPolkadot {
Expand Down Expand Up @@ -199,6 +204,7 @@ pub async fn run(
target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_kusama,
_marker: Default::default(),
},
};

Expand Down
12 changes: 9 additions & 3 deletions relays/bin-substrate/src/chains/millau_messages_to_rialto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sp_core::{Bytes, Pair};
use bp_messages::MessageNonce;
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
use frame_support::weights::Weight;
use messages_relay::message_lane::MessageLane;
use messages_relay::{message_lane::MessageLane, relayer_strategy::DefaultRelayerStrategy};
use relay_millau_client::{
HeaderId as MillauHeaderId, Millau, SigningParams as MillauSigningParams,
};
Expand All @@ -45,8 +45,13 @@ use substrate_relay_helper::{
};

/// Millau-to-Rialto message lane.
pub type MessageLaneMillauMessagesToRialto =
SubstrateMessageLaneToSubstrate<Millau, MillauSigningParams, Rialto, RialtoSigningParams>;
pub type MessageLaneMillauMessagesToRialto = SubstrateMessageLaneToSubstrate<
Millau,
MillauSigningParams,
Rialto,
RialtoSigningParams,
DefaultRelayerStrategy,
>;

#[derive(Clone)]
pub struct MillauMessagesToRialto {
Expand Down Expand Up @@ -196,6 +201,7 @@ pub async fn run(
target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_millau,
_marker: Default::default(),
},
};

Expand Down
12 changes: 9 additions & 3 deletions relays/bin-substrate/src/chains/polkadot_messages_to_kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_core::{Bytes, Pair};
use bp_messages::MessageNonce;
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
use frame_support::weights::Weight;
use messages_relay::message_lane::MessageLane;
use messages_relay::{message_lane::MessageLane, relayer_strategy::DefaultRelayerStrategy};
use relay_kusama_client::{
HeaderId as KusamaHeaderId, Kusama, SigningParams as KusamaSigningParams,
};
Expand All @@ -45,8 +45,13 @@ use substrate_relay_helper::{
};

/// Polkadot-to-Kusama message lane.
pub type MessageLanePolkadotMessagesToKusama =
SubstrateMessageLaneToSubstrate<Polkadot, PolkadotSigningParams, Kusama, KusamaSigningParams>;
pub type MessageLanePolkadotMessagesToKusama = SubstrateMessageLaneToSubstrate<
Polkadot,
PolkadotSigningParams,
Kusama,
KusamaSigningParams,
DefaultRelayerStrategy,
>;

#[derive(Clone)]
pub struct PolkadotMessagesToKusama {
Expand Down Expand Up @@ -198,6 +203,7 @@ pub async fn run(
target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_polkadot,
_marker: Default::default(),
},
};

Expand Down
12 changes: 9 additions & 3 deletions relays/bin-substrate/src/chains/rialto_messages_to_millau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sp_core::{Bytes, Pair};
use bp_messages::MessageNonce;
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
use frame_support::weights::Weight;
use messages_relay::message_lane::MessageLane;
use messages_relay::{message_lane::MessageLane, relayer_strategy::DefaultRelayerStrategy};
use relay_millau_client::{
HeaderId as MillauHeaderId, Millau, SigningParams as MillauSigningParams,
};
Expand All @@ -45,8 +45,13 @@ use substrate_relay_helper::{
};

/// Rialto-to-Millau message lane.
pub type MessageLaneRialtoMessagesToMillau =
SubstrateMessageLaneToSubstrate<Rialto, RialtoSigningParams, Millau, MillauSigningParams>;
pub type MessageLaneRialtoMessagesToMillau = SubstrateMessageLaneToSubstrate<
Rialto,
RialtoSigningParams,
Millau,
MillauSigningParams,
DefaultRelayerStrategy,
>;

#[derive(Clone)]
pub struct RialtoMessagesToMillau {
Expand Down Expand Up @@ -196,6 +201,7 @@ pub async fn run(
target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_rialto,
_marker: Default::default(),
},
};

Expand Down
12 changes: 9 additions & 3 deletions relays/bin-substrate/src/chains/rococo_messages_to_wococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_core::{Bytes, Pair};
use bp_messages::MessageNonce;
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
use frame_support::weights::Weight;
use messages_relay::message_lane::MessageLane;
use messages_relay::{message_lane::MessageLane, relayer_strategy::DefaultRelayerStrategy};
use relay_rococo_client::{
HeaderId as RococoHeaderId, Rococo, SigningParams as RococoSigningParams,
};
Expand All @@ -44,8 +44,13 @@ use substrate_relay_helper::{
};

/// Rococo-to-Wococo message lane.
pub type MessageLaneRococoMessagesToWococo =
SubstrateMessageLaneToSubstrate<Rococo, RococoSigningParams, Wococo, WococoSigningParams>;
pub type MessageLaneRococoMessagesToWococo = SubstrateMessageLaneToSubstrate<
Rococo,
RococoSigningParams,
Wococo,
WococoSigningParams,
DefaultRelayerStrategy,
>;

#[derive(Clone)]
pub struct RococoMessagesToWococo {
Expand Down Expand Up @@ -196,6 +201,7 @@ pub async fn run(
target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_rococo,
_marker: Default::default(),
},
};

Expand Down
12 changes: 9 additions & 3 deletions relays/bin-substrate/src/chains/wococo_messages_to_rococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_core::{Bytes, Pair};
use bp_messages::MessageNonce;
use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
use frame_support::weights::Weight;
use messages_relay::message_lane::MessageLane;
use messages_relay::{message_lane::MessageLane, relayer_strategy::DefaultRelayerStrategy};
use relay_rococo_client::{
HeaderId as RococoHeaderId, Rococo, SigningParams as RococoSigningParams,
};
Expand All @@ -44,8 +44,13 @@ use substrate_relay_helper::{
};

/// Wococo-to-Rococo message lane.
pub type MessageLaneWococoMessagesToRococo =
SubstrateMessageLaneToSubstrate<Wococo, WococoSigningParams, Rococo, RococoSigningParams>;
pub type MessageLaneWococoMessagesToRococo = SubstrateMessageLaneToSubstrate<
Wococo,
WococoSigningParams,
Rococo,
RococoSigningParams,
DefaultRelayerStrategy,
>;

#[derive(Clone)]
pub struct WococoMessagesToRococo {
Expand Down Expand Up @@ -195,6 +200,7 @@ pub async fn run(
target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_wococo,
_marker: Default::default(),
},
};

Expand Down
31 changes: 26 additions & 5 deletions relays/lib-substrate-relay/src/messages_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ use crate::{
messages_source::SubstrateMessagesProof, messages_target::SubstrateMessagesReceivingProof,
on_demand_headers::OnDemandHeadersRelay,
};
use std::marker::PhantomData;

use async_trait::async_trait;
use bp_messages::{LaneId, MessageNonce};
use bp_runtime::{AccountIdOf, IndexOf};
use frame_support::weights::Weight;
use messages_relay::message_lane::{MessageLane, SourceHeaderIdOf, TargetHeaderIdOf};
use messages_relay::{
message_lane::{MessageLane, SourceHeaderIdOf, TargetHeaderIdOf},
relayer_strategy::RelayerStrategy,
};
use relay_substrate_client::{
metrics::{FloatStorageValueMetric, StorageProofOverheadMetric},
BlockNumberOf, Chain, Client, HashOf,
Expand Down Expand Up @@ -145,6 +149,7 @@ pub struct SubstrateMessageLaneToSubstrate<
SourceSignParams,
Target: Chain,
TargetSignParams,
Strategy: RelayerStrategy,
> {
/// Client for the source Substrate chain.
pub source_client: Client<Source>,
Expand All @@ -160,10 +165,18 @@ pub struct SubstrateMessageLaneToSubstrate<
pub target_transactions_mortality: Option<u32>,
/// Account id of relayer at the source chain.
pub relayer_id_at_source: Source::AccountId,
/// marker
pub _marker: PhantomData<Strategy>,
}

impl<Source: Chain, SourceSignParams: Clone, Target: Chain, TargetSignParams: Clone> Clone
for SubstrateMessageLaneToSubstrate<Source, SourceSignParams, Target, TargetSignParams>
impl<
Source: Chain,
SourceSignParams: Clone,
Target: Chain,
TargetSignParams: Clone,
Strategy: RelayerStrategy,
> Clone
for SubstrateMessageLaneToSubstrate<Source, SourceSignParams, Target, TargetSignParams, Strategy>
{
fn clone(&self) -> Self {
Self {
Expand All @@ -174,12 +187,19 @@ impl<Source: Chain, SourceSignParams: Clone, Target: Chain, TargetSignParams: Cl
target_sign: self.target_sign.clone(),
target_transactions_mortality: self.target_transactions_mortality,
relayer_id_at_source: self.relayer_id_at_source.clone(),
_marker: self._marker.clone(),
}
}
}

impl<Source: Chain, SourceSignParams, Target: Chain, TargetSignParams> MessageLane
for SubstrateMessageLaneToSubstrate<Source, SourceSignParams, Target, TargetSignParams>
impl<
Source: Chain,
SourceSignParams,
Target: Chain,
TargetSignParams,
Strategy: RelayerStrategy,
> MessageLane
for SubstrateMessageLaneToSubstrate<Source, SourceSignParams, Target, TargetSignParams, Strategy>
where
SourceSignParams: Clone + Send + Sync + 'static,
TargetSignParams: Clone + Send + Sync + 'static,
Expand All @@ -198,6 +218,7 @@ where

type TargetHeaderNumber = BlockNumberOf<Target>;
type TargetHeaderHash = HashOf<Target>;
type RelayerStrategy = Strategy;
}

/// Returns maximal number of messages and their maximal cumulative dispatch weight, based
Expand Down
10 changes: 4 additions & 6 deletions relays/lib-substrate-relay/src/messages_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,8 @@ where
P::MESSAGE_PALLET_NAME_AT_TARGET,
&self.lane_id,
);
let proof = self
.client
.prove_storage(vec![inbound_data_key], id.1)
.await?
.iter_nodes()
.collect();
let proof =
self.client.prove_storage(vec![inbound_data_key], id.1).await?.iter_nodes().collect();
let proof = FromBridgedChainMessagesDeliveryProof {
bridged_header_hash: id.1,
storage_proof: proof,
Expand Down Expand Up @@ -437,6 +433,7 @@ fn compute_prepaid_messages_refund<P: SubstrateMessageLane>(
#[cfg(test)]
mod tests {
use super::*;
use messages_relay::relayer_strategy::DefaultRelayerStrategy;
use relay_rococo_client::{Rococo, SigningParams as RococoSigningParams};
use relay_wococo_client::{SigningParams as WococoSigningParams, Wococo};

Expand All @@ -449,6 +446,7 @@ mod tests {
RococoSigningParams,
Wococo,
WococoSigningParams,
DefaultRelayerStrategy,
>;

const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str = "";
Expand Down
1 change: 1 addition & 0 deletions relays/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod metrics;

pub mod message_lane;
pub mod message_lane_loop;
pub mod relayer_strategy;

mod message_race_delivery;
mod message_race_loop;
Expand Down
3 changes: 3 additions & 0 deletions relays/messages/src/message_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//! 1) relay new messages from source to target node;
//! 2) relay proof-of-delivery from target to source node.

use crate::relayer_strategy::RelayerStrategy;
use num_traits::{SaturatingAdd, Zero};
use relay_utils::{BlockNumberBase, HeaderId};
use std::{fmt::Debug, ops::Sub};
Expand Down Expand Up @@ -58,6 +59,8 @@ pub trait MessageLane: 'static + Clone + Send + Sync {
type TargetHeaderNumber: BlockNumberBase;
/// Hash of the target header.
type TargetHeaderHash: Clone + Debug + Default + PartialEq + Send + Sync;
/// Relayer strategy
type RelayerStrategy: RelayerStrategy;
}

/// Source header id within given one-way message lane.
Expand Down
Loading