diff --git a/Cargo.lock b/Cargo.lock index 08e5102d3402a..16fd7d44858a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3396,6 +3396,7 @@ dependencies = [ "sp-runtime", "sp-timestamp", "sp-transaction-pool", + "sp-version", "structopt", "substrate-browser-utils", "substrate-build-script-utils", @@ -3601,6 +3602,7 @@ dependencies = [ "sp-inherents", "sp-runtime", "sp-transaction-pool", + "sp-version", "structopt", "substrate-build-script-utils", ] diff --git a/bin/node-template/node/Cargo.toml b/bin/node-template/node/Cargo.toml index 52fc1b4f8dacc..f74b2a3fa14a5 100644 --- a/bin/node-template/node/Cargo.toml +++ b/bin/node-template/node/Cargo.toml @@ -38,6 +38,7 @@ sp-finality-grandpa = { version = "2.0.0-rc3", path = "../../../primitives/final sc-client-api = { version = "2.0.0-rc3", path = "../../../client/api" } sp-runtime = { version = "2.0.0-rc3", path = "../../../primitives/runtime" } sc-basic-authorship = { path = "../../../client/basic-authorship", version = "0.8.0-rc3"} +sp-version = { version = "2.0.0-rc3", path = "../../../primitives/version" } node-template-runtime = { version = "2.0.0-rc3", path = "../runtime" } diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index 634a12d2dd17a..4f0d486f01f3e 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -20,6 +20,7 @@ use crate::cli::Cli; use crate::service; use sc_cli::SubstrateCli; use sc_service::Role; +use sp_version::RuntimeVersion; impl SubstrateCli for Cli { fn impl_name() -> &'static str { @@ -59,6 +60,10 @@ impl SubstrateCli for Cli { )?), }) } + + fn runtime_version() -> &'static RuntimeVersion { + &node_template_runtime::VERSION + } } /// Parse and run command line arguments @@ -72,13 +77,10 @@ pub fn run() -> sc_cli::Result<()> { } None => { let runner = cli.create_runner(&cli.run)?; - runner.run_node_until_exit( - |config| match config.role { - Role::Light => service::new_light(config), - _ => service::new_full(config), - }, - node_template_runtime::VERSION, - ) + runner.run_node_until_exit(|config| match config.role { + Role::Light => service::new_light(config), + _ => service::new_full(config), + }) } } } diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 4e2c0151b7ea5..ab201690fbcc0 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -58,6 +58,7 @@ sp-keyring = { version = "2.0.0-rc3", path = "../../../primitives/keyring" } sp-io = { version = "2.0.0-rc3", path = "../../../primitives/io" } sp-consensus = { version = "0.8.0-rc3", path = "../../../primitives/consensus/common" } sp-transaction-pool = { version = "2.0.0-rc3", path = "../../../primitives/transaction-pool" } +sp-version = { version = "2.0.0-rc3", path = "../../../primitives/version" } # client dependencies sc-client-api = { version = "2.0.0-rc3", path = "../../../client/api" } diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index 4ae4229ba54df..9de38d1116444 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -21,6 +21,7 @@ use node_executor::Executor; use node_runtime::{Block, RuntimeApi}; use sc_cli::{Result, SubstrateCli}; use sc_service::Role; +use sp_version::RuntimeVersion; impl SubstrateCli for Cli { fn impl_name() -> &'static str { @@ -62,6 +63,10 @@ impl SubstrateCli for Cli { )?), }) } + + fn runtime_version() -> &'static RuntimeVersion { + &node_runtime::VERSION + } } /// Parse command line arguments into service configuration. @@ -71,13 +76,10 @@ pub fn run() -> Result<()> { match &cli.subcommand { None => { let runner = cli.create_runner(&cli.run)?; - runner.run_node_until_exit( - |config| match config.role { - Role::Light => service::new_light(config), - _ => service::new_full(config), - }, - node_runtime::VERSION, - ) + runner.run_node_until_exit(|config| match config.role { + Role::Light => service::new_light(config), + _ => service::new_full(config), + }) } Some(Subcommand::Inspect(cmd)) => { let runner = cli.create_runner(cmd)?; diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 9623b08bfbb7f..da85e4ee16999 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -38,6 +38,7 @@ pub use params::*; use regex::Regex; pub use runner::*; use sc_service::{ChainSpec, Configuration, TaskExecutor}; +use sp_version::RuntimeVersion; use std::io::Write; pub use structopt; use structopt::{ @@ -207,6 +208,9 @@ pub trait SubstrateCli: Sized { command.init::()?; Runner::new(self, command) } + + /// Runtime version. + fn runtime_version() -> &'static RuntimeVersion; } /// Initialize the logger diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index aedd41073bc09..a1484e4f7c8a8 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -28,7 +28,6 @@ use log::info; use sc_service::{Configuration, ServiceBuilderCommand, TaskType, TaskManager}; use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; use sp_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL}; -use sp_version::RuntimeVersion; use std::{fmt::Debug, marker::PhantomData, str::FromStr}; #[cfg(target_family = "unix")] @@ -153,7 +152,7 @@ impl Runner { /// 2020-06-03 16:14:21 💾 Database: RocksDb at /tmp/c/chains/flamingfir7/db /// 2020-06-03 16:14:21 ⛓ Native runtime: node-251 (substrate-node-1.tx1.au10) /// ``` - fn print_node_infos(&self, runtime_version: RuntimeVersion) { + fn print_node_infos(&self) { info!("{}", C::impl_name()); info!("✌️ version {}", C::impl_version()); info!( @@ -169,7 +168,7 @@ impl Runner { self.config.database, self.config.database.path().map_or_else(|| "".to_owned(), |p| p.display().to_string()) ); - info!("⛓ Native runtime: {}", runtime_version); + info!("⛓ Native runtime: {}", C::runtime_version()); } /// A helper function that runs a future with tokio and stops if the process receives the signal @@ -205,9 +204,8 @@ impl Runner { pub fn run_node_until_exit( mut self, initialise: impl FnOnce(Configuration) -> sc_service::error::Result, - runtime_version: RuntimeVersion, ) -> Result<()> { - self.print_node_infos(runtime_version); + self.print_node_infos(); let mut task_manager = initialise(self.config)?; self.tokio_runtime.block_on(main(task_manager.future().fuse())) .map_err(|e| e.to_string())?;