mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 01:41:03 +00:00
Parachains finality relay (#1199)
This commit is contained in:
committed by
Bastian Köcher
parent
f64357e7e8
commit
03c2f06a27
@@ -27,6 +27,7 @@ bp-kusama = { path = "../../primitives/chain-kusama" }
|
||||
bp-messages = { path = "../../primitives/messages" }
|
||||
bp-millau = { path = "../../primitives/chain-millau" }
|
||||
bp-polkadot = { path = "../../primitives/chain-polkadot" }
|
||||
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
|
||||
bp-rialto = { path = "../../primitives/chain-rialto" }
|
||||
bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" }
|
||||
bp-rococo = { path = "../../primitives/chain-rococo" }
|
||||
@@ -39,6 +40,7 @@ messages-relay = { path = "../messages" }
|
||||
millau-runtime = { path = "../../bin/millau/runtime" }
|
||||
pallet-bridge-grandpa = { path = "../../modules/grandpa" }
|
||||
pallet-bridge-messages = { path = "../../modules/messages" }
|
||||
parachains-relay = { path = "../parachains" }
|
||||
relay-kusama-client = { path = "../client-kusama" }
|
||||
relay-millau-client = { path = "../client-millau" }
|
||||
relay-polkadot-client = { path = "../client-polkadot" }
|
||||
|
||||
@@ -24,6 +24,7 @@ pub mod polkadot_headers_to_kusama;
|
||||
pub mod polkadot_messages_to_kusama;
|
||||
pub mod rialto_headers_to_millau;
|
||||
pub mod rialto_messages_to_millau;
|
||||
pub mod rialto_parachains_to_millau;
|
||||
pub mod rococo_headers_to_wococo;
|
||||
pub mod rococo_messages_to_wococo;
|
||||
pub mod westend_headers_to_millau;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Rialto-to-Millau parachains sync entrypoint.
|
||||
|
||||
use parachains_relay::ParachainsPipeline;
|
||||
use relay_millau_client::Millau;
|
||||
use relay_rialto_client::Rialto;
|
||||
use substrate_relay_helper::parachains_target::DirectSubmitParachainHeadsCallBuilder;
|
||||
|
||||
/// Rialto-to-Millau parachains sync description.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RialtoToMillauParachains;
|
||||
|
||||
impl ParachainsPipeline for RialtoToMillauParachains {
|
||||
type SourceChain = Rialto;
|
||||
type TargetChain = Millau;
|
||||
}
|
||||
|
||||
/// `submit_parachain_heads` call builder for Rialto-to-Millau parachains sync pipeline.
|
||||
pub type RialtoToMillauParachainsSubmitParachainHeadsCallBuilder =
|
||||
DirectSubmitParachainHeadsCallBuilder<
|
||||
RialtoToMillauParachains,
|
||||
millau_runtime::Runtime,
|
||||
millau_runtime::WitRialtoParachainsInstance,
|
||||
>;
|
||||
@@ -36,6 +36,7 @@ mod reinit_bridge;
|
||||
mod relay_headers;
|
||||
mod relay_headers_and_messages;
|
||||
mod relay_messages;
|
||||
mod relay_parachains;
|
||||
mod resubmit_transactions;
|
||||
|
||||
/// Parse relay CLI args.
|
||||
@@ -85,6 +86,8 @@ pub enum Command {
|
||||
ResubmitTransactions(resubmit_transactions::ResubmitTransactions),
|
||||
/// Register parachain.
|
||||
RegisterParachain(register_parachain::RegisterParachain),
|
||||
///
|
||||
RelayParachains(relay_parachains::RelayParachains),
|
||||
}
|
||||
|
||||
impl Command {
|
||||
@@ -118,6 +121,7 @@ impl Command {
|
||||
Self::EstimateFee(arg) => arg.run().await?,
|
||||
Self::ResubmitTransactions(arg) => arg.run().await?,
|
||||
Self::RegisterParachain(arg) => arg.run().await?,
|
||||
Self::RelayParachains(arg) => arg.run().await?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use bp_polkadot_core::parachains::ParaId;
|
||||
use parachains_relay::{parachains_loop::ParachainSyncParams, ParachainsPipeline};
|
||||
use relay_utils::metrics::{GlobalMetrics, StandaloneMetric};
|
||||
use structopt::StructOpt;
|
||||
use strum::{EnumString, EnumVariantNames, VariantNames};
|
||||
use substrate_relay_helper::{
|
||||
parachains_source::ParachainsSource, parachains_target::ParachainsTarget, TransactionParams,
|
||||
};
|
||||
|
||||
use crate::cli::{
|
||||
PrometheusParams, SourceConnectionParams, TargetConnectionParams, TargetSigningParams,
|
||||
};
|
||||
|
||||
/// Start parachain heads relayer process.
|
||||
#[derive(StructOpt)]
|
||||
pub struct RelayParachains {
|
||||
/// A bridge instance to relay parachains heads for.
|
||||
#[structopt(possible_values = RelayParachainsBridge::VARIANTS, case_insensitive = true)]
|
||||
bridge: RelayParachainsBridge,
|
||||
#[structopt(flatten)]
|
||||
source: SourceConnectionParams,
|
||||
#[structopt(flatten)]
|
||||
target: TargetConnectionParams,
|
||||
#[structopt(flatten)]
|
||||
target_sign: TargetSigningParams,
|
||||
#[structopt(flatten)]
|
||||
prometheus_params: PrometheusParams,
|
||||
}
|
||||
|
||||
/// Parachain heads relay bridge.
|
||||
#[derive(Debug, EnumString, EnumVariantNames)]
|
||||
#[strum(serialize_all = "kebab_case")]
|
||||
pub enum RelayParachainsBridge {
|
||||
RialtoToMillau,
|
||||
}
|
||||
|
||||
macro_rules! select_bridge {
|
||||
($bridge: expr, $generic: tt) => {
|
||||
match $bridge {
|
||||
RelayParachainsBridge::RialtoToMillau => {
|
||||
use crate::chains::rialto_parachains_to_millau::{
|
||||
RialtoToMillauParachains as Pipeline,
|
||||
RialtoToMillauParachainsSubmitParachainHeadsCallBuilder as SubmitParachainHeadsCallBuilder,
|
||||
};
|
||||
|
||||
use bp_millau::BRIDGE_PARAS_PALLET_NAME as BRIDGE_PARAS_PALLET_NAME_AT_TARGET;
|
||||
use bp_rialto::PARAS_PALLET_NAME as PARAS_PALLET_NAME_AT_SOURCE;
|
||||
|
||||
use relay_millau_client::Millau as TargetTransactionSignScheme;
|
||||
|
||||
$generic
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl RelayParachains {
|
||||
/// Run the command.
|
||||
pub async fn run(self) -> anyhow::Result<()> {
|
||||
select_bridge!(self.bridge, {
|
||||
type SourceChain = <Pipeline as ParachainsPipeline>::SourceChain;
|
||||
type TargetChain = <Pipeline as ParachainsPipeline>::TargetChain;
|
||||
|
||||
let source_client = self.source.to_client::<SourceChain>().await?;
|
||||
let source_client = ParachainsSource::<Pipeline>::new(
|
||||
source_client,
|
||||
PARAS_PALLET_NAME_AT_SOURCE.into(),
|
||||
);
|
||||
|
||||
let taret_transaction_params = TransactionParams {
|
||||
signer: self.target_sign.to_keypair::<TargetChain>()?,
|
||||
mortality: self.target_sign.target_transactions_mortality,
|
||||
};
|
||||
let target_client = self.target.to_client::<TargetChain>().await?;
|
||||
let target_client = ParachainsTarget::<
|
||||
Pipeline,
|
||||
TargetTransactionSignScheme,
|
||||
SubmitParachainHeadsCallBuilder,
|
||||
>::new(
|
||||
target_client.clone(),
|
||||
taret_transaction_params,
|
||||
BRIDGE_PARAS_PALLET_NAME_AT_TARGET.into(),
|
||||
);
|
||||
|
||||
let metrics_params: relay_utils::metrics::MetricsParams = self.prometheus_params.into();
|
||||
GlobalMetrics::new()?.register_and_spawn(&metrics_params.registry)?;
|
||||
|
||||
parachains_relay::parachains_loop::run(
|
||||
source_client,
|
||||
target_client,
|
||||
ParachainSyncParams {
|
||||
parachains: vec![ParaId(2000)],
|
||||
stall_timeout: std::time::Duration::from_secs(60),
|
||||
strategy: parachains_relay::parachains_loop::ParachainSyncStrategy::Any,
|
||||
},
|
||||
metrics_params,
|
||||
futures::future::pending(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow::format_err!("{}", e))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user