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

Commit d37e437

Browse files
committed
Merge branch 'master' into rh-storage-macro
2 parents 7523ff0 + 929c9fb commit d37e437

File tree

60 files changed

+7032
-142
lines changed

Some content is hidden

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

60 files changed

+7032
-142
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
polkadot/runtime/wasm/target/
66
substrate/executor/wasm/target/
77
substrate/test-runtime/wasm/target/
8+
demo/runtime/wasm/target/
89
**/._*

Cargo.lock

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ members = [
4040
"substrate/serializer",
4141
"substrate/state-machine",
4242
"substrate/test-runtime",
43+
"demo/runtime",
44+
"demo/primitives",
45+
"demo/executor",
46+
"demo/cli",
4347
]
4448
exclude = [
4549
"polkadot/runtime/wasm",
50+
"demo/runtime/wasm",
4651
"substrate/executor/wasm",
4752
"substrate/pwasm-alloc",
4853
"substrate/pwasm-libc",

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
cd substrate/executor/wasm && ./build.sh && cd ../../..
44
cd substrate/test-runtime/wasm && ./build.sh && cd ../../..
55
cd polkadot/runtime/wasm && ./build.sh && cd ../../..
6+
cd demo/runtime/wasm && ./build.sh && cd ../../..

demo/cli/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "demo-cli"
3+
version = "0.1.0"
4+
authors = ["Parity Technologies <admin@parity.io>"]
5+
description = "Substrate Demo node implementation in Rust."
6+
7+
[dependencies]
8+
clap = { version = "2.27", features = ["yaml"] }
9+
env_logger = "0.4"
10+
error-chain = "0.11"
11+
log = "0.3"
12+
hex-literal = "0.1"
13+
triehash = "0.1"
14+
ed25519 = { path = "../../substrate/ed25519" }
15+
substrate-client = { path = "../../substrate/client" }
16+
substrate-codec = { path = "../../substrate/codec" }
17+
substrate-runtime-io = { path = "../../substrate/runtime-io" }
18+
substrate-state-machine = { path = "../../substrate/state-machine" }
19+
substrate-executor = { path = "../../substrate/executor" }
20+
substrate-primitives = { path = "../../substrate/primitives" }
21+
substrate-rpc-servers = { path = "../../substrate/rpc-servers" }
22+
demo-primitives = { path = "../primitives" }
23+
demo-executor = { path = "../executor" }
24+
demo-runtime = { path = "../runtime" }

demo/cli/src/cli.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: substrate-demo
2+
author: "Parity Team <admin@parity.io>"
3+
about: Substrate Demo Node Rust Implementation
4+
args:
5+
- log:
6+
short: l
7+
value_name: LOG_PATTERN
8+
help: Sets a custom logging
9+
takes_value: true
10+
subcommands:
11+
- validator:
12+
about: Run validator node

demo/cli/src/error.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2017 Parity Technologies (UK) Ltd.
2+
// This file is part of Substrate Demo.
3+
4+
// Substrate Demo 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+
// Substrate Demo 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 Substrate Demo. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! Initialization errors.
18+
19+
use client;
20+
21+
error_chain! {
22+
foreign_links {
23+
Io(::std::io::Error) #[doc="IO error"];
24+
Cli(::clap::Error) #[doc="CLI error"];
25+
}
26+
links {
27+
Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"];
28+
}
29+
}

demo/cli/src/lib.rs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Copyright 2017 Parity Technologies (UK) Ltd.
2+
// This file is part of Substrate Demo.
3+
4+
// Substrate Demo 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+
// Substrate Demo 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 Substrate Demo. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! Substrate Demo CLI library.
18+
19+
#![warn(missing_docs)]
20+
21+
extern crate env_logger;
22+
extern crate ed25519;
23+
extern crate triehash;
24+
extern crate substrate_codec as codec;
25+
extern crate substrate_state_machine as state_machine;
26+
extern crate substrate_client as client;
27+
extern crate substrate_primitives as primitives;
28+
extern crate substrate_rpc_servers as rpc;
29+
extern crate demo_primitives;
30+
extern crate demo_executor;
31+
extern crate demo_runtime;
32+
33+
#[macro_use]
34+
extern crate hex_literal;
35+
#[macro_use]
36+
extern crate clap;
37+
#[macro_use]
38+
extern crate error_chain;
39+
#[macro_use]
40+
extern crate log;
41+
42+
pub mod error;
43+
44+
use codec::Slicable;
45+
use demo_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
46+
use client::genesis;
47+
48+
/// Parse command line arguments and start the node.
49+
///
50+
/// IANA unassigned port ranges that we could use:
51+
/// 6717-6766 Unassigned
52+
/// 8504-8553 Unassigned
53+
/// 9556-9591 Unassigned
54+
/// 9803-9874 Unassigned
55+
/// 9926-9949 Unassigned
56+
pub fn run<I, T>(args: I) -> error::Result<()> where
57+
I: IntoIterator<Item = T>,
58+
T: Into<std::ffi::OsString> + Clone,
59+
{
60+
let yaml = load_yaml!("./cli.yml");
61+
let matches = clap::App::from_yaml(yaml).version(crate_version!()).get_matches_from_safe(args)?;
62+
63+
// TODO [ToDr] Split parameters parsing from actual execution.
64+
let log_pattern = matches.value_of("log").unwrap_or("");
65+
init_logger(log_pattern);
66+
67+
// Create client
68+
let executor = demo_executor::Executor::new();
69+
let mut storage = Default::default();
70+
let god_key = hex!["3d866ec8a9190c8343c2fc593d21d8a6d0c5c4763aaab2349de3a6111d64d124"];
71+
72+
let genesis_config = GenesisConfig {
73+
validators: vec![god_key.clone()],
74+
authorities: vec![god_key.clone()],
75+
balances: vec![(god_key.clone(), 1u64 << 63)].into_iter().collect(),
76+
block_time: 5, // 5 second block time.
77+
session_length: 720, // that's 1 hour per session.
78+
sessions_per_era: 24, // 24 hours per era.
79+
bonding_duration: 90, // 90 days per bond.
80+
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
81+
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
82+
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
83+
candidacy_bond: 1000, // 1000 to become a council candidate
84+
voter_bond: 100, // 100 down to vote for a candidate
85+
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
86+
carry_count: 24, // carry over the 24 runners-up to the next council election
87+
presentation_duration: 120 * 24, // one day for presenting winners.
88+
council_election_voting_period: 7 * 120 * 24, // one week period between possible council elections.
89+
council_term_duration: 180 * 120 * 24, // 180 day term duration for the council.
90+
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
91+
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.
92+
cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
93+
council_proposal_voting_period: 7 * 120 * 24, // 7 day voting period for council members.
94+
};
95+
let prepare_genesis = || {
96+
storage = genesis_config.genesis_map();
97+
let block = genesis::construct_genesis_block(&storage);
98+
storage.extend(additional_storage_with_genesis(&block));
99+
(primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
100+
};
101+
let client = client::new_in_mem(executor, prepare_genesis)?;
102+
103+
let address = "127.0.0.1:9933".parse().unwrap();
104+
let handler = rpc::rpc_handler(client);
105+
let server = rpc::start_http(&address, handler)?;
106+
107+
if let Some(_) = matches.subcommand_matches("validator") {
108+
info!("Starting validator.");
109+
server.wait();
110+
return Ok(());
111+
}
112+
113+
println!("No command given.\n");
114+
let _ = clap::App::from_yaml(yaml).print_long_help();
115+
116+
Ok(())
117+
}
118+
119+
fn init_logger(pattern: &str) {
120+
let mut builder = env_logger::LogBuilder::new();
121+
// Disable info logging by default for some modules:
122+
builder.filter(Some("hyper"), log::LogLevelFilter::Warn);
123+
// Enable info for others.
124+
builder.filter(None, log::LogLevelFilter::Info);
125+
126+
if let Ok(lvl) = std::env::var("RUST_LOG") {
127+
builder.parse(&lvl);
128+
}
129+
130+
builder.parse(pattern);
131+
132+
133+
builder.init().expect("Logger initialized only once.");
134+
}

demo/executor/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "demo-executor"
3+
version = "0.1.0"
4+
authors = ["Parity Technologies <admin@parity.io>"]
5+
description = "Substrate Demo node implementation in Rust."
6+
7+
[dependencies]
8+
hex-literal = "0.1"
9+
triehash = { version = "0.1" }
10+
ed25519 = { path = "../../substrate/ed25519" }
11+
substrate-codec = { path = "../../substrate/codec" }
12+
substrate-runtime-io = { path = "../../substrate/runtime-io" }
13+
substrate-runtime-support = { path = "../../substrate/runtime-support" }
14+
substrate-state-machine = { path = "../../substrate/state-machine" }
15+
substrate-executor = { path = "../../substrate/executor" }
16+
substrate-primitives = { path = "../../substrate/primitives" }
17+
demo-primitives = { path = "../primitives" }
18+
demo-runtime = { path = "../runtime" }
19+
20+
[dev-dependencies]
21+
substrate-keyring = { path = "../../substrate/keyring" }

0 commit comments

Comments
 (0)