From c79631cd95bccd926498f89b5375eb5349fccb73 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 9 Aug 2023 16:57:37 +0300 Subject: [PATCH] Define SubstrateFinalityPipeline Extract basic parts of SubstrateFinalitySyncPipeline into SubstrateFinalityPipeline --- .../kusama_headers_to_bridge_hub_polkadot.rs | 9 ++++++-- .../polkadot_headers_to_bridge_hub_kusama.rs | 9 ++++++-- .../rialto_millau/millau_headers_to_rialto.rs | 7 ++++-- .../rialto_millau/rialto_headers_to_millau.rs | 7 ++++-- .../millau_headers_to_rialto_parachain.rs | 7 ++++-- .../rococo_headers_to_bridge_hub_wococo.rs | 9 ++++++-- .../wococo_headers_to_bridge_hub_rococo.rs | 9 ++++++-- .../westend_headers_to_millau.rs | 7 ++++-- .../lib-substrate-relay/src/finality/mod.rs | 23 ++++++++----------- .../src/finality/source.rs | 8 +++---- .../src/finality_base/mod.rs | 15 ++++++++++++ 11 files changed, 76 insertions(+), 34 deletions(-) diff --git a/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs b/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs index 97d9fdbcd74..5f39f345df5 100644 --- a/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs +++ b/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs @@ -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. @@ -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; +} + +#[async_trait] +impl SubstrateFinalitySyncPipeline for KusamaFinalityToBridgeHubPolkadot { type SubmitFinalityProofCallBuilder = KusamaFinalityToBridgeHubPolkadotCallBuilder; async fn start_relay_guards( diff --git a/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs b/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs index 29d0d54d53f..8b7d2fa52db 100644 --- a/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs +++ b/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs @@ -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. @@ -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; +} + +#[async_trait] +impl SubstrateFinalitySyncPipeline for PolkadotFinalityToBridgeHubKusama { type SubmitFinalityProofCallBuilder = PolkadotFinalityToBridgeHubKusamaCallBuilder; async fn start_relay_guards( diff --git a/relays/bin-substrate/src/bridges/rialto_millau/millau_headers_to_rialto.rs b/relays/bin-substrate/src/bridges/rialto_millau/millau_headers_to_rialto.rs index ea71650d8c6..490ded1f67c 100644 --- a/relays/bin-substrate/src/bridges/rialto_millau/millau_headers_to_rialto.rs +++ b/relays/bin-substrate/src/bridges/rialto_millau/millau_headers_to_rialto.rs @@ -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; +} + +impl SubstrateFinalitySyncPipeline for MillauFinalityToRialto { type SubmitFinalityProofCallBuilder = DirectSubmitGrandpaFinalityProofCallBuilder< Self, rialto_runtime::Runtime, diff --git a/relays/bin-substrate/src/bridges/rialto_millau/rialto_headers_to_millau.rs b/relays/bin-substrate/src/bridges/rialto_millau/rialto_headers_to_millau.rs index 5774e4e0c14..c6ac05011f3 100644 --- a/relays/bin-substrate/src/bridges/rialto_millau/rialto_headers_to_millau.rs +++ b/relays/bin-substrate/src/bridges/rialto_millau/rialto_headers_to_millau.rs @@ -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; +} + +impl SubstrateFinalitySyncPipeline for RialtoFinalityToMillau { type SubmitFinalityProofCallBuilder = DirectSubmitGrandpaFinalityProofCallBuilder< Self, millau_runtime::Runtime, diff --git a/relays/bin-substrate/src/bridges/rialto_parachain_millau/millau_headers_to_rialto_parachain.rs b/relays/bin-substrate/src/bridges/rialto_parachain_millau/millau_headers_to_rialto_parachain.rs index 562f68d783b..79d3bde22fa 100644 --- a/relays/bin-substrate/src/bridges/rialto_parachain_millau/millau_headers_to_rialto_parachain.rs +++ b/relays/bin-substrate/src/bridges/rialto_parachain_millau/millau_headers_to_rialto_parachain.rs @@ -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!( @@ -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; +} + +impl SubstrateFinalitySyncPipeline for MillauFinalityToRialtoParachain { type SubmitFinalityProofCallBuilder = MillauFinalityToRialtoParachainCallBuilder; } diff --git a/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs b/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs index 6358fe21a4d..1927f65e18b 100644 --- a/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs +++ b/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs @@ -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. @@ -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; +} + +#[async_trait] +impl SubstrateFinalitySyncPipeline for RococoFinalityToBridgeHubWococo { type SubmitFinalityProofCallBuilder = RococoFinalityToBridgeHubWococoCallBuilder; async fn start_relay_guards( diff --git a/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs b/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs index a25ec696704..326da34018e 100644 --- a/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs +++ b/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs @@ -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. @@ -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; +} + +#[async_trait] +impl SubstrateFinalitySyncPipeline for WococoFinalityToBridgeHubRococo { type SubmitFinalityProofCallBuilder = WococoFinalityToBridgeHubRococoCallBuilder; async fn start_relay_guards( diff --git a/relays/bin-substrate/src/bridges/westend_millau/westend_headers_to_millau.rs b/relays/bin-substrate/src/bridges/westend_millau/westend_headers_to_millau.rs index 8eca7980d31..eadbc305704 100644 --- a/relays/bin-substrate/src/bridges/westend_millau/westend_headers_to_millau.rs +++ b/relays/bin-substrate/src/bridges/westend_millau/westend_headers_to_millau.rs @@ -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; +} + +impl SubstrateFinalitySyncPipeline for WestendFinalityToMillau { type SubmitFinalityProofCallBuilder = DirectSubmitGrandpaFinalityProofCallBuilder< Self, millau_runtime::Runtime, diff --git a/relays/lib-substrate-relay/src/finality/mod.rs b/relays/lib-substrate-relay/src/finality/mod.rs index 0303fa76a0c..0bec4338a6a 100644 --- a/relays/lib-substrate-relay/src/finality/mod.rs +++ b/relays/lib-substrate-relay/src/finality/mod.rs @@ -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; @@ -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; +pub trait SubstrateFinalitySyncPipeline: + 'static + SubstrateFinalityPipeline + Clone + Debug + Send + Sync +{ /// How submit finality proof call is built? type SubmitFinalityProofCallBuilder: SubmitFinalityProofCallBuilder; @@ -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 { diff --git a/relays/lib-substrate-relay/src/finality/source.rs b/relays/lib-substrate-relay/src/finality/source.rs index 000223c7dcb..5abfc6e86a7 100644 --- a/relays/lib-substrate-relay/src/finality/source.rs +++ b/relays/lib-substrate-relay/src/finality/source.rs @@ -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; @@ -45,10 +46,9 @@ pub type SubstrateFinalityProofsStream

= Pin> + Send>>; /// Substrate finality proof. Specific to the used `FinalityEngine`. -pub type SubstrateFinalityProof

= - <

::FinalityEngine as Engine< -

::SourceChain, - >>::FinalityProof; +pub type SubstrateFinalityProof

= <

::FinalityEngine as Engine< +

::SourceChain, +>>::FinalityProof; /// Substrate node as finality source. pub struct SubstrateFinalitySource { diff --git a/relays/lib-substrate-relay/src/finality_base/mod.rs b/relays/lib-substrate-relay/src/finality_base/mod.rs index a17d8b63beb..185f8bb9efc 100644 --- a/relays/lib-substrate-relay/src/finality_base/mod.rs +++ b/relays/lib-substrate-relay/src/finality_base/mod.rs @@ -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; +}