mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 00:31:02 +00:00
messages bridge between RialtoParachain and Millau (#1218)
This commit is contained in:
committed by
Bastian Köcher
parent
03c2f06a27
commit
5f2f61ced5
@@ -26,6 +26,7 @@ bp-header-chain = { path = "../../primitives/header-chain" }
|
||||
bp-kusama = { path = "../../primitives/chain-kusama" }
|
||||
bp-messages = { path = "../../primitives/messages" }
|
||||
bp-millau = { path = "../../primitives/chain-millau" }
|
||||
bp-parachains = { path = "../../primitives/parachains" }
|
||||
bp-polkadot = { path = "../../primitives/chain-polkadot" }
|
||||
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
|
||||
bp-rialto = { path = "../../primitives/chain-rialto" }
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// 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/>.
|
||||
|
||||
//! Millau-to-RialtoParachain headers sync entrypoint.
|
||||
|
||||
// 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/>.
|
||||
|
||||
//! Millau-to-RialtoParachain headers sync entrypoint.
|
||||
|
||||
use substrate_relay_helper::finality::{
|
||||
engine::Grandpa as GrandpaFinalityEngine, DirectSubmitGrandpaFinalityProofCallBuilder,
|
||||
SubstrateFinalitySyncPipeline,
|
||||
};
|
||||
|
||||
/// Description of Millau -> Rialto finalized headers bridge.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MillauFinalityToRialtoParachain;
|
||||
|
||||
impl SubstrateFinalitySyncPipeline for MillauFinalityToRialtoParachain {
|
||||
type SourceChain = relay_millau_client::Millau;
|
||||
type TargetChain = relay_rialto_parachain_client::RialtoParachain;
|
||||
|
||||
type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
|
||||
type SubmitFinalityProofCallBuilder = DirectSubmitGrandpaFinalityProofCallBuilder<
|
||||
Self,
|
||||
rialto_parachain_runtime::Runtime,
|
||||
rialto_parachain_runtime::MillauGrandpaInstance,
|
||||
>;
|
||||
type TransactionSignScheme = relay_rialto_parachain_client::RialtoParachain;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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/>.
|
||||
|
||||
//! Millau-to-RialtoParachain messages sync entrypoint.
|
||||
|
||||
use messages_relay::relay_strategy::MixStrategy;
|
||||
use relay_millau_client::Millau;
|
||||
use relay_rialto_parachain_client::RialtoParachain;
|
||||
use substrate_relay_helper::messages_lane::{
|
||||
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
|
||||
SubstrateMessageLane,
|
||||
};
|
||||
|
||||
/// Description of Millau -> RialtoParachain messages bridge.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MillauMessagesToRialtoParachain;
|
||||
|
||||
impl SubstrateMessageLane for MillauMessagesToRialtoParachain {
|
||||
const SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
|
||||
Some(bp_rialto_parachain::MILLAU_TO_RIALTO_CONVERSION_RATE_PARAMETER_NAME);
|
||||
const TARGET_TO_SOURCE_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
|
||||
Some(bp_millau::RIALTO_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME);
|
||||
|
||||
const SOURCE_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> = None;
|
||||
const TARGET_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> = None;
|
||||
const AT_SOURCE_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> = None;
|
||||
const AT_TARGET_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> = None;
|
||||
|
||||
type SourceChain = Millau;
|
||||
type TargetChain = RialtoParachain;
|
||||
|
||||
type SourceTransactionSignScheme = Millau;
|
||||
type TargetTransactionSignScheme = RialtoParachain;
|
||||
|
||||
type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
|
||||
Self,
|
||||
rialto_parachain_runtime::Runtime,
|
||||
rialto_parachain_runtime::WithMillauMessagesInstance,
|
||||
>;
|
||||
type ReceiveMessagesDeliveryProofCallBuilder = DirectReceiveMessagesDeliveryProofCallBuilder<
|
||||
Self,
|
||||
millau_runtime::Runtime,
|
||||
millau_runtime::WithRialtoParachainMessagesInstance,
|
||||
>;
|
||||
|
||||
type TargetToSourceChainConversionRateUpdateBuilder = ();
|
||||
|
||||
type RelayStrategy = MixStrategy;
|
||||
}
|
||||
@@ -19,11 +19,14 @@
|
||||
pub mod kusama_headers_to_polkadot;
|
||||
pub mod kusama_messages_to_polkadot;
|
||||
pub mod millau_headers_to_rialto;
|
||||
pub mod millau_headers_to_rialto_parachain;
|
||||
pub mod millau_messages_to_rialto;
|
||||
pub mod millau_messages_to_rialto_parachain;
|
||||
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_parachain_messages_to_millau;
|
||||
pub mod rialto_parachains_to_millau;
|
||||
pub mod rococo_headers_to_wococo;
|
||||
pub mod rococo_messages_to_wococo;
|
||||
|
||||
@@ -16,10 +16,42 @@
|
||||
|
||||
//! Rialto parachain specification for CLI.
|
||||
|
||||
use crate::cli::CliChain;
|
||||
use crate::cli::{
|
||||
bridge,
|
||||
encode_message::{CliEncodeMessage, RawMessage},
|
||||
CliChain,
|
||||
};
|
||||
use bp_messages::LaneId;
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use relay_rialto_parachain_client::RialtoParachain;
|
||||
use relay_substrate_client::BalanceOf;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
impl CliEncodeMessage for RialtoParachain {
|
||||
fn encode_send_message_call(
|
||||
lane: LaneId,
|
||||
payload: RawMessage,
|
||||
fee: BalanceOf<Self>,
|
||||
bridge_instance_index: u8,
|
||||
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
|
||||
Ok(match bridge_instance_index {
|
||||
bridge::RIALTO_PARACHAIN_TO_MILLAU_INDEX =>
|
||||
rialto_parachain_runtime::Call::BridgeMillauMessages(
|
||||
rialto_parachain_runtime::MessagesCall::send_message {
|
||||
lane_id: lane,
|
||||
payload,
|
||||
delivery_and_dispatch_fee: fee,
|
||||
},
|
||||
)
|
||||
.into(),
|
||||
_ => anyhow::bail!(
|
||||
"Unsupported target bridge pallet with instance index: {}",
|
||||
bridge_instance_index
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl CliChain for RialtoParachain {
|
||||
const RUNTIME_VERSION: RuntimeVersion = rialto_parachain_runtime::VERSION;
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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/>.
|
||||
|
||||
//! RialtoParachain-to-Millau messages sync entrypoint.
|
||||
|
||||
use messages_relay::relay_strategy::MixStrategy;
|
||||
use relay_millau_client::Millau;
|
||||
use relay_rialto_parachain_client::RialtoParachain;
|
||||
use substrate_relay_helper::messages_lane::{
|
||||
DirectReceiveMessagesDeliveryProofCallBuilder, DirectReceiveMessagesProofCallBuilder,
|
||||
SubstrateMessageLane,
|
||||
};
|
||||
|
||||
/// Description of RialtoParachain -> Millau messages bridge.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RialtoParachainMessagesToMillau;
|
||||
|
||||
impl SubstrateMessageLane for RialtoParachainMessagesToMillau {
|
||||
const SOURCE_TO_TARGET_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
|
||||
Some(bp_millau::RIALTO_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME);
|
||||
const TARGET_TO_SOURCE_CONVERSION_RATE_PARAMETER_NAME: Option<&'static str> =
|
||||
Some(bp_rialto_parachain::MILLAU_TO_RIALTO_CONVERSION_RATE_PARAMETER_NAME);
|
||||
|
||||
const SOURCE_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> = None;
|
||||
const TARGET_FEE_MULTIPLIER_PARAMETER_NAME: Option<&'static str> = None;
|
||||
const AT_SOURCE_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> = None;
|
||||
const AT_TARGET_TRANSACTION_PAYMENT_PALLET_NAME: Option<&'static str> = None;
|
||||
|
||||
type SourceChain = RialtoParachain;
|
||||
type TargetChain = Millau;
|
||||
|
||||
type SourceTransactionSignScheme = RialtoParachain;
|
||||
type TargetTransactionSignScheme = Millau;
|
||||
|
||||
type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
|
||||
Self,
|
||||
millau_runtime::Runtime,
|
||||
millau_runtime::WithRialtoParachainMessagesInstance,
|
||||
>;
|
||||
type ReceiveMessagesDeliveryProofCallBuilder = DirectReceiveMessagesDeliveryProofCallBuilder<
|
||||
Self,
|
||||
rialto_parachain_runtime::Runtime,
|
||||
rialto_parachain_runtime::WithMillauMessagesInstance,
|
||||
>;
|
||||
|
||||
type TargetToSourceChainConversionRateUpdateBuilder = ();
|
||||
|
||||
type RelayStrategy = MixStrategy;
|
||||
}
|
||||
@@ -23,17 +23,17 @@ use substrate_relay_helper::parachains_target::DirectSubmitParachainHeadsCallBui
|
||||
|
||||
/// Rialto-to-Millau parachains sync description.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RialtoToMillauParachains;
|
||||
pub struct RialtoParachainsToMillau;
|
||||
|
||||
impl ParachainsPipeline for RialtoToMillauParachains {
|
||||
impl ParachainsPipeline for RialtoParachainsToMillau {
|
||||
type SourceChain = Rialto;
|
||||
type TargetChain = Millau;
|
||||
}
|
||||
|
||||
/// `submit_parachain_heads` call builder for Rialto-to-Millau parachains sync pipeline.
|
||||
pub type RialtoToMillauParachainsSubmitParachainHeadsCallBuilder =
|
||||
pub type RialtoParachainsToMillauSubmitParachainHeadsCallBuilder =
|
||||
DirectSubmitParachainHeadsCallBuilder<
|
||||
RialtoToMillauParachains,
|
||||
RialtoParachainsToMillau,
|
||||
millau_runtime::Runtime,
|
||||
millau_runtime::WitRialtoParachainsInstance,
|
||||
>;
|
||||
|
||||
@@ -26,6 +26,8 @@ pub enum FullBridge {
|
||||
WococoToRococo,
|
||||
KusamaToPolkadot,
|
||||
PolkadotToKusama,
|
||||
MillauToRialtoParachain,
|
||||
RialtoParachainToMillau,
|
||||
}
|
||||
|
||||
impl FullBridge {
|
||||
@@ -38,6 +40,8 @@ impl FullBridge {
|
||||
Self::WococoToRococo => WOCOCO_TO_ROCOCO_INDEX,
|
||||
Self::KusamaToPolkadot => KUSAMA_TO_POLKADOT_INDEX,
|
||||
Self::PolkadotToKusama => POLKADOT_TO_KUSAMA_INDEX,
|
||||
Self::MillauToRialtoParachain => MILLAU_TO_RIALTO_PARACHAIN_INDEX,
|
||||
Self::RialtoParachainToMillau => RIALTO_PARACHAIN_TO_MILLAU_INDEX,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +52,8 @@ pub const ROCOCO_TO_WOCOCO_INDEX: u8 = 0;
|
||||
pub const WOCOCO_TO_ROCOCO_INDEX: u8 = 0;
|
||||
pub const KUSAMA_TO_POLKADOT_INDEX: u8 = 0;
|
||||
pub const POLKADOT_TO_KUSAMA_INDEX: u8 = 0;
|
||||
pub const MILLAU_TO_RIALTO_PARACHAIN_INDEX: u8 = 1;
|
||||
pub const RIALTO_PARACHAIN_TO_MILLAU_INDEX: u8 = 0;
|
||||
|
||||
/// The macro allows executing bridge-specific code without going fully generic.
|
||||
///
|
||||
@@ -171,6 +177,44 @@ macro_rules! select_full_bridge {
|
||||
|
||||
$generic
|
||||
},
|
||||
FullBridge::MillauToRialtoParachain => {
|
||||
type Source = relay_millau_client::Millau;
|
||||
#[allow(dead_code)]
|
||||
type Target = relay_rialto_parachain_client::RialtoParachain;
|
||||
|
||||
// Derive-account
|
||||
#[allow(unused_imports)]
|
||||
use bp_rialto_parachain::derive_account_from_millau_id as derive_account;
|
||||
|
||||
// Relay-messages
|
||||
#[allow(unused_imports)]
|
||||
use crate::chains::millau_messages_to_rialto_parachain::MillauMessagesToRialtoParachain as MessagesLane;
|
||||
|
||||
// Send-message / Estimate-fee
|
||||
#[allow(unused_imports)]
|
||||
use bp_rialto_parachain::TO_RIALTO_PARACHAIN_ESTIMATE_MESSAGE_FEE_METHOD as ESTIMATE_MESSAGE_FEE_METHOD;
|
||||
|
||||
$generic
|
||||
}
|
||||
FullBridge::RialtoParachainToMillau => {
|
||||
type Source = relay_rialto_parachain_client::RialtoParachain;
|
||||
#[allow(dead_code)]
|
||||
type Target = relay_millau_client::Millau;
|
||||
|
||||
// Derive-account
|
||||
#[allow(unused_imports)]
|
||||
use bp_millau::derive_account_from_rialto_parachain_id as derive_account;
|
||||
|
||||
// Relay-messages
|
||||
#[allow(unused_imports)]
|
||||
use crate::chains::rialto_parachain_messages_to_millau::RialtoParachainMessagesToMillau as MessagesLane;
|
||||
|
||||
// Send-message / Estimate-fee
|
||||
#[allow(unused_imports)]
|
||||
use bp_millau::TO_MILLAU_ESTIMATE_MESSAGE_FEE_METHOD as ESTIMATE_MESSAGE_FEE_METHOD;
|
||||
|
||||
$generic
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ pub enum InitBridgeName {
|
||||
WococoToRococo,
|
||||
KusamaToPolkadot,
|
||||
PolkadotToKusama,
|
||||
MillauToRialtoParachain,
|
||||
}
|
||||
|
||||
macro_rules! select_bridge {
|
||||
@@ -181,6 +182,28 @@ macro_rules! select_bridge {
|
||||
)
|
||||
}
|
||||
|
||||
$generic
|
||||
},
|
||||
InitBridgeName::MillauToRialtoParachain => {
|
||||
type Source = relay_millau_client::Millau;
|
||||
type Target = relay_rialto_parachain_client::RialtoParachain;
|
||||
type Engine = GrandpaFinalityEngine<Source>;
|
||||
|
||||
fn encode_init_bridge(
|
||||
init_data: InitializationData<<Source as ChainBase>::Header>,
|
||||
) -> <Target as Chain>::Call {
|
||||
let initialize_call = rialto_parachain_runtime::BridgeGrandpaCall::<
|
||||
rialto_parachain_runtime::Runtime,
|
||||
rialto_parachain_runtime::MillauGrandpaInstance,
|
||||
>::initialize {
|
||||
init_data,
|
||||
};
|
||||
rialto_parachain_runtime::SudoCall::sudo {
|
||||
call: Box::new(initialize_call.into()),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
$generic
|
||||
},
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ pub enum RelayHeadersBridge {
|
||||
WococoToRococo,
|
||||
KusamaToPolkadot,
|
||||
PolkadotToKusama,
|
||||
MillauToRialtoParachain,
|
||||
}
|
||||
|
||||
macro_rules! select_bridge {
|
||||
@@ -109,6 +110,14 @@ macro_rules! select_bridge {
|
||||
|
||||
$generic
|
||||
},
|
||||
RelayHeadersBridge::MillauToRialtoParachain => {
|
||||
type Source = relay_millau_client::Millau;
|
||||
type Target = relay_rialto_parachain_client::RialtoParachain;
|
||||
type Finality = crate::chains::millau_headers_to_rialto_parachain::MillauFinalityToRialtoParachain;
|
||||
|
||||
$generic
|
||||
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -480,7 +480,6 @@ impl RelayHeadersAndMessages {
|
||||
right_to_left_transaction_params,
|
||||
params.shared.only_mandatory_headers,
|
||||
);
|
||||
|
||||
// Need 2x capacity since we consider both directions for each lane
|
||||
let mut message_relays = Vec::with_capacity(lanes.len() * 2);
|
||||
for lane in lanes {
|
||||
|
||||
@@ -55,8 +55,8 @@ macro_rules! select_bridge {
|
||||
match $bridge {
|
||||
RelayParachainsBridge::RialtoToMillau => {
|
||||
use crate::chains::rialto_parachains_to_millau::{
|
||||
RialtoToMillauParachains as Pipeline,
|
||||
RialtoToMillauParachainsSubmitParachainHeadsCallBuilder as SubmitParachainHeadsCallBuilder,
|
||||
RialtoParachainsToMillau as Pipeline,
|
||||
RialtoParachainsToMillauSubmitParachainHeadsCallBuilder as SubmitParachainHeadsCallBuilder,
|
||||
};
|
||||
|
||||
use bp_millau::BRIDGE_PARAS_PALLET_NAME as BRIDGE_PARAS_PALLET_NAME_AT_TARGET;
|
||||
|
||||
@@ -6,12 +6,14 @@ edition = "2021"
|
||||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0" }
|
||||
relay-substrate-client = { path = "../client-substrate" }
|
||||
relay-utils = { path = "../utils" }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
bp-rialto = { path = "../../primitives/chain-rialto" }
|
||||
bp-messages = { path = "../../primitives/messages" }
|
||||
bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" }
|
||||
rialto-parachain-runtime = { path = "../../bin/rialto-parachain/runtime" }
|
||||
|
||||
# Substrate Dependencies
|
||||
@@ -19,3 +21,5 @@ rialto-parachain-runtime = { path = "../../bin/rialto-parachain/runtime" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
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" }
|
||||
|
||||
@@ -16,8 +16,15 @@
|
||||
|
||||
//! Types used to connect to the Rialto-Substrate chain.
|
||||
|
||||
use bp_messages::MessageNonce;
|
||||
use codec::Encode;
|
||||
use frame_support::weights::Weight;
|
||||
use relay_substrate_client::{Chain, ChainBase};
|
||||
use relay_substrate_client::{
|
||||
Chain, ChainBase, ChainWithBalances, ChainWithMessages, Error as SubstrateError, SignParam,
|
||||
TransactionSignScheme, UnsignedTransaction,
|
||||
};
|
||||
use sp_core::{storage::StorageKey, Pair};
|
||||
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
|
||||
use std::time::Duration;
|
||||
|
||||
/// Rialto header id.
|
||||
@@ -40,11 +47,11 @@ impl ChainBase for RialtoParachain {
|
||||
type Signature = rialto_parachain_runtime::Signature;
|
||||
|
||||
fn max_extrinsic_size() -> u32 {
|
||||
bp_rialto::Rialto::max_extrinsic_size()
|
||||
bp_rialto_parachain::RialtoParachain::max_extrinsic_size()
|
||||
}
|
||||
|
||||
fn max_extrinsic_weight() -> Weight {
|
||||
bp_rialto::Rialto::max_extrinsic_weight()
|
||||
bp_rialto_parachain::RialtoParachain::max_extrinsic_weight()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,12 +59,111 @@ impl Chain for RialtoParachain {
|
||||
const NAME: &'static str = "RialtoParachain";
|
||||
const TOKEN_ID: Option<&'static str> = None;
|
||||
// should be fixed/changed in https://github.com/paritytech/parity-bridges-common/pull/1199
|
||||
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = "<UNIMPLEMENTED>";
|
||||
// should be removed in https://github.com/paritytech/parity-bridges-common/issues/1246
|
||||
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
|
||||
bp_rialto_parachain::BEST_FINALIZED_RIALTO_PARACHAIN_HEADER_METHOD;
|
||||
const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_secs(5);
|
||||
const STORAGE_PROOF_OVERHEAD: u32 = bp_rialto::EXTRA_STORAGE_PROOF_SIZE;
|
||||
const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_rialto::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE;
|
||||
const STORAGE_PROOF_OVERHEAD: u32 = bp_rialto_parachain::EXTRA_STORAGE_PROOF_SIZE;
|
||||
const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 =
|
||||
bp_rialto_parachain::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE;
|
||||
|
||||
type SignedBlock = rialto_parachain_runtime::SignedBlock;
|
||||
type Call = rialto_parachain_runtime::Call;
|
||||
type WeightToFee = bp_rialto::WeightToFee;
|
||||
type WeightToFee = bp_rialto_parachain::WeightToFee;
|
||||
}
|
||||
|
||||
impl ChainWithBalances for RialtoParachain {
|
||||
fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey {
|
||||
use frame_support::storage::generator::StorageMap;
|
||||
StorageKey(
|
||||
frame_system::Account::<rialto_parachain_runtime::Runtime>::storage_map_final_key(
|
||||
account_id,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ChainWithMessages for RialtoParachain {
|
||||
const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
|
||||
bp_rialto_parachain::WITH_RIALTO_PARACHAIN_MESSAGES_PALLET_NAME;
|
||||
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
|
||||
bp_rialto_parachain::TO_RIALTO_PARACHAIN_MESSAGE_DETAILS_METHOD;
|
||||
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
|
||||
bp_rialto_parachain::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
|
||||
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
|
||||
bp_rialto_parachain::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
|
||||
const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce =
|
||||
bp_rialto_parachain::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
impl TransactionSignScheme for RialtoParachain {
|
||||
type Chain = RialtoParachain;
|
||||
type AccountKeyPair = sp_core::sr25519::Pair;
|
||||
type SignedTransaction = rialto_parachain_runtime::UncheckedExtrinsic;
|
||||
|
||||
fn sign_transaction(param: SignParam<Self>) -> Result<Self::SignedTransaction, SubstrateError> {
|
||||
let raw_payload = SignedPayload::from_raw(
|
||||
param.unsigned.call,
|
||||
(
|
||||
frame_system::CheckNonZeroSender::<rialto_parachain_runtime::Runtime>::new(),
|
||||
frame_system::CheckSpecVersion::<rialto_parachain_runtime::Runtime>::new(),
|
||||
frame_system::CheckTxVersion::<rialto_parachain_runtime::Runtime>::new(),
|
||||
frame_system::CheckGenesis::<rialto_parachain_runtime::Runtime>::new(),
|
||||
frame_system::CheckEra::<rialto_parachain_runtime::Runtime>::from(
|
||||
param.era.frame_era(),
|
||||
),
|
||||
frame_system::CheckNonce::<rialto_parachain_runtime::Runtime>::from(
|
||||
param.unsigned.nonce,
|
||||
),
|
||||
frame_system::CheckWeight::<rialto_parachain_runtime::Runtime>::new(),
|
||||
pallet_transaction_payment::ChargeTransactionPayment::<
|
||||
rialto_parachain_runtime::Runtime,
|
||||
>::from(param.unsigned.tip),
|
||||
),
|
||||
(
|
||||
(),
|
||||
param.spec_version,
|
||||
param.transaction_version,
|
||||
param.genesis_hash,
|
||||
param.era.signed_payload(param.genesis_hash),
|
||||
(),
|
||||
(),
|
||||
(),
|
||||
),
|
||||
);
|
||||
let signature = raw_payload.using_encoded(|payload| param.signer.sign(payload));
|
||||
let signer: sp_runtime::MultiSigner = param.signer.public().into();
|
||||
let (call, extra, _) = raw_payload.deconstruct();
|
||||
|
||||
Ok(rialto_parachain_runtime::UncheckedExtrinsic::new_signed(
|
||||
call.into_decoded()?,
|
||||
signer.into_account().into(),
|
||||
signature.into(),
|
||||
extra,
|
||||
))
|
||||
}
|
||||
|
||||
fn is_signed(tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature.is_some()
|
||||
}
|
||||
|
||||
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
|
||||
tx.signature
|
||||
.as_ref()
|
||||
.map(|(address, _, _)| {
|
||||
*address == rialto_parachain_runtime::Address::Id(signer.public().into())
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn parse_transaction(_tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self::Chain>> {
|
||||
unimplemented!("TODO")
|
||||
}
|
||||
}
|
||||
|
||||
/// RialtoParachain signing params.
|
||||
pub type SigningParams = sp_core::sr25519::Pair;
|
||||
|
||||
/// RialtoParachain header type used in headers sync.
|
||||
pub type SyncHeader = relay_substrate_client::SyncHeader<rialto_parachain_runtime::Header>;
|
||||
|
||||
@@ -298,6 +298,20 @@ fn select_parachains_to_update<P: ParachainsPipeline>(
|
||||
where
|
||||
P::SourceChain: Chain<BlockNumber = RelayBlockNumber>,
|
||||
{
|
||||
log::trace!(
|
||||
target: "bridge",
|
||||
"Selecting {} parachains to update at {} (relay block: {:?}):\n\t\
|
||||
At {}: {:?}\n\t\
|
||||
At {}: {:?}",
|
||||
P::SourceChain::NAME,
|
||||
P::TargetChain::NAME,
|
||||
best_finalized_relay_block,
|
||||
P::SourceChain::NAME,
|
||||
heads_at_source,
|
||||
P::TargetChain::NAME,
|
||||
heads_at_target,
|
||||
);
|
||||
|
||||
heads_at_source
|
||||
.into_iter()
|
||||
.zip(heads_at_target.into_iter())
|
||||
|
||||
Reference in New Issue
Block a user