Add GenesisConfig for Millau and Rialto Runtimes (#401)

* Add Rialto as a target for the Millau node

* Rename Rialto module to Rialto-PoA

This will reduce confusion as the Millau runtime has a
Rialto module as well which refers to the Substrate chain.

* Add Millau as a target for the Rialto node

* Be more explicit about Rialto PoA related code

* Missed some name changes in the Ethereum PoA relay

* Re-export Substrate pallet structs used by node

* Remove `first_scheduled_change` of Millau in Rialto node

* Make Millau's genesis config for Rialto bridge more accurate

* Set initial header for Millau config

* Update initial Millau authorities

Co-authored-by: Svyatoslav Nikolsky <svyatonik@gmail.com>

* RustFmt Millau authorities

Co-authored-by: Svyatoslav Nikolsky <svyatonik@gmail.com>
This commit is contained in:
Hernando Castano
2020-10-09 02:09:06 -04:00
committed by Bastian Köcher
parent 9e9ac8df3c
commit f52c839d6e
13 changed files with 210 additions and 35 deletions
+1 -1
View File
@@ -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
+12 -2
View File
@@ -15,8 +15,8 @@
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
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<BridgeRialtoConfig> {
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,
})
}
+3
View File
@@ -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",
+3 -1
View File
@@ -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<T>},
BridgeCallDispatch: pallet_bridge_call_dispatch::{Module, Event<T>},
System: frame_system::{Module, Call, Config, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
+56
View File
@@ -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 <http://www.gnu.org/licenses/>.
//! 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)
}
+17 -7
View File
@@ -15,8 +15,8 @@
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
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<BridgeRialtoConfig> {
Some(BridgeRialtoConfig {
initial_header: rialto_runtime::rialto::genesis_header(),
fn load_rialto_poa_bridge_config() -> Option<BridgeRialtoPoAConfig> {
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<BridgeKovanConfig> {
initial_validators: rialto_runtime::kovan::genesis_validators(),
})
}
fn load_millau_bridge_config() -> Option<BridgeMillauConfig> {
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,
})
}
+2
View File
@@ -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",
+15 -14
View File
@@ -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<Rialto> 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<RialtoPoA> 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<Kovan> for Runtime {
type RialtoCurrencyExchange = pallet_bridge_currency_exchange::Instance1;
impl pallet_bridge_currency_exchange::Trait<RialtoCurrencyExchange> for Runtime {
type OnTransactionSubmitted = ();
type PeerBlockchain = rialto::RialtoBlockchain;
type PeerBlockchain = rialto_poa::RialtoBlockchain;
type PeerMaybeLockFundsTransaction = exchange::EthTransaction;
type RecipientsMap = bp_currency_exchange::IdentityRecipients<AccountId>;
type Amount = Balance;
@@ -427,11 +428,11 @@ construct_runtime!(
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
BridgeRialto: pallet_bridge_eth_poa::<Instance1>::{Module, Call, Config, Storage, ValidateUnsigned},
BridgeRialtoPoA: pallet_bridge_eth_poa::<Instance1>::{Module, Call, Config, Storage, ValidateUnsigned},
BridgeKovan: pallet_bridge_eth_poa::<Instance2>::{Module, Call, Config, Storage, ValidateUnsigned},
BridgeRialtoCurrencyExchange: pallet_bridge_currency_exchange::<Instance1>::{Module, Call},
BridgeKovanCurrencyExchange: pallet_bridge_currency_exchange::<Instance2>::{Module, Call},
BridgeMillau: pallet_substrate_bridge::{Module, Call, Storage},
BridgeMillau: pallet_substrate_bridge::{Module, Call, Storage, Config<T>},
BridgeCallDispatch: pallet_bridge_call_dispatch::{Module, Event<T>},
System: frame_system::{Module, Call, Config, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
@@ -530,21 +531,21 @@ impl_runtime_apis! {
impl bp_eth_poa::RialtoPoAHeaderApi<Block> 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)
}
}
+87
View File
@@ -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 <http://www.gnu.org/licenses/>.
//! 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)
}
@@ -14,6 +14,8 @@
// 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/>.
//! 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<Address> {
vec![
hex!("005e714f896a8b7cede9d38688c1a81de72a58e4").into(),
@@ -64,7 +66,7 @@ pub fn genesis_validators() -> Vec<Address> {
]
}
/// 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<Self::Transaction> {
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;
+4 -1
View File
@@ -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;
-1
View File
@@ -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 }
+2 -2
View File
@@ -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 {