Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions demo/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion demo/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion demo/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
18 changes: 0 additions & 18 deletions demo/runtime/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions polkadot/api/src/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand All @@ -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(),
]
}

Expand All @@ -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]
Expand Down
1 change: 0 additions & 1 deletion polkadot/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
38 changes: 0 additions & 38 deletions polkadot/cli/poc-1.json

This file was deleted.

32 changes: 16 additions & 16 deletions polkadot/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 {
Expand All @@ -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!(),
})
}
}
}
16 changes: 12 additions & 4 deletions polkadot/cli/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
70 changes: 23 additions & 47 deletions polkadot/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -171,32 +165,14 @@ 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),
Some(s) => PruningMode::keep_blocks(s.parse()
.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");
Expand All @@ -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();

Expand All @@ -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 || {
Expand All @@ -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),
Expand Down
Loading