From 2d9c4c0196c717e6c3c12e85df3b8c2848a2ca52 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Wed, 29 Jun 2022 15:59:50 +0300 Subject: [PATCH] Sync Westmint to Millau (#1482) * sync Westmint to Millau * "Westend parachains at Millau" dashboard --- bridges/bin/millau/node/src/chain_spec.rs | 4 ++ bridges/bin/millau/runtime/src/lib.rs | 29 ++++++++++- bridges/primitives/chain-westend/src/lib.rs | 20 +++++++ .../relays/bin-substrate/src/chains/mod.rs | 1 + .../chains/westend_parachains_to_millau.rs | 52 +++++++++++++++++++ .../bin-substrate/src/cli/relay_parachains.rs | 6 +++ bridges/relays/client-westend/src/lib.rs | 50 +++++++++++++++++- 7 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 bridges/relays/bin-substrate/src/chains/westend_parachains_to_millau.rs diff --git a/bridges/bin/millau/node/src/chain_spec.rs b/bridges/bin/millau/node/src/chain_spec.rs index 3204173598a0..648e51e533ad 100644 --- a/bridges/bin/millau/node/src/chain_spec.rs +++ b/bridges/bin/millau/node/src/chain_spec.rs @@ -144,6 +144,8 @@ fn endowed_accounts() -> Vec { get_account_id_from_seed::("Harry"), get_account_id_from_seed::("Iden"), get_account_id_from_seed::("Ken"), + get_account_id_from_seed::("Leon"), + get_account_id_from_seed::("Mary"), get_account_id_from_seed::("Alice//stash"), get_account_id_from_seed::("Bob//stash"), get_account_id_from_seed::("Charlie//stash"), @@ -154,6 +156,8 @@ fn endowed_accounts() -> Vec { get_account_id_from_seed::("Harry//stash"), get_account_id_from_seed::("Iden//stash"), get_account_id_from_seed::("Ken//stash"), + get_account_id_from_seed::("Leon//stash"), + get_account_id_from_seed::("Mary//stash"), get_account_id_from_seed::("RialtoMessagesOwner"), get_account_id_from_seed::("RialtoParachainMessagesOwner"), pallet_bridge_messages::relayer_fund_account_id::< diff --git a/bridges/bin/millau/runtime/src/lib.rs b/bridges/bin/millau/runtime/src/lib.rs index c5c002c47217..fecbf4f99073 100644 --- a/bridges/bin/millau/runtime/src/lib.rs +++ b/bridges/bin/millau/runtime/src/lib.rs @@ -506,9 +506,10 @@ impl pallet_bridge_messages::Config for Run parameter_types! { pub const RialtoParasPalletName: &'static str = bp_rialto::PARAS_PALLET_NAME; + pub const WestendParasPalletName: &'static str = bp_westend::PARAS_PALLET_NAME; } -/// Instance of the with-Rialto parachains token swap pallet. +/// Instance of the with-Rialto parachains pallet. pub type WithRialtoParachainsInstance = (); impl pallet_bridge_parachains::Config for Runtime { @@ -519,6 +520,17 @@ impl pallet_bridge_parachains::Config for Runtime type HeadsToKeep = HeadersToKeep; } +/// Instance of the with-Westend parachains pallet. +pub type WithWestendParachainsInstance = pallet_bridge_parachains::Instance1; + +impl pallet_bridge_parachains::Config for Runtime { + type WeightInfo = pallet_bridge_parachains::weights::MillauWeight; + type BridgesGrandpaPalletInstance = WestendGrandpaInstance; + type ParasPalletName = WestendParasPalletName; + type TrackedParachains = frame_support::traits::Everything; + type HeadsToKeep = HeadersToKeep; +} + construct_runtime!( pub enum Runtime where Block = Block, @@ -552,6 +564,7 @@ construct_runtime!( // Westend bridge modules. BridgeWestendGrandpa: pallet_bridge_grandpa::::{Pallet, Call, Config, Storage}, + BridgeWestendParachains: pallet_bridge_parachains::::{Pallet, Call, Storage}, // RialtoParachain bridge modules. BridgeRialtoParachains: pallet_bridge_parachains::{Pallet, Call, Storage}, @@ -806,6 +819,20 @@ impl_runtime_apis! { } } + impl bp_westend::WestmintFinalityApi for Runtime { + fn best_finalized() -> Option<(bp_westend::BlockNumber, bp_westend::Hash)> { + // the parachains finality pallet is never decoding parachain heads, so it is + // only done in the integration code + use bp_westend::WESTMINT_PARACHAIN_ID; + let encoded_head = pallet_bridge_parachains::Pallet::< + Runtime, + WithWestendParachainsInstance, + >::best_parachain_head(WESTMINT_PARACHAIN_ID.into())?; + let head = bp_westend::Header::decode(&mut &encoded_head.0[..]).ok()?; + Some((*head.number(), head.hash())) + } + } + impl bp_rialto_parachain::RialtoParachainFinalityApi for Runtime { fn best_finalized() -> Option<(bp_rialto::BlockNumber, bp_rialto::Hash)> { // the parachains finality pallet is never decoding parachain heads, so it is diff --git a/bridges/primitives/chain-westend/src/lib.rs b/bridges/primitives/chain-westend/src/lib.rs index 539cf69eb73a..0dc4ccc65aea 100644 --- a/bridges/primitives/chain-westend/src/lib.rs +++ b/bridges/primitives/chain-westend/src/lib.rs @@ -86,8 +86,13 @@ pub fn derive_account_from_rococo_id(id: bp_runtime::SourceAccount) - AccountIdConverter::convert(encoded_id) } +/// Name of the parachains pallet at the Westend runtime. +pub const PARAS_PALLET_NAME: &str = "Paras"; + /// Name of the With-Westend GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_WESTEND_GRANDPA_PALLET_NAME: &str = "BridgeWestendGrandpa"; +/// Name of the With-Westend parachains bridge pallet instance that is deployed at bridged chains. +pub const WITH_WESTEND_BRIDGE_PARAS_PALLET_NAME: &str = "BridgeWestendParachains"; /// Name of the `WestendFinalityApi::best_finalized` runtime method. pub const BEST_FINALIZED_WESTEND_HEADER_METHOD: &str = "WestendFinalityApi_best_finalized"; @@ -108,4 +113,19 @@ sp_api::decl_runtime_apis! { /// Returns number and hash of the best finalized header known to the bridge module. fn best_finalized() -> Option<(BlockNumber, Hash)>; } + + /// API for querying information about the finalized Westmint headers. + /// + /// This API is implemented by runtimes that are bridging with the Westmint chain, not the + /// Westmint runtime itself. + pub trait WestmintFinalityApi { + /// Returns number and hash of the best finalized header known to the bridge module. + fn best_finalized() -> Option<(BlockNumber, Hash)>; + } } + +/// Identifier of Westmint parachain at the Westend relay chain. +pub const WESTMINT_PARACHAIN_ID: u32 = 2000; + +/// Name of the `WestmintFinalityApi::best_finalized` runtime method. +pub const BEST_FINALIZED_WESTMINT_HEADER_METHOD: &str = "WestmintFinalityApi_best_finalized"; diff --git a/bridges/relays/bin-substrate/src/chains/mod.rs b/bridges/relays/bin-substrate/src/chains/mod.rs index ccc1be434f57..02e17c361d49 100644 --- a/bridges/relays/bin-substrate/src/chains/mod.rs +++ b/bridges/relays/bin-substrate/src/chains/mod.rs @@ -31,6 +31,7 @@ pub mod rialto_parachains_to_millau; pub mod rococo_headers_to_wococo; pub mod rococo_messages_to_wococo; pub mod westend_headers_to_millau; +pub mod westend_parachains_to_millau; pub mod wococo_headers_to_rococo; pub mod wococo_messages_to_rococo; diff --git a/bridges/relays/bin-substrate/src/chains/westend_parachains_to_millau.rs b/bridges/relays/bin-substrate/src/chains/westend_parachains_to_millau.rs new file mode 100644 index 000000000000..3a508ae49b6e --- /dev/null +++ b/bridges/relays/bin-substrate/src/chains/westend_parachains_to_millau.rs @@ -0,0 +1,52 @@ +// 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 . + +//! Westend-to-Millau parachains sync entrypoint. + +use parachains_relay::ParachainsPipeline; +use relay_millau_client::Millau; +use relay_westend_client::{Westend, Westmint}; +use substrate_relay_helper::parachains::{ + DirectSubmitParachainHeadsCallBuilder, SubstrateParachainsPipeline, +}; + +/// Westend-to-Millau parachains sync description. +#[derive(Clone, Debug)] +pub struct WestendParachainsToMillau; + +impl ParachainsPipeline for WestendParachainsToMillau { + type SourceChain = Westend; + type TargetChain = Millau; +} + +impl SubstrateParachainsPipeline for WestendParachainsToMillau { + type SourceParachain = Westmint; + type SourceRelayChain = Westend; + type TargetChain = Millau; + + type SubmitParachainHeadsCallBuilder = WestendParachainsToMillauSubmitParachainHeadsCallBuilder; + type TransactionSignScheme = Millau; + + const SOURCE_PARACHAIN_PARA_ID: u32 = bp_westend::WESTMINT_PARACHAIN_ID; +} + +/// `submit_parachain_heads` call builder for Rialto-to-Millau parachains sync pipeline. +pub type WestendParachainsToMillauSubmitParachainHeadsCallBuilder = + DirectSubmitParachainHeadsCallBuilder< + WestendParachainsToMillau, + millau_runtime::Runtime, + millau_runtime::WithWestendParachainsInstance, + >; diff --git a/bridges/relays/bin-substrate/src/cli/relay_parachains.rs b/bridges/relays/bin-substrate/src/cli/relay_parachains.rs index 8667ff741660..4714f1cc5a99 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_parachains.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_parachains.rs @@ -49,6 +49,7 @@ pub struct RelayParachains { #[strum(serialize_all = "kebab_case")] pub enum RelayParachainsBridge { RialtoToMillau, + WestendToMillau, } macro_rules! select_bridge { @@ -57,6 +58,11 @@ macro_rules! select_bridge { RelayParachainsBridge::RialtoToMillau => { use crate::chains::rialto_parachains_to_millau::RialtoParachainsToMillau as Pipeline; + $generic + }, + RelayParachainsBridge::WestendToMillau => { + use crate::chains::westend_parachains_to_millau::WestendParachainsToMillau as Pipeline; + $generic }, } diff --git a/bridges/relays/client-westend/src/lib.rs b/bridges/relays/client-westend/src/lib.rs index caf0c010c56a..cd2e3caab618 100644 --- a/bridges/relays/client-westend/src/lib.rs +++ b/bridges/relays/client-westend/src/lib.rs @@ -17,7 +17,7 @@ //! Types used to connect to the Westend chain. use frame_support::weights::Weight; -use relay_substrate_client::{Chain, ChainBase, ChainWithBalances, ChainWithGrandpa}; +use relay_substrate_client::{Chain, ChainBase, ChainWithBalances, ChainWithGrandpa, RelayChain}; use sp_core::storage::StorageKey; use std::time::Duration; @@ -65,6 +65,12 @@ impl Chain for Westend { type WeightToFee = bp_westend::WeightToFee; } +impl RelayChain for Westend { + const PARAS_PALLET_NAME: &'static str = bp_westend::PARAS_PALLET_NAME; + const PARACHAINS_FINALITY_PALLET_NAME: &'static str = + bp_westend::WITH_WESTEND_BRIDGE_PARAS_PALLET_NAME; +} + impl ChainWithGrandpa for Westend { const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = bp_westend::WITH_WESTEND_GRANDPA_PALLET_NAME; @@ -75,3 +81,45 @@ impl ChainWithBalances for Westend { StorageKey(bp_westend::account_info_storage_key(account_id)) } } + +/// Westmint parachain definition +#[derive(Debug, Clone, Copy)] +pub struct Westmint; + +// Westmint seems to use the same configuration as all Polkadot-like chains, so we'll use Westend +// primitives here. +impl ChainBase for Westmint { + type BlockNumber = bp_westend::BlockNumber; + type Hash = bp_westend::Hash; + type Hasher = bp_westend::Hasher; + type Header = bp_westend::Header; + + type AccountId = bp_westend::AccountId; + type Balance = bp_westend::Balance; + type Index = bp_westend::Nonce; + type Signature = bp_westend::Signature; + + fn max_extrinsic_size() -> u32 { + bp_westend::Westend::max_extrinsic_size() + } + + fn max_extrinsic_weight() -> Weight { + bp_westend::Westend::max_extrinsic_weight() + } +} + +// Westmint seems to use the same configuration as all Polkadot-like chains, so we'll use Westend +// primitives here. +impl Chain for Westmint { + const NAME: &'static str = "Westmint"; + const TOKEN_ID: Option<&'static str> = None; + const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = + bp_westend::BEST_FINALIZED_WESTMINT_HEADER_METHOD; + const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_secs(6); + const STORAGE_PROOF_OVERHEAD: u32 = bp_westend::EXTRA_STORAGE_PROOF_SIZE; + const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_westend::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE; + + type SignedBlock = bp_westend::SignedBlock; + type Call = bp_westend::Call; + type WeightToFee = bp_westend::WeightToFee; +}