mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
Merge commit 'f9c24ef0db390c355241445af37a5c7999a7dc66' into hc-bump-bridges-subtree-take-2
This commit is contained in:
@@ -23,10 +23,12 @@ structopt = "0.3"
|
||||
bp-header-chain = { path = "../../primitives/header-chain" }
|
||||
bp-kusama = { path = "../../primitives/chain-kusama" }
|
||||
bp-messages = { path = "../../primitives/messages" }
|
||||
bp-message-dispatch = { path = "../../primitives/message-dispatch" }
|
||||
bp-millau = { path = "../../primitives/chain-millau" }
|
||||
bp-polkadot = { path = "../../primitives/chain-polkadot" }
|
||||
bp-rialto = { path = "../../primitives/chain-rialto" }
|
||||
bp-rococo = { path = "../../primitives/chain-rococo" }
|
||||
bp-wococo = { path = "../../primitives/chain-wococo" }
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
bp-westend = { path = "../../primitives/chain-westend" }
|
||||
bridge-runtime-common = { path = "../../bin/runtime-common" }
|
||||
@@ -35,13 +37,13 @@ finality-relay = { path = "../finality" }
|
||||
headers-relay = { path = "../headers" }
|
||||
messages-relay = { path = "../messages" }
|
||||
millau-runtime = { path = "../../bin/millau/runtime" }
|
||||
pallet-bridge-dispatch = { path = "../../modules/dispatch" }
|
||||
pallet-bridge-messages = { path = "../../modules/messages" }
|
||||
relay-kusama-client = { path = "../client-kusama" }
|
||||
relay-millau-client = { path = "../client-millau" }
|
||||
relay-polkadot-client = { path = "../client-polkadot" }
|
||||
relay-rialto-client = { path = "../client-rialto" }
|
||||
relay-rococo-client = { path = "../client-rococo" }
|
||||
relay-wococo-client = { path = "../client-wococo" }
|
||||
relay-substrate-client = { path = "../client-substrate" }
|
||||
relay-utils = { path = "../utils" }
|
||||
relay-westend-client = { path = "../client-westend" }
|
||||
|
||||
@@ -21,9 +21,9 @@ use crate::cli::{
|
||||
encode_call::{self, Call, CliEncodeCall},
|
||||
encode_message, send_message, CliChain,
|
||||
};
|
||||
use bp_message_dispatch::{CallOrigin, MessagePayload};
|
||||
use codec::Decode;
|
||||
use frame_support::weights::{GetDispatchInfo, Weight};
|
||||
use pallet_bridge_dispatch::{CallOrigin, MessagePayload};
|
||||
use relay_millau_client::Millau;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
|
||||
@@ -20,14 +20,15 @@ pub mod millau_headers_to_rialto;
|
||||
pub mod millau_messages_to_rialto;
|
||||
pub mod rialto_headers_to_millau;
|
||||
pub mod rialto_messages_to_millau;
|
||||
pub mod rococo_headers_to_westend;
|
||||
pub mod rococo_headers_to_wococo;
|
||||
pub mod westend_headers_to_millau;
|
||||
pub mod westend_headers_to_rococo;
|
||||
pub mod wococo_headers_to_rococo;
|
||||
|
||||
mod millau;
|
||||
mod rialto;
|
||||
mod rococo;
|
||||
mod westend;
|
||||
mod wococo;
|
||||
|
||||
use relay_utils::metrics::{FloatJsonValueMetric, MetricsParams};
|
||||
|
||||
@@ -131,7 +132,7 @@ mod tests {
|
||||
let payload = send_message::message_payload(
|
||||
Default::default(),
|
||||
call.get_dispatch_info().weight,
|
||||
pallet_bridge_dispatch::CallOrigin::SourceRoot,
|
||||
bp_message_dispatch::CallOrigin::SourceRoot,
|
||||
&call,
|
||||
);
|
||||
assert_eq!(Millau::verify_message(&payload), Ok(()));
|
||||
@@ -141,7 +142,7 @@ mod tests {
|
||||
let payload = send_message::message_payload(
|
||||
Default::default(),
|
||||
call.get_dispatch_info().weight,
|
||||
pallet_bridge_dispatch::CallOrigin::SourceRoot,
|
||||
bp_message_dispatch::CallOrigin::SourceRoot,
|
||||
&call,
|
||||
);
|
||||
assert!(Millau::verify_message(&payload).is_err());
|
||||
@@ -168,7 +169,7 @@ mod tests {
|
||||
let payload = send_message::message_payload(
|
||||
Default::default(),
|
||||
maximal_dispatch_weight,
|
||||
pallet_bridge_dispatch::CallOrigin::SourceRoot,
|
||||
bp_message_dispatch::CallOrigin::SourceRoot,
|
||||
&call,
|
||||
);
|
||||
assert_eq!(Millau::verify_message(&payload), Ok(()));
|
||||
@@ -176,7 +177,7 @@ mod tests {
|
||||
let payload = send_message::message_payload(
|
||||
Default::default(),
|
||||
maximal_dispatch_weight + 1,
|
||||
pallet_bridge_dispatch::CallOrigin::SourceRoot,
|
||||
bp_message_dispatch::CallOrigin::SourceRoot,
|
||||
&call,
|
||||
);
|
||||
assert!(Millau::verify_message(&payload).is_err());
|
||||
@@ -193,7 +194,7 @@ mod tests {
|
||||
let payload = send_message::message_payload(
|
||||
Default::default(),
|
||||
maximal_dispatch_weight,
|
||||
pallet_bridge_dispatch::CallOrigin::SourceRoot,
|
||||
bp_message_dispatch::CallOrigin::SourceRoot,
|
||||
&call,
|
||||
);
|
||||
assert_eq!(Rialto::verify_message(&payload), Ok(()));
|
||||
@@ -201,7 +202,7 @@ mod tests {
|
||||
let payload = send_message::message_payload(
|
||||
Default::default(),
|
||||
maximal_dispatch_weight + 1,
|
||||
pallet_bridge_dispatch::CallOrigin::SourceRoot,
|
||||
bp_message_dispatch::CallOrigin::SourceRoot,
|
||||
&call,
|
||||
);
|
||||
assert!(Rialto::verify_message(&payload).is_err());
|
||||
@@ -270,7 +271,7 @@ mod rococo_tests {
|
||||
votes_ancestries: vec![],
|
||||
};
|
||||
|
||||
let actual = bp_rococo::BridgeGrandpaWestendCall::submit_finality_proof(header.clone(), justification.clone());
|
||||
let actual = bp_rococo::BridgeGrandpaWococoCall::submit_finality_proof(header.clone(), justification.clone());
|
||||
let expected = millau_runtime::BridgeGrandpaRialtoCall::<millau_runtime::Runtime>::submit_finality_proof(
|
||||
header,
|
||||
justification,
|
||||
|
||||
@@ -21,9 +21,9 @@ use crate::cli::{
|
||||
encode_call::{self, Call, CliEncodeCall},
|
||||
encode_message, send_message, CliChain,
|
||||
};
|
||||
use bp_message_dispatch::{CallOrigin, MessagePayload};
|
||||
use codec::Decode;
|
||||
use frame_support::weights::{GetDispatchInfo, Weight};
|
||||
use pallet_bridge_dispatch::{CallOrigin, MessagePayload};
|
||||
use relay_rialto_client::Rialto;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
|
||||
+10
-10
@@ -14,7 +14,7 @@
|
||||
// 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/>.
|
||||
|
||||
//! Rococo-to-Westend headers sync entrypoint.
|
||||
//! Rococo-to-Wococo headers sync entrypoint.
|
||||
|
||||
use crate::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate};
|
||||
|
||||
@@ -23,37 +23,37 @@ use codec::Encode;
|
||||
use relay_rococo_client::{Rococo, SyncHeader as RococoSyncHeader};
|
||||
use relay_substrate_client::{Chain, TransactionSignScheme};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use relay_westend_client::{SigningParams as WestendSigningParams, Westend};
|
||||
use relay_wococo_client::{SigningParams as WococoSigningParams, Wococo};
|
||||
use sp_core::{Bytes, Pair};
|
||||
|
||||
/// Rococo-to-Westend finality sync pipeline.
|
||||
pub(crate) type RococoFinalityToWestend = SubstrateFinalityToSubstrate<Rococo, Westend, WestendSigningParams>;
|
||||
/// Rococo-to-Wococo finality sync pipeline.
|
||||
pub(crate) type RococoFinalityToWococo = SubstrateFinalityToSubstrate<Rococo, Wococo, WococoSigningParams>;
|
||||
|
||||
impl SubstrateFinalitySyncPipeline for RococoFinalityToWestend {
|
||||
impl SubstrateFinalitySyncPipeline for RococoFinalityToWococo {
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_rococo::BEST_FINALIZED_ROCOCO_HEADER_METHOD;
|
||||
|
||||
type TargetChain = Westend;
|
||||
type TargetChain = Wococo;
|
||||
|
||||
fn customize_metrics(params: MetricsParams) -> anyhow::Result<MetricsParams> {
|
||||
crate::chains::add_polkadot_kusama_price_metrics::<Self>(params)
|
||||
}
|
||||
|
||||
fn transactions_author(&self) -> bp_westend::AccountId {
|
||||
fn transactions_author(&self) -> bp_wococo::AccountId {
|
||||
(*self.target_sign.public().as_array_ref()).into()
|
||||
}
|
||||
|
||||
fn make_submit_finality_proof_transaction(
|
||||
&self,
|
||||
transaction_nonce: <Westend as Chain>::Index,
|
||||
transaction_nonce: <Wococo as Chain>::Index,
|
||||
header: RococoSyncHeader,
|
||||
proof: GrandpaJustification<bp_rococo::Header>,
|
||||
) -> Bytes {
|
||||
let call = bp_westend::Call::BridgeGrandpaRococo(bp_westend::BridgeGrandpaRococoCall::submit_finality_proof(
|
||||
let call = bp_wococo::Call::BridgeGrandpaRococo(bp_wococo::BridgeGrandpaRococoCall::submit_finality_proof(
|
||||
header.into_inner(),
|
||||
proof,
|
||||
));
|
||||
let genesis_hash = *self.target_client.genesis_hash();
|
||||
let transaction = Westend::sign_transaction(genesis_hash, &self.target_sign, transaction_nonce, call);
|
||||
let transaction = Wococo::sign_transaction(genesis_hash, &self.target_sign, transaction_nonce, call);
|
||||
|
||||
Bytes(transaction.encode())
|
||||
}
|
||||
@@ -48,7 +48,7 @@ impl SubstrateFinalitySyncPipeline for WestendFinalityToRococo {
|
||||
header: WestendSyncHeader,
|
||||
proof: GrandpaJustification<bp_westend::Header>,
|
||||
) -> Bytes {
|
||||
let call = bp_rococo::Call::BridgeGrandpaWestend(bp_rococo::BridgeGrandpaWestendCall::submit_finality_proof(
|
||||
let call = bp_rococo::Call::BridgeGrandpaWestend(bp_rococo::BridgeGrandpaCall::submit_finality_proof(
|
||||
header.into_inner(),
|
||||
proof,
|
||||
));
|
||||
|
||||
@@ -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/>.
|
||||
|
||||
use crate::cli::{encode_message, CliChain};
|
||||
use frame_support::weights::Weight;
|
||||
use relay_wococo_client::Wococo;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
impl CliChain for Wococo {
|
||||
const RUNTIME_VERSION: RuntimeVersion = bp_wococo::VERSION;
|
||||
|
||||
type KeyPair = sp_core::sr25519::Pair;
|
||||
type MessagePayload = ();
|
||||
|
||||
fn ss58_format() -> u16 {
|
||||
42
|
||||
}
|
||||
|
||||
fn max_extrinsic_weight() -> Weight {
|
||||
0
|
||||
}
|
||||
|
||||
fn encode_message(_message: encode_message::MessagePayload) -> Result<Self::MessagePayload, String> {
|
||||
Err("Sending messages from Wococo is not yet supported.".into())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// 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/>.
|
||||
|
||||
//! Wococo-to-Rococo headers sync entrypoint.
|
||||
|
||||
use crate::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate};
|
||||
|
||||
use bp_header_chain::justification::GrandpaJustification;
|
||||
use codec::Encode;
|
||||
use relay_rococo_client::{Rococo, SigningParams as RococoSigningParams};
|
||||
use relay_substrate_client::{Chain, TransactionSignScheme};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use relay_wococo_client::{SyncHeader as WococoSyncHeader, Wococo};
|
||||
use sp_core::{Bytes, Pair};
|
||||
|
||||
/// Wococo-to-Rococo finality sync pipeline.
|
||||
pub(crate) type WococoFinalityToRococo = SubstrateFinalityToSubstrate<Wococo, Rococo, RococoSigningParams>;
|
||||
|
||||
impl SubstrateFinalitySyncPipeline for WococoFinalityToRococo {
|
||||
const BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET: &'static str = bp_wococo::BEST_FINALIZED_WOCOCO_HEADER_METHOD;
|
||||
|
||||
type TargetChain = Rococo;
|
||||
|
||||
fn customize_metrics(params: MetricsParams) -> anyhow::Result<MetricsParams> {
|
||||
crate::chains::add_polkadot_kusama_price_metrics::<Self>(params)
|
||||
}
|
||||
|
||||
fn transactions_author(&self) -> bp_rococo::AccountId {
|
||||
(*self.target_sign.public().as_array_ref()).into()
|
||||
}
|
||||
|
||||
fn make_submit_finality_proof_transaction(
|
||||
&self,
|
||||
transaction_nonce: <Rococo as Chain>::Index,
|
||||
header: WococoSyncHeader,
|
||||
proof: GrandpaJustification<bp_wococo::Header>,
|
||||
) -> Bytes {
|
||||
let call = bp_rococo::Call::BridgeGrandpaWococo(bp_rococo::BridgeGrandpaWococoCall::submit_finality_proof(
|
||||
header.into_inner(),
|
||||
proof,
|
||||
));
|
||||
let genesis_hash = *self.target_client.genesis_hash();
|
||||
let transaction = Rococo::sign_transaction(genesis_hash, &self.target_sign, transaction_nonce, call);
|
||||
|
||||
Bytes(transaction.encode())
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ macro_rules! select_full_bridge {
|
||||
|
||||
// Derive-account
|
||||
#[allow(unused_imports)]
|
||||
use bp_millau::derive_account_from_rialto_id as derive_account;
|
||||
use bp_rialto::derive_account_from_millau_id as derive_account;
|
||||
|
||||
// Relay-messages
|
||||
#[allow(unused_imports)]
|
||||
@@ -75,7 +75,7 @@ macro_rules! select_full_bridge {
|
||||
|
||||
// Derive-account
|
||||
#[allow(unused_imports)]
|
||||
use bp_rialto::derive_account_from_millau_id as derive_account;
|
||||
use bp_millau::derive_account_from_rialto_id as derive_account;
|
||||
|
||||
// Relay-messages
|
||||
#[allow(unused_imports)]
|
||||
|
||||
@@ -91,11 +91,11 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
format!("{}", rialto_derived),
|
||||
"73gLnUwrAdH4vMjbXCiNEpgyz1PLk9JxCaY4cKzvfSZT73KE"
|
||||
"74GNQjmkcfstRftSQPJgMREchqHM56EvAUXRc266cZ1NYVW5"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", millau_derived),
|
||||
"5rpTJqGv1BPAYy2sXzkPpc3Wx1ZpQtgfuBsrDpNV4HsXAmbi"
|
||||
"5rERgaT1Z8nM3et2epA5i1VtEBfp5wkhwHtVE8HK7BRbjAH2"
|
||||
);
|
||||
assert_eq!(millau_derived, millau2_derived);
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ arg_enum! {
|
||||
MillauToRialto,
|
||||
RialtoToMillau,
|
||||
WestendToMillau,
|
||||
WestendToRococo,
|
||||
RococoToWestend,
|
||||
RococoToWococo,
|
||||
WococoToRococo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,26 +102,26 @@ macro_rules! select_bridge {
|
||||
|
||||
$generic
|
||||
}
|
||||
InitBridgeName::WestendToRococo => {
|
||||
type Source = relay_westend_client::Westend;
|
||||
InitBridgeName::RococoToWococo => {
|
||||
type Source = relay_rococo_client::Rococo;
|
||||
type Target = relay_wococo_client::Wococo;
|
||||
|
||||
fn encode_init_bridge(
|
||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||
) -> <Target as Chain>::Call {
|
||||
bp_wococo::Call::BridgeGrandpaRococo(bp_wococo::BridgeGrandpaRococoCall::initialize(init_data))
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
InitBridgeName::WococoToRococo => {
|
||||
type Source = relay_wococo_client::Wococo;
|
||||
type Target = relay_rococo_client::Rococo;
|
||||
|
||||
fn encode_init_bridge(
|
||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||
) -> <Target as Chain>::Call {
|
||||
bp_rococo::Call::BridgeGrandpaWestend(bp_rococo::BridgeGrandpaWestendCall::initialize(init_data))
|
||||
}
|
||||
|
||||
$generic
|
||||
}
|
||||
InitBridgeName::RococoToWestend => {
|
||||
type Source = relay_rococo_client::Rococo;
|
||||
type Target = relay_westend_client::Westend;
|
||||
|
||||
fn encode_init_bridge(
|
||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||
) -> <Target as Chain>::Call {
|
||||
bp_westend::Call::BridgeGrandpaRococo(bp_westend::BridgeGrandpaRococoCall::initialize(init_data))
|
||||
bp_rococo::Call::BridgeGrandpaWococo(bp_rococo::BridgeGrandpaWococoCall::initialize(init_data))
|
||||
}
|
||||
|
||||
$generic
|
||||
|
||||
@@ -89,8 +89,23 @@ pub enum Command {
|
||||
}
|
||||
|
||||
impl Command {
|
||||
// Initialize logger depending on the command.
|
||||
fn init_logger(&self) {
|
||||
use relay_utils::initialize::{initialize_logger, initialize_relay};
|
||||
|
||||
match self {
|
||||
Self::RelayHeaders(_) | Self::RelayMessages(_) | Self::RelayHeadersAndMessages(_) | Self::InitBridge(_) => {
|
||||
initialize_relay();
|
||||
}
|
||||
_ => {
|
||||
initialize_logger(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the command.
|
||||
pub async fn run(self) -> anyhow::Result<()> {
|
||||
self.init_logger();
|
||||
match self {
|
||||
Self::RelayHeaders(arg) => arg.run().await?,
|
||||
Self::RelayMessages(arg) => arg.run().await?,
|
||||
|
||||
@@ -42,8 +42,8 @@ arg_enum! {
|
||||
MillauToRialto,
|
||||
RialtoToMillau,
|
||||
WestendToMillau,
|
||||
WestendToRococo,
|
||||
RococoToWestend,
|
||||
RococoToWococo,
|
||||
WococoToRococo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,17 +71,17 @@ macro_rules! select_bridge {
|
||||
|
||||
$generic
|
||||
}
|
||||
RelayHeadersBridge::WestendToRococo => {
|
||||
type Source = relay_westend_client::Westend;
|
||||
type Target = relay_rococo_client::Rococo;
|
||||
type Finality = crate::chains::westend_headers_to_rococo::WestendFinalityToRococo;
|
||||
RelayHeadersBridge::RococoToWococo => {
|
||||
type Source = relay_rococo_client::Rococo;
|
||||
type Target = relay_wococo_client::Wococo;
|
||||
type Finality = crate::chains::rococo_headers_to_wococo::RococoFinalityToWococo;
|
||||
|
||||
$generic
|
||||
}
|
||||
RelayHeadersBridge::RococoToWestend => {
|
||||
type Source = relay_rococo_client::Rococo;
|
||||
type Target = relay_westend_client::Westend;
|
||||
type Finality = crate::chains::rococo_headers_to_westend::RococoFinalityToWestend;
|
||||
RelayHeadersBridge::WococoToRococo => {
|
||||
type Source = relay_wococo_client::Wococo;
|
||||
type Target = relay_rococo_client::Rococo;
|
||||
type Finality = crate::chains::wococo_headers_to_rococo::WococoFinalityToRococo;
|
||||
|
||||
$generic
|
||||
}
|
||||
@@ -102,6 +102,7 @@ impl RelayHeaders {
|
||||
Finality::new(target_client.clone(), target_sign),
|
||||
source_client,
|
||||
target_client,
|
||||
false,
|
||||
metrics_params,
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -96,6 +96,9 @@ macro_rules! select_bridge {
|
||||
type LeftToRightMessages = crate::chains::millau_messages_to_rialto::MillauMessagesToRialto;
|
||||
type RightToLeftMessages = crate::chains::rialto_messages_to_millau::RialtoMessagesToMillau;
|
||||
|
||||
const MAX_MISSING_LEFT_HEADERS_AT_RIGHT: bp_millau::BlockNumber = bp_millau::SESSION_LENGTH;
|
||||
const MAX_MISSING_RIGHT_HEADERS_AT_LEFT: bp_rialto::BlockNumber = bp_rialto::SESSION_LENGTH;
|
||||
|
||||
use crate::chains::millau_messages_to_rialto::run as left_to_right_messages;
|
||||
use crate::chains::rialto_messages_to_millau::run as right_to_left_messages;
|
||||
|
||||
@@ -131,11 +134,13 @@ impl RelayHeadersAndMessages {
|
||||
left_client.clone(),
|
||||
right_client.clone(),
|
||||
LeftToRightFinality::new(right_client.clone(), right_sign.clone()),
|
||||
MAX_MISSING_LEFT_HEADERS_AT_RIGHT,
|
||||
);
|
||||
let right_to_left_on_demand_headers = OnDemandHeadersRelay::new(
|
||||
right_client.clone(),
|
||||
left_client.clone(),
|
||||
RightToLeftFinality::new(left_client.clone(), left_sign.clone()),
|
||||
MAX_MISSING_RIGHT_HEADERS_AT_LEFT,
|
||||
);
|
||||
|
||||
let left_to_right_messages = left_to_right_messages(MessagesRelayParams {
|
||||
|
||||
@@ -21,9 +21,9 @@ use crate::cli::{
|
||||
Balance, CliChain, ExplicitOrMaximal, HexBytes, HexLaneId, Origins, SourceConnectionParams, SourceSigningParams,
|
||||
TargetSigningParams,
|
||||
};
|
||||
use bp_message_dispatch::{CallOrigin, MessagePayload};
|
||||
use codec::Encode;
|
||||
use frame_support::{dispatch::GetDispatchInfo, weights::Weight};
|
||||
use pallet_bridge_dispatch::{CallOrigin, MessagePayload};
|
||||
use relay_substrate_client::{Chain, TransactionSignScheme};
|
||||
use sp_core::{Bytes, Pair};
|
||||
use sp_runtime::{traits::IdentifyAccount, AccountId32, MultiSignature, MultiSigner};
|
||||
|
||||
@@ -96,7 +96,7 @@ where
|
||||
SourceChain: Clone + Chain + Debug,
|
||||
BlockNumberOf<SourceChain>: BlockNumberBase,
|
||||
TargetChain: Clone + Chain + Debug,
|
||||
TargetSign: Clone + Send + Sync,
|
||||
TargetSign: 'static + Clone + Send + Sync,
|
||||
{
|
||||
const SOURCE_NAME: &'static str = SourceChain::NAME;
|
||||
const TARGET_NAME: &'static str = TargetChain::NAME;
|
||||
@@ -112,6 +112,7 @@ pub async fn run<SourceChain, TargetChain, P>(
|
||||
pipeline: P,
|
||||
source_client: Client<SourceChain>,
|
||||
target_client: Client<TargetChain>,
|
||||
is_on_demand_task: bool,
|
||||
metrics_params: MetricsParams,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
@@ -137,6 +138,7 @@ where
|
||||
FinalitySource::new(source_client),
|
||||
SubstrateFinalityTarget::new(target_client, pipeline),
|
||||
FinalitySyncParams {
|
||||
is_on_demand_task,
|
||||
tick: std::cmp::max(SourceChain::AVERAGE_BLOCK_INTERVAL, TargetChain::AVERAGE_BLOCK_INTERVAL),
|
||||
recent_finality_proofs_limit: RECENT_FINALITY_PROOFS_LIMIT,
|
||||
stall_timeout: STALL_TIMEOUT,
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use relay_utils::initialize::initialize_logger;
|
||||
|
||||
mod chains;
|
||||
mod cli;
|
||||
mod finality_pipeline;
|
||||
@@ -31,7 +29,6 @@ mod messages_target;
|
||||
mod on_demand_headers;
|
||||
|
||||
fn main() {
|
||||
initialize_logger(false);
|
||||
let command = cli::parse_args();
|
||||
let run = command.run();
|
||||
let result = async_std::task::block_on(run);
|
||||
|
||||
@@ -203,7 +203,7 @@ mod tests {
|
||||
// reserved for messages dispatch allows dispatch of non-trivial messages.
|
||||
//
|
||||
// Any significant change in this values should attract additional attention.
|
||||
(1020, 216_583_333_334),
|
||||
(1013, 216_583_333_334),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ impl<C, P, R, I> RelayClient for SubstrateMessagesSource<C, P, R, I>
|
||||
where
|
||||
C: Chain,
|
||||
P: SubstrateMessageLane,
|
||||
R: Send + Sync,
|
||||
R: 'static + Send + Sync,
|
||||
I: Send + Sync + Instance,
|
||||
{
|
||||
type Error = SubstrateError;
|
||||
|
||||
@@ -93,7 +93,7 @@ impl<C, P, R, I> RelayClient for SubstrateMessagesTarget<C, P, R, I>
|
||||
where
|
||||
C: Chain,
|
||||
P: SubstrateMessageLane,
|
||||
R: Send + Sync,
|
||||
R: 'static + Send + Sync,
|
||||
I: Send + Sync + Instance,
|
||||
{
|
||||
type Error = SubstrateError;
|
||||
|
||||
@@ -20,14 +20,22 @@ use crate::finality_pipeline::{SubstrateFinalitySyncPipeline, SubstrateFinalityT
|
||||
use crate::finality_target::SubstrateFinalityTarget;
|
||||
|
||||
use bp_header_chain::justification::GrandpaJustification;
|
||||
use finality_relay::TargetClient as FinalityTargetClient;
|
||||
use finality_relay::{
|
||||
FinalitySyncPipeline, SourceClient as FinalitySourceClient, TargetClient as FinalityTargetClient,
|
||||
};
|
||||
use futures::{
|
||||
channel::{mpsc, oneshot},
|
||||
select, FutureExt, StreamExt,
|
||||
};
|
||||
use num_traits::Zero;
|
||||
use relay_substrate_client::{BlockNumberOf, Chain, Client, HashOf, HeaderIdOf, SyncHeader};
|
||||
use relay_utils::{metrics::MetricsParams, BlockNumberBase, HeaderId};
|
||||
use num_traits::{CheckedSub, Zero};
|
||||
use relay_substrate_client::{
|
||||
finality_source::FinalitySource as SubstrateFinalitySource, BlockNumberOf, Chain, Client, HashOf, HeaderIdOf,
|
||||
SyncHeader,
|
||||
};
|
||||
use relay_utils::{
|
||||
metrics::MetricsParams, relay_loop::Client as RelayClient, BlockNumberBase, FailedClient, HeaderId,
|
||||
MaybeConnectionError,
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// On-demand Substrate <-> Substrate headers relay.
|
||||
@@ -49,6 +57,7 @@ impl<SourceChain: Chain> OnDemandHeadersRelay<SourceChain> {
|
||||
source_client: Client<SourceChain>,
|
||||
target_client: Client<TargetChain>,
|
||||
pipeline: SubstrateFinalityToSubstrate<SourceChain, TargetChain, TargetSign>,
|
||||
maximal_headers_difference: SourceChain::BlockNumber,
|
||||
) -> Self
|
||||
where
|
||||
SourceChain: Chain + Debug,
|
||||
@@ -68,7 +77,14 @@ impl<SourceChain: Chain> OnDemandHeadersRelay<SourceChain> {
|
||||
{
|
||||
let (required_header_tx, required_header_rx) = mpsc::channel(1);
|
||||
async_std::task::spawn(async move {
|
||||
background_task(source_client, target_client, pipeline, required_header_rx).await;
|
||||
background_task(
|
||||
source_client,
|
||||
target_client,
|
||||
pipeline,
|
||||
maximal_headers_difference,
|
||||
required_header_rx,
|
||||
)
|
||||
.await;
|
||||
});
|
||||
|
||||
let background_task_name = format!(
|
||||
@@ -100,6 +116,7 @@ async fn background_task<SourceChain, TargetChain, TargetSign>(
|
||||
source_client: Client<SourceChain>,
|
||||
target_client: Client<TargetChain>,
|
||||
pipeline: SubstrateFinalityToSubstrate<SourceChain, TargetChain, TargetSign>,
|
||||
maximal_headers_difference: SourceChain::BlockNumber,
|
||||
mut required_header_rx: mpsc::Receiver<HeaderIdOf<SourceChain>>,
|
||||
) where
|
||||
SourceChain: Chain + Debug,
|
||||
@@ -118,7 +135,11 @@ async fn background_task<SourceChain, TargetChain, TargetSign>(
|
||||
FinalityTargetClient<SubstrateFinalityToSubstrate<SourceChain, TargetChain, TargetSign>>,
|
||||
{
|
||||
let relay_task_name = on_demand_headers_relay_name::<SourceChain, TargetChain>();
|
||||
let finality_target = SubstrateFinalityTarget::new(target_client.clone(), pipeline.clone());
|
||||
let mut finality_source = SubstrateFinalitySource::<
|
||||
_,
|
||||
SubstrateFinalityToSubstrate<SourceChain, TargetChain, TargetSign>,
|
||||
>::new(source_client.clone());
|
||||
let mut finality_target = SubstrateFinalityTarget::new(target_client.clone(), pipeline.clone());
|
||||
|
||||
let mut active_headers_relay = None;
|
||||
let mut required_header_number = Zero::zero();
|
||||
@@ -150,30 +171,45 @@ async fn background_task<SourceChain, TargetChain, TargetSign>(
|
||||
},
|
||||
}
|
||||
|
||||
// read best finalized source block from target
|
||||
let available_header_number = match finality_target.best_finalized_source_block_number().await {
|
||||
Ok(available_header_number) => available_header_number,
|
||||
Err(error) => {
|
||||
log::error!(
|
||||
target: "bridge",
|
||||
"Failed to read best finalized {} header from {} in {} relay: {:?}",
|
||||
SourceChain::NAME,
|
||||
TargetChain::NAME,
|
||||
relay_task_name,
|
||||
error,
|
||||
);
|
||||
// read best finalized source header number from source
|
||||
let best_finalized_source_header_at_source =
|
||||
best_finalized_source_header_at_source(&finality_source, &relay_task_name).await;
|
||||
if matches!(best_finalized_source_header_at_source, Err(ref e) if e.is_connection_error()) {
|
||||
relay_utils::relay_loop::reconnect_failed_client(
|
||||
FailedClient::Source,
|
||||
relay_utils::relay_loop::RECONNECT_DELAY,
|
||||
&mut finality_source,
|
||||
&mut finality_target,
|
||||
)
|
||||
.await;
|
||||
continue;
|
||||
}
|
||||
|
||||
// we don't know what's happening with target client, so better to stop on-demand relay than
|
||||
// submit unneeded transactions
|
||||
// => assume that required header is known to the target node
|
||||
required_header_number
|
||||
}
|
||||
};
|
||||
// read best finalized source header number from target
|
||||
let best_finalized_source_header_at_target =
|
||||
best_finalized_source_header_at_target::<SourceChain, _, _>(&finality_target, &relay_task_name).await;
|
||||
if matches!(best_finalized_source_header_at_target, Err(ref e) if e.is_connection_error()) {
|
||||
relay_utils::relay_loop::reconnect_failed_client(
|
||||
FailedClient::Target,
|
||||
relay_utils::relay_loop::RECONNECT_DELAY,
|
||||
&mut finality_source,
|
||||
&mut finality_target,
|
||||
)
|
||||
.await;
|
||||
continue;
|
||||
}
|
||||
|
||||
// start or stop headers relay if required
|
||||
let activate = required_header_number > available_header_number;
|
||||
match (activate, active_headers_relay.is_some()) {
|
||||
(true, false) => {
|
||||
let action = select_on_demand_relay_action::<SourceChain>(
|
||||
best_finalized_source_header_at_source.ok(),
|
||||
best_finalized_source_header_at_target.ok(),
|
||||
required_header_number,
|
||||
maximal_headers_difference,
|
||||
&relay_task_name,
|
||||
active_headers_relay.is_some(),
|
||||
);
|
||||
match action {
|
||||
OnDemandRelayAction::Start => {
|
||||
let (relay_exited_tx, new_relay_exited_rx) = oneshot::channel();
|
||||
active_headers_relay = start_on_demand_headers_relay(
|
||||
relay_task_name.clone(),
|
||||
@@ -186,14 +222,127 @@ async fn background_task<SourceChain, TargetChain, TargetSign>(
|
||||
relay_exited_rx = new_relay_exited_rx.right_future();
|
||||
}
|
||||
}
|
||||
(false, true) => {
|
||||
OnDemandRelayAction::Stop => {
|
||||
stop_on_demand_headers_relay(active_headers_relay.take()).await;
|
||||
}
|
||||
_ => (),
|
||||
OnDemandRelayAction::None => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Read best finalized source block number from source client.
|
||||
///
|
||||
/// Returns `None` if we have failed to read the number.
|
||||
async fn best_finalized_source_header_at_source<SourceChain: Chain, P>(
|
||||
finality_source: &SubstrateFinalitySource<SourceChain, P>,
|
||||
relay_task_name: &str,
|
||||
) -> Result<SourceChain::BlockNumber, <SubstrateFinalitySource<SourceChain, P> as RelayClient>::Error>
|
||||
where
|
||||
SubstrateFinalitySource<SourceChain, P>: FinalitySourceClient<P>,
|
||||
P: FinalitySyncPipeline<Number = SourceChain::BlockNumber>,
|
||||
{
|
||||
finality_source.best_finalized_block_number().await.map_err(|error| {
|
||||
log::error!(
|
||||
target: "bridge",
|
||||
"Failed to read best finalized source header from source in {} relay: {:?}",
|
||||
relay_task_name,
|
||||
error,
|
||||
);
|
||||
|
||||
error
|
||||
})
|
||||
}
|
||||
|
||||
/// Read best finalized source block number from target client.
|
||||
///
|
||||
/// Returns `None` if we have failed to read the number.
|
||||
async fn best_finalized_source_header_at_target<SourceChain: Chain, TargetChain: Chain, P>(
|
||||
finality_target: &SubstrateFinalityTarget<TargetChain, P>,
|
||||
relay_task_name: &str,
|
||||
) -> Result<SourceChain::BlockNumber, <SubstrateFinalityTarget<TargetChain, P> as RelayClient>::Error>
|
||||
where
|
||||
SubstrateFinalityTarget<TargetChain, P>: FinalityTargetClient<P>,
|
||||
P: FinalitySyncPipeline<Number = SourceChain::BlockNumber>,
|
||||
{
|
||||
finality_target
|
||||
.best_finalized_source_block_number()
|
||||
.await
|
||||
.map_err(|error| {
|
||||
log::error!(
|
||||
target: "bridge",
|
||||
"Failed to read best finalized source header from target in {} relay: {:?}",
|
||||
relay_task_name,
|
||||
error,
|
||||
);
|
||||
|
||||
error
|
||||
})
|
||||
}
|
||||
|
||||
/// What to do with the on-demand relay task?
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum OnDemandRelayAction {
|
||||
Start,
|
||||
Stop,
|
||||
None,
|
||||
}
|
||||
|
||||
fn select_on_demand_relay_action<C: Chain>(
|
||||
best_finalized_source_header_at_source: Option<C::BlockNumber>,
|
||||
best_finalized_source_header_at_target: Option<C::BlockNumber>,
|
||||
mut required_source_header_at_target: C::BlockNumber,
|
||||
maximal_headers_difference: C::BlockNumber,
|
||||
relay_task_name: &str,
|
||||
is_active: bool,
|
||||
) -> OnDemandRelayAction {
|
||||
// if we have been unable to read header number from the target, then let's assume
|
||||
// that it is the same as required header number. Otherwise we risk submitting
|
||||
// unneeded transactions
|
||||
let best_finalized_source_header_at_target =
|
||||
best_finalized_source_header_at_target.unwrap_or(required_source_header_at_target);
|
||||
|
||||
// if we have been unable to read header number from the source, then let's assume
|
||||
// that it is the same as at the target
|
||||
let best_finalized_source_header_at_source =
|
||||
best_finalized_source_header_at_source.unwrap_or(best_finalized_source_header_at_target);
|
||||
|
||||
// if there are too many source headers missing from the target node, require some
|
||||
// new headers at target
|
||||
//
|
||||
// why do we need that? When complex headers+messages relay is used, it'll normally only relay
|
||||
// headers when there are undelivered messages/confirmations. But security model of the
|
||||
// `pallet-bridge-grandpa` module relies on the fact that headers are synced in real-time and
|
||||
// that it'll see authorities-change header before unbonding period will end for previous
|
||||
// authorities set.
|
||||
let current_headers_difference = best_finalized_source_header_at_source
|
||||
.checked_sub(&best_finalized_source_header_at_target)
|
||||
.unwrap_or_else(Zero::zero);
|
||||
if current_headers_difference > maximal_headers_difference {
|
||||
required_source_header_at_target = best_finalized_source_header_at_source;
|
||||
|
||||
// don't log if relay is already running
|
||||
if !is_active {
|
||||
log::trace!(
|
||||
target: "bridge",
|
||||
"Too many {} headers missing at target in {} relay ({} vs {}). Going to sync up to the {}",
|
||||
C::NAME,
|
||||
relay_task_name,
|
||||
best_finalized_source_header_at_source,
|
||||
best_finalized_source_header_at_target,
|
||||
best_finalized_source_header_at_source,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// now let's select what to do with relay
|
||||
let needs_to_be_active = required_source_header_at_target > best_finalized_source_header_at_target;
|
||||
match (needs_to_be_active, is_active) {
|
||||
(true, false) => OnDemandRelayAction::Start,
|
||||
(false, true) => OnDemandRelayAction::Stop,
|
||||
_ => OnDemandRelayAction::None,
|
||||
}
|
||||
}
|
||||
|
||||
/// On-demand headers relay task name.
|
||||
fn on_demand_headers_relay_name<SourceChain: Chain, TargetChain: Chain>() -> String {
|
||||
format!("on-demand-{}-to-{}", SourceChain::NAME, TargetChain::NAME)
|
||||
@@ -219,7 +368,7 @@ where
|
||||
TargetSign: 'static,
|
||||
{
|
||||
let headers_relay_future =
|
||||
crate::finality_pipeline::run(pipeline, source_client, target_client, MetricsParams::disabled());
|
||||
crate::finality_pipeline::run(pipeline, source_client, target_client, true, MetricsParams::disabled());
|
||||
let closure_task_name = task_name.clone();
|
||||
async_std::task::Builder::new()
|
||||
.name(task_name.clone())
|
||||
@@ -253,3 +402,52 @@ async fn stop_on_demand_headers_relay(task: Option<async_std::task::JoinHandle<(
|
||||
log::info!(target: "bridge", "Cancelled {} headers relay", task_name);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
type TestChain = relay_millau_client::Millau;
|
||||
|
||||
const AT_SOURCE: Option<bp_millau::BlockNumber> = Some(10);
|
||||
const AT_TARGET: Option<bp_millau::BlockNumber> = Some(1);
|
||||
|
||||
#[test]
|
||||
fn starts_relay_when_headers_are_required() {
|
||||
assert_eq!(
|
||||
select_on_demand_relay_action::<TestChain>(AT_SOURCE, AT_TARGET, 5, 100, "test", false),
|
||||
OnDemandRelayAction::Start,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
select_on_demand_relay_action::<TestChain>(AT_SOURCE, AT_TARGET, 5, 100, "test", true),
|
||||
OnDemandRelayAction::None,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn starts_relay_when_too_many_headers_missing() {
|
||||
assert_eq!(
|
||||
select_on_demand_relay_action::<TestChain>(AT_SOURCE, AT_TARGET, 0, 5, "test", false),
|
||||
OnDemandRelayAction::Start,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
select_on_demand_relay_action::<TestChain>(AT_SOURCE, AT_TARGET, 0, 5, "test", true),
|
||||
OnDemandRelayAction::None,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stops_relay_if_required_header_is_synced() {
|
||||
assert_eq!(
|
||||
select_on_demand_relay_action::<TestChain>(AT_SOURCE, AT_TARGET, AT_TARGET.unwrap(), 100, "test", true),
|
||||
OnDemandRelayAction::Stop,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
select_on_demand_relay_action::<TestChain>(AT_SOURCE, AT_TARGET, AT_TARGET.unwrap(), 100, "test", false),
|
||||
OnDemandRelayAction::None,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user