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

Commit b4cb978

Browse files
authored
Dump genesis to JSON file (#218)
* 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
1 parent c2b45e2 commit b4cb978

File tree

49 files changed

+688
-490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+688
-490
lines changed

Cargo.lock

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ members = [
5656
"substrate/test-runtime",
5757
"substrate/telemetry",
5858
"substrate/keystore",
59-
6059
"demo/cli",
6160
"demo/executor",
6261
"demo/primitives",

demo/cli/src/lib.rs

+52-63
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ extern crate log;
4848
pub mod error;
4949

5050
use std::sync::Arc;
51-
use client::genesis;
5251
use demo_primitives::Hash;
5352
use demo_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
54-
SessionConfig, StakingConfig, BuildExternalities};
55-
use demo_runtime::{Block, Header, UncheckedExtrinsic};
53+
SessionConfig, StakingConfig, BuildStorage};
54+
use demo_runtime::{Block, UncheckedExtrinsic};
5655
use futures::{Future, Sink, Stream};
5756

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

104-
struct GenesisBuilder;
105-
106-
impl client::GenesisBuilder<Block> for GenesisBuilder {
107-
fn build(self) -> (Header, Vec<(Vec<u8>, Vec<u8>)>) {
108-
let god_key = hex!["3d866ec8a9190c8343c2fc593d21d8a6d0c5c4763aaab2349de3a6111d64d124"];
109-
let genesis_config = GenesisConfig {
110-
consensus: Some(ConsensusConfig {
111-
code: vec![], // TODO
112-
authorities: vec![god_key.clone()],
113-
}),
114-
system: None,
115-
// block_time: 5, // 5 second block time.
116-
session: Some(SessionConfig {
117-
validators: vec![god_key.clone().into()],
118-
session_length: 720, // that's 1 hour per session.
119-
}),
120-
staking: Some(StakingConfig {
121-
current_era: 0,
122-
intentions: vec![],
123-
transaction_base_fee: 100,
124-
transaction_byte_fee: 1,
125-
transfer_fee: 0,
126-
creation_fee: 0,
127-
contract_fee: 0,
128-
reclaim_rebate: 0,
129-
existential_deposit: 500,
130-
balances: vec![(god_key.clone().into(), 1u64 << 63)].into_iter().collect(),
131-
validator_count: 12,
132-
sessions_per_era: 24, // 24 hours per era.
133-
bonding_duration: 90, // 90 days per bond.
134-
}),
135-
democracy: Some(DemocracyConfig {
136-
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
137-
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
138-
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
139-
}),
140-
council: Some(CouncilConfig {
141-
active_council: vec![],
142-
candidacy_bond: 1000, // 1000 to become a council candidate
143-
voter_bond: 100, // 100 down to vote for a candidate
144-
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
145-
carry_count: 24, // carry over the 24 runners-up to the next council election
146-
presentation_duration: 120 * 24, // one day for presenting winners.
147-
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
148-
term_duration: 180 * 120 * 24, // 180 day term duration for the council.
149-
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
150-
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.
151-
152-
cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
153-
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
154-
}),
155-
};
156-
157-
let storage = genesis_config.build_externalities();
158-
let block = genesis::construct_genesis_block::<Block>(&storage);
159-
(block.header, storage.into_iter().collect())
160-
}
161-
}
162-
163-
let client = Arc::new(client::new_in_mem(executor, GenesisBuilder)?);
103+
let god_key = hex!["3d866ec8a9190c8343c2fc593d21d8a6d0c5c4763aaab2349de3a6111d64d124"];
104+
let genesis_storage = GenesisConfig {
105+
consensus: Some(ConsensusConfig {
106+
code: vec![], // TODO
107+
authorities: vec![god_key.clone()],
108+
}),
109+
system: None,
110+
// block_time: 5, // 5 second block time.
111+
session: Some(SessionConfig {
112+
validators: vec![god_key.clone().into()],
113+
session_length: 720, // that's 1 hour per session.
114+
}),
115+
staking: Some(StakingConfig {
116+
current_era: 0,
117+
intentions: vec![],
118+
transaction_base_fee: 100,
119+
transaction_byte_fee: 1,
120+
transfer_fee: 0,
121+
creation_fee: 0,
122+
contract_fee: 0,
123+
reclaim_rebate: 0,
124+
existential_deposit: 500,
125+
balances: vec![(god_key.clone().into(), 1u64 << 63)].into_iter().collect(),
126+
validator_count: 12,
127+
sessions_per_era: 24, // 24 hours per era.
128+
bonding_duration: 90, // 90 days per bond.
129+
}),
130+
democracy: Some(DemocracyConfig {
131+
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
132+
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
133+
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
134+
}),
135+
council: Some(CouncilConfig {
136+
active_council: vec![],
137+
candidacy_bond: 1000, // 1000 to become a council candidate
138+
voter_bond: 100, // 100 down to vote for a candidate
139+
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
140+
carry_count: 24, // carry over the 24 runners-up to the next council election
141+
presentation_duration: 120 * 24, // one day for presenting winners.
142+
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
143+
term_duration: 180 * 120 * 24, // 180 day term duration for the council.
144+
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
145+
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.
146+
147+
cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
148+
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
149+
}),
150+
}.build_storage();
151+
152+
let client = Arc::new(client::new_in_mem::<_, Block, _>(executor, genesis_storage)?);
164153
let mut core = ::tokio_core::reactor::Core::new().expect("Unable to spawn event loop.");
165154

