Skip to content

Commit

Permalink
Start version guards for the ED loop (paritytech#2678)
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Apr 9, 2024
1 parent 9193317 commit cf7948c
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
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]
Expand Down
11 changes: 9 additions & 2 deletions bridges/relays/bin-substrate/src/cli/detect_equivocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -73,8 +73,15 @@ where
Self::Source: ChainWithTransactions,
{
async fn start(data: DetectEquivocations) -> anyhow::Result<()> {
let source_client = data.source.into_client::<Self::Source>().await?;
Self::Equivocation::start_relay_guards(
&source_client,
source_client.can_start_version_guard(),
)
.await?;

equivocation::run::<Self::Equivocation>(
data.source.into_client::<Self::Source>().await?,
source_client,
data.target.into_client::<Self::Target>().await?,
data.source_sign.transaction_params::<Self::Source>()?,
data.prometheus_params.into_metrics_params()?,
Expand Down
8 changes: 2 additions & 6 deletions bridges/relays/bin-substrate/src/cli/relay_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Self::Finality>(
source_client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,11 @@ where

<L2R as ParachainToRelayHeadersCliBridge>::RelayFinality::start_relay_guards(
&self.common.right.client,
&self.left_headers_to_right_transaction_params,
self.common.right.client.can_start_version_guard(),
)
.await?;
<R2L as ParachainToRelayHeadersCliBridge>::RelayFinality::start_relay_guards(
&self.common.left.client,
&self.right_headers_to_left_transaction_params,
self.common.left.client.can_start_version_guard(),
)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,11 @@ where

<L2R as RelayToRelayHeadersCliBridge>::Finality::start_relay_guards(
&self.common.right.client,
&self.left_headers_to_right_transaction_params,
self.common.right.client.can_start_version_guard(),
)
.await?;
<R2L as ParachainToRelayHeadersCliBridge>::RelayFinality::start_relay_guards(
&self.common.left.client,
&self.right_headers_to_left_transaction_params,
self.common.left.client.can_start_version_guard(),
)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,11 @@ where

<L2R as RelayToRelayHeadersCliBridge>::Finality::start_relay_guards(
&self.common.right.client,
&self.left_to_right_transaction_params,
self.common.right.client.can_start_version_guard(),
)
.await?;
<R2L as RelayToRelayHeadersCliBridge>::Finality::start_relay_guards(
&self.common.left.client,
&self.right_to_left_transaction_params,
self.common.left.client.can_start_version_guard(),
)
.await?;
Expand Down
14 changes: 14 additions & 0 deletions bridges/relays/lib-substrate-relay/src/equivocation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ pub trait SubstrateEquivocationDetectionPipeline:
{
/// How the `report_equivocation` call is built ?
type ReportEquivocationCallBuilder: ReportEquivocationCallBuilder<Self>;

/// Add relay guards if required.
async fn start_relay_guards(
source_client: &Client<Self::SourceChain>,
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<P> = <<P as SubstrateFinalityPipeline>::FinalityEngine as Engine<
Expand Down
11 changes: 8 additions & 3 deletions bridges/relays/lib-substrate-relay/src/finality/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,15 @@ pub trait SubstrateFinalitySyncPipeline: BaseSubstrateFinalitySyncPipeline {

/// Add relay guards if required.
async fn start_relay_guards(
_target_client: &Client<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
_enable_version_guard: bool,
target_client: &Client<Self::TargetChain>,
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(())
}
}
Expand Down

0 comments on commit cf7948c

Please sign in to comment.