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

Substrate demo (a basic blockchain made with substrate) #79

Merged
merged 93 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
acab9a3
Block builder (substrate)
gavofyork Feb 12, 2018
9acd3f9
Fix wasm build
gavofyork Feb 12, 2018
ca5900f
Bulid on any block
gavofyork Feb 13, 2018
d11cfe1
Test for block builder.
gavofyork Feb 13, 2018
b973ccc
Block import tests for client.
gavofyork Feb 13, 2018
ec61865
Tidy ups
gavofyork Feb 13, 2018
cec06a7
Repotted client
gavofyork Feb 13, 2018
38cd36a
Avoid pointless work
gavofyork Feb 13, 2018
8b7abca
All backend stuff now manages optional storage.
gavofyork Feb 13, 2018
9dba812
Native runtime-io now supports empty storage items.
gavofyork Feb 13, 2018
0f591c6
Finish up the API transition.
gavofyork Feb 14, 2018
79c6b4c
Merge branch 'master' into gav-optional-storage
gavofyork Feb 15, 2018
a802b7e
Build fix.
gavofyork Feb 15, 2018
3928c1c
Fix tests.
gavofyork Feb 15, 2018
002ab5f
Merge branch 'master' into gav-optional-storage
gavofyork Feb 16, 2018
61db63f
Remerge in changes to client.
gavofyork Feb 16, 2018
5d1a3a7
Final fixes.
gavofyork Feb 16, 2018
212d370
Unrevert typos
gavofyork Feb 17, 2018
780e549
Remove accidentally committed change
gavofyork Feb 18, 2018
e552875
Bring back zero copy
gavofyork Feb 18, 2018
0a08196
Fix merge.
gavofyork Feb 18, 2018
e25960b
Refactor out some duped code
gavofyork Feb 19, 2018
9042880
Merge branch 'master' into gav-demo
gavofyork Feb 20, 2018
af3a413
Add docs.
gavofyork Feb 20, 2018
2b13856
More mssing doc.
gavofyork Feb 20, 2018
08060a6
Fix up wasm build.
gavofyork Feb 20, 2018
036142c
Introduce substrate-demo
gavofyork Feb 20, 2018
38bf4d7
Remove bad files.
gavofyork Feb 20, 2018
a2fb006
Tidy up unneeded code.
gavofyork Feb 20, 2018
775cb5a
Add needed file.
gavofyork Feb 20, 2018
0b83481
Initial staging ground for interior wasm smart-contracts.
gavofyork Feb 20, 2018
3413d14
More work on Ext & calls.
gavofyork Feb 22, 2018
0a82fd2
Fix logic
gavofyork Feb 23, 2018
b098eb2
comment
gavofyork Feb 23, 2018
73c4141
Remove unneeded call depth.
gavofyork Feb 25, 2018
9ef9c01
Use BTreeMap rather than HashMap in demo runtime.
gavofyork Feb 25, 2018
59c371f
Initial draft of stakeholder democracy.
gavofyork Feb 25, 2018
696f22a
Tests for referenda.
gavofyork Feb 26, 2018
98b74bc
Design of the approval voting module for council election.
gavofyork Feb 27, 2018
87bc061
Implement next_tally.
gavofyork Feb 28, 2018
f5ad966
More work on governance.
gavofyork Feb 28, 2018
afcff76
Submit candidacy.
gavofyork Mar 1, 2018
264384d
presenting a winner.
gavofyork Mar 1, 2018
822a5dc
Final bit of core logic for the council.
gavofyork Mar 1, 2018
9a1d638
remove inactive voter.
gavofyork Mar 1, 2018
4618367
Space out votes by a minimum period.
gavofyork Mar 1, 2018
9af17a5
Candidacy tests
gavofyork Mar 2, 2018
511775c
More candidate tests.
gavofyork Mar 2, 2018
2eeb88e
More tests for voting.
gavofyork Mar 2, 2018
5ea3f2b
Test for tally
gavofyork Mar 2, 2018
bcb2b39
More tests, for runners-up.
gavofyork Mar 2, 2018
3541d4e
test: second tally uses runners-up.
gavofyork Mar 2, 2018
a0c405f
Tests: various error cases with present.
gavofyork Mar 2, 2018
899e26e
tests: presenting losers
gavofyork Mar 2, 2018
4777806
cleanups.
gavofyork Mar 2, 2018
f0d5f53
Merge branch 'master' into gav-demo
gavofyork Mar 2, 2018
f276b4d
tests: Retract inactive voter
gavofyork Mar 2, 2018
05b6a8d
Additional docs & test.
gavofyork Mar 2, 2018
2bf2799
Add one vote worth of time for voters to unregister before they becom…
gavofyork Mar 2, 2018
999c082
Avoid allowing same accounts to be doubly-elected.
gavofyork Mar 2, 2018
0c9265f
test: against double presentations.
gavofyork Mar 2, 2018
3c911cd
Update docs
gavofyork Mar 2, 2018
002ddab
Simultaneous referendums and multiple voting variants.
gavofyork Mar 3, 2018
b8cc3a1
Introduce logic for deposits.
gavofyork Mar 3, 2018
9aeb95c
Deposits, not fees.
gavofyork Mar 3, 2018
fffbadd
cleanups.
gavofyork Mar 3, 2018
6dfe148
Introduce minimum deposit
gavofyork Mar 3, 2018
907fac7
Tests for public referenda.
gavofyork Mar 4, 2018
0bbd6b3
Tests for public referenda.
gavofyork Mar 4, 2018
8df2342
remove string constants <-- @rphmeier
gavofyork Mar 4, 2018
c73e3f9
Ensure council always sorted by expiry.
gavofyork Mar 4, 2018
0bb5791
Initial council vote logic.
gavofyork Mar 4, 2018
f780504
More tests for council voting.
gavofyork Mar 5, 2018
25b8c20
council vetoing & tests.
gavofyork Mar 5, 2018
7ef0b17
Another few tests for council_vote.
gavofyork Mar 5, 2018
8b37acf
Final tests.
gavofyork Mar 6, 2018
bb7f398
Move council over to new Keyring API.
gavofyork Mar 6, 2018
8be2cc8
Move democracy module over no new Keyring API
gavofyork Mar 6, 2018
7e6e40d
Introduce stake reservation; make panicking tests better.
gavofyork Mar 6, 2018
7e8e404
Genesis map.
gavofyork Mar 7, 2018
2d66a63
Use a struct!
gavofyork Mar 7, 2018
22d4829
Tests for staking reserved balances & slashing.
gavofyork Mar 10, 2018
5450807
Public function dispatching.
gavofyork Mar 10, 2018
e09096c
Safe panic.
gavofyork Mar 10, 2018
128fa23
Fix tests and avoid use of old keys.
gavofyork Mar 10, 2018
d347030
Fix grumbles.
gavofyork Mar 11, 2018
b6897d5
Minor typos.
gavofyork Mar 11, 2018
6029553
Cleanups and introduce all dispatchable endpoints.
gavofyork Mar 12, 2018
f3439c9
Additional function ids for derivation.
gavofyork Mar 12, 2018
23b030a
Formatting.
gavofyork Mar 12, 2018
016a7b6
Remove stray printlns.
gavofyork Mar 14, 2018
0f81021
Merge branch 'master' into gav-demo
gavofyork Mar 14, 2018
5c9a40a
Update wasm.
gavofyork Mar 14, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
polkadot/runtime/wasm/target/
substrate/executor/wasm/target/
substrate/test-runtime/wasm/target/
demo/runtime/wasm/target/
**/._*
78 changes: 78 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ members = [
"substrate/serializer",
"substrate/state-machine",
"substrate/test-runtime",
"demo/runtime",
"demo/primitives",
"demo/executor",
"demo/cli",
]
exclude = [
"polkadot/runtime/wasm",
"demo/runtime/wasm",
"substrate/executor/wasm",
"substrate/pwasm-alloc",
"substrate/pwasm-libc",
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
cd substrate/executor/wasm && ./build.sh && cd ../../..
cd substrate/test-runtime/wasm && ./build.sh && cd ../../..
cd polkadot/runtime/wasm && ./build.sh && cd ../../..
cd demo/runtime/wasm && ./build.sh && cd ../../..
24 changes: 24 additions & 0 deletions demo/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "demo-cli"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Substrate Demo node implementation in Rust."

[dependencies]
clap = { version = "2.27", features = ["yaml"] }
env_logger = "0.4"
error-chain = "0.11"
log = "0.3"
hex-literal = "0.1"
triehash = "0.1"
ed25519 = { path = "../../substrate/ed25519" }
substrate-client = { path = "../../substrate/client" }
substrate-codec = { path = "../../substrate/codec" }
substrate-runtime-io = { path = "../../substrate/runtime-io" }
substrate-state-machine = { path = "../../substrate/state-machine" }
substrate-executor = { path = "../../substrate/executor" }
substrate-primitives = { path = "../../substrate/primitives" }
substrate-rpc-servers = { path = "../../substrate/rpc-servers" }
demo-primitives = { path = "../primitives" }
demo-executor = { path = "../executor" }
demo-runtime = { path = "../runtime" }
12 changes: 12 additions & 0 deletions demo/cli/src/cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: substrate-demo
author: "Parity Team <admin@parity.io>"
about: Substrate Demo Node Rust Implementation
args:
- log:
short: l
value_name: LOG_PATTERN
help: Sets a custom logging
takes_value: true
subcommands:
- validator:
about: Run validator node
29 changes: 29 additions & 0 deletions demo/cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Substrate Demo.

// Substrate Demo 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.

// Substrate Demo 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 Substrate Demo. If not, see <http://www.gnu.org/licenses/>.

//! Initialization errors.

use client;

error_chain! {
foreign_links {
Io(::std::io::Error) #[doc="IO error"];
Cli(::clap::Error) #[doc="CLI error"];
}
links {
Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"];
}
}
134 changes: 134 additions & 0 deletions demo/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Substrate Demo.

// Substrate Demo 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.

// Substrate Demo 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 Substrate Demo. If not, see <http://www.gnu.org/licenses/>.

//! Substrate Demo CLI library.

#![warn(missing_docs)]

extern crate env_logger;
extern crate ed25519;
extern crate triehash;
extern crate substrate_codec as codec;
extern crate substrate_state_machine as state_machine;
extern crate substrate_client as client;
extern crate substrate_primitives as primitives;
extern crate substrate_rpc_servers as rpc;
extern crate demo_primitives;
extern crate demo_executor;
extern crate demo_runtime;

#[macro_use]
extern crate hex_literal;
#[macro_use]
extern crate clap;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate log;

pub mod error;

use codec::Slicable;
use demo_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
use client::genesis;

/// Parse command line arguments and start the node.
///
/// IANA unassigned port ranges that we could use:
/// 6717-6766 Unassigned
/// 8504-8553 Unassigned
/// 9556-9591 Unassigned
/// 9803-9874 Unassigned
/// 9926-9949 Unassigned
pub fn run<I, T>(args: I) -> error::Result<()> where
I: IntoIterator<Item = T>,
T: Into<std::ffi::OsString> + Clone,
{
let yaml = load_yaml!("./cli.yml");
let matches = clap::App::from_yaml(yaml).version(crate_version!()).get_matches_from_safe(args)?;

// TODO [ToDr] Split parameters parsing from actual execution.
let log_pattern = matches.value_of("log").unwrap_or("");
init_logger(log_pattern);

// Create client
let executor = demo_executor::Executor::new();
let mut storage = Default::default();
let god_key = hex!["3d866ec8a9190c8343c2fc593d21d8a6d0c5c4763aaab2349de3a6111d64d124"];

let genesis_config = GenesisConfig {
validators: vec![god_key.clone()],
authorities: vec![god_key.clone()],
balances: vec![(god_key.clone(), 1u64 << 63)].into_iter().collect(),
block_time: 5, // 5 second block time.
session_length: 720, // that's 1 hour per session.
sessions_per_era: 24, // 24 hours per era.
bonding_duration: 90, // 90 days per bond.
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
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.
council_election_voting_period: 7 * 120 * 24, // one week period between possible council elections.
council_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.
council_proposal_voting_period: 7 * 120 * 24, // 7 day voting period for council members.
};
let prepare_genesis = || {
storage = genesis_config.genesis_map();
let block = genesis::construct_genesis_block(&storage);
storage.extend(additional_storage_with_genesis(&block));
(primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
};
let client = client::new_in_mem(executor, prepare_genesis)?;

let address = "127.0.0.1:9933".parse().unwrap();
let handler = rpc::rpc_handler(client);
let server = rpc::start_http(&address, handler)?;

if let Some(_) = matches.subcommand_matches("validator") {
info!("Starting validator.");
server.wait();
return Ok(());
}

println!("No command given.\n");
let _ = clap::App::from_yaml(yaml).print_long_help();

Ok(())
}

fn init_logger(pattern: &str) {
let mut builder = env_logger::LogBuilder::new();
// Disable info logging by default for some modules:
builder.filter(Some("hyper"), log::LogLevelFilter::Warn);
// Enable info for others.
builder.filter(None, log::LogLevelFilter::Info);

if let Ok(lvl) = std::env::var("RUST_LOG") {
builder.parse(&lvl);
}

builder.parse(pattern);


builder.init().expect("Logger initialized only once.");
}
21 changes: 21 additions & 0 deletions demo/executor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "demo-executor"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Substrate Demo node implementation in Rust."

[dependencies]
hex-literal = "0.1"
triehash = { version = "0.1" }
ed25519 = { path = "../../substrate/ed25519" }
substrate-codec = { path = "../../substrate/codec" }
substrate-runtime-io = { path = "../../substrate/runtime-io" }
substrate-runtime-support = { path = "../../substrate/runtime-support" }
substrate-state-machine = { path = "../../substrate/state-machine" }
substrate-executor = { path = "../../substrate/executor" }
substrate-primitives = { path = "../../substrate/primitives" }
demo-primitives = { path = "../primitives" }
demo-runtime = { path = "../runtime" }

[dev-dependencies]
substrate-keyring = { path = "../../substrate/keyring" }
Loading