From 49752d9a8cfaa37a312287a9f312148156419a8c Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 24 Jul 2019 13:44:45 +0200 Subject: [PATCH 01/10] Move node-cli within node --- Cargo.lock | 82 ++++++++++------------- Cargo.toml | 46 ++++++++++++- build.rs | 29 ++++++++ node/cli/Cargo.toml | 52 -------------- node/cli/build.rs | 50 -------------- node/{cli => }/doc/shell-completion.adoc | 0 node/{cli => }/res/flaming-fir.json | 0 node/{cli => }/src/chain_spec.rs | 0 node/{cli => }/src/factory_impl.rs | 0 node/{cli => }/src/lib.rs | 0 node/src/main.rs | 6 +- node/{cli => }/src/service.rs | 0 test-utils/chain-spec-builder/Cargo.toml | 2 +- test-utils/chain-spec-builder/src/main.rs | 2 +- 14 files changed, 115 insertions(+), 154 deletions(-) delete mode 100644 node/cli/Cargo.toml delete mode 100644 node/cli/build.rs rename node/{cli => }/doc/shell-completion.adoc (100%) rename node/{cli => }/res/flaming-fir.json (100%) rename node/{cli => }/src/chain_spec.rs (100%) rename node/{cli => }/src/factory_impl.rs (100%) rename node/{cli => }/src/lib.rs (100%) rename node/{cli => }/src/service.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 48edf4fa283ef..e6e3226ad7731 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -385,7 +385,7 @@ name = "chain-spec-builder" version = "2.0.0" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "node-cli 2.0.0", + "substrate 2.0.0", "substrate-primitives 2.0.0", "substrate-service 2.0.0", ] @@ -2241,49 +2241,6 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "node-cli" -version = "2.0.0" -dependencies = [ - "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "node-executor 2.0.0", - "node-primitives 2.0.0", - "node-runtime 2.0.0", - "parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "sr-io 2.0.0", - "sr-primitives 2.0.0", - "srml-balances 2.0.0", - "srml-contracts 2.0.0", - "srml-finality-tracker 2.0.0", - "srml-indices 2.0.0", - "srml-system 2.0.0", - "srml-timestamp 2.0.0", - "structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "substrate-basic-authorship 2.0.0", - "substrate-cli 2.0.0", - "substrate-client 2.0.0", - "substrate-consensus-aura 2.0.0", - "substrate-consensus-aura-primitives 2.0.0", - "substrate-consensus-common 2.0.0", - "substrate-finality-grandpa 2.0.0", - "substrate-finality-grandpa-primitives 2.0.0", - "substrate-inherents 2.0.0", - "substrate-keyring 2.0.0", - "substrate-keystore 2.0.0", - "substrate-network 2.0.0", - "substrate-primitives 2.0.0", - "substrate-service 2.0.0", - "substrate-service-test 2.0.0", - "substrate-telemetry 2.0.0", - "substrate-transaction-pool 2.0.0", - "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", - "transaction-factory 0.0.1", -] - [[package]] name = "node-executor" version = "2.0.0" @@ -4150,8 +4107,43 @@ name = "substrate" version = "2.0.0" dependencies = [ "ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "node-cli 2.0.0", + "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "node-executor 2.0.0", + "node-primitives 2.0.0", + "node-runtime 2.0.0", + "parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-io 2.0.0", + "sr-primitives 2.0.0", + "srml-balances 2.0.0", + "srml-contracts 2.0.0", + "srml-finality-tracker 2.0.0", + "srml-indices 2.0.0", + "srml-system 2.0.0", + "srml-timestamp 2.0.0", + "structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-basic-authorship 2.0.0", + "substrate-cli 2.0.0", + "substrate-client 2.0.0", + "substrate-consensus-aura 2.0.0", + "substrate-consensus-aura-primitives 2.0.0", + "substrate-consensus-common 2.0.0", + "substrate-finality-grandpa 2.0.0", + "substrate-finality-grandpa-primitives 2.0.0", + "substrate-inherents 2.0.0", + "substrate-keyring 2.0.0", + "substrate-keystore 2.0.0", + "substrate-network 2.0.0", + "substrate-primitives 2.0.0", + "substrate-service 2.0.0", + "substrate-service-test 2.0.0", + "substrate-telemetry 2.0.0", + "substrate-transaction-pool 2.0.0", + "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "transaction-factory 0.0.1", "vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index a6a7b8d17ba35..366c4205063bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,10 @@ name = "substrate" path = "node/src/main.rs" +[lib] +name = "substrate_node_cli" +path = "node/src/lib.rs" + [package] name = "substrate" version = "2.0.0" @@ -10,11 +14,50 @@ build = "build.rs" edition = "2018" [dependencies] -cli = { package = "node-cli", path = "node/cli" } +log = "0.4" +tokio = "0.1.7" futures = "0.1" ctrlc = { version = "3.0", features = ["termination"] } +exit-future = "0.1" +cli = { package = "substrate-cli", path = "core/cli" } +parity-codec = { version = "4.1.1" } +sr-io = { path = "core/sr-io" } +client = { package = "substrate-client", path = "core/client" } +primitives = { package = "substrate-primitives", path = "core/primitives" } +inherents = { package = "substrate-inherents", path = "core/inherents" } +node-runtime = { path = "node/runtime" } +node-primitives = { path = "node/primitives" } +hex-literal = "0.2" +substrate-basic-authorship = { path = "core/basic-authorship" } +substrate-service = { path = "core/service" } +transaction_pool = { package = "substrate-transaction-pool", path = "core/transaction-pool" } +network = { package = "substrate-network", path = "core/network" } +aura = { package = "substrate-consensus-aura", path = "core/consensus/aura" } +aura_primitives = { package = "substrate-consensus-aura-primitives", path = "core/consensus/aura/primitives" } +grandpa = { package = "substrate-finality-grandpa", path = "core/finality-grandpa" } +grandpa_primitives = { package = "substrate-finality-grandpa-primitives", path = "core/finality-grandpa/primitives" } +sr-primitives = { path = "core/sr-primitives" } +node-executor = { path = "node/executor" } +substrate-keystore = { path = "core/keystore" } +substrate-telemetry = { package = "substrate-telemetry", path = "core/telemetry" } +structopt = "0.2" +transaction-factory = { path = "test-utils/transaction-factory" } +keyring = { package = "substrate-keyring", path = "core/keyring" } +indices = { package = "srml-indices", path = "srml/indices" } +timestamp = { package = "srml-timestamp", path = "srml/timestamp", default-features = false } +rand = "0.6" +finality_tracker = { package = "srml-finality-tracker", path = "srml/finality-tracker", default-features = false } +contracts = { package = "srml-contracts", path = "srml/contracts" } +system = { package = "srml-system", path = "srml/system" } +balances = { package = "srml-balances", path = "srml/balances" } + +[dev-dependencies] +consensus-common = { package = "substrate-consensus-common", path = "core/consensus/common" } +service-test = { package = "substrate-service-test", path = "core/service/test" } [build-dependencies] +cli = { package = "substrate-cli", path = "core/cli" } +structopt = "0.2" vergen = "3" [workspace] @@ -86,7 +129,6 @@ members = [ "srml/system", "srml/timestamp", "srml/treasury", - "node/cli", "node/executor", "node/primitives", "node/runtime", diff --git a/build.rs b/build.rs index 273700c525c88..303a4c0f770eb 100644 --- a/build.rs +++ b/build.rs @@ -14,6 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . +use cli::{NoCustom, CoreParams}; +use std::{fs, env, path::Path}; +use structopt::{StructOpt, clap::Shell}; use vergen::{ConstantsFlags, generate_cargo_keys}; const ERROR_MSG: &str = "Failed to generate metadata files"; @@ -21,4 +24,30 @@ const ERROR_MSG: &str = "Failed to generate metadata files"; fn main() { generate_cargo_keys(ConstantsFlags::all()).expect(ERROR_MSG); println!("cargo:rerun-if-changed=.git/HEAD"); + build_shell_completion(); +} + +/// Build shell completion scripts for all known shells +/// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123 +fn build_shell_completion() { + for shell in &[Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] { + build_completion(shell); + } +} + +/// Build the shell auto-completion for a given Shell +fn build_completion(shell: &Shell) { + let outdir = match env::var_os("OUT_DIR") { + None => return, + Some(dir) => dir, + }; + let path = Path::new(&outdir) + .parent().unwrap() + .parent().unwrap() + .parent().unwrap() + .join("completion-scripts"); + + fs::create_dir(&path).ok(); + + CoreParams::::clap().gen_completions("substrate-node", *shell, &path); } diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml deleted file mode 100644 index 17efcc400f35b..0000000000000 --- a/node/cli/Cargo.toml +++ /dev/null @@ -1,52 +0,0 @@ -[package] -name = "node-cli" -version = "2.0.0" -authors = ["Parity Technologies "] -description = "Substrate node implementation in Rust." -build = "build.rs" -edition = "2018" - -[dependencies] -log = "0.4" -tokio = "0.1.7" -futures = "0.1" -exit-future = "0.1" -cli = { package = "substrate-cli", path = "../../core/cli" } -parity-codec = { version = "4.1.1" } -sr-io = { path = "../../core/sr-io" } -client = { package = "substrate-client", path = "../../core/client" } -primitives = { package = "substrate-primitives", path = "../../core/primitives" } -inherents = { package = "substrate-inherents", path = "../../core/inherents" } -node-runtime = { path = "../runtime" } -node-primitives = { path = "../primitives" } -hex-literal = "0.2" -substrate-basic-authorship = { path = "../../core/basic-authorship" } -substrate-service = { path = "../../core/service" } -transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" } -network = { package = "substrate-network", path = "../../core/network" } -aura = { package = "substrate-consensus-aura", path = "../../core/consensus/aura" } -aura_primitives = { package = "substrate-consensus-aura-primitives", path = "../../core/consensus/aura/primitives" } -grandpa = { package = "substrate-finality-grandpa", path = "../../core/finality-grandpa" } -grandpa_primitives = { package = "substrate-finality-grandpa-primitives", path = "../../core/finality-grandpa/primitives" } -sr-primitives = { path = "../../core/sr-primitives" } -node-executor = { path = "../executor" } -substrate-keystore = { path = "../../core/keystore" } -substrate-telemetry = { package = "substrate-telemetry", path = "../../core/telemetry" } -structopt = "0.2" -transaction-factory = { path = "../../test-utils/transaction-factory" } -keyring = { package = "substrate-keyring", path = "../../core/keyring" } -indices = { package = "srml-indices", path = "../../srml/indices" } -timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default-features = false } -rand = "0.6" -finality_tracker = { package = "srml-finality-tracker", path = "../../srml/finality-tracker", default-features = false } -contracts = { package = "srml-contracts", path = "../../srml/contracts" } -system = { package = "srml-system", path = "../../srml/system" } -balances = { package = "srml-balances", path = "../../srml/balances" } - -[dev-dependencies] -consensus-common = { package = "substrate-consensus-common", path = "../../core/consensus/common" } -service-test = { package = "substrate-service-test", path = "../../core/service/test" } - -[build-dependencies] -cli = { package = "substrate-cli", path = "../../core/cli" } -structopt = "0.2" diff --git a/node/cli/build.rs b/node/cli/build.rs deleted file mode 100644 index e7a7b271f1503..0000000000000 --- a/node/cli/build.rs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2017-2019 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate 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 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. If not, see . - -use cli::{NoCustom, CoreParams}; - -use std::{fs, env, path::Path}; - -use structopt::{StructOpt, clap::Shell}; - -fn main() { - build_shell_completion(); -} - -/// Build shell completion scripts for all known shells -/// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123 -fn build_shell_completion() { - for shell in &[Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] { - build_completion(shell); - } -} - -/// Build the shell auto-completion for a given Shell -fn build_completion(shell: &Shell) { - let outdir = match env::var_os("OUT_DIR") { - None => return, - Some(dir) => dir, - }; - let path = Path::new(&outdir) - .parent().unwrap() - .parent().unwrap() - .parent().unwrap() - .join("completion-scripts"); - - fs::create_dir(&path).ok(); - - CoreParams::::clap().gen_completions("substrate-node", *shell, &path); -} diff --git a/node/cli/doc/shell-completion.adoc b/node/doc/shell-completion.adoc similarity index 100% rename from node/cli/doc/shell-completion.adoc rename to node/doc/shell-completion.adoc diff --git a/node/cli/res/flaming-fir.json b/node/res/flaming-fir.json similarity index 100% rename from node/cli/res/flaming-fir.json rename to node/res/flaming-fir.json diff --git a/node/cli/src/chain_spec.rs b/node/src/chain_spec.rs similarity index 100% rename from node/cli/src/chain_spec.rs rename to node/src/chain_spec.rs diff --git a/node/cli/src/factory_impl.rs b/node/src/factory_impl.rs similarity index 100% rename from node/cli/src/factory_impl.rs rename to node/src/factory_impl.rs diff --git a/node/cli/src/lib.rs b/node/src/lib.rs similarity index 100% rename from node/cli/src/lib.rs rename to node/src/lib.rs diff --git a/node/src/main.rs b/node/src/main.rs index 15b603e7a2706..2e402e542829b 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -18,7 +18,7 @@ #![warn(missing_docs)] -use cli::VersionInfo; +use substrate_node_cli::VersionInfo; use futures::sync::oneshot; use futures::{future, Future}; @@ -26,7 +26,7 @@ use std::cell::RefCell; // handles ctrl-c struct Exit; -impl cli::IntoExit for Exit { +impl substrate_node_cli::IntoExit for Exit { type Exit = future::MapErr, fn(oneshot::Canceled) -> ()>; fn into_exit(self) -> Self::Exit { // can't use signal directly here because CtrlC takes only `Fn`. @@ -54,7 +54,7 @@ fn main() { support_url: "https://github.com/paritytech/substrate/issues/new", }; - if let Err(e) = cli::run(::std::env::args(), Exit, version) { + if let Err(e) = substrate_node_cli::run(::std::env::args(), Exit, version) { eprintln!("Error starting the node: {}\n\n{:?}", e, e); std::process::exit(1) } diff --git a/node/cli/src/service.rs b/node/src/service.rs similarity index 100% rename from node/cli/src/service.rs rename to node/src/service.rs diff --git a/test-utils/chain-spec-builder/Cargo.toml b/test-utils/chain-spec-builder/Cargo.toml index a54094d8c7920..dcdca9cf34105 100644 --- a/test-utils/chain-spec-builder/Cargo.toml +++ b/test-utils/chain-spec-builder/Cargo.toml @@ -6,6 +6,6 @@ edition = "2018" [dependencies] clap = { version = "~2.32", features = ["yaml"] } -node-cli = { path = "../../node/cli" } +substrate = { path = "../.." } substrate-primitives = { path = "../../core/primitives" } substrate-service = { path = "../../core/service" } diff --git a/test-utils/chain-spec-builder/src/main.rs b/test-utils/chain-spec-builder/src/main.rs index 211e8321e3fd1..9730629ee3c21 100644 --- a/test-utils/chain-spec-builder/src/main.rs +++ b/test-utils/chain-spec-builder/src/main.rs @@ -1,6 +1,6 @@ use clap::{App, load_yaml}; -use node_cli::chain_spec; +use substrate::chain_spec; use substrate_service::chain_ops::build_spec; fn genesis_constructor() -> chain_spec::GenesisConfig { From b10f097ff8f0e9c00dbef55711093c3135fe0b01 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 24 Jul 2019 14:04:44 +0200 Subject: [PATCH 02/10] Move executor inside node --- Cargo.lock | 42 +++++-------------- Cargo.toml | 21 +++++++++- core/service/Cargo.toml | 2 +- core/service/src/lib.rs | 2 +- node/executor/Cargo.toml | 36 ---------------- node/{executor/src/lib.rs => src/executor.rs} | 6 +-- node/src/lib.rs | 1 + node/src/service.rs | 4 +- 8 files changed, 38 insertions(+), 76 deletions(-) delete mode 100644 node/executor/Cargo.toml rename node/{executor/src/lib.rs => src/executor.rs} (99%) diff --git a/Cargo.lock b/Cargo.lock index e6e3226ad7731..689358c6910d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2241,35 +2241,6 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "node-executor" -version = "2.0.0" -dependencies = [ - "node-primitives 2.0.0", - "node-runtime 2.0.0", - "parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "sr-io 2.0.0", - "sr-primitives 2.0.0", - "srml-balances 2.0.0", - "srml-contracts 2.0.0", - "srml-grandpa 2.0.0", - "srml-indices 2.0.0", - "srml-session 2.0.0", - "srml-staking 2.0.0", - "srml-support 2.0.0", - "srml-system 2.0.0", - "srml-timestamp 2.0.0", - "srml-treasury 2.0.0", - "substrate-executor 2.0.0", - "substrate-keyring 2.0.0", - "substrate-primitives 2.0.0", - "substrate-state-machine 2.0.0", - "substrate-test-client 2.0.0", - "substrate-trie 2.0.0", - "trie-root 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "node-primitives" version = "2.0.0" @@ -4111,7 +4082,6 @@ dependencies = [ "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "node-executor 2.0.0", "node-primitives 2.0.0", "node-runtime 2.0.0", "parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4122,8 +4092,12 @@ dependencies = [ "srml-contracts 2.0.0", "srml-finality-tracker 2.0.0", "srml-indices 2.0.0", + "srml-session 2.0.0", + "srml-staking 2.0.0", + "srml-support 2.0.0", "srml-system 2.0.0", "srml-timestamp 2.0.0", + "srml-treasury 2.0.0", "structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-basic-authorship 2.0.0", "substrate-cli 2.0.0", @@ -4131,6 +4105,7 @@ dependencies = [ "substrate-consensus-aura 2.0.0", "substrate-consensus-aura-primitives 2.0.0", "substrate-consensus-common 2.0.0", + "substrate-executor 2.0.0", "substrate-finality-grandpa 2.0.0", "substrate-finality-grandpa-primitives 2.0.0", "substrate-inherents 2.0.0", @@ -4140,11 +4115,16 @@ dependencies = [ "substrate-primitives 2.0.0", "substrate-service 2.0.0", "substrate-service-test 2.0.0", + "substrate-state-machine 2.0.0", "substrate-telemetry 2.0.0", + "substrate-test-client 2.0.0", "substrate-transaction-pool 2.0.0", + "substrate-trie 2.0.0", "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "transaction-factory 0.0.1", + "trie-root 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4724,7 +4704,6 @@ dependencies = [ "futures-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "node-executor 2.0.0", "node-primitives 2.0.0", "node-runtime 2.0.0", "parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4735,6 +4714,7 @@ dependencies = [ "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", + "substrate 2.0.0", "substrate-client 2.0.0", "substrate-client-db 2.0.0", "substrate-consensus-common 2.0.0", diff --git a/Cargo.toml b/Cargo.toml index 366c4205063bb..628237e86ac06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,6 @@ aura_primitives = { package = "substrate-consensus-aura-primitives", path = "cor grandpa = { package = "substrate-finality-grandpa", path = "core/finality-grandpa" } grandpa_primitives = { package = "substrate-finality-grandpa-primitives", path = "core/finality-grandpa/primitives" } sr-primitives = { path = "core/sr-primitives" } -node-executor = { path = "node/executor" } substrate-keystore = { path = "core/keystore" } substrate-telemetry = { package = "substrate-telemetry", path = "core/telemetry" } structopt = "0.2" @@ -50,16 +49,35 @@ finality_tracker = { package = "srml-finality-tracker", path = "srml/finality-tr contracts = { package = "srml-contracts", path = "srml/contracts" } system = { package = "srml-system", path = "srml/system" } balances = { package = "srml-balances", path = "srml/balances" } +trie-root = "0.14.0" +state_machine = { package = "substrate-state-machine", path = "core/state-machine" } +substrate-executor = { path = "core/executor" } +trie = { package = "substrate-trie", path = "core/trie" } [dev-dependencies] consensus-common = { package = "substrate-consensus-common", path = "core/consensus/common" } service-test = { package = "substrate-service-test", path = "core/service/test" } +test-client = { package = "substrate-test-client", path = "core/test-client" } +keyring = { package = "substrate-keyring", path = "core/keyring" } +runtime_support = { package = "srml-support", path = "srml/support" } +balances = { package = "srml-balances", path = "srml/balances" } +session = { package = "srml-session", path = "srml/session" } +staking = { package = "srml-staking", path = "srml/staking" } +system = { package = "srml-system", path = "srml/system" } +timestamp = { package = "srml-timestamp", path = "srml/timestamp" } +treasury = { package = "srml-treasury", path = "srml/treasury" } +contracts = { package = "srml-contracts", path = "srml/contracts" } +indices = { package = "srml-indices", path = "srml/indices" } +wabt = "~0.7.4" [build-dependencies] cli = { package = "substrate-cli", path = "core/cli" } structopt = "0.2" vergen = "3" +[features] +benchmarks = [] + [workspace] members = [ "core/cli", @@ -129,7 +147,6 @@ members = [ "srml/system", "srml/timestamp", "srml/treasury", - "node/executor", "node/primitives", "node/runtime", "node/rpc-client", diff --git a/core/service/Cargo.toml b/core/service/Cargo.toml index 6a15e2eeb6c31..1cda77623c6ae 100644 --- a/core/service/Cargo.toml +++ b/core/service/Cargo.toml @@ -37,7 +37,7 @@ parity-multiaddr = { package = "parity-multiaddr", version = "0.5.0" } [dev-dependencies] substrate-test-runtime-client = { path = "../test-runtime/client" } -node-executor = { path = "../../node/executor" } +substrate = { path = "../.." } node-primitives = { path = "../../node/primitives" } node-runtime = { path = "../../node/runtime" } grandpa = { package = "substrate-finality-grandpa", path = "../../core/finality-grandpa" } diff --git a/core/service/src/lib.rs b/core/service/src/lib.rs index a38009120f9e7..e14b365c8e180 100644 --- a/core/service/src/lib.rs +++ b/core/service/src/lib.rs @@ -1022,7 +1022,7 @@ where /// RuntimeApi = RuntimeApi, /// // Declare the network protocol and give an initializer. /// NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) }, -/// RuntimeDispatch = node_executor::Executor, +/// RuntimeDispatch = substrate::executor::Executor, /// FullTransactionPoolApi = FullChainApi /// { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, /// LightTransactionPoolApi = LightChainApi diff --git a/node/executor/Cargo.toml b/node/executor/Cargo.toml deleted file mode 100644 index 345401141913c..0000000000000 --- a/node/executor/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "node-executor" -version = "2.0.0" -authors = ["Parity Technologies "] -description = "Substrate node implementation in Rust." -edition = "2018" - -[dependencies] -trie-root = "0.14.0" -parity-codec = "4.1.1" -runtime_io = { package = "sr-io", path = "../../core/sr-io" } -state_machine = { package = "substrate-state-machine", path = "../../core/state-machine" } -substrate-executor = { path = "../../core/executor" } -primitives = { package = "substrate-primitives", path = "../../core/primitives" } -trie = { package = "substrate-trie", path = "../../core/trie" } -node-primitives = { path = "../primitives" } -node-runtime = { path = "../runtime" } - -[dev-dependencies] -test-client = { package = "substrate-test-client", path = "../../core/test-client" } -keyring = { package = "substrate-keyring", path = "../../core/keyring" } -runtime_primitives = { package = "sr-primitives", path = "../../core/sr-primitives" } -runtime_support = { package = "srml-support", path = "../../srml/support" } -balances = { package = "srml-balances", path = "../../srml/balances" } -session = { package = "srml-session", path = "../../srml/session" } -staking = { package = "srml-staking", path = "../../srml/staking" } -system = { package = "srml-system", path = "../../srml/system" } -timestamp = { package = "srml-timestamp", path = "../../srml/timestamp" } -treasury = { package = "srml-treasury", path = "../../srml/treasury" } -contracts = { package = "srml-contracts", path = "../../srml/contracts" } -grandpa = { package = "srml-grandpa", path = "../../srml/grandpa" } -indices = { package = "srml-indices", path = "../../srml/indices" } -wabt = "~0.7.4" - -[features] -benchmarks = [] diff --git a/node/executor/src/lib.rs b/node/src/executor.rs similarity index 99% rename from node/executor/src/lib.rs rename to node/src/executor.rs index b55461492625d..f046e99c3866c 100644 --- a/node/executor/src/lib.rs +++ b/node/src/executor.rs @@ -47,9 +47,9 @@ mod tests { NativeOrEncoded }; use node_primitives::{Hash, BlockNumber, AccountId, Balance, Index}; - use runtime_primitives::traits::{Header as HeaderT, Hash as HashT}; - use runtime_primitives::{generic::Era, ApplyOutcome, ApplyError, ApplyResult, Perbill}; - use runtime_primitives::weights::{WeightMultiplier, SimpleDispatchInfo, WeighData}; + use sr_primitives::traits::{Header as HeaderT, Hash as HashT}; + use sr_primitives::{generic::Era, ApplyOutcome, ApplyError, ApplyResult, Perbill}; + use sr_primitives::weights::{WeightMultiplier, SimpleDispatchInfo, WeighData}; use {balances, contracts, indices, staking, system, timestamp}; use contracts::ContractAddressFor; use system::{EventRecord, Phase}; diff --git a/node/src/lib.rs b/node/src/lib.rs index b18fa57411ce5..2011506a846c6 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -21,6 +21,7 @@ pub use cli::error; pub mod chain_spec; +mod executor; mod service; mod factory_impl; diff --git a/node/src/service.rs b/node/src/service.rs index 53d6f927b485b..81d0090bf297b 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -21,10 +21,10 @@ use std::sync::Arc; use std::time::Duration; +use crate::executor; use aura::{import_queue, start_aura, AuraImportQueue, SlotDuration}; use client::{self, LongestChain}; use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider}; -use node_executor; use primitives::Pair; use grandpa_primitives::AuthorityPair as GrandpaPair; use futures::prelude::*; @@ -71,7 +71,7 @@ construct_service_factory! { FinalityPair = GrandpaPair, RuntimeApi = RuntimeApi, NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) }, - RuntimeDispatch = node_executor::Executor, + RuntimeDispatch = executor::Executor, FullTransactionPoolApi = transaction_pool::ChainApi, FullExecutor, Block, RuntimeApi>, Block> { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, LightTransactionPoolApi = transaction_pool::ChainApi, LightExecutor, Block, RuntimeApi>, Block> From e7980cb2368d96c1ec30a7edf6c29d899587ee58 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 24 Jul 2019 14:08:21 +0200 Subject: [PATCH 03/10] Move main.rs to src/bin/ --- Cargo.toml | 2 +- node/src/{ => bin}/main.rs | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename node/src/{ => bin}/main.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 628237e86ac06..f49bb93c27deb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [[bin]] name = "substrate" -path = "node/src/main.rs" +path = "node/src/bin/main.rs" [lib] name = "substrate_node_cli" diff --git a/node/src/main.rs b/node/src/bin/main.rs similarity index 100% rename from node/src/main.rs rename to node/src/bin/main.rs From 59c5206c9e22e30cc27a76a9aea2a3e4b6d2de11 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 24 Jul 2019 14:37:41 +0200 Subject: [PATCH 04/10] Fix node-rpc-client --- Cargo.lock | 2 +- node/rpc-client/Cargo.toml | 2 +- node/rpc-client/src/main.rs | 2 +- node/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 689358c6910d2..eda1f254368f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2263,7 +2263,7 @@ dependencies = [ "hyper 0.12.31 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core-client 12.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "node-primitives 2.0.0", + "substrate 2.0.0", "substrate-rpc 2.0.0", ] diff --git a/node/rpc-client/Cargo.toml b/node/rpc-client/Cargo.toml index ea255808e463e..e61a39c67bcf2 100644 --- a/node/rpc-client/Cargo.toml +++ b/node/rpc-client/Cargo.toml @@ -10,5 +10,5 @@ futures = "0.1.26" hyper = "0.12" jsonrpc-core-client = { version = "12.0.0", features = ["http", "ws"] } log = "0.4" -node-primitives = { path = "../primitives" } +substrate = { path = "../.." } substrate-rpc = { path = "../../core/rpc", version = "2.0.0" } diff --git a/node/rpc-client/src/main.rs b/node/rpc-client/src/main.rs index fe057bcbeaf42..f569455dca171 100644 --- a/node/rpc-client/src/main.rs +++ b/node/rpc-client/src/main.rs @@ -23,7 +23,7 @@ use futures::Future; use hyper::rt; -use node_primitives::Hash; +use substrate::primitives::Hash; use substrate_rpc::author::{ AuthorClient, hash::ExtrinsicOrHash, diff --git a/node/src/lib.rs b/node/src/lib.rs index 2011506a846c6..08ca20fb89eb3 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -21,7 +21,7 @@ pub use cli::error; pub mod chain_spec; -mod executor; +pub mod executor; mod service; mod factory_impl; From ed70fd1f921b4441cd02e98cbafce7532ca95d24 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 24 Jul 2019 14:40:59 +0200 Subject: [PATCH 05/10] Fix rpc-client again --- Cargo.lock | 2 +- node/rpc-client/Cargo.toml | 2 +- node/rpc-client/src/main.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eda1f254368f6..689358c6910d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2263,7 +2263,7 @@ dependencies = [ "hyper 0.12.31 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core-client 12.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "substrate 2.0.0", + "node-primitives 2.0.0", "substrate-rpc 2.0.0", ] diff --git a/node/rpc-client/Cargo.toml b/node/rpc-client/Cargo.toml index e61a39c67bcf2..ea255808e463e 100644 --- a/node/rpc-client/Cargo.toml +++ b/node/rpc-client/Cargo.toml @@ -10,5 +10,5 @@ futures = "0.1.26" hyper = "0.12" jsonrpc-core-client = { version = "12.0.0", features = ["http", "ws"] } log = "0.4" -substrate = { path = "../.." } +node-primitives = { path = "../primitives" } substrate-rpc = { path = "../../core/rpc", version = "2.0.0" } diff --git a/node/rpc-client/src/main.rs b/node/rpc-client/src/main.rs index f569455dca171..fe057bcbeaf42 100644 --- a/node/rpc-client/src/main.rs +++ b/node/rpc-client/src/main.rs @@ -23,7 +23,7 @@ use futures::Future; use hyper::rt; -use substrate::primitives::Hash; +use node_primitives::Hash; use substrate_rpc::author::{ AuthorClient, hash::ExtrinsicOrHash, From 7c2ab0a32158e118cbef134e9c35df465b8c5c31 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 24 Jul 2019 14:47:24 +0200 Subject: [PATCH 06/10] Line widths --- node/src/service.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/node/src/service.rs b/node/src/service.rs index 81d0090bf297b..1aef21e64bb6a 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -72,10 +72,12 @@ construct_service_factory! { RuntimeApi = RuntimeApi, NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) }, RuntimeDispatch = executor::Executor, - FullTransactionPoolApi = transaction_pool::ChainApi, FullExecutor, Block, RuntimeApi>, Block> - { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, - LightTransactionPoolApi = transaction_pool::ChainApi, LightExecutor, Block, RuntimeApi>, Block> - { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, + FullTransactionPoolApi = transaction_pool::ChainApi< + client::Client, FullExecutor, Block, RuntimeApi>, Block + > { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, + LightTransactionPoolApi = transaction_pool::ChainApi< + client::Client, LightExecutor, Block, RuntimeApi>, Block + > { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, Genesis = GenesisConfig, Configuration = NodeConfig, FullService = FullComponents @@ -159,7 +161,9 @@ construct_service_factory! { LightService = LightComponents { |config| >::new(config) }, FullImportQueue = AuraImportQueue - { |config: &mut FactoryFullConfiguration , client: Arc>, select_chain: Self::SelectChain| { + { |config: &mut FactoryFullConfiguration, + client: Arc>, + select_chain: Self::SelectChain| { let slot_duration = SlotDuration::get_or_compute(&*client)?; let (block_import, link_half) = grandpa::block_import::<_, _, _, RuntimeApi, FullClient, _>( From 25952e5014ce6e66b0b93f1c43f68c4581a6b079 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 24 Jul 2019 14:49:23 +0200 Subject: [PATCH 07/10] Fix integration tests --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 832b7541625a9..5c1a3b2ebd4e6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -161,7 +161,7 @@ test-linux-stable-int: - echo "___Logs will be partly shown at the end in case of failure.___" - echo "___Full log will be saved to the job artifacts only in case of failure.___" - RUST_LOG=sync=trace,consensus=trace,client=trace,state-db=trace,db=trace,forks=trace,state_db=trace,storage_cache=trace - time cargo test -p node-cli --release --verbose --locked -- --ignored --test-threads=1 + time cargo test -p substrate --release --verbose --locked -- --ignored --test-threads=1 &> ${CI_COMMIT_SHORT_SHA}_int_failure.log - sccache -s after_script: From d6cd1ddbc01d37c6fb09d2b8a2674e6122526d97 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 24 Jul 2019 14:58:27 +0200 Subject: [PATCH 08/10] Fix tests --- node/src/executor.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/node/src/executor.rs b/node/src/executor.rs index f046e99c3866c..82d6b23538f3c 100644 --- a/node/src/executor.rs +++ b/node/src/executor.rs @@ -35,7 +35,6 @@ native_executor_instance!( #[cfg(test)] mod tests { - use runtime_io; use super::Executor; use substrate_executor::{WasmExecutor, NativeExecutionDispatch}; use parity_codec::{Encode, Decode, Joiner}; @@ -129,7 +128,7 @@ mod tests { let key = AccountKeyring::from_public(&signed).unwrap(); let signature = payload.using_encoded(|b| { if b.len() > 256 { - key.sign(&runtime_io::blake2_256(b)) + key.sign(&sr_io::blake2_256(b)) } else { key.sign(b) } @@ -272,7 +271,7 @@ mod tests { ).0; assert!(r.is_ok()); - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt()) - creation_fee()); assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS); }); @@ -308,7 +307,7 @@ mod tests { ).0; assert!(r.is_ok()); - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt()) - creation_fee()); assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS); }); @@ -540,7 +539,7 @@ mod tests { None, ).0.unwrap(); - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt()) - creation_fee()); assert_eq!(Balances::total_balance(&bob()), 169 * DOLLARS); let events = vec![ @@ -575,7 +574,7 @@ mod tests { None, ).0.unwrap(); - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { // TODO TODO: this needs investigating: why are we deducting creation fee twice here? and why bob also pays it? assert_eq!(Balances::total_balance(&alice()), 32 * DOLLARS - 2 * transfer_fee(&xt()) - 2 * creation_fee()); assert_eq!(Balances::total_balance(&bob()), 179 * DOLLARS - transfer_fee(&xt()) - creation_fee()); @@ -632,14 +631,14 @@ mod tests { WasmExecutor::new().call(&mut t, 8, COMPACT_CODE, "Core_execute_block", &block1.0).unwrap(); - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt()) - creation_fee()); assert_eq!(Balances::total_balance(&bob()), 169 * DOLLARS); }); WasmExecutor::new().call(&mut t, 8, COMPACT_CODE, "Core_execute_block", &block2.0).unwrap(); - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { assert_eq!(Balances::total_balance(&alice()), 32 * DOLLARS - 2 * transfer_fee(&xt()) - 2 * creation_fee()); assert_eq!(Balances::total_balance(&bob()), 179 * DOLLARS - 1 * transfer_fee(&xt()) - creation_fee()); }); @@ -787,7 +786,7 @@ mod tests { WasmExecutor::new().call(&mut t, 8, COMPACT_CODE,"Core_execute_block", &b.0).unwrap(); - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { // Verify that the contract constructor worked well and code of TRANSFER contract is actually deployed. assert_eq!( &contracts::ContractInfoOf::::get(addr) @@ -885,7 +884,7 @@ mod tests { let r = ApplyResult::decode(&mut &r[..]).unwrap(); assert_eq!(r, Ok(ApplyOutcome::Success)); - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - 1 * transfer_fee(&xt()) - creation_fee()); assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS); }); @@ -942,7 +941,7 @@ mod tests { let mut prev_multiplier = WeightMultiplier::default(); - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { assert_eq!(System::next_weight_multiplier(), prev_multiplier); }); @@ -995,7 +994,7 @@ mod tests { ).0.unwrap(); // weight multiplier is increased for next block. - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { let fm = System::next_weight_multiplier(); println!("After a big block: {:?} -> {:?}", prev_multiplier, fm); assert!(fm > prev_multiplier); @@ -1012,7 +1011,7 @@ mod tests { ).0.unwrap(); // weight multiplier is increased for next block. - runtime_io::with_externalities(&mut t, || { + sr_io::with_externalities(&mut t, || { let fm = System::next_weight_multiplier(); println!("After a small block: {:?} -> {:?}", prev_multiplier, fm); assert!(fm < prev_multiplier); From 859078eaf744e7cda11771eda5fffcb82c11a843 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 24 Jul 2019 15:08:57 +0200 Subject: [PATCH 09/10] Fix chain-spec-builder --- test-utils/chain-spec-builder/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-utils/chain-spec-builder/src/main.rs b/test-utils/chain-spec-builder/src/main.rs index 9730629ee3c21..b0b08a18942d6 100644 --- a/test-utils/chain-spec-builder/src/main.rs +++ b/test-utils/chain-spec-builder/src/main.rs @@ -1,6 +1,6 @@ use clap::{App, load_yaml}; -use substrate::chain_spec; +use substrate_node_cli::chain_spec; use substrate_service::chain_ops::build_spec; fn genesis_constructor() -> chain_spec::GenesisConfig { From 0e2b2fadf881a71ccf0184cc8db9bf80733e9673 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 24 Jul 2019 15:29:02 +0200 Subject: [PATCH 10/10] Fix service doctest --- core/service/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/service/src/lib.rs b/core/service/src/lib.rs index e14b365c8e180..daeeafc3f9e95 100644 --- a/core/service/src/lib.rs +++ b/core/service/src/lib.rs @@ -1022,7 +1022,7 @@ where /// RuntimeApi = RuntimeApi, /// // Declare the network protocol and give an initializer. /// NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) }, -/// RuntimeDispatch = substrate::executor::Executor, +/// RuntimeDispatch = substrate_node_cli::executor::Executor, /// FullTransactionPoolApi = FullChainApi /// { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, /// LightTransactionPoolApi = LightChainApi