Skip to content

Commit

Permalink
Add basic equivocation detection pipeline schema (paritytech#2338) (p…
Browse files Browse the repository at this point in the history
…aritytech#2341)

* Move finality Engine to finality_base folder

* Define SubstrateFinalityPipeline

Extract basic parts of SubstrateFinalitySyncPipeline into
SubstrateFinalityPipeline

* Add equivocation detection pipeline

* Fix comment
  • Loading branch information
serban300 committed Apr 9, 2024
1 parent ccfae2f commit 12cba37
Show file tree
Hide file tree
Showing 34 changed files with 234 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use crate::cli::bridge::{CliBridgeBase, RelayToRelayHeadersCliBridge};
use async_trait::async_trait;
use relay_substrate_client::{AccountKeyPairOf, Client};
use substrate_relay_helper::{
finality::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalitySyncPipeline},
finality::SubstrateFinalitySyncPipeline,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
TransactionParams,
};

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 @@ -21,7 +21,8 @@ use crate::cli::bridge::{CliBridgeBase, RelayToRelayHeadersCliBridge};
use async_trait::async_trait;
use relay_substrate_client::{AccountKeyPairOf, Client};
use substrate_relay_helper::{
finality::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalitySyncPipeline},
finality::SubstrateFinalitySyncPipeline,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
TransactionParams,
};

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 @@ -17,20 +17,23 @@
//! Millau-to-Rialto headers sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, RelayToRelayHeadersCliBridge};
use substrate_relay_helper::finality::{
engine::Grandpa as GrandpaFinalityEngine, DirectSubmitGrandpaFinalityProofCallBuilder,
SubstrateFinalitySyncPipeline,
use substrate_relay_helper::{
finality::{DirectSubmitGrandpaFinalityProofCallBuilder, SubstrateFinalitySyncPipeline},
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 @@ -17,20 +17,23 @@
//! Rialto-to-Millau headers sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, RelayToRelayHeadersCliBridge};
use substrate_relay_helper::finality::{
engine::Grandpa as GrandpaFinalityEngine, DirectSubmitGrandpaFinalityProofCallBuilder,
SubstrateFinalitySyncPipeline,
use substrate_relay_helper::{
finality::{DirectSubmitGrandpaFinalityProofCallBuilder, SubstrateFinalitySyncPipeline},
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 @@ -35,8 +35,9 @@
//! Millau-to-RialtoParachain headers sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, MessagesCliBridge, RelayToRelayHeadersCliBridge};
use substrate_relay_helper::finality::{
engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalitySyncPipeline,
use substrate_relay_helper::{
finality::SubstrateFinalitySyncPipeline,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
};

substrate_relay_helper::generate_submit_finality_proof_call_builder!(
Expand All @@ -50,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 @@ -21,7 +21,8 @@ use crate::cli::bridge::{CliBridgeBase, RelayToRelayHeadersCliBridge};
use async_trait::async_trait;
use relay_substrate_client::{AccountKeyPairOf, Client};
use substrate_relay_helper::{
finality::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalitySyncPipeline},
finality::SubstrateFinalitySyncPipeline,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
TransactionParams,
};

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 @@ -21,7 +21,8 @@ use crate::cli::bridge::{CliBridgeBase, RelayToRelayHeadersCliBridge};
use async_trait::async_trait;
use relay_substrate_client::{AccountKeyPairOf, Client};
use substrate_relay_helper::{
finality::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalitySyncPipeline},
finality::SubstrateFinalitySyncPipeline,
finality_base::{engine::Grandpa as GrandpaFinalityEngine, SubstrateFinalityPipeline},
TransactionParams,
};

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 @@ -17,20 +17,23 @@
//! Westend-to-Millau headers sync entrypoint.

use crate::cli::bridge::{CliBridgeBase, RelayToRelayHeadersCliBridge};
use substrate_relay_helper::finality::{
engine::Grandpa as GrandpaFinalityEngine, DirectSubmitGrandpaFinalityProofCallBuilder,
SubstrateFinalitySyncPipeline,
use substrate_relay_helper::{
finality::{DirectSubmitGrandpaFinalityProofCallBuilder, SubstrateFinalitySyncPipeline},
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
2 changes: 1 addition & 1 deletion bridges/relays/bin-substrate/src/cli/init_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use relay_substrate_client::{AccountKeyPairOf, Chain, UnsignedTransaction};
use sp_core::Pair;
use structopt::StructOpt;
use strum::{EnumString, EnumVariantNames, VariantNames};
use substrate_relay_helper::finality::engine::{Engine, Grandpa as GrandpaFinalityEngine};
use substrate_relay_helper::finality_base::engine::{Engine, Grandpa as GrandpaFinalityEngine};

/// Initialize bridge pallet.
#[derive(StructOpt)]
Expand Down
1 change: 1 addition & 0 deletions bridges/relays/client-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ bp-runtime = { path = "../../primitives/runtime" }
# Substrate Dependencies

sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" }
3 changes: 3 additions & 0 deletions bridges/relays/client-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use relay_substrate_client::{
Chain, ChainWithBalances, ChainWithGrandpa, RelayChain, UnderlyingChainProvider,
};
use sp_core::storage::StorageKey;
use sp_session::MembershipProof;
use std::time::Duration;

/// Kusama header id.
Expand Down Expand Up @@ -52,6 +53,8 @@ impl Chain for Kusama {
impl ChainWithGrandpa for Kusama {
const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str =
KUSAMA_SYNCED_HEADERS_GRANDPA_INFO_METHOD;

type KeyOwnerProof = MembershipProof;
}

impl ChainWithBalances for Kusama {
Expand Down
1 change: 1 addition & 0 deletions bridges/relays/client-millau/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "mast
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" }
3 changes: 3 additions & 0 deletions bridges/relays/client-millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use relay_substrate_client::{
};
use sp_core::{storage::StorageKey, Pair};
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
use sp_session::MembershipProof;
use std::time::Duration;

/// Millau header id.
Expand Down Expand Up @@ -69,6 +70,8 @@ impl Chain for Millau {
impl ChainWithGrandpa for Millau {
const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str =
MILLAU_SYNCED_HEADERS_GRANDPA_INFO_METHOD;

type KeyOwnerProof = MembershipProof;
}

impl ChainWithBalances for Millau {
Expand Down
1 change: 1 addition & 0 deletions bridges/relays/client-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ bp-runtime = { path = "../../primitives/runtime" }
# Substrate Dependencies

sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" }
3 changes: 3 additions & 0 deletions bridges/relays/client-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use relay_substrate_client::{
Chain, ChainWithBalances, ChainWithGrandpa, RelayChain, UnderlyingChainProvider,
};
use sp_core::storage::StorageKey;
use sp_session::MembershipProof;
use std::time::Duration;

/// Polkadot header id.
Expand Down Expand Up @@ -52,6 +53,8 @@ impl Chain for Polkadot {
impl ChainWithGrandpa for Polkadot {
const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str =
POLKADOT_SYNCED_HEADERS_GRANDPA_INFO_METHOD;

type KeyOwnerProof = MembershipProof;
}

impl ChainWithBalances for Polkadot {
Expand Down
1 change: 1 addition & 0 deletions bridges/relays/client-rialto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "mas
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" }
3 changes: 3 additions & 0 deletions bridges/relays/client-rialto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use relay_substrate_client::{
};
use sp_core::{storage::StorageKey, Pair};
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
use sp_session::MembershipProof;
use std::time::Duration;

/// Rialto header id.
Expand Down Expand Up @@ -54,6 +55,8 @@ impl Chain for Rialto {
impl ChainWithGrandpa for Rialto {
const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str =
RIALTO_SYNCED_HEADERS_GRANDPA_INFO_METHOD;

type KeyOwnerProof = MembershipProof;
}

impl RelayChain for Rialto {
Expand Down
1 change: 1 addition & 0 deletions bridges/relays/client-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ bp-runtime = { path = "../../primitives/runtime" }
# Substrate Dependencies

sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" }
3 changes: 3 additions & 0 deletions bridges/relays/client-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use relay_substrate_client::{
Chain, ChainWithBalances, ChainWithGrandpa, RelayChain, UnderlyingChainProvider,
};
use sp_core::storage::StorageKey;
use sp_session::MembershipProof;
use std::time::Duration;

/// Rococo header id.
Expand Down Expand Up @@ -52,6 +53,8 @@ impl Chain for Rococo {
impl ChainWithGrandpa for Rococo {
const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str =
ROCOCO_SYNCED_HEADERS_GRANDPA_INFO_METHOD;

type KeyOwnerProof = MembershipProof;
}

impl ChainWithBalances for Rococo {
Expand Down
3 changes: 3 additions & 0 deletions bridges/relays/client-substrate/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ pub trait ChainWithGrandpa: Chain + UnderlyingChainWithGrandpaProvider {
/// Keep in mind that this method is normally provided by the other chain, which is
/// bridged with this chain.
const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str;

/// The type of the key owner proof used by the grandpa engine.
type KeyOwnerProof;
}

/// Substrate-based parachain from minimal relay-client point of view.
Expand Down
1 change: 1 addition & 0 deletions bridges/relays/client-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ bp-westend = { path = "../../primitives/chain-westend" }
# Substrate Dependencies

sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" }
3 changes: 3 additions & 0 deletions bridges/relays/client-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use relay_substrate_client::{
Chain, ChainWithBalances, ChainWithGrandpa, RelayChain, UnderlyingChainProvider,
};
use sp_core::storage::StorageKey;
use sp_session::MembershipProof;
use std::time::Duration;

/// Westend header id.
Expand Down Expand Up @@ -52,6 +53,8 @@ impl Chain for Westend {
impl ChainWithGrandpa for Westend {
const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str =
WESTEND_SYNCED_HEADERS_GRANDPA_INFO_METHOD;

type KeyOwnerProof = MembershipProof;
}

impl RelayChain for Westend {
Expand Down
1 change: 1 addition & 0 deletions bridges/relays/client-wococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ bp-wococo = { path = "../../primitives/chain-wococo" }

# Substrate Dependencies
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" }
3 changes: 3 additions & 0 deletions bridges/relays/client-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use relay_substrate_client::{
Chain, ChainWithBalances, ChainWithGrandpa, RelayChain, UnderlyingChainProvider,
};
use sp_core::storage::StorageKey;
use sp_session::MembershipProof;
use std::time::Duration;

/// Wococo header id.
Expand Down Expand Up @@ -52,6 +53,8 @@ impl Chain for Wococo {
impl ChainWithGrandpa for Wococo {
const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str =
WOCOCO_SYNCED_HEADERS_GRANDPA_INFO_METHOD;

type KeyOwnerProof = MembershipProof;
}

impl ChainWithBalances for Wococo {
Expand Down
Loading

0 comments on commit 12cba37

Please sign in to comment.