Skip to content

Commit

Permalink
Support for kusama-polkadot relaying (paritytech#2128)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur authored May 12, 2023
1 parent 01f4b7f commit 5fc377a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
38 changes: 38 additions & 0 deletions relays/bin-substrate/src/cli/init_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ use codec::Encode;

use crate::{
bridges::{
kusama_polkadot::{
kusama_headers_to_bridge_hub_polkadot::KusamaToBridgeHubPolkadotCliBridge,
polkadot_headers_to_bridge_hub_kusama::PolkadotToBridgeHubKusamaCliBridge,
},
rialto_millau::{
millau_headers_to_rialto::MillauToRialtoCliBridge,
rialto_headers_to_millau::RialtoToMillauCliBridge,
Expand Down Expand Up @@ -66,6 +70,8 @@ pub enum InitBridgeName {
MillauToRialtoParachain,
RococoToBridgeHubWococo,
WococoToBridgeHubRococo,
KusamaToBridgeHubPolkadot,
PolkadotToBridgeHubKusama,
}

#[async_trait]
Expand Down Expand Up @@ -198,6 +204,34 @@ impl BridgeInitializer for WococoToBridgeHubRococoCliBridge {
}
}

impl BridgeInitializer for KusamaToBridgeHubPolkadotCliBridge {
type Engine = GrandpaFinalityEngine<Self::Source>;

fn encode_init_bridge(
init_data: <Self::Engine as Engine<Self::Source>>::InitializationData,
) -> <Self::Target as Chain>::Call {
relay_bridge_hub_polkadot_client::runtime::Call::BridgeKusamaGrandpa(
relay_bridge_hub_polkadot_client::runtime::BridgeKusamaGrandpaCall::initialize {
init_data,
},
)
}
}

impl BridgeInitializer for PolkadotToBridgeHubKusamaCliBridge {
type Engine = GrandpaFinalityEngine<Self::Source>;

fn encode_init_bridge(
init_data: <Self::Engine as Engine<Self::Source>>::InitializationData,
) -> <Self::Target as Chain>::Call {
relay_bridge_hub_kusama_client::runtime::Call::BridgePolkadotGrandpa(
relay_bridge_hub_kusama_client::runtime::BridgePolkadotGrandpaCall::initialize {
init_data,
},
)
}
}

impl InitBridge {
/// Run the command.
pub async fn run(self) -> anyhow::Result<()> {
Expand All @@ -211,6 +245,10 @@ impl InitBridge {
RococoToBridgeHubWococoCliBridge::init_bridge(self),
InitBridgeName::WococoToBridgeHubRococo =>
WococoToBridgeHubRococoCliBridge::init_bridge(self),
InitBridgeName::KusamaToBridgeHubPolkadot =>
KusamaToBridgeHubPolkadotCliBridge::init_bridge(self),
InitBridgeName::PolkadotToBridgeHubKusama =>
PolkadotToBridgeHubKusamaCliBridge::init_bridge(self),
}
.await
}
Expand Down
51 changes: 51 additions & 0 deletions relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ use relay_to_relay::*;

use crate::{
bridges::{
kusama_polkadot::{
kusama_parachains_to_bridge_hub_polkadot::BridgeHubKusamaToBridgeHubPolkadotCliBridge,
polkadot_parachains_to_bridge_hub_kusama::BridgeHubPolkadotToBridgeHubKusamaCliBridge,
},
rialto_millau::{
millau_headers_to_rialto::MillauToRialtoCliBridge,
rialto_headers_to_millau::RialtoToMillauCliBridge,
Expand Down Expand Up @@ -202,6 +206,10 @@ declare_chain_cli_schema!(Rococo, rococo);
declare_chain_cli_schema!(BridgeHubRococo, bridge_hub_rococo);
declare_chain_cli_schema!(Wococo, wococo);
declare_chain_cli_schema!(BridgeHubWococo, bridge_hub_wococo);
declare_chain_cli_schema!(Kusama, kusama);
declare_chain_cli_schema!(BridgeHubKusama, bridge_hub_kusama);
declare_chain_cli_schema!(Polkadot, polkadot);
declare_chain_cli_schema!(BridgeHubPolkadot, bridge_hub_polkadot);
// Means to override signers of different layer transactions.
declare_chain_cli_schema!(MillauHeadersToRialto, millau_headers_to_rialto);
declare_chain_cli_schema!(MillauHeadersToRialtoParachain, millau_headers_to_rialto_parachain);
Expand All @@ -217,10 +225,21 @@ declare_chain_cli_schema!(
WococoParachainsToBridgeHubRococo,
wococo_parachains_to_bridge_hub_rococo
);
declare_chain_cli_schema!(KusamaHeadersToBridgeHubPolkadot, kusama_headers_to_bridge_hub_polkadot);
declare_chain_cli_schema!(
KusamaParachainsToBridgeHubPolkadot,
kusama_parachains_to_bridge_hub_polkadot
);
declare_chain_cli_schema!(PolkadotHeadersToBridgeHubKusama, polkadot_headers_to_bridge_hub_kusama);
declare_chain_cli_schema!(
PolkadotParachainsToBridgeHubKusama,
polkadot_parachains_to_bridge_hub_kusama
);
// All supported bridges.
declare_relay_to_relay_bridge_schema!(Millau, Rialto);
declare_relay_to_parachain_bridge_schema!(Millau, RialtoParachain, Rialto);
declare_parachain_to_parachain_bridge_schema!(BridgeHubRococo, Rococo, BridgeHubWococo, Wococo);
declare_parachain_to_parachain_bridge_schema!(BridgeHubKusama, Kusama, BridgeHubPolkadot, Polkadot);

/// Base portion of the bidirectional complex relay.
///
Expand Down Expand Up @@ -463,6 +482,32 @@ impl Full2WayBridge for BridgeHubRococoBridgeHubWococoFull2WayBridge {
}
}

/// BridgeHubKusama <> BridgeHubPolkadot complex relay.
pub struct BridgeHubKusamaBridgeHubPolkadotFull2WayBridge {
base: <Self as Full2WayBridge>::Base,
}

#[async_trait]
impl Full2WayBridge for BridgeHubKusamaBridgeHubPolkadotFull2WayBridge {
type Base = ParachainToParachainBridge<Self::L2R, Self::R2L>;
type Left = relay_bridge_hub_kusama_client::BridgeHubKusama;
type Right = relay_bridge_hub_polkadot_client::BridgeHubPolkadot;
type L2R = BridgeHubKusamaToBridgeHubPolkadotCliBridge;
type R2L = BridgeHubPolkadotToBridgeHubKusamaCliBridge;

fn new(base: Self::Base) -> anyhow::Result<Self> {
Ok(Self { base })
}

fn base(&self) -> &Self::Base {
&self.base
}

fn mut_base(&mut self) -> &mut Self::Base {
&mut self.base
}
}

/// Complex headers+messages relay.
#[derive(Debug, PartialEq, StructOpt)]
pub enum RelayHeadersAndMessages {
Expand All @@ -472,6 +517,8 @@ pub enum RelayHeadersAndMessages {
MillauRialtoParachain(MillauRialtoParachainHeadersAndMessages),
/// BridgeHubRococo <> BridgeHubWococo relay.
BridgeHubRococoBridgeHubWococo(BridgeHubRococoBridgeHubWococoHeadersAndMessages),
/// BridgeHubKusama <> BridgeHubPolkadot relay.
BridgeHubKusamaBridgeHubPolkadot(BridgeHubKusamaBridgeHubPolkadotHeadersAndMessages),
}

impl RelayHeadersAndMessages {
Expand All @@ -488,6 +535,10 @@ impl RelayHeadersAndMessages {
BridgeHubRococoBridgeHubWococoFull2WayBridge::new(params.into_bridge().await?)?
.run()
.await,
RelayHeadersAndMessages::BridgeHubKusamaBridgeHubPolkadot(params) =>
BridgeHubKusamaBridgeHubPolkadotFull2WayBridge::new(params.into_bridge().await?)?
.run()
.await,
}
}
}
Expand Down

0 comments on commit 5fc377a

Please sign in to comment.