mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-10 04:07:59 +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:
committed by
Gav Wood
parent
276c464b50
commit
9b885ba092
Generated
+4
-1
@@ -1407,7 +1407,6 @@ dependencies = [
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1542,6 +1541,7 @@ dependencies = [
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"exit-future 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1551,6 +1551,9 @@ dependencies = [
|
||||
"polkadot-primitives 0.1.0",
|
||||
"polkadot-runtime 0.1.0",
|
||||
"polkadot-transaction-pool 0.1.0",
|
||||
"serde 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-client 0.1.0",
|
||||
"substrate-client-db 0.1.0",
|
||||
|
||||
@@ -49,7 +49,7 @@ pub mod error;
|
||||
|
||||
use std::sync::Arc;
|
||||
use demo_primitives::Hash;
|
||||
use demo_runtime::{Block, BlockId, UncheckedExtrinsic, BuildStorage, GenesisConfig,
|
||||
use demo_runtime::{Block, BlockId, UncheckedExtrinsic, GenesisConfig,
|
||||
ConsensusConfig, CouncilConfig, DemocracyConfig, SessionConfig, StakingConfig,
|
||||
TimestampConfig};
|
||||
use futures::{Future, Sink, Stream};
|
||||
@@ -101,10 +101,10 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
let executor = demo_executor::Executor::new();
|
||||
|
||||
let god_key = hex!["3d866ec8a9190c8343c2fc593d21d8a6d0c5c4763aaab2349de3a6111d64d124"];
|
||||
let genesis_storage = GenesisConfig {
|
||||
let genesis_config = GenesisConfig {
|
||||
consensus: Some(ConsensusConfig {
|
||||
code: vec![], // TODO
|
||||
authorities: vec![god_key.clone()],
|
||||
authorities: vec![god_key.clone().into()],
|
||||
}),
|
||||
system: None,
|
||||
session: Some(SessionConfig {
|
||||
@@ -152,9 +152,9 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
timestamp: Some(TimestampConfig {
|
||||
period: 5, // 5 second block time.
|
||||
}),
|
||||
}.build_storage();
|
||||
};
|
||||
|
||||
let client = Arc::new(client::new_in_mem::<_, Block, _>(executor, genesis_storage)?);
|
||||
let client = Arc::new(client::new_in_mem::<_, Block, _>(executor, genesis_config)?);
|
||||
let mut core = ::tokio_core::reactor::Core::new().expect("Unable to spawn event loop.");
|
||||
|
||||
let _rpc_servers = {
|
||||
|
||||
@@ -207,7 +207,7 @@ mod tests {
|
||||
democracy: Some(Default::default()),
|
||||
council: Some(Default::default()),
|
||||
timestamp: Some(Default::default()),
|
||||
}.build_storage()
|
||||
}.build_storage().unwrap()
|
||||
}
|
||||
|
||||
fn construct_block(number: BlockNumber, parent_hash: Hash, state_root: Hash, extrinsics: Vec<BareExtrinsic>) -> (Vec<u8>, Hash) {
|
||||
|
||||
@@ -97,7 +97,7 @@ pub type Timestamp = timestamp::Module<Concrete>;
|
||||
pub struct SessionKeyConversion;
|
||||
impl Convert<AccountId, SessionKey> for SessionKeyConversion {
|
||||
fn convert(a: AccountId) -> SessionKey {
|
||||
a.0
|
||||
a.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Generated
-18
@@ -172,11 +172,6 @@ dependencies = [
|
||||
name = "environmental"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "error-chain"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ethbloom"
|
||||
version = "0.5.0"
|
||||
@@ -329,16 +324,6 @@ dependencies = [
|
||||
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kvdb"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/paritytech/parity.git#dec390a89fe038337399315daf15e628ffbb4d8e"
|
||||
dependencies = [
|
||||
"elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-bytes 0.1.0 (git+https://github.com/paritytech/parity.git)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "0.2.11"
|
||||
@@ -995,7 +980,6 @@ dependencies = [
|
||||
"ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashdb 0.1.1 (git+https://github.com/paritytech/parity.git)",
|
||||
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"kvdb 0.1.0 (git+https://github.com/paritytech/parity.git)",
|
||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memorydb 0.1.1 (git+https://github.com/paritytech/parity.git)",
|
||||
"parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1182,7 +1166,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda"
|
||||
"checksum elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "88d4851b005ef16de812ea9acdb7bece2f0a40dd86c07b85631d7dafa54537bb"
|
||||
"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b"
|
||||
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
|
||||
"checksum ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a93a43ce2e9f09071449da36bfa7a1b20b950ee344b6904ff23de493b03b386"
|
||||
"checksum ethcore-bytes 0.1.0 (git+https://github.com/paritytech/parity.git)" = "<none>"
|
||||
"checksum ethcore-logger 1.12.0 (git+https://github.com/paritytech/parity.git)" = "<none>"
|
||||
@@ -1200,7 +1183,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)" = "<none>"
|
||||
"checksum keccak-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b7f51f30d7986536accaec4a6a288008dfb3dbffe8a2863a65292bc395a3ae7"
|
||||
"checksum keccak-hash 0.1.2 (git+https://github.com/paritytech/parity.git)" = "<none>"
|
||||
"checksum kvdb 0.1.0 (git+https://github.com/paritytech/parity.git)" = "<none>"
|
||||
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
|
||||
"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739"
|
||||
"checksum libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)" = "ac8ebf8343a981e2fa97042b14768f02ed3e1d602eac06cae6166df3c8ced206"
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
@@ -190,7 +190,7 @@ mod tests {
|
||||
use client::LocalCallExecutor;
|
||||
use client::in_mem::Backend as InMemory;
|
||||
use substrate_executor::NativeExecutionDispatch;
|
||||
use runtime::{GenesisConfig, ConsensusConfig, SessionConfig, BuildStorage};
|
||||
use runtime::{GenesisConfig, ConsensusConfig, SessionConfig};
|
||||
|
||||
fn validators() -> Vec<AccountId> {
|
||||
vec![
|
||||
@@ -201,8 +201,8 @@ mod tests {
|
||||
|
||||
fn session_keys() -> Vec<SessionKey> {
|
||||
vec![
|
||||
Keyring::One.to_raw_public(),
|
||||
Keyring::Two.to_raw_public(),
|
||||
Keyring::One.to_raw_public().into(),
|
||||
Keyring::Two.to_raw_public().into(),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ mod tests {
|
||||
timestamp: Some(Default::default()),
|
||||
};
|
||||
|
||||
::client::new_in_mem(LocalDispatch::new(), genesis_config.build_storage()).unwrap()
|
||||
::client::new_in_mem(LocalDispatch::new(), genesis_config).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -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"
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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),
|
||||
|
||||
@@ -261,7 +261,7 @@ impl<C, N, P> bft::ProposerFactory<Block> for ProposerFactory<C, N, P>
|
||||
let (group_info, local_duty) = make_group_info(
|
||||
duty_roster,
|
||||
authorities,
|
||||
sign_with.public().0,
|
||||
sign_with.public().into(),
|
||||
)?;
|
||||
|
||||
let active_parachains = self.client.active_parachains(&checked_id)?;
|
||||
@@ -490,7 +490,7 @@ impl<C, R, P> bft::Proposer<Block> for Proposer<C, R, P>
|
||||
let offset = offset.low_u64() as usize + round_number;
|
||||
|
||||
let proposer = authorities[offset % authorities.len()].clone();
|
||||
trace!(target: "bft", "proposer for round {} is {}", round_number, Hash::from(proposer));
|
||||
trace!(target: "bft", "proposer for round {} is {}", round_number, proposer);
|
||||
|
||||
proposer
|
||||
}
|
||||
|
||||
@@ -92,16 +92,16 @@ fn process_message(msg: net::LocalizedBftMessage<Block>, local_id: &AuthorityId,
|
||||
sender: proposal.sender,
|
||||
digest_signature: ed25519::LocalizedSignature {
|
||||
signature: proposal.digest_signature,
|
||||
signer: ed25519::Public(proposal.sender),
|
||||
signer: proposal.sender.into(),
|
||||
},
|
||||
full_signature: ed25519::LocalizedSignature {
|
||||
signature: proposal.full_signature,
|
||||
signer: ed25519::Public(proposal.sender),
|
||||
signer: proposal.sender.into(),
|
||||
}
|
||||
};
|
||||
bft::check_proposal(authorities, &msg.parent_hash, &proposal)?;
|
||||
|
||||
trace!(target: "bft", "importing proposal message for round {} from {}", proposal.round_number, Hash::from(proposal.sender));
|
||||
trace!(target: "bft", "importing proposal message for round {} from {}", proposal.round_number, proposal.sender);
|
||||
proposal
|
||||
}),
|
||||
net::generic_message::SignedConsensusMessage::Vote(vote) => bft::generic::LocalizedMessage::Vote({
|
||||
@@ -110,7 +110,7 @@ fn process_message(msg: net::LocalizedBftMessage<Block>, local_id: &AuthorityId,
|
||||
sender: vote.sender,
|
||||
signature: ed25519::LocalizedSignature {
|
||||
signature: vote.signature,
|
||||
signer: ed25519::Public(vote.sender),
|
||||
signer: vote.sender.into(),
|
||||
},
|
||||
vote: match vote.vote {
|
||||
net::generic_message::ConsensusVote::Prepare(r, h) => bft::generic::Vote::Prepare(r as usize, h),
|
||||
@@ -120,7 +120,7 @@ fn process_message(msg: net::LocalizedBftMessage<Block>, local_id: &AuthorityId,
|
||||
};
|
||||
bft::check_vote::<Block>(authorities, &msg.parent_hash, &vote)?;
|
||||
|
||||
trace!(target: "bft", "importing vote {:?} from {}", vote.vote, Hash::from(vote.sender));
|
||||
trace!(target: "bft", "importing vote {:?} from {}", vote.vote, vote.sender);
|
||||
vote
|
||||
}),
|
||||
}),
|
||||
|
||||
@@ -62,17 +62,16 @@ impl table::Context for TableContext {
|
||||
|
||||
impl TableContext {
|
||||
fn local_id(&self) -> AuthorityId {
|
||||
self.key.public().0
|
||||
self.key.public().into()
|
||||
}
|
||||
|
||||
fn sign_statement(&self, statement: table::Statement) -> table::SignedStatement {
|
||||
let signature = ::sign_table_statement(&statement, &self.key, &self.parent_hash).into();
|
||||
let local_id = self.key.public().0;
|
||||
|
||||
table::SignedStatement {
|
||||
statement,
|
||||
signature,
|
||||
sender: local_id,
|
||||
sender: self.local_id(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -468,10 +467,10 @@ mod tests {
|
||||
let mut groups = HashMap::new();
|
||||
|
||||
let para_id = ParaId::from(1);
|
||||
let local_id = Keyring::Alice.to_raw_public();
|
||||
let local_id = Keyring::Alice.to_raw_public().into();
|
||||
let local_key = Arc::new(Keyring::Alice.pair());
|
||||
|
||||
let validity_other = Keyring::Bob.to_raw_public();
|
||||
let validity_other = Keyring::Bob.to_raw_public().into();
|
||||
let validity_other_key = Keyring::Bob.pair();
|
||||
let parent_hash = Default::default();
|
||||
|
||||
@@ -518,10 +517,10 @@ mod tests {
|
||||
let mut groups = HashMap::new();
|
||||
|
||||
let para_id = ParaId::from(1);
|
||||
let local_id = Keyring::Alice.to_raw_public();
|
||||
let local_id = Keyring::Alice.to_raw_public().into();
|
||||
let local_key = Arc::new(Keyring::Alice.pair());
|
||||
|
||||
let validity_other = Keyring::Bob.to_raw_public();
|
||||
let validity_other = Keyring::Bob.to_raw_public().into();
|
||||
let validity_other_key = Keyring::Bob.pair();
|
||||
let parent_hash = Default::default();
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ pub type Timestamp = timestamp::Module<Concrete>;
|
||||
pub struct SessionKeyConversion;
|
||||
impl Convert<AccountId, SessionKey> for SessionKeyConversion {
|
||||
fn convert(a: AccountId) -> SessionKey {
|
||||
a.0
|
||||
a.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -181,10 +181,14 @@ impl<T: Trait> Executable for Module<T> {
|
||||
|
||||
/// Parachains module genesis configuration.
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GenesisConfig<T: Trait> {
|
||||
/// The initial parachains, mapped to code.
|
||||
pub parachains: Vec<(Id, Vec<u8>)>,
|
||||
/// Phantom data.
|
||||
#[serde(skip)]
|
||||
pub phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
@@ -201,7 +205,7 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T>
|
||||
{
|
||||
fn build_storage(mut self) -> runtime_io::TestExternalities {
|
||||
fn build_storage(mut self) -> ::std::result::Result<runtime_io::TestExternalities, String> {
|
||||
use std::collections::HashMap;
|
||||
use runtime_io::twox_128;
|
||||
use codec::Slicable;
|
||||
@@ -220,7 +224,7 @@ impl<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T>
|
||||
map.insert(key, code.encode());
|
||||
}
|
||||
|
||||
map.into()
|
||||
Ok(map.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,20 +273,20 @@ mod tests {
|
||||
type Parachains = Module<Test>;
|
||||
|
||||
fn new_test_ext(parachains: Vec<(Id, Vec<u8>)>) -> runtime_io::TestExternalities {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage();
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(consensus::GenesisConfig::<Test>{
|
||||
code: vec![],
|
||||
authorities: vec![1, 2, 3],
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(session::GenesisConfig::<Test>{
|
||||
session_length: 1000,
|
||||
validators: vec![1, 2, 3, 4, 5, 6, 7, 8],
|
||||
broken_percent_late: 100,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(GenesisConfig::<Test>{
|
||||
parachains: parachains,
|
||||
phantom: PhantomData,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t
|
||||
}
|
||||
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -14,6 +14,10 @@ slog = "^2"
|
||||
clap = "2.27"
|
||||
tokio-core = "0.1.12"
|
||||
exit-future = "0.1"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_derive = "1.0"
|
||||
hex-literal = "0.1"
|
||||
ed25519 = { path = "../../substrate/ed25519" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
polkadot-runtime = { path = "../runtime" }
|
||||
|
||||
File diff suppressed because one or more lines are too long
+136
-62
@@ -16,71 +16,127 @@
|
||||
|
||||
//! 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 std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use primitives::{AuthorityId, storage::{StorageKey, StorageData}};
|
||||
use runtime_primitives::{BuildStorage, StorageMap};
|
||||
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
|
||||
SessionConfig, StakingConfig, TimestampConfig};
|
||||
use chain_spec::ChainSpec;
|
||||
use serde_json as json;
|
||||
|
||||
enum Config {
|
||||
Local(GenesisConfig),
|
||||
Raw(&'static [u8]),
|
||||
enum GenesisSource {
|
||||
File(PathBuf),
|
||||
Embedded(&'static [u8]),
|
||||
Factory(fn() -> Genesis),
|
||||
}
|
||||
|
||||
/// 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 GenesisSource {
|
||||
fn resolve(&self) -> Result<Genesis, String> {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct GenesisContainer {
|
||||
genesis: Genesis,
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
match *self {
|
||||
GenesisSource::File(ref path) => {
|
||||
let file = File::open(path).map_err(|e| format!("Error opening spec file: {}", e))?;
|
||||
let genesis: GenesisContainer = json::from_reader(file).map_err(|e| format!("Error parsing spec file: {}", e))?;
|
||||
Ok(genesis.genesis)
|
||||
},
|
||||
GenesisSource::Embedded(buf) => {
|
||||
let genesis: GenesisContainer = json::from_reader(buf).map_err(|e| format!("Error parsing embedded file: {}", e))?;
|
||||
Ok(genesis.genesis)
|
||||
},
|
||||
GenesisSource::Factory(f) => Ok(f()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
impl<'a> BuildStorage for &'a ChainSpec {
|
||||
fn build_storage(self) -> Result<StorageMap, String> {
|
||||
match self.genesis.resolve()? {
|
||||
Genesis::Runtime(gc) => gc.build_storage(),
|
||||
Genesis::Raw(map) => Ok(map.into_iter().map(|(k, v)| (k.0, v.0)).collect()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
enum Genesis {
|
||||
Runtime(GenesisConfig),
|
||||
Raw(HashMap<StorageKey, StorageData>),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ChainSpecFile {
|
||||
pub name: String,
|
||||
pub boot_nodes: Vec<String>,
|
||||
}
|
||||
|
||||
/// A configuration of a chain. Can be used to build a genesis block.
|
||||
pub struct ChainSpec {
|
||||
spec: ChainSpecFile,
|
||||
genesis: GenesisSource,
|
||||
}
|
||||
|
||||
impl ChainSpec {
|
||||
pub fn boot_nodes(&self) -> &[String] {
|
||||
&self.spec.boot_nodes
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
&self.spec.name
|
||||
}
|
||||
|
||||
/// Parse json content into a `ChainSpec`
|
||||
pub fn from_embedded(json: &'static [u8]) -> Result<Self, String> {
|
||||
let spec = json::from_slice(json).map_err(|e| format!("Error parsing spec file: {}", e))?;
|
||||
Ok(ChainSpec {
|
||||
spec,
|
||||
genesis: GenesisSource::Embedded(json),
|
||||
})
|
||||
}
|
||||
|
||||
/// 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)
|
||||
/// Parse json file into a `ChainSpec`
|
||||
pub fn from_json_file(path: PathBuf) -> Result<Self, String> {
|
||||
let file = File::open(&path).map_err(|e| format!("Error opening spec file: {}", e))?;
|
||||
let spec = json::from_reader(file).map_err(|e| format!("Error parsing spec file: {}", e))?;
|
||||
Ok(ChainSpec {
|
||||
spec,
|
||||
genesis: GenesisSource::File(path),
|
||||
})
|
||||
}
|
||||
|
||||
/// 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 }
|
||||
/// Dump to json string.
|
||||
pub fn to_json(self, raw: bool) -> Result<String, String> {
|
||||
let genesis = match (raw, self.genesis.resolve()?) {
|
||||
(true, Genesis::Runtime(g)) => {
|
||||
let storage = g.build_storage()?.into_iter()
|
||||
.map(|(k, v)| (StorageKey(k), StorageData(v)))
|
||||
.collect();
|
||||
|
||||
Genesis::Raw(storage)
|
||||
},
|
||||
(_, genesis) => genesis,
|
||||
};
|
||||
let mut spec = json::to_value(self.spec).map_err(|e| format!("Error generating spec json: {}", e))?;
|
||||
{
|
||||
let map = spec.as_object_mut().expect("spec is an object");
|
||||
map.insert("genesis".to_owned(), json::to_value(genesis).map_err(|e| format!("Error generating genesis json: {}", e))?);
|
||||
}
|
||||
json::to_string_pretty(&spec).map_err(|e| format!("Error generating spec json: {}", e))
|
||||
}
|
||||
|
||||
/// PoC-2 testnet config.
|
||||
fn poc_2_testnet_config() -> Self {
|
||||
pub fn poc_1_testnet_config() -> Result<Self, String> {
|
||||
Self::from_embedded(include_bytes!("../res/poc-1.json"))
|
||||
}
|
||||
|
||||
fn poc_2_testnet_config_genesis() -> Genesis {
|
||||
let initial_authorities = vec![
|
||||
hex!["82c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf5"].into(),
|
||||
hex!["4de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7"].into(),
|
||||
@@ -90,7 +146,7 @@ impl PresetConfig {
|
||||
let endowed_accounts = vec![
|
||||
hex!["f295940fa750df68a686fcf4abd4111c8a9c5a5a5a83c4c8639c451a94a7adfd"].into(),
|
||||
];
|
||||
let genesis_config = Config::Local(GenesisConfig {
|
||||
Genesis::Runtime(GenesisConfig {
|
||||
consensus: Some(ConsensusConfig {
|
||||
code: include_bytes!("../../runtime/wasm/genesis.wasm").to_vec(), // TODO change
|
||||
authorities: initial_authorities.clone(),
|
||||
@@ -142,16 +198,22 @@ impl PresetConfig {
|
||||
timestamp: Some(TimestampConfig {
|
||||
period: 5, // 5 second block time.
|
||||
}),
|
||||
});
|
||||
})
|
||||
}
|
||||
/// PoC-2 testnet config.
|
||||
pub fn poc_2_testnet_config() -> Self {
|
||||
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 }
|
||||
ChainSpec {
|
||||
spec: ChainSpecFile { name: "PoC-2 Testnet".to_owned(), boot_nodes },
|
||||
genesis: GenesisSource::Factory(Self::poc_2_testnet_config_genesis),
|
||||
}
|
||||
}
|
||||
|
||||
fn testnet_config(initial_authorities: Vec<AuthorityId>) -> PresetConfig {
|
||||
fn testnet_genesis(initial_authorities: Vec<AuthorityId>) -> Genesis {
|
||||
let endowed_accounts = vec![
|
||||
ed25519::Pair::from_seed(b"Alice ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Bob ").public().0.into(),
|
||||
@@ -160,7 +222,7 @@ impl PresetConfig {
|
||||
ed25519::Pair::from_seed(b"Eve ").public().0.into(),
|
||||
ed25519::Pair::from_seed(b"Ferdie ").public().0.into(),
|
||||
];
|
||||
let genesis_config = Config::Local(GenesisConfig {
|
||||
Genesis::Runtime(GenesisConfig {
|
||||
consensus: Some(ConsensusConfig {
|
||||
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm").to_vec(),
|
||||
authorities: initial_authorities.clone(),
|
||||
@@ -194,7 +256,7 @@ impl PresetConfig {
|
||||
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(),
|
||||
active_council: endowed_accounts.iter().filter(|a| initial_authorities.iter().find(|&b| a.0 == b.0).is_none()).map(|a| (a.clone(), 1000000)).collect(),
|
||||
candidacy_bond: 10,
|
||||
voter_bond: 2,
|
||||
present_slash_per_voter: 1,
|
||||
@@ -212,23 +274,35 @@ impl PresetConfig {
|
||||
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![
|
||||
fn development_config_genesis() -> Genesis {
|
||||
Self::testnet_genesis(vec![
|
||||
ed25519::Pair::from_seed(b"Alice ").public().into(),
|
||||
])
|
||||
}
|
||||
|
||||
/// Local testnet config (multivalidator Alice + Bob)
|
||||
fn local_testnet_config() -> Self {
|
||||
Self::testnet_config(vec![
|
||||
/// Development config (single validator Alice)
|
||||
pub fn development_config() -> Self {
|
||||
ChainSpec {
|
||||
spec: ChainSpecFile { name: "Development".to_owned(), boot_nodes: vec![] },
|
||||
genesis: GenesisSource::Factory(Self::development_config_genesis),
|
||||
}
|
||||
}
|
||||
|
||||
fn local_testnet_genesis() -> Genesis {
|
||||
Self::testnet_genesis(vec![
|
||||
ed25519::Pair::from_seed(b"Alice ").public().into(),
|
||||
ed25519::Pair::from_seed(b"Bob ").public().into(),
|
||||
])
|
||||
}
|
||||
|
||||
/// Local testnet config (multivalidator Alice + Bob)
|
||||
pub fn local_testnet_config() -> Self {
|
||||
ChainSpec {
|
||||
spec: ChainSpecFile { name: "Local Testnet".to_owned(), boot_nodes: vec![] },
|
||||
genesis: GenesisSource::Factory(Self::local_testnet_genesis),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,13 @@ use consensus;
|
||||
use keystore::Store as Keystore;
|
||||
use network;
|
||||
use polkadot_api;
|
||||
use runtime_primitives::MakeStorage;
|
||||
use polkadot_executor::Executor as LocalDispatch;
|
||||
use polkadot_primitives::{Block, BlockId, Hash};
|
||||
use state_machine;
|
||||
use substrate_executor::NativeExecutor;
|
||||
use transaction_pool::{self, TransactionPool};
|
||||
use error;
|
||||
use chain_spec::ChainSpec;
|
||||
|
||||
/// Code executor.
|
||||
pub type CodeExecutor = NativeExecutor<LocalDispatch>;
|
||||
@@ -48,7 +48,7 @@ pub trait Components {
|
||||
type Executor: 'static + client::CallExecutor<Block> + Send + Sync;
|
||||
|
||||
/// Create client.
|
||||
fn build_client(&self, settings: client_db::DatabaseSettings, executor: CodeExecutor, genesis_storage: MakeStorage)
|
||||
fn build_client(&self, settings: client_db::DatabaseSettings, executor: CodeExecutor, chain_spec: &ChainSpec)
|
||||
-> Result<(Arc<Client<Self::Backend, Self::Executor, Block>>, Option<Arc<network::OnDemand<Block, network::Service<Block>>>>), error::Error>;
|
||||
|
||||
/// Create api.
|
||||
@@ -74,9 +74,9 @@ impl Components for FullComponents {
|
||||
type Api = Client<Self::Backend, Self::Executor, Block>;
|
||||
type Executor = client::LocalCallExecutor<client_db::Backend<Block>, NativeExecutor<LocalDispatch>>;
|
||||
|
||||
fn build_client(&self, db_settings: client_db::DatabaseSettings, executor: CodeExecutor, genesis_storage: MakeStorage)
|
||||
fn build_client(&self, db_settings: client_db::DatabaseSettings, executor: CodeExecutor, chain_spec: &ChainSpec)
|
||||
-> Result<(Arc<client::Client<Self::Backend, Self::Executor, Block>>, Option<Arc<network::OnDemand<Block, network::Service<Block>>>>), error::Error> {
|
||||
Ok((Arc::new(client_db::new_client(db_settings, executor, genesis_storage)?), None))
|
||||
Ok((Arc::new(client_db::new_client(db_settings, executor, chain_spec)?), None))
|
||||
}
|
||||
|
||||
fn build_api(&self, client: Arc<client::Client<Self::Backend, Self::Executor, Block>>) -> Arc<Self::Api> {
|
||||
@@ -122,14 +122,14 @@ impl Components for LightComponents {
|
||||
client::light::blockchain::Blockchain<client_db::light::LightStorage<Block>, network::OnDemand<Block, network::Service<Block>>>,
|
||||
network::OnDemand<Block, network::Service<Block>>>;
|
||||
|
||||
fn build_client(&self, db_settings: client_db::DatabaseSettings, executor: CodeExecutor, genesis_storage: MakeStorage)
|
||||
fn build_client(&self, db_settings: client_db::DatabaseSettings, executor: CodeExecutor, spec: &ChainSpec)
|
||||
-> Result<(Arc<client::Client<Self::Backend, Self::Executor, Block>>, Option<Arc<network::OnDemand<Block, network::Service<Block>>>>), error::Error> {
|
||||
let db_storage = client_db::light::LightStorage::new(db_settings)?;
|
||||
let light_blockchain = client::light::new_light_blockchain(db_storage);
|
||||
let fetch_checker = Arc::new(client::light::new_fetch_checker(light_blockchain.clone(), executor));
|
||||
let fetcher = Arc::new(network::OnDemand::new(fetch_checker));
|
||||
let client_backend = client::light::new_light_backend(light_blockchain, fetcher.clone());
|
||||
let client = client::light::new_light(client_backend, fetcher.clone(), genesis_storage)?;
|
||||
let client = client::light::new_light(client_backend, fetcher.clone(), spec)?;
|
||||
Ok((Arc::new(client), Some(fetcher)))
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Service configuration.
|
||||
|
||||
use transaction_pool;
|
||||
use runtime_primitives::MakeStorage;
|
||||
use chain_spec::ChainSpec;
|
||||
pub use network::Role;
|
||||
pub use network::NetworkConfiguration;
|
||||
pub use client_db::PruningMode;
|
||||
@@ -38,30 +38,30 @@ pub struct Configuration {
|
||||
pub pruning: PruningMode,
|
||||
/// Additional key seeds.
|
||||
pub keys: Vec<String>,
|
||||
/// The name of the chain.
|
||||
pub chain_name: String,
|
||||
/// Chain configuration.
|
||||
pub genesis_storage: MakeStorage,
|
||||
pub chain_spec: ChainSpec,
|
||||
/// Telemetry server URL, optional - only `Some` if telemetry reporting is enabled
|
||||
pub telemetry: Option<String>,
|
||||
/// Node name.
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl Default for Configuration {
|
||||
fn default() -> Configuration {
|
||||
Configuration {
|
||||
impl Configuration {
|
||||
/// Create default config for given chain spec.
|
||||
pub fn default_with_spec(chain_spec: ChainSpec) -> Configuration {
|
||||
let mut configuration = Configuration {
|
||||
chain_spec,
|
||||
name: Default::default(),
|
||||
roles: Role::FULL,
|
||||
transaction_pool: Default::default(),
|
||||
network: Default::default(),
|
||||
keystore_path: Default::default(),
|
||||
database_path: Default::default(),
|
||||
keys: Default::default(),
|
||||
chain_name: Default::default(),
|
||||
genesis_storage: Box::new(Default::default),
|
||||
telemetry: Default::default(),
|
||||
name: "Anonymous".into(),
|
||||
pruning: PruningMode::ArchiveAll,
|
||||
}
|
||||
};
|
||||
configuration.network.boot_nodes = configuration.chain_spec.boot_nodes().to_vec();
|
||||
configuration
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ extern crate ed25519;
|
||||
extern crate clap;
|
||||
extern crate exit_future;
|
||||
extern crate tokio_timer;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate polkadot_primitives;
|
||||
extern crate polkadot_runtime;
|
||||
extern crate polkadot_executor;
|
||||
@@ -49,10 +51,15 @@ extern crate error_chain;
|
||||
extern crate slog; // needed until we can reexport `slog_info` from `substrate_telemetry`
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
#[macro_use]
|
||||
extern crate hex_literal;
|
||||
|
||||
mod components;
|
||||
mod error;
|
||||
mod config;
|
||||
mod chain_spec;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
@@ -69,6 +76,7 @@ use exit_future::Signal;
|
||||
pub use self::error::{ErrorKind, Error};
|
||||
pub use self::components::{Components, FullComponents, LightComponents};
|
||||
pub use config::{Configuration, Role, PruningMode};
|
||||
pub use chain_spec::ChainSpec;
|
||||
|
||||
/// Polkadot service.
|
||||
pub struct Service<Components: components::Components> {
|
||||
@@ -121,7 +129,7 @@ impl<Components> Service<Components>
|
||||
pruning: config.pruning,
|
||||
};
|
||||
|
||||
let (client, on_demand) = components.build_client(db_settings, executor, config.genesis_storage)?;
|
||||
let (client, on_demand) = components.build_client(db_settings, executor, &config.chain_spec)?;
|
||||
let api = components.build_api(client.clone());
|
||||
let best_header = client.best_block_header()?;
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ impl<H> From<PrimitiveJustification<H>> for UncheckedJustification<H> {
|
||||
round_number: just.round_number as usize,
|
||||
digest: just.hash,
|
||||
signatures: just.signatures.into_iter().map(|(from, sig)| LocalizedSignature {
|
||||
signer: ed25519::Public(from),
|
||||
signer: from.into(),
|
||||
signature: sig,
|
||||
}).collect(),
|
||||
}
|
||||
@@ -183,7 +183,7 @@ impl<B: Block, P: Proposer<B>> generic::Context for BftInstance<B, P>
|
||||
type EvaluateProposal = <P::Evaluate as IntoFuture>::Future;
|
||||
|
||||
fn local_id(&self) -> AuthorityId {
|
||||
self.key.public().0
|
||||
self.key.public().into()
|
||||
}
|
||||
|
||||
fn proposal(&self) -> Self::CreateProposal {
|
||||
@@ -345,7 +345,7 @@ impl<B, P, I> BftService<B, P, I>
|
||||
/// Get the local Authority ID.
|
||||
pub fn local_id(&self) -> AuthorityId {
|
||||
// TODO: based on a header and some keystore.
|
||||
self.key.public().0
|
||||
self.key.public().into()
|
||||
}
|
||||
|
||||
/// Signal that a valid block with the given header has been imported.
|
||||
@@ -445,7 +445,7 @@ fn check_justification_signed_message<H>(authorities: &[AuthorityId], message: &
|
||||
{
|
||||
// TODO: return additional error information.
|
||||
just.check(authorities.len() - max_faulty_of(authorities.len()), |_, _, sig| {
|
||||
let auth_id = sig.signer.0;
|
||||
let auth_id = sig.signer.clone().into();
|
||||
if !authorities.contains(&auth_id) { return None }
|
||||
|
||||
if ed25519::verify_strong(&sig.signature, message, &sig.signer) {
|
||||
@@ -565,7 +565,7 @@ pub fn sign_message<B: Block + Clone>(message: Message<B>, key: &ed25519::Pair,
|
||||
round_number: r,
|
||||
proposal,
|
||||
digest: header_hash,
|
||||
sender: signer.0,
|
||||
sender: signer.clone().into(),
|
||||
digest_signature: sign_action(action_header),
|
||||
full_signature: sign_action(action_propose),
|
||||
})
|
||||
@@ -579,7 +579,7 @@ pub fn sign_message<B: Block + Clone>(message: Message<B>, key: &ed25519::Pair,
|
||||
|
||||
::generic::LocalizedMessage::Vote(::generic::LocalizedVote {
|
||||
vote: vote,
|
||||
sender: signer.0,
|
||||
sender: signer.clone().into(),
|
||||
signature: sign_action(action),
|
||||
})
|
||||
}
|
||||
@@ -705,10 +705,10 @@ mod tests {
|
||||
fn future_gets_preempted() {
|
||||
let client = FakeClient {
|
||||
authorities: vec![
|
||||
Keyring::One.to_raw_public(),
|
||||
Keyring::Two.to_raw_public(),
|
||||
Keyring::Alice.to_raw_public(),
|
||||
Keyring::Eve.to_raw_public(),
|
||||
Keyring::One.to_raw_public().into(),
|
||||
Keyring::Two.to_raw_public().into(),
|
||||
Keyring::Alice.to_raw_public().into(),
|
||||
Keyring::Eve.to_raw_public().into(),
|
||||
],
|
||||
imported_heights: Mutex::new(HashSet::new()),
|
||||
};
|
||||
@@ -755,10 +755,10 @@ mod tests {
|
||||
let hash = [0xff; 32].into();
|
||||
|
||||
let authorities = vec![
|
||||
Keyring::One.to_raw_public(),
|
||||
Keyring::Two.to_raw_public(),
|
||||
Keyring::Alice.to_raw_public(),
|
||||
Keyring::Eve.to_raw_public(),
|
||||
Keyring::One.to_raw_public().into(),
|
||||
Keyring::Two.to_raw_public().into(),
|
||||
Keyring::Alice.to_raw_public().into(),
|
||||
Keyring::Eve.to_raw_public().into(),
|
||||
];
|
||||
|
||||
let authorities_keys = vec![
|
||||
@@ -816,8 +816,8 @@ mod tests {
|
||||
let parent_hash = Default::default();
|
||||
|
||||
let authorities = vec![
|
||||
Keyring::Alice.to_raw_public(),
|
||||
Keyring::Eve.to_raw_public(),
|
||||
Keyring::Alice.to_raw_public().into(),
|
||||
Keyring::Eve.to_raw_public().into(),
|
||||
];
|
||||
|
||||
let block = TestBlock {
|
||||
@@ -853,8 +853,8 @@ mod tests {
|
||||
let hash: H256 = [0xff; 32].into();
|
||||
|
||||
let authorities = vec![
|
||||
Keyring::Alice.to_raw_public(),
|
||||
Keyring::Eve.to_raw_public(),
|
||||
Keyring::Alice.to_raw_public().into(),
|
||||
Keyring::Eve.to_raw_public().into(),
|
||||
];
|
||||
|
||||
let vote = sign_message::<TestBlock>(::generic::Message::Vote(::generic::Vote::Prepare(1, hash)), &Keyring::Alice.pair(), parent_hash);;
|
||||
|
||||
@@ -168,7 +168,7 @@ impl<B, E, Block> Client<B, E, Block> where
|
||||
build_genesis_storage: S,
|
||||
) -> error::Result<Self> {
|
||||
if backend.blockchain().header(BlockId::Number(Zero::zero()))?.is_none() {
|
||||
let genesis_storage = build_genesis_storage.build_storage();
|
||||
let genesis_storage = build_genesis_storage.build_storage()?;
|
||||
let genesis_block = genesis::construct_genesis_block::<Block>(&genesis_storage);
|
||||
info!("Initialising Genesis block/state (state: {}, header-hash: {})", genesis_block.header().state_root(), genesis_block.header().hash());
|
||||
let mut op = backend.begin_operation(BlockId::Hash(Default::default()))?;
|
||||
@@ -497,9 +497,9 @@ mod tests {
|
||||
|
||||
assert_eq!(client.info().unwrap().chain.best_number, 0);
|
||||
assert_eq!(client.authorities_at(&BlockId::Number(0)).unwrap(), vec![
|
||||
Keyring::Alice.to_raw_public(),
|
||||
Keyring::Bob.to_raw_public(),
|
||||
Keyring::Charlie.to_raw_public()
|
||||
Keyring::Alice.to_raw_public().into(),
|
||||
Keyring::Bob.to_raw_public().into(),
|
||||
Keyring::Charlie.to_raw_public().into()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ mod tests {
|
||||
#[test]
|
||||
fn construct_genesis_should_work_with_native() {
|
||||
let mut storage = GenesisConfig::new_simple(
|
||||
vec![Keyring::One.to_raw_public(), Keyring::Two.to_raw_public()], 1000
|
||||
vec![Keyring::One.to_raw_public().into(), Keyring::Two.to_raw_public().into()], 1000
|
||||
).genesis_map();
|
||||
let block = construct_genesis_block::<Block>(&storage);
|
||||
let genesis_hash = block.header.hash();
|
||||
@@ -148,7 +148,7 @@ mod tests {
|
||||
#[test]
|
||||
fn construct_genesis_should_work_with_wasm() {
|
||||
let mut storage = GenesisConfig::new_simple(
|
||||
vec![Keyring::One.to_raw_public(), Keyring::Two.to_raw_public()], 1000
|
||||
vec![Keyring::One.to_raw_public().into(), Keyring::Two.to_raw_public().into()], 1000
|
||||
).genesis_map();
|
||||
let block = construct_genesis_block::<Block>(&storage);
|
||||
let genesis_hash = block.header.hash();
|
||||
@@ -171,7 +171,7 @@ mod tests {
|
||||
#[should_panic]
|
||||
fn construct_genesis_with_bad_transaction_should_panic() {
|
||||
let mut storage = GenesisConfig::new_simple(
|
||||
vec![Keyring::One.to_raw_public(), Keyring::Two.to_raw_public()], 68
|
||||
vec![Keyring::One.to_raw_public().into(), Keyring::Two.to_raw_public().into()], 68
|
||||
).genesis_map();
|
||||
let block = construct_genesis_block::<Block>(&storage);
|
||||
let genesis_hash = block.header.hash();
|
||||
|
||||
@@ -23,7 +23,7 @@ extern crate untrusted;
|
||||
extern crate blake2_rfc;
|
||||
|
||||
use ring::{rand, signature};
|
||||
use primitives::hash::H512;
|
||||
use primitives::{hash::H512, AuthorityId};
|
||||
use base58::{ToBase58, FromBase58};
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -166,6 +166,18 @@ impl AsRef<Pair> for Pair {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<AuthorityId> for Public {
|
||||
fn into(self) -> AuthorityId {
|
||||
AuthorityId(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AuthorityId> for Public {
|
||||
fn from(id: AuthorityId) -> Self {
|
||||
Public(id.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Display for Public {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
write!(f, "{}", self.to_ss58check())
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -127,7 +127,7 @@ mod tests {
|
||||
let hash_2 = [1; 32].into();
|
||||
|
||||
assert!(evaluate_misbehavior::<Block, H256>(
|
||||
&key.public().0,
|
||||
&key.public().into(),
|
||||
parent_hash,
|
||||
&MisbehaviorKind::BftDoublePrepare(
|
||||
1,
|
||||
@@ -139,7 +139,7 @@ mod tests {
|
||||
// same signature twice is not misbehavior.
|
||||
let signed = sign_prepare(&key, 1, hash_1, parent_hash);
|
||||
assert!(evaluate_misbehavior::<Block, H256>(
|
||||
&key.public().0,
|
||||
&key.public().into(),
|
||||
parent_hash,
|
||||
&MisbehaviorKind::BftDoublePrepare(
|
||||
1,
|
||||
@@ -150,7 +150,7 @@ mod tests {
|
||||
|
||||
// misbehavior has wrong target.
|
||||
assert!(evaluate_misbehavior::<Block, H256>(
|
||||
&Keyring::Two.to_raw_public(),
|
||||
&Keyring::Two.to_raw_public().into(),
|
||||
parent_hash,
|
||||
&MisbehaviorKind::BftDoublePrepare(
|
||||
1,
|
||||
@@ -168,7 +168,7 @@ mod tests {
|
||||
let hash_2 = [1; 32].into();
|
||||
|
||||
assert!(evaluate_misbehavior::<Block, H256>(
|
||||
&key.public().0,
|
||||
&key.public().into(),
|
||||
parent_hash,
|
||||
&MisbehaviorKind::BftDoubleCommit(
|
||||
1,
|
||||
@@ -180,7 +180,7 @@ mod tests {
|
||||
// same signature twice is not misbehavior.
|
||||
let signed = sign_commit(&key, 1, hash_1, parent_hash);
|
||||
assert!(evaluate_misbehavior::<Block, H256>(
|
||||
&key.public().0,
|
||||
&key.public().into(),
|
||||
parent_hash,
|
||||
&MisbehaviorKind::BftDoubleCommit(
|
||||
1,
|
||||
@@ -191,7 +191,7 @@ mod tests {
|
||||
|
||||
// misbehavior has wrong target.
|
||||
assert!(evaluate_misbehavior::<Block, H256>(
|
||||
&Keyring::Two.to_raw_public(),
|
||||
&Keyring::Two.to_raw_public().into(),
|
||||
parent_hash,
|
||||
&MisbehaviorKind::BftDoubleCommit(
|
||||
1,
|
||||
|
||||
@@ -31,7 +31,7 @@ fn bft_messages_include_those_sent_before_asking_for_stream() {
|
||||
let mut io = TestIo::new(&peer.queue, None);
|
||||
let bft_message = generic::BftMessage::Consensus(generic::SignedConsensusMessage::Vote(generic::SignedConsensusVote {
|
||||
vote: generic::ConsensusVote::AdvanceRound(0),
|
||||
sender: [0; 32],
|
||||
sender: Default::default(),
|
||||
signature: Default::default(),
|
||||
}));
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
// 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/>.
|
||||
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||
use codec::Slicable;
|
||||
use H256;
|
||||
|
||||
/// An identifier for an authority in the consensus algorithm. The same size as ed25519::Public.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub struct AuthorityId(pub [u8; 32]);
|
||||
|
||||
impl AuthorityId {
|
||||
/// Create an id from byte slice.
|
||||
pub fn from_slice(data: &[u8]) -> Self {
|
||||
let mut r = [0u8; 32];
|
||||
r.copy_from_slice(data);
|
||||
AuthorityId(r)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl ::std::fmt::Display for AuthorityId {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
write!(f, "{}", ::hexdisplay::HexDisplay::from(&self.0))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl ::std::fmt::Debug for AuthorityId {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
write!(f, "{}", ::hexdisplay::HexDisplay::from(&self.0))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl ::std::hash::Hash for AuthorityId {
|
||||
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.0.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8; 32]> for AuthorityId {
|
||||
fn as_ref(&self) -> &[u8; 32] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[u8]> for AuthorityId {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
&self.0[..]
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<[u8; 32]> for AuthorityId {
|
||||
fn into(self) -> [u8; 32] {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 32]> for AuthorityId {
|
||||
fn from(a: [u8; 32]) -> Self {
|
||||
AuthorityId(a)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<AuthorityId> for AuthorityId {
|
||||
fn as_ref(&self) -> &AuthorityId {
|
||||
&self
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<H256> for AuthorityId {
|
||||
fn into(self) -> H256 {
|
||||
self.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Serialize for AuthorityId {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
::bytes::serialize(&self.0, serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<'de> Deserialize<'de> for AuthorityId {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
|
||||
::bytes::deserialize_check_len(deserializer, ::bytes::ExpectedLen::Exact(32))
|
||||
.map(|x| AuthorityId::from_slice(&x))
|
||||
}
|
||||
}
|
||||
|
||||
impl Slicable for AuthorityId {
|
||||
fn decode<I: ::codec::Input>(input: &mut I) -> Option<Self> {
|
||||
<[u8; 32] as ::codec::Slicable>::decode(input).map(AuthorityId)
|
||||
}
|
||||
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
self.0.using_encoded(f)
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Simply type for representing Vec<u8> with regards to serde.
|
||||
//! Simple type for representing Vec<u8> with regards to serde.
|
||||
|
||||
use core::fmt;
|
||||
|
||||
|
||||
@@ -77,15 +77,14 @@ pub mod hash;
|
||||
pub mod sandbox;
|
||||
pub mod storage;
|
||||
pub mod uint;
|
||||
mod authority_id;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub use self::hash::{H160, H256, H512};
|
||||
pub use self::uint::{U256, U512};
|
||||
|
||||
/// An identifier for an authority in the consensus algorithm. The same as ed25519::Public.
|
||||
pub type AuthorityId = [u8; 32];
|
||||
pub use authority_id::AuthorityId;
|
||||
|
||||
/// A 512-bit value interpreted as a signature.
|
||||
pub type Signature = hash::H512;
|
||||
|
||||
@@ -42,7 +42,7 @@ use rstd::prelude::*;
|
||||
use runtime_support::{storage, Parameter};
|
||||
use runtime_support::dispatch::Result;
|
||||
use runtime_support::storage::unhashed::StorageVec;
|
||||
use primitives::traits::{RefInto, MaybeEmpty};
|
||||
use primitives::traits::{RefInto, MaybeSerializeDebug, MaybeEmpty};
|
||||
use primitives::bft::MisbehaviorReport;
|
||||
|
||||
pub const AUTHORITY_AT: &'static [u8] = b":auth:";
|
||||
@@ -60,7 +60,7 @@ pub type KeyValue = (Vec<u8>, Vec<u8>);
|
||||
|
||||
pub trait Trait: system::Trait {
|
||||
type PublicAux: RefInto<Self::AccountId> + MaybeEmpty; // MaybeEmpty is for Timestamp's usage.
|
||||
type SessionKey: Parameter + Default;
|
||||
type SessionKey: Parameter + Default + MaybeSerializeDebug;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
@@ -118,8 +118,12 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GenesisConfig<T: Trait> {
|
||||
pub authorities: Vec<T::SessionKey>,
|
||||
#[serde(with = "substrate_primitives::bytes")]
|
||||
pub code: Vec<u8>,
|
||||
}
|
||||
|
||||
@@ -136,7 +140,7 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
{
|
||||
fn build_storage(self) -> runtime_io::TestExternalities {
|
||||
fn build_storage(self) -> ::std::result::Result<runtime_io::TestExternalities, String> {
|
||||
use codec::{Slicable, KeyedVec};
|
||||
let auth_count = self.authorities.len() as u32;
|
||||
let mut r: runtime_io::TestExternalities = self.authorities.into_iter().enumerate().map(|(i, v)|
|
||||
@@ -144,6 +148,6 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
).collect();
|
||||
r.insert(AUTHORITY_COUNT.to_vec(), auth_count.encode());
|
||||
r.insert(CODE.to_vec(), self.code);
|
||||
r
|
||||
Ok(r)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,6 +545,9 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GenesisConfig<T: Trait> {
|
||||
// for the voting onto the council
|
||||
pub candidacy_bond: T::Balance,
|
||||
@@ -587,11 +590,11 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
{
|
||||
fn build_storage(self) -> runtime_io::TestExternalities {
|
||||
fn build_storage(self) -> ::std::result::Result<runtime_io::TestExternalities, String> {
|
||||
use codec::Slicable;
|
||||
use runtime_io::twox_128;
|
||||
|
||||
map![
|
||||
Ok(map![
|
||||
twox_128(<CandidacyBond<T>>::key()).to_vec() => self.candidacy_bond.encode(),
|
||||
twox_128(<VotingBond<T>>::key()).to_vec() => self.voter_bond.encode(),
|
||||
twox_128(<PresentSlashPerVoter<T>>::key()).to_vec() => self.present_slash_per_voter.encode(),
|
||||
@@ -606,7 +609,7 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
twox_128(<voting::CooloffPeriod<T>>::key()).to_vec() => self.cooloff_period.encode(),
|
||||
twox_128(<voting::VotingPeriod<T>>::key()).to_vec() => self.voting_period.encode(),
|
||||
twox_128(<voting::Proposals<T>>::key()).to_vec() => vec![0u8; 0].encode()
|
||||
]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -665,16 +668,16 @@ mod tests {
|
||||
impl Trait for Test {}
|
||||
|
||||
pub fn new_test_ext(with_council: bool) -> runtime_io::TestExternalities {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage();
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(consensus::GenesisConfig::<Test>{
|
||||
code: vec![],
|
||||
authorities: vec![],
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(session::GenesisConfig::<Test>{
|
||||
session_length: 1, //??? or 2?
|
||||
validators: vec![10, 20],
|
||||
broken_percent_late: 100,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(staking::GenesisConfig::<Test>{
|
||||
sessions_per_era: 1,
|
||||
current_era: 0,
|
||||
@@ -691,12 +694,12 @@ mod tests {
|
||||
reclaim_rebate: 0,
|
||||
early_era_slash: 0,
|
||||
session_reward: 0,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(democracy::GenesisConfig::<Test>{
|
||||
launch_period: 1,
|
||||
voting_period: 3,
|
||||
minimum_deposit: 1,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(GenesisConfig::<Test>{
|
||||
candidacy_bond: 9,
|
||||
voter_bond: 3,
|
||||
@@ -714,8 +717,8 @@ mod tests {
|
||||
term_duration: 5,
|
||||
cooloff_period: 2,
|
||||
voting_period: 1,
|
||||
}.build_storage());
|
||||
t.extend(timestamp::GenesisConfig::<Test>::default().build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(timestamp::GenesisConfig::<Test>::default().build_storage().unwrap());
|
||||
t
|
||||
}
|
||||
|
||||
|
||||
@@ -296,6 +296,9 @@ impl<T: Trait> Executable for Module<T> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GenesisConfig<T: Trait> {
|
||||
pub launch_period: T::BlockNumber,
|
||||
pub voting_period: T::BlockNumber,
|
||||
@@ -335,18 +338,18 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
{
|
||||
fn build_storage(self) -> runtime_io::TestExternalities {
|
||||
fn build_storage(self) -> ::std::result::Result<runtime_io::TestExternalities, String> {
|
||||
use codec::Slicable;
|
||||
use runtime_io::twox_128;
|
||||
|
||||
map![
|
||||
Ok(map![
|
||||
twox_128(<LaunchPeriod<T>>::key()).to_vec() => self.launch_period.encode(),
|
||||
twox_128(<VotingPeriod<T>>::key()).to_vec() => self.voting_period.encode(),
|
||||
twox_128(<MinimumDeposit<T>>::key()).to_vec() => self.minimum_deposit.encode(),
|
||||
twox_128(<ReferendumCount<T>>::key()).to_vec() => (0 as ReferendumIndex).encode(),
|
||||
twox_128(<NextTally<T>>::key()).to_vec() => (0 as ReferendumIndex).encode(),
|
||||
twox_128(<PublicPropCount<T>>::key()).to_vec() => (0 as PropIndex).encode()
|
||||
]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,16 +409,16 @@ mod tests {
|
||||
}
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage();
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(consensus::GenesisConfig::<Test>{
|
||||
code: vec![],
|
||||
authorities: vec![],
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(session::GenesisConfig::<Test>{
|
||||
session_length: 1, //??? or 2?
|
||||
validators: vec![10, 20],
|
||||
broken_percent_late: 100,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(staking::GenesisConfig::<Test>{
|
||||
sessions_per_era: 1,
|
||||
current_era: 0,
|
||||
@@ -432,13 +435,13 @@ mod tests {
|
||||
reclaim_rebate: 0,
|
||||
early_era_slash: 0,
|
||||
session_reward: 0,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(GenesisConfig::<Test>{
|
||||
launch_period: 1,
|
||||
voting_period: 1,
|
||||
minimum_deposit: 1,
|
||||
}.build_storage());
|
||||
t.extend(timestamp::GenesisConfig::<Test>::default().build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(timestamp::GenesisConfig::<Test>::default().build_storage().unwrap());
|
||||
t
|
||||
}
|
||||
|
||||
|
||||
@@ -269,7 +269,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn staking_balance_transfer_dispatch_works() {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage();
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(staking::GenesisConfig::<Test> {
|
||||
sessions_per_era: 0,
|
||||
current_era: 0,
|
||||
@@ -286,7 +286,7 @@ mod tests {
|
||||
reclaim_rebate: 0,
|
||||
early_era_slash: 0,
|
||||
session_reward: 0,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
let xt = primitives::testing::TestXt((1, 0, Call::transfer(2.into(), 69)));
|
||||
with_externalities(&mut t, || {
|
||||
Executive::initialise_block(&Header::new(1, H256::default(), H256::default(), [69u8; 32].into(), Digest::default()));
|
||||
@@ -297,11 +297,11 @@ mod tests {
|
||||
}
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage();
|
||||
t.extend(consensus::GenesisConfig::<Test>::default().build_storage());
|
||||
t.extend(session::GenesisConfig::<Test>::default().build_storage());
|
||||
t.extend(staking::GenesisConfig::<Test>::default().build_storage());
|
||||
t.extend(timestamp::GenesisConfig::<Test>::default().build_storage());
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(consensus::GenesisConfig::<Test>::default().build_storage().unwrap());
|
||||
t.extend(session::GenesisConfig::<Test>::default().build_storage().unwrap());
|
||||
t.extend(staking::GenesisConfig::<Test>::default().build_storage().unwrap());
|
||||
t.extend(timestamp::GenesisConfig::<Test>::default().build_storage().unwrap());
|
||||
t
|
||||
}
|
||||
|
||||
|
||||
@@ -56,27 +56,16 @@ use traits::{Verify, Lazy};
|
||||
#[cfg(feature = "std")]
|
||||
pub type StorageMap = HashMap<Vec<u8>, Vec<u8>>;
|
||||
|
||||
/// A simple function allowing StorageMap to be created.
|
||||
#[cfg(feature = "std")]
|
||||
pub type MakeStorage = Box<FnMut() -> StorageMap>;
|
||||
|
||||
/// Complex storage builder stuff.
|
||||
#[cfg(feature = "std")]
|
||||
pub trait BuildStorage {
|
||||
fn build_storage(self) -> StorageMap;
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl BuildStorage for MakeStorage {
|
||||
fn build_storage(mut self) -> StorageMap {
|
||||
self()
|
||||
}
|
||||
fn build_storage(self) -> Result<StorageMap, String>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl BuildStorage for StorageMap {
|
||||
fn build_storage(self) -> StorageMap {
|
||||
self
|
||||
fn build_storage(self) -> Result<StorageMap, String> {
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,6 +230,9 @@ macro_rules! impl_outer_config {
|
||||
( pub struct $main:ident for $concrete:ident { $( $config:ident => $snake:ident, )* } ) => {
|
||||
__impl_outer_config_types! { $concrete $( $config $snake )* }
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct $main {
|
||||
$(
|
||||
pub $snake: Option<$config>,
|
||||
@@ -248,14 +240,14 @@ macro_rules! impl_outer_config {
|
||||
}
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl $crate::BuildStorage for $main {
|
||||
fn build_storage(self) -> $crate::StorageMap {
|
||||
fn build_storage(self) -> ::std::result::Result<$crate::StorageMap, String> {
|
||||
let mut s = $crate::StorageMap::new();
|
||||
$(
|
||||
if let Some(extra) = self.$snake {
|
||||
s.extend(extra.build_storage());
|
||||
s.extend(extra.build_storage()?);
|
||||
}
|
||||
)*
|
||||
s
|
||||
Ok(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,6 +220,9 @@ impl<T: Trait> Executable for Module<T> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GenesisConfig<T: Trait> {
|
||||
pub session_length: T::BlockNumber,
|
||||
pub validators: Vec<T::AccountId>,
|
||||
@@ -241,17 +244,17 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
{
|
||||
fn build_storage(self) -> runtime_io::TestExternalities {
|
||||
fn build_storage(self) -> ::std::result::Result<runtime_io::TestExternalities, String> {
|
||||
use runtime_io::twox_128;
|
||||
use codec::Slicable;
|
||||
use primitives::traits::As;
|
||||
map![
|
||||
Ok(map![
|
||||
twox_128(<SessionLength<T>>::key()).to_vec() => self.session_length.encode(),
|
||||
twox_128(<CurrentIndex<T>>::key()).to_vec() => T::BlockNumber::sa(0).encode(),
|
||||
twox_128(<CurrentStart<T>>::key()).to_vec() => T::Moment::zero().encode(),
|
||||
twox_128(<Validators<T>>::key()).to_vec() => self.validators.encode(),
|
||||
twox_128(<BrokenPercentLate<T>>::key()).to_vec() => self.broken_percent_late.encode()
|
||||
]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,19 +300,19 @@ mod tests {
|
||||
type Session = Module<Test>;
|
||||
|
||||
fn new_test_ext() -> runtime_io::TestExternalities {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage();
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(consensus::GenesisConfig::<Test>{
|
||||
code: vec![],
|
||||
authorities: vec![1, 2, 3],
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(timestamp::GenesisConfig::<Test>{
|
||||
period: 5,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(GenesisConfig::<Test>{
|
||||
session_length: 2,
|
||||
validators: vec![1, 2, 3],
|
||||
broken_percent_late: 30,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ use super::{Trait, ENUM_SET_SIZE, EnumSet, NextEnumSet, Intentions, CurrentEra,
|
||||
ExistentialDeposit, TransactionByteFee, TransactionBaseFee, TotalStake,
|
||||
SessionsPerEra, ValidatorCount, FreeBalance, SessionReward, EarlyEraSlash};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GenesisConfig<T: Trait> {
|
||||
pub sessions_per_era: T::BlockNumber,
|
||||
pub current_era: T::BlockNumber,
|
||||
@@ -120,7 +123,7 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
}
|
||||
|
||||
impl<T: Trait> primitives::BuildStorage for GenesisConfig<T> {
|
||||
fn build_storage(self) -> runtime_io::TestExternalities {
|
||||
fn build_storage(self) -> Result<runtime_io::TestExternalities, String> {
|
||||
let total_stake: T::Balance = self.balances.iter().fold(Zero::zero(), |acc, &(_, n)| acc + n);
|
||||
|
||||
let mut r: runtime_io::TestExternalities = map![
|
||||
@@ -150,6 +153,6 @@ impl<T: Trait> primitives::BuildStorage for GenesisConfig<T> {
|
||||
for (who, value) in self.balances.into_iter() {
|
||||
r.insert(twox_128(&<FreeBalance<T>>::key_for(who)).to_vec(), value.encode());
|
||||
}
|
||||
r
|
||||
Ok(r)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ impl Trait for Test {
|
||||
}
|
||||
|
||||
pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64, current_era: u64, monied: bool, reward: u64) -> runtime_io::TestExternalities {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage();
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
let balance_factor = if ext_deposit > 0 {
|
||||
256
|
||||
} else {
|
||||
@@ -69,12 +69,12 @@ pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64
|
||||
t.extend(consensus::GenesisConfig::<Test>{
|
||||
code: vec![],
|
||||
authorities: vec![],
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(session::GenesisConfig::<Test>{
|
||||
session_length,
|
||||
validators: vec![10, 20],
|
||||
broken_percent_late: 30,
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(GenesisConfig::<Test>{
|
||||
sessions_per_era,
|
||||
current_era,
|
||||
@@ -99,10 +99,10 @@ pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64
|
||||
reclaim_rebate: 0,
|
||||
session_reward: reward,
|
||||
early_era_slash: if monied { 20 } else { 0 },
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t.extend(timestamp::GenesisConfig::<Test>{
|
||||
period: 5
|
||||
}.build_storage());
|
||||
}.build_storage().unwrap());
|
||||
t
|
||||
}
|
||||
|
||||
|
||||
@@ -193,6 +193,9 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GenesisConfig<T: Trait>(PhantomData<T>);
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
@@ -205,16 +208,16 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
{
|
||||
fn build_storage(self) -> runtime_io::TestExternalities {
|
||||
fn build_storage(self) -> Result<runtime_io::TestExternalities, String> {
|
||||
use runtime_io::twox_128;
|
||||
use codec::Slicable;
|
||||
|
||||
map![
|
||||
Ok(map![
|
||||
twox_128(&<BlockHash<T>>::key_for(T::BlockNumber::zero())).to_vec() => [69u8; 32].encode(),
|
||||
twox_128(<Number<T>>::key()).to_vec() => 1u64.encode(),
|
||||
twox_128(<ParentHash<T>>::key()).to_vec() => [69u8; 32].encode(),
|
||||
twox_128(<RandomSeed<T>>::key()).to_vec() => [0u8; 32].encode(),
|
||||
twox_128(<ExtrinsicIndex<T>>::key()).to_vec() => [0u8; 4].encode()
|
||||
]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,9 @@ impl<T: Trait> Executable for Module<T> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GenesisConfig<T: Trait> {
|
||||
pub period: T::Moment,
|
||||
}
|
||||
@@ -123,13 +126,13 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T>
|
||||
{
|
||||
fn build_storage(self) -> runtime_primitives::StorageMap {
|
||||
fn build_storage(self) -> ::std::result::Result<runtime_primitives::StorageMap, String> {
|
||||
use runtime_io::twox_128;
|
||||
use codec::Slicable;
|
||||
map![
|
||||
Ok(map![
|
||||
twox_128(<BlockPeriod<T>>::key()).to_vec() => self.period.encode(),
|
||||
twox_128(<Now<T>>::key()).to_vec() => T::Moment::sa(0).encode()
|
||||
]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,8 +172,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn timestamp_works() {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage();
|
||||
t.extend(GenesisConfig::<Test> { period: 0 }.build_storage());
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(GenesisConfig::<Test> { period: 0 }.build_storage().unwrap());
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
Timestamp::set_timestamp(42);
|
||||
@@ -182,8 +185,8 @@ mod tests {
|
||||
#[test]
|
||||
#[should_panic(expected = "Timestamp must be updated only once in the block")]
|
||||
fn double_timestamp_should_fail() {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage();
|
||||
t.extend(GenesisConfig::<Test> { period: 5 }.build_storage());
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(GenesisConfig::<Test> { period: 5 }.build_storage().unwrap());
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
Timestamp::set_timestamp(42);
|
||||
@@ -195,8 +198,8 @@ mod tests {
|
||||
#[test]
|
||||
#[should_panic(expected = "Timestamp but increment by at least <BlockPeriod> between sequential blocks")]
|
||||
fn block_period_is_enforced() {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage();
|
||||
t.extend(GenesisConfig::<Test> { period: 5 }.build_storage());
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
t.extend(GenesisConfig::<Test> { period: 5 }.build_storage().unwrap());
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
Timestamp::set_timestamp(42);
|
||||
|
||||
@@ -88,9 +88,9 @@ fn fake_justify(header: &runtime::Header) -> bft::UncheckedJustification<runtime
|
||||
|
||||
fn genesis_config() -> GenesisConfig {
|
||||
GenesisConfig::new_simple(vec![
|
||||
Keyring::Alice.to_raw_public(),
|
||||
Keyring::Bob.to_raw_public(),
|
||||
Keyring::Charlie.to_raw_public()
|
||||
Keyring::Alice.to_raw_public().into(),
|
||||
Keyring::Bob.to_raw_public().into(),
|
||||
Keyring::Charlie.to_raw_public().into(),
|
||||
], 1000)
|
||||
}
|
||||
|
||||
|
||||
-18
@@ -137,11 +137,6 @@ dependencies = [
|
||||
name = "environmental"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "error-chain"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ethbloom"
|
||||
version = "0.5.0"
|
||||
@@ -294,16 +289,6 @@ dependencies = [
|
||||
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kvdb"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/paritytech/parity.git#dec390a89fe038337399315daf15e628ffbb4d8e"
|
||||
dependencies = [
|
||||
"elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-bytes 0.1.0 (git+https://github.com/paritytech/parity.git)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "0.2.11"
|
||||
@@ -753,7 +738,6 @@ dependencies = [
|
||||
"ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashdb 0.1.1 (git+https://github.com/paritytech/parity.git)",
|
||||
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"kvdb 0.1.0 (git+https://github.com/paritytech/parity.git)",
|
||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memorydb 0.1.1 (git+https://github.com/paritytech/parity.git)",
|
||||
"parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -955,7 +939,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda"
|
||||
"checksum elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "88d4851b005ef16de812ea9acdb7bece2f0a40dd86c07b85631d7dafa54537bb"
|
||||
"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b"
|
||||
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
|
||||
"checksum ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a93a43ce2e9f09071449da36bfa7a1b20b950ee344b6904ff23de493b03b386"
|
||||
"checksum ethcore-bytes 0.1.0 (git+https://github.com/paritytech/parity.git)" = "<none>"
|
||||
"checksum ethcore-logger 1.12.0 (git+https://github.com/paritytech/parity.git)" = "<none>"
|
||||
@@ -973,7 +956,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum integer-sqrt 0.1.0 (git+https://github.com/paritytech/integer-sqrt-rs.git)" = "<none>"
|
||||
"checksum keccak-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b7f51f30d7986536accaec4a6a288008dfb3dbffe8a2863a65292bc395a3ae7"
|
||||
"checksum keccak-hash 0.1.2 (git+https://github.com/paritytech/parity.git)" = "<none>"
|
||||
"checksum kvdb 0.1.0 (git+https://github.com/paritytech/parity.git)" = "<none>"
|
||||
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
|
||||
"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739"
|
||||
"checksum libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)" = "ac8ebf8343a981e2fa97042b14768f02ed3e1d602eac06cae6166df3c8ced206"
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Reference in New Issue
Block a user