From a76918e6b9f8b15493d4a21d242fbd36237e44f4 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Tue, 14 Nov 2023 09:28:10 +0200 Subject: [PATCH] Start version guards for the ED loop (#2678) --- .../kusama_headers_to_bridge_hub_polkadot.rs | 16 ---------------- .../polkadot_headers_to_bridge_hub_kusama.rs | 16 ---------------- ...ot_bulletin_headers_to_bridge_hub_polkadot.rs | 16 ---------------- .../polkadot_headers_to_polkadot_bulletin.rs | 16 ---------------- .../rococo_headers_to_bridge_hub_westend.rs | 16 ---------------- .../westend_headers_to_bridge_hub_rococo.rs | 16 ---------------- .../rococo_headers_to_bridge_hub_wococo.rs | 16 ---------------- .../wococo_headers_to_bridge_hub_rococo.rs | 16 ---------------- .../src/cli/detect_equivocations.rs | 11 +++++++++-- .../bin-substrate/src/cli/relay_headers.rs | 8 ++------ .../parachain_to_parachain.rs | 2 -- .../relay_to_parachain.rs | 2 -- .../relay_headers_and_messages/relay_to_relay.rs | 2 -- .../lib-substrate-relay/src/equivocation/mod.rs | 14 ++++++++++++++ .../lib-substrate-relay/src/finality/mod.rs | 11 ++++++++--- 15 files changed, 33 insertions(+), 145 deletions(-) diff --git a/bridges/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs b/bridges/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs index a5419a725e2e1..2dc9c131305ad 100644 --- a/bridges/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs +++ b/bridges/relays/bin-substrate/src/bridges/kusama_polkadot/kusama_headers_to_bridge_hub_polkadot.rs @@ -21,12 +21,10 @@ use crate::cli::bridge::{ }; use async_trait::async_trait; -use relay_substrate_client::{AccountKeyPairOf, Client}; use substrate_relay_helper::{ equivocation::SubstrateEquivocationDetectionPipeline, finality::SubstrateFinalitySyncPipeline, finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline}, - TransactionParams, }; /// Description of Kusama -> PolkadotBridgeHub finalized headers bridge. @@ -58,20 +56,6 @@ impl SubstrateFinalityPipeline for KusamaFinalityToBridgeHubPolkadot { #[async_trait] impl SubstrateFinalitySyncPipeline for KusamaFinalityToBridgeHubPolkadot { type SubmitFinalityProofCallBuilder = SubmitFinalityProofCallBuilder; - - async fn start_relay_guards( - target_client: &Client, - _transaction_params: &TransactionParams>, - enable_version_guard: bool, - ) -> relay_substrate_client::Result<()> { - if enable_version_guard { - relay_substrate_client::guard::abort_on_spec_version_change( - target_client.clone(), - target_client.simple_runtime_version().await?.spec_version, - ); - } - Ok(()) - } } #[async_trait] diff --git a/bridges/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs b/bridges/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs index 5899b8c25f6e0..589bf2546e8c1 100644 --- a/bridges/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs +++ b/bridges/relays/bin-substrate/src/bridges/kusama_polkadot/polkadot_headers_to_bridge_hub_kusama.rs @@ -21,12 +21,10 @@ use crate::cli::bridge::{ }; use async_trait::async_trait; -use relay_substrate_client::{AccountKeyPairOf, Client}; use substrate_relay_helper::{ equivocation::SubstrateEquivocationDetectionPipeline, finality::SubstrateFinalitySyncPipeline, finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline}, - TransactionParams, }; /// Description of Polkadot -> KusamaBridgeHub finalized headers bridge. @@ -58,20 +56,6 @@ impl SubstrateFinalityPipeline for PolkadotFinalityToBridgeHubKusama { #[async_trait] impl SubstrateFinalitySyncPipeline for PolkadotFinalityToBridgeHubKusama { type SubmitFinalityProofCallBuilder = SubmitFinalityProofCallBuilder; - - async fn start_relay_guards( - target_client: &Client, - _transaction_params: &TransactionParams>, - enable_version_guard: bool, - ) -> relay_substrate_client::Result<()> { - if enable_version_guard { - relay_substrate_client::guard::abort_on_spec_version_change( - target_client.clone(), - target_client.simple_runtime_version().await?.spec_version, - ); - } - Ok(()) - } } #[async_trait] diff --git a/bridges/relays/bin-substrate/src/bridges/polkadot_bulletin/polkadot_bulletin_headers_to_bridge_hub_polkadot.rs b/bridges/relays/bin-substrate/src/bridges/polkadot_bulletin/polkadot_bulletin_headers_to_bridge_hub_polkadot.rs index 33f59feda3bae..dbf89ddeec398 100644 --- a/bridges/relays/bin-substrate/src/bridges/polkadot_bulletin/polkadot_bulletin_headers_to_bridge_hub_polkadot.rs +++ b/bridges/relays/bin-substrate/src/bridges/polkadot_bulletin/polkadot_bulletin_headers_to_bridge_hub_polkadot.rs @@ -22,12 +22,10 @@ use crate::cli::bridge::{ }; use async_trait::async_trait; -use relay_substrate_client::{AccountKeyPairOf, Client}; use substrate_relay_helper::{ equivocation::SubstrateEquivocationDetectionPipeline, finality::SubstrateFinalitySyncPipeline, finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline}, - TransactionParams, }; /// Description of `PolkadotBulletin` -> `PolkadotBridgeHub` finalized headers bridge. @@ -59,20 +57,6 @@ impl SubstrateFinalityPipeline for PolkadotBulletinFinalityToBridgeHubPolkadot { #[async_trait] impl SubstrateFinalitySyncPipeline for PolkadotBulletinFinalityToBridgeHubPolkadot { type SubmitFinalityProofCallBuilder = SubmitFinalityProofCallBuilder; - - async fn start_relay_guards( - target_client: &Client, - _transaction_params: &TransactionParams>, - enable_version_guard: bool, - ) -> relay_substrate_client::Result<()> { - if enable_version_guard { - relay_substrate_client::guard::abort_on_spec_version_change( - target_client.clone(), - target_client.simple_runtime_version().await?.spec_version, - ); - } - Ok(()) - } } #[async_trait] diff --git a/bridges/relays/bin-substrate/src/bridges/polkadot_bulletin/polkadot_headers_to_polkadot_bulletin.rs b/bridges/relays/bin-substrate/src/bridges/polkadot_bulletin/polkadot_headers_to_polkadot_bulletin.rs index 7770fd1559444..897c2ac884f91 100644 --- a/bridges/relays/bin-substrate/src/bridges/polkadot_bulletin/polkadot_headers_to_polkadot_bulletin.rs +++ b/bridges/relays/bin-substrate/src/bridges/polkadot_bulletin/polkadot_headers_to_polkadot_bulletin.rs @@ -21,12 +21,10 @@ use crate::cli::bridge::{ }; use async_trait::async_trait; -use relay_substrate_client::{AccountKeyPairOf, Client}; use substrate_relay_helper::{ equivocation::SubstrateEquivocationDetectionPipeline, finality::SubstrateFinalitySyncPipeline, finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline}, - TransactionParams, }; /// Description of Polkadot -> `PolkadotBulletin` finalized headers bridge. @@ -58,20 +56,6 @@ impl SubstrateFinalityPipeline for PolkadotFinalityToPolkadotBulletin { #[async_trait] impl SubstrateFinalitySyncPipeline for PolkadotFinalityToPolkadotBulletin { type SubmitFinalityProofCallBuilder = SubmitFinalityProofCallBuilder; - - async fn start_relay_guards( - target_client: &Client, - _transaction_params: &TransactionParams>, - enable_version_guard: bool, - ) -> relay_substrate_client::Result<()> { - if enable_version_guard { - relay_substrate_client::guard::abort_on_spec_version_change( - target_client.clone(), - target_client.simple_runtime_version().await?.spec_version, - ); - } - Ok(()) - } } #[async_trait] diff --git a/bridges/relays/bin-substrate/src/bridges/rococo_westend/rococo_headers_to_bridge_hub_westend.rs b/bridges/relays/bin-substrate/src/bridges/rococo_westend/rococo_headers_to_bridge_hub_westend.rs index 75f6ff6f25c20..24d0b6603157a 100644 --- a/bridges/relays/bin-substrate/src/bridges/rococo_westend/rococo_headers_to_bridge_hub_westend.rs +++ b/bridges/relays/bin-substrate/src/bridges/rococo_westend/rococo_headers_to_bridge_hub_westend.rs @@ -21,12 +21,10 @@ use crate::cli::bridge::{ }; use async_trait::async_trait; -use relay_substrate_client::{AccountKeyPairOf, Client}; use substrate_relay_helper::{ equivocation::SubstrateEquivocationDetectionPipeline, finality::SubstrateFinalitySyncPipeline, finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline}, - TransactionParams, }; /// Description of Rococo -> Westend finalized headers bridge. @@ -58,20 +56,6 @@ impl SubstrateFinalityPipeline for RococoFinalityToBridgeHubWestend { #[async_trait] impl SubstrateFinalitySyncPipeline for RococoFinalityToBridgeHubWestend { type SubmitFinalityProofCallBuilder = SubmitFinalityProofCallBuilder; - - async fn start_relay_guards( - target_client: &Client, - _transaction_params: &TransactionParams>, - enable_version_guard: bool, - ) -> relay_substrate_client::Result<()> { - if enable_version_guard { - relay_substrate_client::guard::abort_on_spec_version_change( - target_client.clone(), - target_client.simple_runtime_version().await?.spec_version, - ); - } - Ok(()) - } } #[async_trait] diff --git a/bridges/relays/bin-substrate/src/bridges/rococo_westend/westend_headers_to_bridge_hub_rococo.rs b/bridges/relays/bin-substrate/src/bridges/rococo_westend/westend_headers_to_bridge_hub_rococo.rs index 1532e06b95386..451089b2ce009 100644 --- a/bridges/relays/bin-substrate/src/bridges/rococo_westend/westend_headers_to_bridge_hub_rococo.rs +++ b/bridges/relays/bin-substrate/src/bridges/rococo_westend/westend_headers_to_bridge_hub_rococo.rs @@ -21,12 +21,10 @@ use crate::cli::bridge::{ }; use async_trait::async_trait; -use relay_substrate_client::{AccountKeyPairOf, Client}; use substrate_relay_helper::{ equivocation::SubstrateEquivocationDetectionPipeline, finality::SubstrateFinalitySyncPipeline, finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline}, - TransactionParams, }; /// Description of Westend -> Rococo finalized headers bridge. @@ -58,20 +56,6 @@ impl SubstrateFinalityPipeline for WestendFinalityToBridgeHubRococo { #[async_trait] impl SubstrateFinalitySyncPipeline for WestendFinalityToBridgeHubRococo { type SubmitFinalityProofCallBuilder = SubmitFinalityProofCallBuilder; - - async fn start_relay_guards( - target_client: &Client, - _transaction_params: &TransactionParams>, - enable_version_guard: bool, - ) -> relay_substrate_client::Result<()> { - if enable_version_guard { - relay_substrate_client::guard::abort_on_spec_version_change( - target_client.clone(), - target_client.simple_runtime_version().await?.spec_version, - ); - } - Ok(()) - } } #[async_trait] diff --git a/bridges/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs b/bridges/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs index d89ba35849c69..b9b9a89ba0f52 100644 --- a/bridges/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs +++ b/bridges/relays/bin-substrate/src/bridges/rococo_wococo/rococo_headers_to_bridge_hub_wococo.rs @@ -21,12 +21,10 @@ use crate::cli::bridge::{ }; use async_trait::async_trait; -use relay_substrate_client::{AccountKeyPairOf, Client}; use substrate_relay_helper::{ equivocation::SubstrateEquivocationDetectionPipeline, finality::SubstrateFinalitySyncPipeline, finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline}, - TransactionParams, }; /// Description of Rococo -> Wococo finalized headers bridge. @@ -58,20 +56,6 @@ impl SubstrateFinalityPipeline for RococoFinalityToBridgeHubWococo { #[async_trait] impl SubstrateFinalitySyncPipeline for RococoFinalityToBridgeHubWococo { type SubmitFinalityProofCallBuilder = SubmitFinalityProofCallBuilder; - - async fn start_relay_guards( - target_client: &Client, - _transaction_params: &TransactionParams>, - enable_version_guard: bool, - ) -> relay_substrate_client::Result<()> { - if enable_version_guard { - relay_substrate_client::guard::abort_on_spec_version_change( - target_client.clone(), - target_client.simple_runtime_version().await?.spec_version, - ); - } - Ok(()) - } } #[async_trait] diff --git a/bridges/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs b/bridges/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs index 44d91f06e3e78..c000a2764e26e 100644 --- a/bridges/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs +++ b/bridges/relays/bin-substrate/src/bridges/rococo_wococo/wococo_headers_to_bridge_hub_rococo.rs @@ -21,12 +21,10 @@ use crate::cli::bridge::{ }; use async_trait::async_trait; -use relay_substrate_client::{AccountKeyPairOf, Client}; use substrate_relay_helper::{ equivocation::SubstrateEquivocationDetectionPipeline, finality::SubstrateFinalitySyncPipeline, finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline}, - TransactionParams, }; /// Description of Wococo -> Rococo finalized headers bridge. @@ -58,20 +56,6 @@ impl SubstrateFinalityPipeline for WococoFinalityToBridgeHubRococo { #[async_trait] impl SubstrateFinalitySyncPipeline for WococoFinalityToBridgeHubRococo { type SubmitFinalityProofCallBuilder = SubmitFinalityProofCallBuilder; - - async fn start_relay_guards( - target_client: &Client, - _transaction_params: &TransactionParams>, - enable_version_guard: bool, - ) -> relay_substrate_client::Result<()> { - if enable_version_guard { - relay_substrate_client::guard::abort_on_spec_version_change( - target_client.clone(), - target_client.simple_runtime_version().await?.spec_version, - ); - } - Ok(()) - } } #[async_trait] diff --git a/bridges/relays/bin-substrate/src/cli/detect_equivocations.rs b/bridges/relays/bin-substrate/src/cli/detect_equivocations.rs index 142a3f8e69a88..bc456e025499e 100644 --- a/bridges/relays/bin-substrate/src/cli/detect_equivocations.rs +++ b/bridges/relays/bin-substrate/src/cli/detect_equivocations.rs @@ -37,7 +37,7 @@ use async_trait::async_trait; use relay_substrate_client::ChainWithTransactions; use structopt::StructOpt; use strum::{EnumString, EnumVariantNames, VariantNames}; -use substrate_relay_helper::equivocation; +use substrate_relay_helper::{equivocation, equivocation::SubstrateEquivocationDetectionPipeline}; /// Start equivocation detection loop. #[derive(StructOpt)] @@ -73,8 +73,15 @@ where Self::Source: ChainWithTransactions, { async fn start(data: DetectEquivocations) -> anyhow::Result<()> { + let source_client = data.source.into_client::().await?; + Self::Equivocation::start_relay_guards( + &source_client, + source_client.can_start_version_guard(), + ) + .await?; + equivocation::run::( - data.source.into_client::().await?, + source_client, data.target.into_client::().await?, data.source_sign.transaction_params::()?, data.prometheus_params.into_metrics_params()?, diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers.rs b/bridges/relays/bin-substrate/src/cli/relay_headers.rs index 800e8587d8b25..d3a7fa09367df 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers.rs @@ -96,12 +96,8 @@ trait HeadersRelayer: RelayToRelayHeadersCliBridge { signer: target_sign, mortality: target_transactions_mortality, }; - Self::Finality::start_relay_guards( - &target_client, - &target_transactions_params, - target_client.can_start_version_guard(), - ) - .await?; + Self::Finality::start_relay_guards(&target_client, target_client.can_start_version_guard()) + .await?; substrate_relay_helper::finality::run::( source_client, diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs index 24d6f00861d00..1610f648bdcdd 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs @@ -218,13 +218,11 @@ where ::RelayFinality::start_relay_guards( &self.common.right.client, - &self.left_headers_to_right_transaction_params, self.common.right.client.can_start_version_guard(), ) .await?; ::RelayFinality::start_relay_guards( &self.common.left.client, - &self.right_headers_to_left_transaction_params, self.common.left.client.can_start_version_guard(), ) .await?; diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs index ef47e44dc1837..98b313cc0960d 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs @@ -200,13 +200,11 @@ where ::Finality::start_relay_guards( &self.common.right.client, - &self.left_headers_to_right_transaction_params, self.common.right.client.can_start_version_guard(), ) .await?; ::RelayFinality::start_relay_guards( &self.common.left.client, - &self.right_headers_to_left_transaction_params, self.common.left.client.can_start_version_guard(), ) .await?; diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs index a313628933ba6..a75263540a55f 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs @@ -156,13 +156,11 @@ where ::Finality::start_relay_guards( &self.common.right.client, - &self.left_to_right_transaction_params, self.common.right.client.can_start_version_guard(), ) .await?; ::Finality::start_relay_guards( &self.common.left.client, - &self.right_to_left_transaction_params, self.common.left.client.can_start_version_guard(), ) .await?; diff --git a/bridges/relays/lib-substrate-relay/src/equivocation/mod.rs b/bridges/relays/lib-substrate-relay/src/equivocation/mod.rs index ee0928c2af137..f6d58cbaa4ab4 100644 --- a/bridges/relays/lib-substrate-relay/src/equivocation/mod.rs +++ b/bridges/relays/lib-substrate-relay/src/equivocation/mod.rs @@ -66,6 +66,20 @@ pub trait SubstrateEquivocationDetectionPipeline: { /// How the `report_equivocation` call is built ? type ReportEquivocationCallBuilder: ReportEquivocationCallBuilder; + + /// Add relay guards if required. + async fn start_relay_guards( + source_client: &Client, + enable_version_guard: bool, + ) -> relay_substrate_client::Result<()> { + if enable_version_guard { + relay_substrate_client::guard::abort_on_spec_version_change( + source_client.clone(), + source_client.simple_runtime_version().await?.spec_version, + ); + } + Ok(()) + } } type FinalityProoffOf

= <

::FinalityEngine as Engine< diff --git a/bridges/relays/lib-substrate-relay/src/finality/mod.rs b/bridges/relays/lib-substrate-relay/src/finality/mod.rs index 98aec1d52b908..b8cf27ea78fde 100644 --- a/bridges/relays/lib-substrate-relay/src/finality/mod.rs +++ b/bridges/relays/lib-substrate-relay/src/finality/mod.rs @@ -75,10 +75,15 @@ pub trait SubstrateFinalitySyncPipeline: BaseSubstrateFinalitySyncPipeline { /// Add relay guards if required. async fn start_relay_guards( - _target_client: &Client, - _transaction_params: &TransactionParams>, - _enable_version_guard: bool, + target_client: &Client, + enable_version_guard: bool, ) -> relay_substrate_client::Result<()> { + if enable_version_guard { + relay_substrate_client::guard::abort_on_spec_version_change( + target_client.clone(), + target_client.simple_runtime_version().await?.spec_version, + ); + } Ok(()) } }