mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-11-30 14:29:57 +00:00
Serialisable genesis config (#229)
* Genesis serialization * Custom type for AuthorityId * Merge w master * Fixed a few minor issues * Fixed unmerged file * Renamed tag * Deferred genesis loading * Upated wasm runtime * Minor issues
This commit is contained in:
1 parent
276c464b50
commit
9b885ba092
51 files changed
+557
-368
No files matched your search
@@ -15,7 +15,6 @@ time = "0.1"
|
||||
slog = "^2"
|
||||
ansi_term = "0.10"
|
||||
lazy_static = "1.0"
|
||||
hex-literal = "0.1"
|
||||
triehash = "0.1"
|
||||
ed25519 = { path = "../../substrate/ed25519" }
|
||||
app_dirs = "1.2"
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"0x9768f3cbdd14c1a63474dfbdbe052f42": "0x80f4030000000000",
|
||||
"0x3b700687fecdff5ec1c4a5b714521eb6": "0x0000000000000000",
|
||||
"0xa059ae3b3ef725721e97452642803b61": "0x0c00000000000000",
|
||||
"0x81c1e7165a6371a30eda241a30ea26dd": "0x6400000000000000",
|
||||
"0x45e71d57a2e3a4eace16dbc9286652e3": "0x00000000",
|
||||
"0x1d72be21946c0b245c026b7be8256cc5": "0x00000000",
|
||||
"0xd68ee884e4baac617d9823d543ab9295": "0x0000000000000010",
|
||||
"0x1d007e138cb61e2524a67b15ec01d8cb": "0x0000000000000010",
|
||||
"0xbfde7c86a8efd60ee5db2de6446703d5": "0xc04e000000000000",
|
||||
"0x3a617574683a6c656e": "0x04000000",
|
||||
"0xb54b186fe8782c2a03f2fd15f95c26bf": "0x00000000",
|
||||
"0x9dd24013e492bdbb3544fba06734baf7": "0xd002000000000000",
|
||||
"0xd52c584b1e542130e5b277f1af7b7714": "0x00000000",
|
||||
"0x3a617574683a03000000": "0x8101764f45778d4980dadaceee6e8af2517d3ab91ac9bec9cd1714fa5994081c",
|
||||
"0x916dbd78366f27a9597bd4c831e7914d": "0x00e9070000000000",
|
||||
"0xf37d2c26c6953b18878dbc1dc65edbc0": "0x1800000000000000",
|
||||
"0x8d62e0fbc08e8694f8991f88d763c5fb": "0x5a00000000000000",
|
||||
"0xa659ecb253960cfd890e08809104b815": "0x809d000000000000",
|
||||
"0x3a617574683a00000000": "0x82c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf5",
|
||||
"0x3a617574683a02000000": "0x063d7787ebca768b7445dfebe7d62cbb1625ff4dba288ea34488da266dd6dca5",
|
||||
"0xe885ffcc2245c8b7d128685cac6b1a0b": "0x0100000000000000",
|
||||
"0x94b01408fc662bcf2e97df23ce6d67e2": "0x0100000000000000",
|
||||
"0x6cac40e934558080fbf29c55c113b461": "0x0000000000000000",
|
||||
"0x8379e35e0cd953085e0404b9223c0cb0": "0xc04e000000000000",
|
||||
"0x5a3dcf1edb28ea65a038d1eef6767380": "0x003b010000000000",
|
||||
"0x7a5bafa684003bc748abe89bfbd20f76": "0xe803000000000000",
|
||||
"0x3d5680071e92ff27a2914bba661e5d83": "0x400b000000000000",
|
||||
"0x274351e20682cb2ed212b6eab04ef89f": "0x00000000",
|
||||
"0x3a617574683a01000000": "0x4de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7",
|
||||
"0x482b5d7b62ccccac45d55bd43c767266": "0x6400000000000000",
|
||||
"0x35b8ced31f34a951bc3b56db2f425c51": "0x00000000",
|
||||
"0x98b9e95963cac608a3d0d537fbeaf5c2": "0x0400000082c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf54de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7063d7787ebca768b7445dfebe7d62cbb1625ff4dba288ea34488da266dd6dca58101764f45778d4980dadaceee6e8af2517d3ab91ac9bec9cd1714fa5994081c",
|
||||
"0xce83497694648564e47482d0dc444564": "0x18000000",
|
||||
"0xa0c2154e69bce912f28e890561fcb95c": "0x0400000082c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf54de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7063d7787ebca768b7445dfebe7d62cbb1625ff4dba288ea34488da266dd6dca58101764f45778d4980dadaceee6e8af2517d3ab91ac9bec9cd1714fa5994081c",
|
||||
"0x9b7ecc8eb0fade7c91d94b8715fc9ee1": "0xe803000000000000",
|
||||
"0x3a636f6465": "0x0061736d010000000197011760027f7f0060057f7f7f7f7f017f60017f017f60037f7f7f017f60017f0060000060037f7f7f0060047f7f7f7f006000017e60027f7f017f60027f7e0060037e7f7f0060017f017e600a7f7f7f7f7f7f7f7f7f7f0060017e0060067f7f7f7f7f7f0060047f7f7f7f017f60047f7f7f7f017e60067f7f7f7f7f7f017f60057f7f7f7f7f0060027f7f017e60027f7e017f60037f7f7e0002f1031603656e76146578745f6765745f73746f726167655f696e746f000103656e760a6578745f6d616c6c6f63000203656e76086578745f66726565000403656e760c6578745f74776f785f313238000603656e760f6578745f7365745f73746f72616765000703656e76116578745f636c6561725f73746f72616765000003656e760a6578745f6d656d636d70000303656e76186578745f656e756d6572617465645f747269655f726f6f74000703656e760e6578745f7072696e745f75746638000003656e760d6578745f7072696e745f6e756d000e03656e760a6578745f6d656d637079000303656e760b6578745f6d656d6d6f7665000303656e760a6578745f6d656d736574000303656e76166578745f73616e64626f785f6d656d6f72795f6e6577000903656e76176578745f73616e64626f785f696e7374616e7469617465001203656e76126578745f73616e64626f785f696e766f6b65001003656e76166578745f73616e64626f785f6d656d6f72795f676574001003656e76166578745f73616e64626f785f6d656d6f72795f736574001003656e760e6578745f626c616b65325f323536000603656e760d6578745f7072696e745f686578000003656e76106578745f73746f726167655f726f6f74000403656e76126578745f656432353531395f766572696679001003d001ce010003040505050500030000020404050400060000060505000804040900000505040004030004060a040b0005000c0c00040405060404060d0504050002040400050505050505050505050505050505050505040504050405050405040505040504050405040504050405040506060000060007070f070f0710070707071107130906000409060000040500140014061404140a06041414140002060a15000000000400000004040000040c000405070a1400000000000413060706160704140616060000060000000000000000090405017001161605030100110609017f0141d0c3c0000b07a8010b066d656d6f7279020011727573745f626567696e5f756e77696e64004d066d616c6c6f630052046672656500530b617574686f72697469657300a10110696e697469616c6973655f626c6f636b00a3010f6170706c795f65787472696e73696300a5010d657865637574655f626c6f636b00a7010e66696e616c6973655f626c6f636b00ab010f76616c696461746f725f636f756e7400ac010a76616c696461746f727300ad010930010041010b158f019001910192019301cc01cd01ce01c601cf01d001d101c701d30195019b01d4019401d501d6019c010abbe40cce01ea0403067f017e057f230041106b220224002002410036020020012001280208220341002001280200220420012802042205200241042003100022032003417f461b2203410420034104491b6a22063602080240024002400240200341034d0d0020022802002207ad420c7e2208422088a70d022008a72203417f4c0d01024002402003450d002003100122090d010c050b410421090b20022007360204200220093602002002410036020802402007450d00200141086a210a4100210b4100210c03402002410036020c200a4100200420052002410c6a41042006100022012001417f461b2201410420014104491b20066a2206360200024002400240200141034d0d00200228020c2201417f4c0d01024002402001450d00200110012203450d0a20034100200110171a0c010b410121030b200a20014100200420052003200120061000220d200d417f461b220d200d20014b1b20066a220636020002402001200d4b0d002003450d01200c41016a210c2001ad22084220862008842108200b2002280204470d0320021018200241086a280200210b200228020021090c030b200310020b200228020021060240200b450d00200b410c6c21032006210103400240200141046a280200450d00200128020010020b2001410c6a2101200341746a22030d000b0b2002280204450d04200610020c040b1019000b2009200b410c6c6a2201200837020420012003360200200241086a200b41016a220b360200200c2007490d000b200228020021090b2009450d002000200229020437020420002009360200200241106a24000f0b20004100360200200241106a24000f0b101a000b101b000b101c000b0a00200020012002100c0b810101057f410421010240024002400240200041046a2802002202450d00200241186c2201417f4c0d0320002802002103200110012204450d022004200320012002410c6c2205200520014b1b101e1a20031002200241017421010c010b413010012204450d010b20002004360200200041046a20013602000f0b101c000b1073000b05001041000b05001041000b05001041000b0500104e000bc11105097f037e017f017e027f230041a0026b220224002001280200210320024180026a20012802042204412020044120491b22056a41004100412020056b2005411f4b1b10171a20024180026a20032005101e1a2001200420056b22063602042001200320056a22053602000240024002400240024002400240024002402004411f4d0d00200241e0016a41186a220420024180026a41186a2203290300370300200241e0016a41106a220720024180026a41106a2208290300370300200241e0016a41086a220920024180026a41086a220a29030037030020022002290380023703e00120032004290300220b37030020082007290300220c370300200a2009290300220d370300200241c0006a41086a2204200d370300200241c0006a41106a2203200c370300200241c0006a41186a2207200b370300200220022903e001220b3703402002200b37038002200241206a41186a2007290300370300200241206a41106a2003290300370300200241206a41086a200429030037030020022002290340370320200242003703800220024180026a20052006410820064108491b2204101e1a200141046a2207200620046b22033602002001200520046a2204360200200641074d0d01200229038002210c20024180026a2003412020034120491b22056a41004100412020056b2005411f4b1b10171a20024180026a20042005101e1a2007200320056b22063602002001200420056a22043602002003411f4d0d02200241e0016a41186a220320024180026a41186a2207290300370300200241e0Line truncated
|
||||
"0x0346fb0f1ce64e1a02c4959d38ebad38": "0x00000000"}
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
//! Predefined chains.
|
||||
|
||||
use service;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// The chain specification (this should eventually be replaced by a more general JSON-based chain
|
||||
/// specification).
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -32,6 +35,19 @@ pub enum ChainSpec {
|
||||
Custom(String),
|
||||
}
|
||||
|
||||
/// Get a chain config from a spec setting.
|
||||
impl ChainSpec {
|
||||
pub(crate) fn load(self) -> Result<service::ChainSpec, String> {
|
||||
Ok(match self {
|
||||
ChainSpec::PoC1Testnet => service::ChainSpec::poc_1_testnet_config()?,
|
||||
ChainSpec::Development => service::ChainSpec::development_config(),
|
||||
ChainSpec::LocalTestnet => service::ChainSpec::local_testnet_config(),
|
||||
ChainSpec::PoC2Testnet => service::ChainSpec::poc_2_testnet_config(),
|
||||
ChainSpec::Custom(f) => service::ChainSpec::from_json_file(PathBuf::from(f))?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for ChainSpec {
|
||||
fn from(s: &'a str) -> Self {
|
||||
match s {
|
||||
@@ -55,19 +71,3 @@ impl From<ChainSpec> for String {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Display for ChainSpec {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
if let ChainSpec::Custom(n) = self {
|
||||
write!(f, "Custom ({})", n)
|
||||
} else {
|
||||
write!(f, "{}", match *self {
|
||||
ChainSpec::Development => "Development",
|
||||
ChainSpec::LocalTestnet => "Local Testnet",
|
||||
ChainSpec::PoC1Testnet => "PoC-1 Testnet",
|
||||
ChainSpec::PoC2Testnet => "PoC-2 Testnet",
|
||||
_ => unreachable!(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,10 +45,6 @@ args:
|
||||
long: dev
|
||||
help: Run in development mode; implies --chain=dev --validator --key Alice
|
||||
takes_value: false
|
||||
- build-genesis:
|
||||
long: build-genesis
|
||||
help: Build a genesis.json file, outputing to stdout
|
||||
takes_value: false
|
||||
- port:
|
||||
long: port
|
||||
value_name: PORT
|
||||
@@ -96,3 +92,15 @@ args:
|
||||
help: The URL of the telemetry server. Implies --telemetry
|
||||
takes_value: true
|
||||
subcommands:
|
||||
- build-spec:
|
||||
about: Build a spec.json file, outputing to stdout
|
||||
args:
|
||||
- raw:
|
||||
long: raw
|
||||
help: Force raw genesis storage output.
|
||||
takes_value: false
|
||||
- chain:
|
||||
long: chain
|
||||
value_name: CHAIN_SPEC
|
||||
help: Specify the chain specification (one of dev, local or poc-2)
|
||||
takes_value: true
|
||||
@@ -58,26 +58,17 @@ extern crate clap;
|
||||
extern crate error_chain;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate hex_literal;
|
||||
|
||||
pub mod error;
|
||||
mod informant;
|
||||
mod chain_spec;
|
||||
mod preset_config;
|
||||
|
||||
pub use chain_spec::ChainSpec;
|
||||
pub use preset_config::PresetConfig;
|
||||
|
||||
use std::io;
|
||||
use std::fs::File;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::collections::HashMap;
|
||||
use substrate_primitives::hexdisplay::HexDisplay;
|
||||
use substrate_primitives::storage::{StorageData, StorageKey};
|
||||
use substrate_telemetry::{init_telemetry, TelemetryConfig};
|
||||
use runtime_primitives::StorageMap;
|
||||
use polkadot_primitives::Block;
|
||||
|
||||
use futures::sync::mpsc;
|
||||
@@ -106,10 +97,13 @@ impl substrate_rpc::system::SystemApi for SystemConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_storage_json(filename: &str) -> Option<StorageMap> {
|
||||
let file = File::open(PathBuf::from(filename)).ok()?;
|
||||
let h: HashMap<StorageKey, StorageData> = ::serde_json::from_reader(&file).ok()?;
|
||||
Some(h.into_iter().map(|(k, v)| (k.0, v.0)).collect())
|
||||
fn load_spec(matches: &clap::ArgMatches) -> Result<service::ChainSpec, String> {
|
||||
let chain_spec = matches.value_of("chain")
|
||||
.map(ChainSpec::from)
|
||||
.unwrap_or_else(|| if matches.is_present("dev") { ChainSpec::Development } else { ChainSpec::PoC2Testnet });
|
||||
let spec = chain_spec.load()?;
|
||||
info!("Chain specification: {}", spec.name());
|
||||
Ok(spec)
|
||||
}
|
||||
|
||||
/// Parse command line arguments and start the node.
|
||||
@@ -124,8 +118,6 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<std::ffi::OsString> + Clone,
|
||||
{
|
||||
let core = reactor::Core::new().expect("tokio::Core could not be created");
|
||||
|
||||
let yaml = load_yaml!("./cli.yml");
|
||||
let matches = match clap::App::from_yaml(yaml).version(&(crate_version!().to_owned() + "\n")[..]).get_matches_from_safe(args) {
|
||||
Ok(m) => m,
|
||||
@@ -146,20 +138,22 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
info!(" version {}", crate_version!());
|
||||
info!(" by Parity Technologies, 2017, 2018");
|
||||
|
||||
let mut config = service::Configuration::default();
|
||||
if let Some(matches) = matches.subcommand_matches("build-spec") {
|
||||
let spec = load_spec(&matches)?;
|
||||
info!("Building chain spec");
|
||||
let json = spec.to_json(matches.is_present("raw"))?;
|
||||
print!("{}", json);
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
let spec = load_spec(&matches)?;
|
||||
let mut config = service::Configuration::default_with_spec(spec);
|
||||
|
||||
if let Some(name) = matches.value_of("name") {
|
||||
config.name = name.into();
|
||||
info!("Node name: {}", config.name);
|
||||
}
|
||||
|
||||
let chain_spec = matches.value_of("chain")
|
||||
.map(ChainSpec::from)
|
||||
.unwrap_or_else(|| if matches.is_present("dev") { ChainSpec::Development } else { ChainSpec::PoC2Testnet });
|
||||
info!("Chain specification: {}", chain_spec);
|
||||
|
||||
config.chain_name = chain_spec.clone().into();
|
||||
|
||||
let base_path = matches.value_of("base-path")
|
||||
.map(|x| Path::new(x).to_owned())
|
||||
.unwrap_or_else(default_base_path);
|
||||
@@ -171,6 +165,7 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
.into();
|
||||
|
||||
config.database_path = db_path(&base_path).to_string_lossy().into();
|
||||
|
||||
config.pruning = match matches.value_of("pruning") {
|
||||
Some("archive") => PruningMode::ArchiveAll,
|
||||
None => PruningMode::keep_blocks(256),
|
||||
@@ -178,25 +173,6 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
.map_err(|_| error::ErrorKind::Input("Invalid pruning mode specified".to_owned()))?),
|
||||
};
|
||||
|
||||
let (mut genesis_storage, boot_nodes) = PresetConfig::from_spec(chain_spec)
|
||||
.map(PresetConfig::deconstruct)
|
||||
.unwrap_or_else(|f| (Box::new(move ||
|
||||
read_storage_json(&f)
|
||||
.map(|s| { info!("{} storage items read from {}", s.len(), f); s })
|
||||
.unwrap_or_else(|| panic!("Bad genesis state file: {}", f))
|
||||
), vec![]));
|
||||
|
||||
if matches.is_present("build-genesis") {
|
||||
info!("Building genesis");
|
||||
for (i, (k, v)) in genesis_storage().iter().enumerate() {
|
||||
print!("{}\n\"0x{}\": \"0x{}\"", if i > 0 {','} else {'{'}, HexDisplay::from(k), HexDisplay::from(v));
|
||||
}
|
||||
println!("\n}}");
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
config.genesis_storage = genesis_storage;
|
||||
|
||||
let role =
|
||||
if matches.is_present("collator") {
|
||||
info!("Starting collator");
|
||||
@@ -214,10 +190,9 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
|
||||
config.roles = role;
|
||||
{
|
||||
config.network.boot_nodes = matches
|
||||
config.network.boot_nodes.extend(matches
|
||||
.values_of("bootnodes")
|
||||
.map_or(Default::default(), |v| v.map(|n| n.to_owned()).collect());
|
||||
config.network.boot_nodes.extend(boot_nodes);
|
||||
.map_or(Default::default(), |v| v.map(|n| n.to_owned()).collect::<Vec<_>>()));
|
||||
config.network.config_path = Some(network_path(&base_path).to_string_lossy().into());
|
||||
config.network.net_config_path = config.network.config_path.clone();
|
||||
|
||||
@@ -241,12 +216,12 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
}
|
||||
|
||||
let sys_conf = SystemConfiguration {
|
||||
chain_name: config.chain_name.clone(),
|
||||
chain_name: config.chain_spec.name().to_owned(),
|
||||
};
|
||||
|
||||
let _guard = if matches.is_present("telemetry") || matches.value_of("telemetry-url").is_some() {
|
||||
let name = config.name.clone();
|
||||
let chain_name = config.chain_name.clone();
|
||||
let chain_name = config.chain_spec.name().to_owned();
|
||||
Some(init_telemetry(TelemetryConfig {
|
||||
url: matches.value_of("telemetry-url").unwrap_or(DEFAULT_TELEMETRY_URL).into(),
|
||||
on_connect: Box::new(move || {
|
||||
@@ -263,6 +238,7 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
None
|
||||
};
|
||||
|
||||
let core = reactor::Core::new().expect("tokio::Core could not be created");
|
||||
match role == service::Role::LIGHT {
|
||||
true => run_until_exit(core, service::new_light(config)?, &matches, sys_conf),
|
||||
false => run_until_exit(core, service::new_full(config)?, &matches, sys_conf),
|
||||
|
||||
@@ -1,234 +0,0 @@
|
||||
// Copyright 2017 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot 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.
|
||||
|
||||
// Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Polkadot chain configurations.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use ed25519;
|
||||
use serde_json;
|
||||
use substrate_primitives::{AuthorityId, storage::{StorageKey, StorageData}};
|
||||
use runtime_primitives::{MakeStorage, BuildStorage, StorageMap};
|
||||
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
|
||||
SessionConfig, StakingConfig, TimestampConfig};
|
||||
use chain_spec::ChainSpec;
|
||||
|
||||
enum Config {
|
||||
Local(GenesisConfig),
|
||||
Raw(&'static [u8]),
|
||||
}
|
||||
|
||||
/// A configuration of a chain. Can be used to build a genesis block.
|
||||
pub struct PresetConfig {
|
||||
genesis_config: Config,
|
||||
pub(crate) boot_nodes: Vec<String>,
|
||||
}
|
||||
|
||||
impl BuildStorage for Config {
|
||||
fn build_storage(self) -> StorageMap {
|
||||
match self {
|
||||
Config::Local(gc) => gc.build_storage(),
|
||||
Config::Raw(json) => {
|
||||
let h: HashMap<StorageKey, StorageData> = serde_json::from_slice(json).expect("Data is from an internal source and is guaranteed to be of the correct format");
|
||||
h.into_iter().map(|(k, v)| (k.0, v.0)).collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PresetConfig {
|
||||
/// Get a chain config from a spec, if it's predefined.
|
||||
pub fn from_spec(chain_spec: ChainSpec) -> Result<Self, String> {
|
||||
Ok(match chain_spec {
|
||||
ChainSpec::PoC1Testnet => Self::poc_1_testnet_config(),
|
||||
ChainSpec::Development => Self::development_config(),
|
||||
ChainSpec::LocalTestnet => Self::local_testnet_config(),
|
||||
ChainSpec::PoC2Testnet => Self::poc_2_testnet_config(),
|
||||
ChainSpec::Custom(f) => return Err(f),
|
||||
})
|
||||
}
|
||||
|
||||
/// Provide the boot nodes and a storage-builder function.
|
||||
// TODO: Change return type to FnOnce as soon as Box<FnOnce> is callable or BoxFn is stablised.
|
||||
pub fn deconstruct(self) -> (MakeStorage, Vec<String>) {
|
||||
let mut gc = Some(self.genesis_config);
|
||||
let f = move || gc.take().map(BuildStorage::build_storage).unwrap_or_default();
|
||||
(Box::new(f), self.boot_nodes)
|
||||
}
|
||||
|
||||
/// PoC-1 testnet config.
|
||||
fn poc_1_testnet_config() -> Self {
|
||||
let genesis_config = Config::Raw(include_bytes!("../poc-1.json"));
|
||||
let boot_nodes = vec![
|
||||
"enode://a93a29fa68d965452bf0ff8c1910f5992fe2273a72a1ee8d3a3482f68512a61974211ba32bb33f051ceb1530b8ba3527fc36224ba6b9910329025e6d9153cf50@104.211.54.233:30333".into(),
|
||||
"enode://051b18f63a316c4c5fef4631f8c550ae0adba179153588406fac3e5bbbbf534ebeda1bf475dceda27a531f6cdef3846ab6a010a269aa643a1fec7bff51af66bd@104.211.48.51:30333".into(),
|
||||
"enode://c831ec9011d2c02d2c4620fc88db6d897a40d2f88fd75f47b9e4cf3b243999acb6f01b7b7343474650b34eeb1363041a422a91f1fc3850e43482983ee15aa582@104.211.48.247:30333".into(),
|
||||
];
|
||||
PresetConfig { genesis_config, boot_nodes }
|
||||
}
|
||||
|
||||
/// PoC-2 testnet config.
|
||||
fn poc_2_testnet_config() -> Self {
|
||||
let initial_authorities = vec![
|
||||
hex!["82c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf5"].into(),
|
||||
hex!["4de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7"].into(),
|
||||
hex!["063d7787ebca768b7445dfebe7d62cbb1625ff4dba288ea34488da266dd6dca5"].into(),
|
||||
hex!["8101764f45778d4980dadaceee6e8af2517d3ab91ac9bec9cd1714fa5994081c"].into(),
|
||||
];
|
||||
let endowed_accounts = vec![
|
||||
hex!["f295940fa750df68a686fcf4abd4111c8a9c5a5a5a83c4c8639c451a94a7adfd"].into(),
|
||||
];
|
||||
let genesis_config = Config::Local(GenesisConfig {
|
||||
consensus: Some(ConsensusConfig {
|
||||
code: include_bytes!("../../runtime/wasm/genesis.wasm").to_vec(), // TODO change
|
||||
authorities: initial_authorities.clone(),
|
||||
}),
|
||||
system: None,
|
||||
session: Some(SessionConfig {
|
||||
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
|
||||
session_length: 60, // that's 5 minutes per session.
|
||||
broken_percent_late: 50,
|
||||
}),
|
||||
staking: Some(StakingConfig {
|
||||
current_era: 0,
|
||||
intentions: initial_authorities.iter().cloned().map(Into::into).collect(),
|
||||
transaction_base_fee: 100,
|
||||
transaction_byte_fee: 1,
|
||||
existential_deposit: 500,
|
||||
transfer_fee: 0,
|
||||
creation_fee: 0,
|
||||
contract_fee: 0,
|
||||
reclaim_rebate: 0,
|
||||
early_era_slash: 10000,
|
||||
session_reward: 100,
|
||||
balances: endowed_accounts.iter().map(|&k|(k, 1u128 << 60)).collect(),
|
||||
validator_count: 12,
|
||||
sessions_per_era: 12, // 1 hour per era
|
||||
bonding_duration: 24, // 1 day per bond.
|
||||
}),
|
||||
democracy: Some(DemocracyConfig {
|
||||
launch_period: 12 * 60 * 24, // 1 day per public referendum
|
||||
voting_period: 12 * 60 * 24 * 3, // 3 days to discuss & vote on an active referendum
|
||||
minimum_deposit: 5000, // 12000 as the minimum deposit for a referendum
|
||||
}),
|
||||
council: Some(CouncilConfig {
|
||||
active_council: vec![],
|
||||
candidacy_bond: 5000, // 5000 to become a council candidate
|
||||
voter_bond: 1000, // 1000 down to vote for a candidate
|
||||
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
|
||||
carry_count: 6, // carry over the 6 runners-up to the next council election
|
||||
presentation_duration: 12 * 60 * 24, // one day for presenting winners.
|
||||
approval_voting_period: 12 * 60 * 24 * 2, // two days period between possible council elections.
|
||||
term_duration: 12 * 60 * 24 * 24, // 24 day term duration for the council.
|
||||
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
|
||||
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.
|
||||
|
||||
cooloff_period: 12 * 60 * 24 * 4, // 4 day cooling off period if council member vetoes a proposal.
|
||||
voting_period: 12 * 60 * 24, // 1 day voting period for council members.
|
||||
}),
|
||||
parachains: Some(Default::default()),
|
||||
timestamp: Some(TimestampConfig {
|
||||
period: 5, // 5 second block time.
|
||||
}),
|
||||
});
|
||||
let boot_nodes = vec![
|
||||
"enode://a93a29fa68d965452bf0ff8c1910f5992fe2273a72a1ee8d3a3482f68512a61974211ba32bb33f051ceb1530b8ba3527fc36224ba6b9910329025e6d9153cf50@104.211.54.233:30333".into(),
|
||||
"enode://051b18f63a316c4c5fef4631f8c550ae0adba179153588406fac3e5bbbbf534ebeda1bf475dceda27a531f6cdef3846ab6a010a269aa643a1fec7bff51af66bd@104.211.48.51:30333".into(),
|
||||
"enode://c831ec9011d2c02d2c4620fc88db6d897a40d2f88fd75f47b9e4cf3b243999acb6f01b7b7343474650b34eeb1363041a422a91f1fc3850e43482983ee15aa582@104.211.48.247:30333".into(),
|
||||
];
|
||||
PresetConfig { genesis_config, boot_nodes }
|
||||
}
|
||||
|
||||
fn testnet_config(initial_authorities: Vec<AuthorityId>) -> PresetConfig {
|
||||
let endowed_accounts = vec![
|
||||
ed25519::Pair::from_seed(b"Alice ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Bob ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Charlie ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Dave ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Eve ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Ferdie ").public().0.into(),
|
||||
];
|
||||
let genesis_config = Config::Local(GenesisConfig {
|
||||
consensus: Some(ConsensusConfig {
|
||||
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm").to_vec(),
|
||||
authorities: initial_authorities.clone(),
|
||||
}),
|
||||
system: None,
|
||||
session: Some(SessionConfig {
|
||||
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
|
||||
session_length: 10,
|
||||
broken_percent_late: 30,
|
||||
}),
|
||||
staking: Some(StakingConfig {
|
||||
current_era: 0,
|
||||
intentions: initial_authorities.iter().cloned().map(Into::into).collect(),
|
||||
transaction_base_fee: 1,
|
||||
transaction_byte_fee: 0,
|
||||
existential_deposit: 500,
|
||||
transfer_fee: 0,
|
||||
creation_fee: 0,
|
||||
contract_fee: 0,
|
||||
reclaim_rebate: 0,
|
||||
balances: endowed_accounts.iter().map(|&k|(k, (1u128 << 60))).collect(),
|
||||
validator_count: 2,
|
||||
sessions_per_era: 5,
|
||||
bonding_duration: 2,
|
||||
early_era_slash: 0,
|
||||
session_reward: 0,
|
||||
}),
|
||||
democracy: Some(DemocracyConfig {
|
||||
launch_period: 9,
|
||||
voting_period: 18,
|
||||
minimum_deposit: 10,
|
||||
}),
|
||||
council: Some(CouncilConfig {
|
||||
active_council: endowed_accounts.iter().filter(|a| initial_authorities.iter().find(|&b| &a.0 == b).is_none()).map(|a| (a.clone(), 1000000)).collect(),
|
||||
candidacy_bond: 10,
|
||||
voter_bond: 2,
|
||||
present_slash_per_voter: 1,
|
||||
carry_count: 4,
|
||||
presentation_duration: 10,
|
||||
approval_voting_period: 20,
|
||||
term_duration: 1000000,
|
||||
desired_seats: (endowed_accounts.len() - initial_authorities.len()) as u32,
|
||||
inactive_grace_period: 1,
|
||||
|
||||
cooloff_period: 75,
|
||||
voting_period: 20,
|
||||
}),
|
||||
parachains: Some(Default::default()),
|
||||
timestamp: Some(TimestampConfig {
|
||||
period: 5, // 5 second block time.
|
||||
}),
|
||||
});
|
||||
let boot_nodes = Vec::new();
|
||||
PresetConfig { genesis_config, boot_nodes }
|
||||
}
|
||||
|
||||
/// Development config (single validator Alice)
|
||||
fn development_config() -> Self {
|
||||
Self::testnet_config(vec![
|
||||
ed25519::Pair::from_seed(b"Alice ").public().into(),
|
||||
])
|
||||
}
|
||||
|
||||
/// Local testnet config (multivalidator Alice + Bob)
|
||||
fn local_testnet_config() -> Self {
|
||||
Self::testnet_config(vec![
|
||||
ed25519::Pair::from_seed(b"Alice ").public().into(),
|
||||
ed25519::Pair::from_seed(b"Bob ").public().into(),
|
||||
])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user