Skip to content

Commit

Permalink
Millau -> Rialto messages relay (paritytech#399)
Browse files Browse the repository at this point in the history
* Millau messages -> Rialto relay

* prepare for custom race strategy of delivery race

* custom strategy for delivery race

* update TODOs

* add reference to issue 457

* impl reconnect

* clippy

* fix check in test

* fmt

* removed obsolete TODO

* fixed another TODOs

* fmt

* use MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE const from primitives

* Update relays/messages-relay/src/message_lane_loop.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* added SubstrateMessagesProof typedef

* fix test

* removed comment

* additional_proof_required -> ProofParameters

* typo

* multiline literal

* clippy

* fix typo

* and_then -> await

* update_source_latest_confirmed_nonce

* Update relays/messages-relay/src/message_race_delivery.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
  • Loading branch information
3 people authored and serban300 committed Apr 9, 2024
1 parent 173a362 commit 1104e1d
Show file tree
Hide file tree
Showing 27 changed files with 1,510 additions and 455 deletions.
2 changes: 1 addition & 1 deletion bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl pallet_shift_session_manager::Trait for Runtime {}

parameter_types! {
pub const MaxMessagesToPruneAtOnce: bp_message_lane::MessageNonce = 8;
pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce = 128;
pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce = bp_millau::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE;
}

impl pallet_message_lane::Trait for Runtime {
Expand Down
4 changes: 2 additions & 2 deletions bridges/bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use bp_message_lane::{
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce,
};
use bp_runtime::InstanceId;
use bp_runtime::{InstanceId, RIALTO_BRIDGE_INSTANCE};
use bridge_runtime_common::messages::{self, ChainWithMessageLanes, MessageBridge};
use frame_support::{
weights::{Weight, WeightToFeePolynomial},
Expand Down Expand Up @@ -75,7 +75,7 @@ pub type FromRialtoMessageDispatch = messages::target::FromBridgedChainMessageDi
pub struct WithRialtoMessageBridge;

impl MessageBridge for WithRialtoMessageBridge {
const INSTANCE: InstanceId = *b"rlto";
const INSTANCE: InstanceId = RIALTO_BRIDGE_INSTANCE;

const RELAYER_FEE_PERCENT: u32 = 10;

Expand Down
3 changes: 2 additions & 1 deletion bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_bridge_currency_exchange::Call as BridgeCurrencyExchangeCall;
pub use pallet_bridge_eth_poa::Call as BridgeEthPoACall;
pub use pallet_message_lane::Call as MessageLaneCall;
pub use pallet_substrate_bridge::Call as BridgeMillauCall;
pub use pallet_timestamp::Call as TimestampCall;

Expand Down Expand Up @@ -428,7 +429,7 @@ impl pallet_shift_session_manager::Trait for Runtime {}

parameter_types! {
pub const MaxMessagesToPruneAtOnce: bp_message_lane::MessageNonce = 8;
pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce = 128;
pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce = bp_rialto::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE;
}

impl pallet_message_lane::Trait for Runtime {
Expand Down
4 changes: 2 additions & 2 deletions bridges/bin/rialto/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use bp_message_lane::{
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce,
};
use bp_runtime::InstanceId;
use bp_runtime::{InstanceId, MILLAU_BRIDGE_INSTANCE};
use bridge_runtime_common::messages::{self, ChainWithMessageLanes, MessageBridge};
use frame_support::{
weights::{Weight, WeightToFeePolynomial},
Expand Down Expand Up @@ -78,7 +78,7 @@ type FromMillauMessagesProof = messages::target::FromBridgedChainMessagesProof<W
pub struct WithMillauMessageBridge;

impl MessageBridge for WithMillauMessageBridge {
const INSTANCE: InstanceId = *b"mlau";
const INSTANCE: InstanceId = MILLAU_BRIDGE_INSTANCE;

const RELAYER_FEE_PERCENT: u32 = 10;

Expand Down
2 changes: 2 additions & 0 deletions bridges/primitives/millau/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

# Bridge Dependencies

bp-message-lane = { path = "../message-lane", default-features = false }
bp-runtime = { path = "../runtime", default-features = false }

# Substrate Based Dependencies
Expand All @@ -23,6 +24,7 @@ sp-std = { version = "2.0", default-features = false }
[features]
default = ["std"]
std = [
"bp-message-lane/std",
"bp-runtime/std",
"frame-support/std",
"sp-api/std",
Expand Down
4 changes: 4 additions & 0 deletions bridges/primitives/millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// Runtime-generated DecodeLimit::decode_all_With_depth_limit
#![allow(clippy::unnecessary_mut_passed)]

use bp_message_lane::MessageNonce;
use bp_runtime::Chain;
use frame_support::{weights::Weight, RuntimeDebug};
use sp_core::Hasher as HasherT;
Expand All @@ -37,6 +38,9 @@ pub const AVAILABLE_BLOCK_RATIO: u32 = 75;
/// transactions minus 10% for initialization).
pub const MAXIMUM_EXTRINSIC_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT / 100 * (AVAILABLE_BLOCK_RATIO as Weight - 10);

/// Maximal number of unconfirmed messages at inbound lane.
pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 128;

/// Block number type used in Millau.
pub type BlockNumber = u32;

Expand Down
2 changes: 2 additions & 0 deletions bridges/primitives/rialto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

# Bridge Dependencies

bp-message-lane = { path = "../message-lane", default-features = false }
bp-runtime = { path = "../runtime", default-features = false }

# Substrate Based Dependencies
Expand All @@ -23,6 +24,7 @@ sp-std = { version = "2.0", default-features = false }
[features]
default = ["std"]
std = [
"bp-message-lane/std",
"bp-runtime/std",
"frame-support/std",
"sp-api/std",
Expand Down
4 changes: 4 additions & 0 deletions bridges/primitives/rialto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// Runtime-generated DecodeLimit::decode_all_With_depth_limit
#![allow(clippy::unnecessary_mut_passed)]

use bp_message_lane::MessageNonce;
use bp_runtime::Chain;
use frame_support::{weights::Weight, RuntimeDebug};
use sp_core::Hasher as HasherT;
Expand All @@ -37,6 +38,9 @@ pub const AVAILABLE_BLOCK_RATIO: u32 = 75;
/// transactions minus 10% for initialization).
pub const MAXIMUM_EXTRINSIC_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT / 100 * (AVAILABLE_BLOCK_RATIO as Weight - 10);

/// Maximal number of unconfirmed messages at inbound lane.
pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 128;

/// Block number type used in Rialto.
pub type BlockNumber = u32;

Expand Down
1 change: 1 addition & 0 deletions bridges/primitives/runtime/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub trait Chain: Send + Sync + 'static {
+ MaybeSerializeDeserialize
+ sp_std::hash::Hash
+ Copy
+ Default
+ MaybeDisplay
+ AtLeast32BitUnsigned
+ FromStr
Expand Down
8 changes: 5 additions & 3 deletions bridges/relays/messages-relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ mod metrics;

pub mod message_lane;
pub mod message_lane_loop;
pub mod message_race_delivery;
pub mod message_race_loop;
pub mod message_race_receiving;

mod message_race_delivery;
mod message_race_loop;
mod message_race_receiving;
mod message_race_strategy;
19 changes: 11 additions & 8 deletions bridges/relays/messages-relay/src/message_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,45 @@

use relay_utils::HeaderId;

use num_traits::{One, Zero};
use num_traits::{CheckedSub, One, Zero};
use std::fmt::Debug;

/// One-way message lane.
pub trait MessageLane {
pub trait MessageLane: Clone + Send + Sync {
/// Name of the messages source.
const SOURCE_NAME: &'static str;
/// Name of the messages target.
const TARGET_NAME: &'static str;

/// Message nonce type.
type MessageNonce: Clone
+ Send
+ Sync
+ Copy
+ Debug
+ Default
+ From<u32>
+ Into<u64>
+ Ord
+ CheckedSub
+ std::ops::Add<Output = Self::MessageNonce>
+ One
+ Zero;

/// Messages proof.
type MessagesProof: Clone;
type MessagesProof: Clone + Send + Sync;
/// Messages receiving proof.
type MessagesReceivingProof: Clone;
type MessagesReceivingProof: Clone + Send + Sync;

/// Number of the source header.
type SourceHeaderNumber: Clone + Debug + Default + Ord + PartialEq + Into<u64>;
type SourceHeaderNumber: Clone + Debug + Ord + PartialEq + Into<u64> + Send + Sync;
/// Hash of the source header.
type SourceHeaderHash: Clone + Debug + Default + PartialEq;
type SourceHeaderHash: Clone + Debug + Default + PartialEq + Send + Sync;

/// Number of the target header.
type TargetHeaderNumber: Clone + Debug + Default + Ord + PartialEq + Into<u64>;
type TargetHeaderNumber: Clone + Debug + Ord + PartialEq + Into<u64> + Send + Sync;
/// Hash of the target header.
type TargetHeaderHash: Clone + Debug + Default + PartialEq;
type TargetHeaderHash: Clone + Debug + Default + PartialEq + Send + Sync;
}

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

0 comments on commit 1104e1d

Please sign in to comment.