Skip to content

Commit

Permalink
Define SubstrateFinalityPipeline
Browse files Browse the repository at this point in the history
Extract basic parts of SubstrateFinalitySyncPipeline into
SubstrateFinalityPipeline
  • Loading branch information
serban300 committed Aug 9, 2023
1 parent 2f5d02e commit c79631c
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use async_trait::async_trait;
use relay_substrate_client::{AccountKeyPairOf, Client};
use substrate_relay_helper::{
finality::SubstrateFinalitySyncPipeline,
finality_base::engine::Grandpa as GrandpaFinalityEngine, TransactionParams,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
TransactionParams,
};

/// Description of Kusama -> PolkadotBridgeHub finalized headers bridge.
Expand All @@ -37,11 +38,15 @@ substrate_relay_helper::generate_submit_finality_proof_call_builder!(
);

#[async_trait]
impl SubstrateFinalitySyncPipeline for KusamaFinalityToBridgeHubPolkadot {
impl SubstrateFinalityPipeline for KusamaFinalityToBridgeHubPolkadot {
type SourceChain = relay_kusama_client::Kusama;
type TargetChain = relay_bridge_hub_polkadot_client::BridgeHubPolkadot;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
}

#[async_trait]
impl SubstrateFinalitySyncPipeline for KusamaFinalityToBridgeHubPolkadot {
type SubmitFinalityProofCallBuilder = KusamaFinalityToBridgeHubPolkadotCallBuilder;

async fn start_relay_guards(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use async_trait::async_trait;
use relay_substrate_client::{AccountKeyPairOf, Client};
use substrate_relay_helper::{
finality::SubstrateFinalitySyncPipeline,
finality_base::engine::Grandpa as GrandpaFinalityEngine, TransactionParams,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
TransactionParams,
};

/// Description of Polkadot -> KusamaBridgeHub finalized headers bridge.
Expand All @@ -37,11 +38,15 @@ substrate_relay_helper::generate_submit_finality_proof_call_builder!(
);

#[async_trait]
impl SubstrateFinalitySyncPipeline for PolkadotFinalityToBridgeHubKusama {
impl SubstrateFinalityPipeline for PolkadotFinalityToBridgeHubKusama {
type SourceChain = relay_polkadot_client::Polkadot;
type TargetChain = relay_bridge_hub_kusama_client::BridgeHubKusama;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
}

#[async_trait]
impl SubstrateFinalitySyncPipeline for PolkadotFinalityToBridgeHubKusama {
type SubmitFinalityProofCallBuilder = PolkadotFinalityToBridgeHubKusamaCallBuilder;

async fn start_relay_guards(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, RelayToRelayHeadersCliBridge};
use substrate_relay_helper::{
finality::{DirectSubmitGrandpaFinalityProofCallBuilder, SubstrateFinalitySyncPipeline},
finality_base::engine::Grandpa as GrandpaFinalityEngine,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

/// Description of Millau -> Rialto finalized headers bridge.
#[derive(Clone, Debug)]
pub struct MillauFinalityToRialto;

impl SubstrateFinalitySyncPipeline for MillauFinalityToRialto {
impl SubstrateFinalityPipeline for MillauFinalityToRialto {
type SourceChain = relay_millau_client::Millau;
type TargetChain = relay_rialto_client::Rialto;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
}

impl SubstrateFinalitySyncPipeline for MillauFinalityToRialto {
type SubmitFinalityProofCallBuilder = DirectSubmitGrandpaFinalityProofCallBuilder<
Self,
rialto_runtime::Runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, RelayToRelayHeadersCliBridge};
use substrate_relay_helper::{
finality::{DirectSubmitGrandpaFinalityProofCallBuilder, SubstrateFinalitySyncPipeline},
finality_base::engine::Grandpa as GrandpaFinalityEngine,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

/// Description of Millau -> Rialto finalized headers bridge.
#[derive(Clone, Debug)]
pub struct RialtoFinalityToMillau;

impl SubstrateFinalitySyncPipeline for RialtoFinalityToMillau {
impl SubstrateFinalityPipeline for RialtoFinalityToMillau {
type SourceChain = relay_rialto_client::Rialto;
type TargetChain = relay_millau_client::Millau;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
}

impl SubstrateFinalitySyncPipeline for RialtoFinalityToMillau {
type SubmitFinalityProofCallBuilder = DirectSubmitGrandpaFinalityProofCallBuilder<
Self,
millau_runtime::Runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, RelayToRelayHeadersCliBridge};
use substrate_relay_helper::{
finality::SubstrateFinalitySyncPipeline,
finality_base::engine::Grandpa as GrandpaFinalityEngine,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

substrate_relay_helper::generate_submit_finality_proof_call_builder!(
Expand All @@ -51,11 +51,14 @@ substrate_relay_helper::generate_submit_finality_proof_call_builder!(
#[derive(Clone, Debug)]
pub struct MillauFinalityToRialtoParachain;

impl SubstrateFinalitySyncPipeline for MillauFinalityToRialtoParachain {
impl SubstrateFinalityPipeline for MillauFinalityToRialtoParachain {
type SourceChain = relay_millau_client::Millau;
type TargetChain = relay_rialto_parachain_client::RialtoParachain;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
}

impl SubstrateFinalitySyncPipeline for MillauFinalityToRialtoParachain {
type SubmitFinalityProofCallBuilder = MillauFinalityToRialtoParachainCallBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use async_trait::async_trait;
use relay_substrate_client::{AccountKeyPairOf, Client};
use substrate_relay_helper::{
finality::SubstrateFinalitySyncPipeline,
finality_base::engine::Grandpa as GrandpaFinalityEngine, TransactionParams,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
TransactionParams,
};

/// Description of Rococo -> Wococo finalized headers bridge.
Expand All @@ -37,11 +38,15 @@ substrate_relay_helper::generate_submit_finality_proof_call_builder!(
);

#[async_trait]
impl SubstrateFinalitySyncPipeline for RococoFinalityToBridgeHubWococo {
impl SubstrateFinalityPipeline for RococoFinalityToBridgeHubWococo {
type SourceChain = relay_rococo_client::Rococo;
type TargetChain = relay_bridge_hub_wococo_client::BridgeHubWococo;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
}

#[async_trait]
impl SubstrateFinalitySyncPipeline for RococoFinalityToBridgeHubWococo {
type SubmitFinalityProofCallBuilder = RococoFinalityToBridgeHubWococoCallBuilder;

async fn start_relay_guards(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use async_trait::async_trait;
use relay_substrate_client::{AccountKeyPairOf, Client};
use substrate_relay_helper::{
finality::SubstrateFinalitySyncPipeline,
finality_base::engine::Grandpa as GrandpaFinalityEngine, TransactionParams,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
TransactionParams,
};

/// Description of Wococo -> Rococo finalized headers bridge.
Expand All @@ -37,11 +38,15 @@ substrate_relay_helper::generate_submit_finality_proof_call_builder!(
);

#[async_trait]
impl SubstrateFinalitySyncPipeline for WococoFinalityToBridgeHubRococo {
impl SubstrateFinalityPipeline for WococoFinalityToBridgeHubRococo {
type SourceChain = relay_wococo_client::Wococo;
type TargetChain = relay_bridge_hub_rococo_client::BridgeHubRococo;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
}

#[async_trait]
impl SubstrateFinalitySyncPipeline for WococoFinalityToBridgeHubRococo {
type SubmitFinalityProofCallBuilder = WococoFinalityToBridgeHubRococoCallBuilder;

async fn start_relay_guards(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@
use crate::cli::bridge::{CliBridgeBase, RelayToRelayHeadersCliBridge};
use substrate_relay_helper::{
finality::{DirectSubmitGrandpaFinalityProofCallBuilder, SubstrateFinalitySyncPipeline},
finality_base::engine::Grandpa as GrandpaFinalityEngine,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

/// Description of Westend -> Millau finalized headers bridge.
#[derive(Clone, Debug)]
pub struct WestendFinalityToMillau;

impl SubstrateFinalitySyncPipeline for WestendFinalityToMillau {
impl SubstrateFinalityPipeline for WestendFinalityToMillau {
type SourceChain = relay_westend_client::Westend;
type TargetChain = relay_millau_client::Millau;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
}

impl SubstrateFinalitySyncPipeline for WestendFinalityToMillau {
type SubmitFinalityProofCallBuilder = DirectSubmitGrandpaFinalityProofCallBuilder<
Self,
millau_runtime::Runtime,
Expand Down
23 changes: 9 additions & 14 deletions relays/lib-substrate-relay/src/finality/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ use crate::{
TransactionParams,
};

use crate::finality_base::engine::Engine;
use crate::finality_base::{engine::Engine, SubstrateFinalityPipeline};
use async_trait::async_trait;
use bp_header_chain::justification::GrandpaJustification;
use finality_relay::FinalitySyncPipeline;
use pallet_bridge_grandpa::{Call as BridgeGrandpaCall, Config as BridgeGrandpaConfig};
use relay_substrate_client::{
transaction_stall_timeout, AccountIdOf, AccountKeyPairOf, BlockNumberOf, CallOf, Chain,
ChainWithTransactions, Client, HashOf, HeaderOf, SyncHeader,
transaction_stall_timeout, AccountIdOf, AccountKeyPairOf, BlockNumberOf, CallOf, Chain, Client,
HashOf, HeaderOf, SyncHeader,
};
use relay_utils::metrics::MetricsParams;
use sp_core::Pair;
Expand All @@ -50,14 +50,9 @@ pub(crate) const RECENT_FINALITY_PROOFS_LIMIT: usize = 4096;

/// Substrate -> Substrate finality proofs synchronization pipeline.
#[async_trait]
pub trait SubstrateFinalitySyncPipeline: 'static + Clone + Debug + Send + Sync {
/// Headers of this chain are submitted to the `TargetChain`.
type SourceChain: Chain;
/// Headers of the `SourceChain` are submitted to this chain.
type TargetChain: ChainWithTransactions;

/// Finality engine.
type FinalityEngine: Engine<Self::SourceChain>;
pub trait SubstrateFinalitySyncPipeline:
'static + SubstrateFinalityPipeline + Clone + Debug + Send + Sync
{
/// How submit finality proof call is built?
type SubmitFinalityProofCallBuilder: SubmitFinalityProofCallBuilder<Self>;

Expand Down Expand Up @@ -143,16 +138,16 @@ macro_rules! generate_submit_finality_proof_call_builder {
fn build_submit_finality_proof_call(
header: relay_substrate_client::SyncHeader<
relay_substrate_client::HeaderOf<
<$pipeline as $crate::finality::SubstrateFinalitySyncPipeline>::SourceChain
<$pipeline as $crate::finality_base::SubstrateFinalityPipeline>::SourceChain
>
>,
proof: bp_header_chain::justification::GrandpaJustification<
relay_substrate_client::HeaderOf<
<$pipeline as $crate::finality::SubstrateFinalitySyncPipeline>::SourceChain
<$pipeline as $crate::finality_base::SubstrateFinalityPipeline>::SourceChain
>
>,
) -> relay_substrate_client::CallOf<
<$pipeline as $crate::finality::SubstrateFinalitySyncPipeline>::TargetChain
<$pipeline as $crate::finality_base::SubstrateFinalityPipeline>::TargetChain
> {
bp_runtime::paste::item! {
$bridge_grandpa($submit_finality_proof {
Expand Down
8 changes: 4 additions & 4 deletions relays/lib-substrate-relay/src/finality/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
finality_base::engine::Engine,
};

use crate::finality_base::SubstrateFinalityPipeline;
use async_std::sync::{Arc, Mutex};
use async_trait::async_trait;
use bp_header_chain::FinalityProof;
Expand All @@ -45,10 +46,9 @@ pub type SubstrateFinalityProofsStream<P> =
Pin<Box<dyn Stream<Item = SubstrateFinalityProof<P>> + Send>>;

/// Substrate finality proof. Specific to the used `FinalityEngine`.
pub type SubstrateFinalityProof<P> =
<<P as SubstrateFinalitySyncPipeline>::FinalityEngine as Engine<
<P as SubstrateFinalitySyncPipeline>::SourceChain,
>>::FinalityProof;
pub type SubstrateFinalityProof<P> = <<P as SubstrateFinalityPipeline>::FinalityEngine as Engine<
<P as SubstrateFinalityPipeline>::SourceChain,
>>::FinalityProof;

/// Substrate node as finality source.
pub struct SubstrateFinalitySource<P: SubstrateFinalitySyncPipeline, SourceClnt> {
Expand Down
15 changes: 15 additions & 0 deletions relays/lib-substrate-relay/src/finality_base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@
//! finality pipelines.
pub mod engine;

use async_trait::async_trait;
use relay_substrate_client::{Chain, ChainWithTransactions};
use std::fmt::Debug;

/// Substrate -> Substrate finality proofs synchronization pipeline.
#[async_trait]
pub trait SubstrateFinalityPipeline: 'static + Clone + Debug + Send + Sync {
/// Headers of this chain are submitted to the `TargetChain`.
type SourceChain: Chain;
/// Headers of the `SourceChain` are submitted to this chain.
type TargetChain: ChainWithTransactions;
/// Finality engine.
type FinalityEngine: engine::Engine<Self::SourceChain>;
}

0 comments on commit c79631c

Please sign in to comment.