diff --git a/bridges/bin/millau/node/Cargo.toml b/bridges/bin/millau/node/Cargo.toml index a6dc223e84ca..5051d0dba7ce 100644 --- a/bridges/bin/millau/node/Cargo.toml +++ b/bridges/bin/millau/node/Cargo.toml @@ -14,7 +14,7 @@ jsonrpc-core = "15.0.0" structopt = "0.3.17" # Bridge dependencies - +bp-rialto = { path = "../../../primitives/rialto" } millau-runtime = { path = "../runtime" } # Substrate Dependencies diff --git a/bridges/bin/millau/node/src/chain_spec.rs b/bridges/bin/millau/node/src/chain_spec.rs index df66c3318e5b..a3e95398fda9 100644 --- a/bridges/bin/millau/node/src/chain_spec.rs +++ b/bridges/bin/millau/node/src/chain_spec.rs @@ -15,8 +15,8 @@ // along with Parity Bridges Common. If not, see . use millau_runtime::{ - AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, SessionConfig, SessionKeys, Signature, - SudoConfig, SystemConfig, WASM_BINARY, + AccountId, AuraConfig, BalancesConfig, BridgeRialtoConfig, GenesisConfig, GrandpaConfig, SessionConfig, + SessionKeys, Signature, SudoConfig, SystemConfig, WASM_BINARY, }; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{sr25519, Pair, Public}; @@ -155,6 +155,7 @@ fn testnet_genesis( pallet_grandpa: Some(GrandpaConfig { authorities: Vec::new(), }), + pallet_substrate_bridge: load_rialto_bridge_config(), pallet_sudo: Some(SudoConfig { key: root_key }), pallet_session: Some(SessionConfig { keys: initial_authorities @@ -164,3 +165,12 @@ fn testnet_genesis( }), } } + +fn load_rialto_bridge_config() -> Option { + Some(BridgeRialtoConfig { + initial_header: Some(millau_runtime::rialto::initial_header()), + initial_authority_list: millau_runtime::rialto::initial_authority_set().authorities, + initial_set_id: millau_runtime::rialto::initial_authority_set().set_id, + first_scheduled_change: None, + }) +} diff --git a/bridges/bin/millau/runtime/Cargo.toml b/bridges/bin/millau/runtime/Cargo.toml index e961ccf8c8d7..eb37ea473f36 100644 --- a/bridges/bin/millau/runtime/Cargo.toml +++ b/bridges/bin/millau/runtime/Cargo.toml @@ -9,6 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false, features = ["derive"] } +hex-literal = "0.3" serde = { version = "1.0.115", optional = true, features = ["derive"] } # Bridge dependencies @@ -40,6 +41,7 @@ sp-block-builder = { version = "2.0", default-features = false } sp-consensus-aura = { version = "0.8", default-features = false } sp-core = { version = "2.0", default-features = false } sp-inherents = { version = "2.0", default-features = false } +sp-finality-grandpa = { version = "2.0", default-features = false } sp-offchain = { version = "2.0", default-features = false } sp-runtime = { version = "2.0", default-features = false } sp-session = { version = "2.0", default-features = false } @@ -79,6 +81,7 @@ std = [ "sp-consensus-aura/std", "sp-core/std", "sp-inherents/std", + "sp-finality-grandpa/std", "sp-offchain/std", "sp-runtime/std", "sp-session/std", diff --git a/bridges/bin/millau/runtime/src/lib.rs b/bridges/bin/millau/runtime/src/lib.rs index b9d0f638a84f..340639e36733 100644 --- a/bridges/bin/millau/runtime/src/lib.rs +++ b/bridges/bin/millau/runtime/src/lib.rs @@ -28,6 +28,8 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +pub mod rialto; + use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -321,7 +323,7 @@ construct_runtime!( NodeBlock = opaque::Block, UncheckedExtrinsic = UncheckedExtrinsic { - BridgeRialto: pallet_substrate_bridge::{Module, Call, Storage}, + BridgeRialto: pallet_substrate_bridge::{Module, Call, Storage, Config}, BridgeCallDispatch: pallet_bridge_call_dispatch::{Module, Event}, System: frame_system::{Module, Call, Config, Storage, Event}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage}, diff --git a/bridges/bin/millau/runtime/src/rialto.rs b/bridges/bin/millau/runtime/src/rialto.rs new file mode 100644 index 000000000000..0c25d93e93dd --- /dev/null +++ b/bridges/bin/millau/runtime/src/rialto.rs @@ -0,0 +1,56 @@ +// Copyright 2020 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 . + +//! Configuration parameters for the Rialto Substrate chain. + +use bp_rialto::Header; +use pallet_substrate_bridge::AuthoritySet; +use sp_core::crypto::Public; +use sp_finality_grandpa::AuthorityId; +use sp_std::vec; + +/// The first header known to the pallet. +/// +/// Note that this does not need to be the genesis header of the Rialto +/// chain since the pallet may start at any arbitrary header. +// To get this we first need to call the `chain_getBlockHash` RPC method, and then +// we can use the result from that and call the `chain_getBlock` RPC method to get +// the rest of the info. +// +// In this case we've grabbed the genesis block of the Rialto Substrate chain. +pub fn initial_header() -> Header { + Header { + parent_hash: Default::default(), + number: Default::default(), + state_root: Default::default(), + extrinsics_root: Default::default(), + digest: Default::default(), + } +} + +/// The first set of Grandpa authorities known to the pallet. +/// +/// Note that this doesn't have to be the "genesis" authority set, as the +/// pallet can be configured to start from any height. +pub fn initial_authority_set() -> AuthoritySet { + let set_id = 0; + let authorities = vec![ + (AuthorityId::from_slice(&[1; 32]), 1), + (AuthorityId::from_slice(&[2; 32]), 1), + (AuthorityId::from_slice(&[3; 32]), 1), + ]; + AuthoritySet::new(authorities, set_id) +} diff --git a/bridges/bin/rialto/node/src/chain_spec.rs b/bridges/bin/rialto/node/src/chain_spec.rs index 62f28fb49a88..4b66d656f839 100644 --- a/bridges/bin/rialto/node/src/chain_spec.rs +++ b/bridges/bin/rialto/node/src/chain_spec.rs @@ -15,8 +15,8 @@ // along with Parity Bridges Common. If not, see . use rialto_runtime::{ - AccountId, AuraConfig, BalancesConfig, BridgeKovanConfig, BridgeRialtoConfig, GenesisConfig, GrandpaConfig, - SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig, WASM_BINARY, + AccountId, AuraConfig, BalancesConfig, BridgeKovanConfig, BridgeMillauConfig, BridgeRialtoPoAConfig, GenesisConfig, + GrandpaConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig, WASM_BINARY, }; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{sr25519, Pair, Public}; @@ -152,11 +152,12 @@ fn testnet_genesis( pallet_aura: Some(AuraConfig { authorities: Vec::new(), }), - pallet_bridge_eth_poa_Instance1: load_rialto_bridge_config(), + pallet_bridge_eth_poa_Instance1: load_rialto_poa_bridge_config(), pallet_bridge_eth_poa_Instance2: load_kovan_bridge_config(), pallet_grandpa: Some(GrandpaConfig { authorities: Vec::new(), }), + pallet_substrate_bridge: load_millau_bridge_config(), pallet_sudo: Some(SudoConfig { key: root_key }), pallet_session: Some(SessionConfig { keys: initial_authorities @@ -167,11 +168,11 @@ fn testnet_genesis( } } -fn load_rialto_bridge_config() -> Option { - Some(BridgeRialtoConfig { - initial_header: rialto_runtime::rialto::genesis_header(), +fn load_rialto_poa_bridge_config() -> Option { + Some(BridgeRialtoPoAConfig { + initial_header: rialto_runtime::rialto_poa::genesis_header(), initial_difficulty: 0.into(), - initial_validators: rialto_runtime::rialto::genesis_validators(), + initial_validators: rialto_runtime::rialto_poa::genesis_validators(), }) } @@ -182,3 +183,12 @@ fn load_kovan_bridge_config() -> Option { initial_validators: rialto_runtime::kovan::genesis_validators(), }) } + +fn load_millau_bridge_config() -> Option { + Some(BridgeMillauConfig { + initial_header: Some(rialto_runtime::millau::initial_header()), + initial_authority_list: rialto_runtime::millau::initial_authority_set().authorities, + initial_set_id: rialto_runtime::millau::initial_authority_set().set_id, + first_scheduled_change: None, + }) +} diff --git a/bridges/bin/rialto/runtime/Cargo.toml b/bridges/bin/rialto/runtime/Cargo.toml index 60de3e70b448..fc7058f010cf 100644 --- a/bridges/bin/rialto/runtime/Cargo.toml +++ b/bridges/bin/rialto/runtime/Cargo.toml @@ -47,6 +47,7 @@ sp-api = { version = "2.0", default-features = false } sp-block-builder = { version = "2.0", default-features = false } sp-consensus-aura = { version = "0.8", default-features = false } sp-core = { version = "2.0", default-features = false } +sp-finality-grandpa = { version = "2.0", default-features = false } sp-inherents = { version = "2.0", default-features = false } sp-io = { version = "2.0", default-features = false } sp-offchain = { version = "2.0", default-features = false } @@ -95,6 +96,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-finality-grandpa/std", "sp-inherents/std", "sp-io/std", "sp-offchain/std", diff --git a/bridges/bin/rialto/runtime/src/lib.rs b/bridges/bin/rialto/runtime/src/lib.rs index 6259e99a0285..a693e8897397 100644 --- a/bridges/bin/rialto/runtime/src/lib.rs +++ b/bridges/bin/rialto/runtime/src/lib.rs @@ -33,7 +33,8 @@ pub mod exchange; #[cfg(feature = "runtime-benchmarks")] pub mod benches; pub mod kovan; -pub mod rialto; +pub mod millau; +pub mod rialto_poa; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; use sp_api::impl_runtime_apis; @@ -227,12 +228,12 @@ impl pallet_aura::Trait for Runtime { type AuthorityId = AuraId; } -type Rialto = pallet_bridge_eth_poa::Instance1; -impl pallet_bridge_eth_poa::Trait for Runtime { - type AuraConfiguration = rialto::BridgeAuraConfiguration; - type FinalityVotesCachingInterval = rialto::FinalityVotesCachingInterval; - type ValidatorsConfiguration = rialto::BridgeValidatorsConfiguration; - type PruningStrategy = rialto::PruningStrategy; +type RialtoPoA = pallet_bridge_eth_poa::Instance1; +impl pallet_bridge_eth_poa::Trait for Runtime { + type AuraConfiguration = rialto_poa::BridgeAuraConfiguration; + type FinalityVotesCachingInterval = rialto_poa::FinalityVotesCachingInterval; + type ValidatorsConfiguration = rialto_poa::BridgeValidatorsConfiguration; + type PruningStrategy = rialto_poa::PruningStrategy; type OnHeadersSubmitted = (); } @@ -248,7 +249,7 @@ impl pallet_bridge_eth_poa::Trait for Runtime { type RialtoCurrencyExchange = pallet_bridge_currency_exchange::Instance1; impl pallet_bridge_currency_exchange::Trait for Runtime { type OnTransactionSubmitted = (); - type PeerBlockchain = rialto::RialtoBlockchain; + type PeerBlockchain = rialto_poa::RialtoBlockchain; type PeerMaybeLockFundsTransaction = exchange::EthTransaction; type RecipientsMap = bp_currency_exchange::IdentityRecipients; type Amount = Balance; @@ -427,11 +428,11 @@ construct_runtime!( NodeBlock = opaque::Block, UncheckedExtrinsic = UncheckedExtrinsic { - BridgeRialto: pallet_bridge_eth_poa::::{Module, Call, Config, Storage, ValidateUnsigned}, + BridgeRialtoPoA: pallet_bridge_eth_poa::::{Module, Call, Config, Storage, ValidateUnsigned}, BridgeKovan: pallet_bridge_eth_poa::::{Module, Call, Config, Storage, ValidateUnsigned}, BridgeRialtoCurrencyExchange: pallet_bridge_currency_exchange::::{Module, Call}, BridgeKovanCurrencyExchange: pallet_bridge_currency_exchange::::{Module, Call}, - BridgeMillau: pallet_substrate_bridge::{Module, Call, Storage}, + BridgeMillau: pallet_substrate_bridge::{Module, Call, Storage, Config}, BridgeCallDispatch: pallet_bridge_call_dispatch::{Module, Event}, System: frame_system::{Module, Call, Config, Storage, Event}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage}, @@ -530,21 +531,21 @@ impl_runtime_apis! { impl bp_eth_poa::RialtoPoAHeaderApi for Runtime { fn best_block() -> (u64, bp_eth_poa::H256) { - let best_block = BridgeRialto::best_block(); + let best_block = BridgeRialtoPoA::best_block(); (best_block.number, best_block.hash) } fn finalized_block() -> (u64, bp_eth_poa::H256) { - let finalized_block = BridgeRialto::finalized_block(); + let finalized_block = BridgeRialtoPoA::finalized_block(); (finalized_block.number, finalized_block.hash) } fn is_import_requires_receipts(header: bp_eth_poa::AuraHeader) -> bool { - BridgeRialto::is_import_requires_receipts(header) + BridgeRialtoPoA::is_import_requires_receipts(header) } fn is_known_block(hash: bp_eth_poa::H256) -> bool { - BridgeRialto::is_known_block(hash) + BridgeRialtoPoA::is_known_block(hash) } } diff --git a/bridges/bin/rialto/runtime/src/millau.rs b/bridges/bin/rialto/runtime/src/millau.rs new file mode 100644 index 000000000000..47568f41742a --- /dev/null +++ b/bridges/bin/rialto/runtime/src/millau.rs @@ -0,0 +1,87 @@ +// Copyright 2020 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 . + +//! Configuration parameters for the Millau Substrate chain. + +use bp_rialto::Header; +use hex_literal::hex; +use pallet_substrate_bridge::AuthoritySet; +use sp_core::crypto::Public; +use sp_finality_grandpa::AuthorityId; +use sp_std::vec; + +/// The first header known to the pallet. +/// +/// Note that this does not need to be the genesis header of the Millau +/// chain since the pallet may start at any arbitrary header. +// To get this we first need to call the `chain_getBlockHash` RPC method, and then +// we can use the result from that and call the `chain_getBlock` RPC method to get +// the rest of the info. +// +// In this case we've grabbed the genesis block of the Millau Substrate chain. +pub fn initial_header() -> Header { + Header { + parent_hash: Default::default(), + number: Default::default(), + state_root: hex!("bb65e8ba99408ebfefea9d28f74403d41da6858fa075c51fcc71dc383455c530").into(), + extrinsics_root: hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into(), + digest: Default::default(), + } +} + +/// The first set of Grandpa authorities known to the pallet. +/// +/// Note that this doesn't have to be the "genesis" authority set, as the +/// pallet can be configured to start from any height. +pub fn initial_authority_set() -> AuthoritySet { + let set_id = 0; + + // These authorities are: Alice, Bob, Charlie, Dave, and Eve. + let authorities = vec![ + ( + AuthorityId::from_slice(&hex!( + "88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee" + )), + 1, + ), + ( + AuthorityId::from_slice(&hex!( + "d17c2d7823ebf260fd138f2d7e27d114c0145d968b5ff5006125f2414fadae69" + )), + 1, + ), + ( + AuthorityId::from_slice(&hex!( + "439660b36c6c03afafca027b910b4fecf99801834c62a5e6006f27d978de234f" + )), + 1, + ), + ( + AuthorityId::from_slice(&hex!( + "5e639b43e0052c47447dac87d6fd2b6ec50bdd4d0f614e4299c665249bbd09d9" + )), + 1, + ), + ( + AuthorityId::from_slice(&hex!( + "1dfe3e22cc0d45c70779c1095f7489a8ef3cf52d62fbd8c2fa38c9f1723502b5" + )), + 1, + ), + ]; + + AuthoritySet::new(authorities, set_id) +} diff --git a/bridges/bin/rialto/runtime/src/rialto.rs b/bridges/bin/rialto/runtime/src/rialto_poa.rs similarity index 92% rename from bridges/bin/rialto/runtime/src/rialto.rs rename to bridges/bin/rialto/runtime/src/rialto_poa.rs index 4e92e800eccd..4839579b04e0 100644 --- a/bridges/bin/rialto/runtime/src/rialto.rs +++ b/bridges/bin/rialto/runtime/src/rialto_poa.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . +//! Configuration parameters for the Rialto PoA chain. + use crate::exchange::EthereumTransactionInclusionProof; use bp_eth_poa::{Address, AuraHeader, RawTransaction, U256}; @@ -50,12 +52,12 @@ pub fn aura_configuration() -> AuraConfiguration { } } -/// Validators configuration for Rialto chain. +/// Validators configuration for Rialto PoA chain. pub fn validators_configuration() -> ValidatorsConfiguration { ValidatorsConfiguration::Single(ValidatorsSource::List(genesis_validators())) } -/// Genesis validators set of Rialto chain. +/// Genesis validators set of Rialto PoA chain. pub fn genesis_validators() -> Vec
{ vec![ hex!("005e714f896a8b7cede9d38688c1a81de72a58e4").into(), @@ -64,7 +66,7 @@ pub fn genesis_validators() -> Vec
{ ] } -/// Genesis header of the Rialto chain. +/// Genesis header of the Rialto PoA chain. /// /// To obtain genesis header from a running node, invoke: /// ```bash @@ -93,7 +95,7 @@ pub fn genesis_header() -> AuraHeader { } } -/// Rialto headers pruning strategy. +/// Rialto PoA headers pruning strategy. /// /// We do not prune unfinalized headers because exchange module only accepts /// claims from finalized headers. And if we're pruning unfinalized headers, then @@ -107,7 +109,7 @@ impl TPruningStrategy for PruningStrategy { } } -/// The Rialto Blockchain as seen by the runtime. +/// The Rialto PoA Blockchain as seen by the runtime. pub struct RialtoBlockchain; impl BaseHeaderChain for RialtoBlockchain { @@ -116,7 +118,7 @@ impl BaseHeaderChain for RialtoBlockchain { fn verify_transaction_inclusion_proof(proof: &Self::TransactionInclusionProof) -> Option { let is_transaction_finalized = - crate::BridgeRialto::verify_transaction_finalized(proof.block, proof.index, &proof.proof); + crate::BridgeRialtoPoA::verify_transaction_finalized(proof.block, proof.index, &proof.proof); if !is_transaction_finalized { return None; diff --git a/bridges/modules/substrate/src/lib.rs b/bridges/modules/substrate/src/lib.rs index 25276ace0913..c4406b6a3ccb 100644 --- a/bridges/modules/substrate/src/lib.rs +++ b/bridges/modules/substrate/src/lib.rs @@ -31,13 +31,16 @@ // Runtime-generated enums #![allow(clippy::large_enum_variant)] -use crate::storage::{AuthoritySet, ImportedHeader, ScheduledChange}; +use crate::storage::ImportedHeader; use bp_runtime::{BlockNumberOf, Chain, HashOf, HeaderOf}; use frame_support::{decl_error, decl_module, decl_storage, dispatch::DispatchResult}; use frame_system::ensure_signed; use sp_runtime::traits::Header as HeaderT; use sp_std::{marker::PhantomData, prelude::*}; +// Re-export since the node uses these when configuring genesis +pub use storage::{AuthoritySet, ScheduledChange}; + mod justification; mod storage; mod storage_proof; diff --git a/bridges/primitives/rialto/Cargo.toml b/bridges/primitives/rialto/Cargo.toml index b03806905167..9c9cb4bc8160 100644 --- a/bridges/primitives/rialto/Cargo.toml +++ b/bridges/primitives/rialto/Cargo.toml @@ -13,7 +13,6 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies - frame-support = { version = "2.0", default-features = false } sp-api = { version = "2.0", default-features = false } sp-core = { version = "2.0", default-features = false } diff --git a/bridges/relays/ethereum/src/instances.rs b/bridges/relays/ethereum/src/instances.rs index bfdccd0ba34d..7f29c26d8c36 100644 --- a/bridges/relays/ethereum/src/instances.rs +++ b/bridges/relays/ethereum/src/instances.rs @@ -60,7 +60,7 @@ impl BridgeInstance for RialtoPoA { .collect(), ); - rialto_runtime::Call::BridgeRialto(pallet_call) + rialto_runtime::Call::BridgeRialtoPoA(pallet_call) } fn build_unsigned_header_call(&self, header: QueuedEthereumHeader) -> Call { @@ -69,7 +69,7 @@ impl BridgeInstance for RialtoPoA { into_substrate_ethereum_receipts(header.extra()), ); - rialto_runtime::Call::BridgeRialto(pallet_call) + rialto_runtime::Call::BridgeRialtoPoA(pallet_call) } fn build_currency_exchange_call(&self, proof: Proof) -> Call {