166155
let _rpc_servers = {

demo/executor/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mod tests {
5151
use runtime_primitives::{ApplyOutcome, ApplyError, ApplyResult, MaybeUnsigned};
5252
use {staking, system};
5353
use demo_runtime::{Header, Block, UncheckedExtrinsic, Extrinsic, Call, Concrete, Staking,
54-
BuildExternalities, GenesisConfig, SessionConfig, StakingConfig, BareExtrinsic};
54+
BuildStorage, GenesisConfig, SessionConfig, StakingConfig, BareExtrinsic};
5555
use ed25519::{Public, Pair};
5656

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

209209
fn construct_block(number: BlockNumber, parent_hash: Hash, state_root: Hash, extrinsics: Vec<BareExtrinsic>) -> (Vec<u8>, Hash) {

demo/runtime/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use runtime_primitives::generic;
5151
use runtime_primitives::traits::{Convert, HasPublicAux, BlakeTwo256};
5252

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

5656
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
5757
#[derive(Clone, Copy, PartialEq, Eq)]
Binary file not shown.
Binary file not shown.

polkadot/api/src/full.rs

+18-28
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ impl<B: LocalBackend<Block>> LocalPolkadotApi for Client<B, LocalCallExecutor<B,
187187
mod tests {
188188
use super::*;
189189
use keyring::Keyring;
190-
use client::{self, LocalCallExecutor};
190+
use client::LocalCallExecutor;
191191
use client::in_mem::Backend as InMemory;
192192
use substrate_executor::NativeExecutionDispatch;
193-
use runtime::{GenesisConfig, ConsensusConfig, SessionConfig, BuildExternalities};
193+
use runtime::{GenesisConfig, ConsensusConfig, SessionConfig, BuildStorage};
194194

195195
fn validators() -> Vec<AccountId> {
196196
vec![
@@ -207,33 +207,23 @@ mod tests {
207207
}
208208

209209
fn client() -> Client<InMemory<Block>, LocalCallExecutor<InMemory<Block>, NativeExecutor<LocalDispatch>>, Block> {
210-
struct GenesisBuilder;
211-
212-
impl client::GenesisBuilder<Block> for GenesisBuilder {
213-
fn build(self) -> (Header, Vec<(Vec<u8>, Vec<u8>)>) {
214-
let genesis_config = GenesisConfig {
215-
consensus: Some(ConsensusConfig {
216-
code: LocalDispatch::native_equivalent().to_vec(),
217-
authorities: session_keys(),
218-
}),
219-
system: None,
220-
session: Some(SessionConfig {
221-
validators: validators(),
222-
session_length: 100,
223-
}),
224-
council: Some(Default::default()),
225-
democracy: Some(Default::default()),
226-
parachains: Some(Default::default()),
227-
staking: Some(Default::default()),
228-
};
229-
230-
let storage = genesis_config.build_externalities();
231-
let block = ::client::genesis::construct_genesis_block::<Block>(&storage);
232-
(block.header, storage.into_iter().collect())
233-
}
234-
}
210+
let genesis_config = GenesisConfig {
211+
consensus: Some(ConsensusConfig {
212+
code: LocalDispatch::native_equivalent().to_vec(),
213+
authorities: session_keys(),
214+
}),
215+
system: None,
216+
session: Some(SessionConfig {
217+
validators: validators(),
218+
session_length: 100,
219+
}),
220+
council: Some(Default::default()),
221+
democracy: Some(Default::default()),
222+
parachains: Some(Default::default()),
223+
staking: Some(Default::default()),
224+
};
235225

236-
::client::new_in_mem(LocalDispatch::new(), GenesisBuilder).unwrap()
226+
::client::new_in_mem(LocalDispatch::new(), genesis_config.build_storage()).unwrap()
237227
}
238228

239229
#[test]

polkadot/cli/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ futures = "0.1.17"
2424
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
2525
fdlimit = "0.1"
2626
parking_lot = "0.4"
27+
serde_json = "1.0"
28+
serde = "1.0"
2729
substrate-client = { path = "../../substrate/client" }
2830
substrate-state-machine = { path = "../../substrate/state-machine" }
2931
substrate-rpc = { path = "../../substrate/rpc" }
3032
substrate-rpc-servers = { path = "../../substrate/rpc-servers" }
3133
substrate-network = { path = "../../substrate/network" }
34+
substrate-primitives = { path = "../../substrate/primitives" }
35+
substrate-runtime-primitives = { path = "../../substrate/runtime/primitives" }
3236
substrate-telemetry = { path = "../../substrate/telemetry" }
3337
polkadot-primitives = { path = "../primitives" }
38+
polkadot-runtime = { path = "../runtime" }
3439
polkadot-service = { path = "../service" }
3540
polkadot-transaction-pool = { path = "../transaction-pool" }

polkadot/cli/poc-1.json

+38
Large diffs are not rendered by default.

polkadot/cli/src/chain_spec.rs

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2017 Parity Technologies (UK) Ltd.
2+
// This file is part of Polkadot.
3+
4+
// Polkadot is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Polkadot is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.?
16+
17+
//! Predefined chains.
18+
19+
/// The chain specification (this should eventually be replaced by a more general JSON-based chain
20+
/// specification).
21+
#[derive(Clone, Debug)]
22+
pub enum ChainSpec {
23+
/// Whatever the current runtime is, with just Alice as an auth.
24+
Development,
25+
/// Whatever the current runtime is, with simple Alice/Bob auths.
26+
LocalTestnet,
27+
/// The PoC-1 testnet.
28+
PoC1Testnet,
29+
/// The PoC-2 testnet.
30+
PoC2Testnet,
31+
/// Custom Genesis file.
32+
Custom(String),
33+
}
34+
35+
impl<'a> From<&'a str> for ChainSpec {
36+
fn from(s: &'a str) -> Self {
37+
match s {
38+
"dev" => ChainSpec::Development,
39+
"local" => ChainSpec::LocalTestnet,
40+
"poc-1" => ChainSpec::PoC1Testnet,
41+
"poc-2" => ChainSpec::PoC2Testnet,
42+
s => ChainSpec::Custom(s.into()),
43+
}
44+
}
45+
}
46+
47+
impl From<ChainSpec> for String {
48+
fn from(s: ChainSpec) -> String {
49+
match s {
50+
ChainSpec::Development => "dev".into(),
51+
ChainSpec::LocalTestnet => "local".into(),
52+
ChainSpec::PoC1Testnet => "poc-1".into(),
53+
ChainSpec::PoC2Testnet => "poc-2".into(),
54+
ChainSpec::Custom(f) => format!("custom ({})", f),
55+
}
56+
}
57+
}
58+
59+
impl ::std::fmt::Display for ChainSpec {
60+
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
61+
if let ChainSpec::Custom(n) = self {
62+
write!(f, "Custom ({})", n)
63+
} else {
64+
write!(f, "{}", match *self {
65+
ChainSpec::Development => "Development",
66+
ChainSpec::LocalTestnet => "Local Testnet",
67+
ChainSpec::PoC1Testnet => "PoC-1 Testnet",
68+
ChainSpec::PoC2Testnet => "PoC-2 Testnet",
69+
_ => unreachable!(),
70+
})
71+
}
72+
}
73+
}

polkadot/cli/src/cli.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ args:
2727
- node-key:
2828
long: node-key
2929
value_name: KEY
30-
help: Specify node secret key (64-character hex string).
30+
help: Specify node secret key (64-character hex string)
3131
takes_value: true
3232
- collator:
3333
long: collator
@@ -41,6 +41,14 @@ args:
4141
long: light
4242
help: Run in light client mode
4343
takes_value: false
44+
- dev:
45+
long: dev
46+
help: Run in development mode; implies --chain=dev --validator --key Alice
47+
takes_value: false
48+
- build-genesis:
49+
long: build-genesis
50+
help: Build a genesis.json file, outputing to stdout
51+
takes_value: false
4452
- port:
4553
long: port
4654
value_name: PORT
@@ -80,6 +88,6 @@ args:
8088
- telemetry-url:
8189
long: telemetry-url
8290
value_name: TELEMETRY_URL
83-
help: The URL of the telemetry server. Implies --telemetry.
91+
help: The URL of the telemetry server. Implies --telemetry
8492
takes_value: true
8593
subcommands:

0 commit comments

Comments
 (0)