Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Dump genesis to JSON file (#218)
Browse files Browse the repository at this point in the history
* Merge remote-tracking branch 'origin/master' into gav-xts-dont-panic

* Update wasm.

* consensus, session and staking all panic-safe.

* Democracy doesn't panic in apply.

* Fix tests.

* Extra helper macro, council depanicked.

* Fix one test.

* Fix up all council tests. No panics!

* Council voting depanicked.

* Dispatch returns result.

* session & staking tests updated

* Fix democracy tests.

* Fix council tests.

* Fix up polkadot parachains in runtime

* Fix borked merge

* More Slicable support

Support general `Option` and array types.

* Basic storage types.

* Existential deposit for contract creation

* Basic implemnetation along with removals

* Fix tests.

* externalities builder fix.

* Tests.

* Fix up the runtime.

* Fix tests.

* Add generic `Address` type.

* Initial function integration of Address into Extrinsic.

* Fix build

* All tests compile.

* Fix (some) tests.

* Fix signing.

* Push error.

* transfer can accept Address

* Make Address generic over AccountIndex

* Fix test

* Make Council use Address for dispatch.

* Fix build

* Bend over backwards to support braindead derive.

* Repot some files.

* Fix tests.

* Fix grumbles

* Remove Default bound

* Fix build for new nightly.

* Make `apply_extrinsic` never panic, return useful Result.

* More merge hell

* Doesn't build, but might do soon

* Serde woes

* get substrate-runtime-staking compiling

* Polkadot builds again!

* Fix all build.

* Fix tests & binaries.

* Reserve some extra initial byte values of address for future format changes

* Make semantic of `ReservedBalance` clear.

* Fix panic handler.

* Integrate other balance transformations into the new model

Fix up staking tests.

* Fix runtime tests.

* Fix panic build.

* Tests for demonstrating interaction between balance types.

* Repot some runtime code

* Fix checkedblock in non-std builds

* Get rid of `DoLookup` phantom.

* Attempt to make transaction_pool work with lookups.

* Remove vscode settings

* New attempt at making transaction pool work.

* It builds again!

* --all builds

* Fix tests.

* New build.

* Test account nonce reset.

* polkadot transaction pool tests/framework.

* Initial draft (working).

* Address grumbles.

* Revert bad `map_or`

* Rebuild binaries, workaround.

* Avoid checking in vscode

* reconnecting, shared, slog

* CLI options for name and telemetry url

* ensure telemetry url imples enabled

* Avoid casting to usize early.

* Provide on-connect event for session message

* Better port

* heartbeat and some renaming

* transaction pool stuff

* minor renaming.

* report telemetry

* cleanups.

* Fix for previous cleanup

* dump genesis, dev mode, renaming

* Rework chain spec/config &c. to allow for genesis file loading.

* Avoid producing genesis storage when unneeded

* Allow reading JSON genesis state dumps

* tests work again

* better logging.

* Fix wasm build.

* Introduce PoC-1 spec

* Made block message compatible with poc-1

* Squashed changes for dumping genesis block.

* Binaries.

* Made block message compatible with poc-1

* Remove dead code.

* Fix bad merge.

* Argument passing and returning values when invoking sandboxed funcs (#189)

* Fixed block download sequence (#223)

* Trie-based execution proof (#177)

* TrieBasedBackend

* trie tests

* redunant return_value removed

* use Trie::get_with to record trie proofs

* Relaying tx/blocks by light clients (#190)

* do not import external transactions into light tx pool

* do not announce blocks on light clients

* blocks_are_not_announced_by_light_nodes
  • Loading branch information
gavofyork authored Jun 21, 2018
1 parent c2b45e2 commit b4cb978
Show file tree
Hide file tree
Showing 49 changed files with 688 additions and 490 deletions.
7 changes: 6 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ members = [
"substrate/test-runtime",
"substrate/telemetry",
"substrate/keystore",

"demo/cli",
"demo/executor",
"demo/primitives",
Expand Down
115 changes: 52 additions & 63 deletions demo/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ extern crate log;
pub mod error;

use std::sync::Arc;
use client::genesis;
use demo_primitives::Hash;
use demo_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
SessionConfig, StakingConfig, BuildExternalities};
use demo_runtime::{Block, Header, UncheckedExtrinsic};
SessionConfig, StakingConfig, BuildStorage};
use demo_runtime::{Block, UncheckedExtrinsic};
use futures::{Future, Sink, Stream};

struct DummyPool;
Expand Down Expand Up @@ -101,66 +100,56 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
// Create client
let executor = demo_executor::Executor::new();

struct GenesisBuilder;

impl client::GenesisBuilder<Block> for GenesisBuilder {
fn build(self) -> (Header, Vec<(Vec<u8>, Vec<u8>)>) {
let god_key = hex!["3d866ec8a9190c8343c2fc593d21d8a6d0c5c4763aaab2349de3a6111d64d124"];
let genesis_config = GenesisConfig {
consensus: Some(ConsensusConfig {
code: vec![], // TODO
authorities: vec![god_key.clone()],
}),
system: None,
// block_time: 5, // 5 second block time.
session: Some(SessionConfig {
validators: vec![god_key.clone().into()],
session_length: 720, // that's 1 hour per session.
}),
staking: Some(StakingConfig {
current_era: 0,
intentions: vec![],
transaction_base_fee: 100,
transaction_byte_fee: 1,
transfer_fee: 0,
creation_fee: 0,
contract_fee: 0,
reclaim_rebate: 0,
existential_deposit: 500,
balances: vec![(god_key.clone().into(), 1u64 << 63)].into_iter().collect(),
validator_count: 12,
sessions_per_era: 24, // 24 hours per era.
bonding_duration: 90, // 90 days per bond.
}),
democracy: Some(DemocracyConfig {
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
}),
council: Some(CouncilConfig {
active_council: vec![],
candidacy_bond: 1000, // 1000 to become a council candidate
voter_bond: 100, // 100 down to vote for a candidate
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
carry_count: 24, // carry over the 24 runners-up to the next council election
presentation_duration: 120 * 24, // one day for presenting winners.
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
term_duration: 180 * 120 * 24, // 180 day term duration for the council.
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.

cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
}),
};

let storage = genesis_config.build_externalities();
let block = genesis::construct_genesis_block::<Block>(&storage);
(block.header, storage.into_iter().collect())
}
}

let client = Arc::new(client::new_in_mem(executor, GenesisBuilder)?);
let god_key = hex!["3d866ec8a9190c8343c2fc593d21d8a6d0c5c4763aaab2349de3a6111d64d124"];
let genesis_storage = GenesisConfig {
consensus: Some(ConsensusConfig {
code: vec![], // TODO
authorities: vec![god_key.clone()],
}),
system: None,
// block_time: 5, // 5 second block time.
session: Some(SessionConfig {
validators: vec![god_key.clone().into()],
session_length: 720, // that's 1 hour per session.
}),
staking: Some(StakingConfig {
current_era: 0,
intentions: vec![],
transaction_base_fee: 100,
transaction_byte_fee: 1,
transfer_fee: 0,
creation_fee: 0,
contract_fee: 0,
reclaim_rebate: 0,
existential_deposit: 500,
balances: vec![(god_key.clone().into(), 1u64 << 63)].into_iter().collect(),
validator_count: 12,
sessions_per_era: 24, // 24 hours per era.
bonding_duration: 90, // 90 days per bond.
}),
democracy: Some(DemocracyConfig {
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
}),
council: Some(CouncilConfig {
active_council: vec![],
candidacy_bond: 1000, // 1000 to become a council candidate
voter_bond: 100, // 100 down to vote for a candidate
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
carry_count: 24, // carry over the 24 runners-up to the next council election
presentation_duration: 120 * 24, // one day for presenting winners.
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
term_duration: 180 * 120 * 24, // 180 day term duration for the council.
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.

cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
}),
}.build_storage();

let client = Arc::new(client::new_in_mem::<_, Block, _>(executor, genesis_storage)?);
let mut core = ::tokio_core::reactor::Core::new().expect("Unable to spawn event loop.");

let _rpc_servers = {
Expand Down
4 changes: 2 additions & 2 deletions demo/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod tests {
use runtime_primitives::{ApplyOutcome, ApplyError, ApplyResult, MaybeUnsigned};
use {staking, system};
use demo_runtime::{Header, Block, UncheckedExtrinsic, Extrinsic, Call, Concrete, Staking,
BuildExternalities, GenesisConfig, SessionConfig, StakingConfig, BareExtrinsic};
BuildStorage, GenesisConfig, SessionConfig, StakingConfig, BareExtrinsic};
use ed25519::{Public, Pair};

const BLOATY_CODE: &[u8] = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm");
Expand Down Expand Up @@ -203,7 +203,7 @@ mod tests {
}),
democracy: Some(Default::default()),
council: Some(Default::default()),
}.build_externalities()
}.build_storage()
}

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 @@ -51,7 +51,7 @@ use runtime_primitives::generic;
use runtime_primitives::traits::{Convert, HasPublicAux, BlakeTwo256};

#[cfg(any(feature = "std", test))]
pub use runtime_primitives::BuildExternalities;
pub use runtime_primitives::BuildStorage;

// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, Copy, PartialEq, Eq)]
Expand Down
Binary file not shown.
Binary file not shown.
46 changes: 18 additions & 28 deletions polkadot/api/src/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ impl<B: LocalBackend<Block>> LocalPolkadotApi for Client<B, LocalCallExecutor<B,
mod tests {
use super::*;
use keyring::Keyring;
use client::{self, LocalCallExecutor};
use client::LocalCallExecutor;
use client::in_mem::Backend as InMemory;
use substrate_executor::NativeExecutionDispatch;
use runtime::{GenesisConfig, ConsensusConfig, SessionConfig, BuildExternalities};
use runtime::{GenesisConfig, ConsensusConfig, SessionConfig, BuildStorage};

fn validators() -> Vec<AccountId> {
vec![
Expand All @@ -207,33 +207,23 @@ mod tests {
}

fn client() -> Client<InMemory<Block>, LocalCallExecutor<InMemory<Block>, NativeExecutor<LocalDispatch>>, Block> {
struct GenesisBuilder;

impl client::GenesisBuilder<Block> for GenesisBuilder {
fn build(self) -> (Header, Vec<(Vec<u8>, Vec<u8>)>) {
let genesis_config = GenesisConfig {
consensus: Some(ConsensusConfig {
code: LocalDispatch::native_equivalent().to_vec(),
authorities: session_keys(),
}),
system: None,
session: Some(SessionConfig {
validators: validators(),
session_length: 100,
}),
council: Some(Default::default()),
democracy: Some(Default::default()),
parachains: Some(Default::default()),
staking: Some(Default::default()),
};

let storage = genesis_config.build_externalities();
let block = ::client::genesis::construct_genesis_block::<Block>(&storage);
(block.header, storage.into_iter().collect())
}
}
let genesis_config = GenesisConfig {

This comment has been minimized.

Copy link
@ltfschoen

ltfschoen Jun 22, 2018

Contributor

Would it be preferable for this genesis_config variable be declared outside of the client function and renamed to genesis_storage instead so it's consistent with the approach used on Line 104, 150, and 152 of paritytech/polkadot@b4cb978#diff-b348982d1cac42639ad4b15a2b13f3b2R104 of demo/cli/src/lib.rs?

consensus: Some(ConsensusConfig {
code: LocalDispatch::native_equivalent().to_vec(),
authorities: session_keys(),
}),
system: None,
session: Some(SessionConfig {
validators: validators(),
session_length: 100,
}),
council: Some(Default::default()),
democracy: Some(Default::default()),
parachains: Some(Default::default()),
staking: Some(Default::default()),
};

::client::new_in_mem(LocalDispatch::new(), GenesisBuilder).unwrap()
::client::new_in_mem(LocalDispatch::new(), genesis_config.build_storage()).unwrap()
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions polkadot/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ futures = "0.1.17"
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
fdlimit = "0.1"
parking_lot = "0.4"
serde_json = "1.0"
serde = "1.0"
substrate-client = { path = "../../substrate/client" }
substrate-state-machine = { path = "../../substrate/state-machine" }
substrate-rpc = { path = "../../substrate/rpc" }
substrate-rpc-servers = { path = "../../substrate/rpc-servers" }
substrate-network = { path = "../../substrate/network" }
substrate-primitives = { path = "../../substrate/primitives" }
substrate-runtime-primitives = { path = "../../substrate/runtime/primitives" }
substrate-telemetry = { path = "../../substrate/telemetry" }
polkadot-primitives = { path = "../primitives" }
polkadot-runtime = { path = "../runtime" }
polkadot-service = { path = "../service" }
polkadot-transaction-pool = { path = "../transaction-pool" }
38 changes: 38 additions & 0 deletions polkadot/cli/poc-1.json

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions polkadot/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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/>.?

//! Predefined chains.

/// The chain specification (this should eventually be replaced by a more general JSON-based chain
/// specification).
#[derive(Clone, Debug)]
pub enum ChainSpec {
/// Whatever the current runtime is, with just Alice as an auth.
Development,
/// Whatever the current runtime is, with simple Alice/Bob auths.
LocalTestnet,
/// The PoC-1 testnet.
PoC1Testnet,
/// The PoC-2 testnet.
PoC2Testnet,
/// Custom Genesis file.
Custom(String),
}

impl<'a> From<&'a str> for ChainSpec {
fn from(s: &'a str) -> Self {
match s {
"dev" => ChainSpec::Development,
"local" => ChainSpec::LocalTestnet,
"poc-1" => ChainSpec::PoC1Testnet,
"poc-2" => ChainSpec::PoC2Testnet,
s => ChainSpec::Custom(s.into()),
}
}
}

impl From<ChainSpec> for String {
fn from(s: ChainSpec) -> String {
match s {
ChainSpec::Development => "dev".into(),
ChainSpec::LocalTestnet => "local".into(),
ChainSpec::PoC1Testnet => "poc-1".into(),
ChainSpec::PoC2Testnet => "poc-2".into(),
ChainSpec::Custom(f) => format!("custom ({})", f),
}
}
}

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!(),
})
}
}
}
12 changes: 10 additions & 2 deletions polkadot/cli/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ args:
- node-key:
long: node-key
value_name: KEY
help: Specify node secret key (64-character hex string).
help: Specify node secret key (64-character hex string)
takes_value: true
- collator:
long: collator
Expand All @@ -41,6 +41,14 @@ args:
long: light
help: Run in light client mode
takes_value: false
- dev:
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 @@ -80,6 +88,6 @@ args:
- telemetry-url:
long: telemetry-url
value_name: TELEMETRY_URL
help: The URL of the telemetry server. Implies --telemetry.
help: The URL of the telemetry server. Implies --telemetry
takes_value: true
subcommands:
Loading

0 comments on commit b4cb978

Please sign in to comment.