Skip to content

Commit

Permalink
Add GenesisConfig for Millau and Rialto Runtimes (paritytech#401)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and bkchr committed Apr 10, 2024
1 parent 9e9ac8d commit f52c839
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 35 deletions.
2 changes: 1 addition & 1 deletion bridges/bin/millau/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions bridges/bin/millau/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand All @@ -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 changes: 3 additions & 0 deletions bridges/bin/millau/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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},
Expand Down
56 changes: 56 additions & 0 deletions bridges/bin/millau/runtime/src/rialto.rs
Original file line number Diff line number Diff line change
@@ -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)
}
24 changes: 17 additions & 7 deletions bridges/bin/rialto/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand All @@ -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(),
})
}

Expand All @@ -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 changes: 2 additions & 0 deletions bridges/bin/rialto/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down
29 changes: 15 additions & 14 deletions bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = ();
}

Expand All @@ -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;
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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)
}
}

Expand Down
87 changes: 87 additions & 0 deletions bridges/bin/rialto/runtime/src/millau.rs
Original file line number Diff line number Diff line change
@@ -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)
}
Loading

0 comments on commit f52c839

Please sign in to comment.