From 1bf2504ebf47bb4531d15ee1b33c1fe5443b36b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= <git@kchr.de> Date: Wed, 5 Jul 2023 09:38:06 +0200 Subject: [PATCH] sc-cli: Remove `SubstrateCli::native_runtime_version` function (#14511) The native runtime will be removed in the near future and thus this function will not be required anymore. \# Code changes Downstream users just need to remove `native_runtime_version` from their implementation of the `SubstrateCli` trait. --- .../bin/node-template/node/src/command.rs | 6 +--- substrate/bin/node/cli/src/command.rs | 6 +--- substrate/bin/node/executor/benches/bench.rs | 8 +++--- .../client/cli/src/commands/insert_key.rs | 4 --- substrate/client/cli/src/lib.rs | 2 -- substrate/client/cli/src/runner.rs | 28 ++----------------- 6 files changed, 9 insertions(+), 45 deletions(-) diff --git a/substrate/bin/node-template/node/src/command.rs b/substrate/bin/node-template/node/src/command.rs index 6ea0f0b750e..8fc697b5f9c 100644 --- a/substrate/bin/node-template/node/src/command.rs +++ b/substrate/bin/node-template/node/src/command.rs @@ -6,7 +6,7 @@ use crate::{ }; use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE}; use node_template_runtime::{Block, EXISTENTIAL_DEPOSIT}; -use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli}; +use sc_cli::SubstrateCli; use sc_service::PartialComponents; use sp_keyring::Sr25519Keyring; @@ -46,10 +46,6 @@ impl SubstrateCli for Cli { Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), }) } - - fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion { - &node_template_runtime::VERSION - } } /// Parse and run command line arguments diff --git a/substrate/bin/node/cli/src/command.rs b/substrate/bin/node/cli/src/command.rs index 941b9031fb1..b138b397eff 100644 --- a/substrate/bin/node/cli/src/command.rs +++ b/substrate/bin/node/cli/src/command.rs @@ -26,7 +26,7 @@ use frame_benchmarking_cli::*; use kitchensink_runtime::{ExistentialDeposit, RuntimeApi}; use node_executor::ExecutorDispatch; use node_primitives::Block; -use sc_cli::{ChainSpec, Result, RuntimeVersion, SubstrateCli}; +use sc_cli::{Result, SubstrateCli}; use sc_service::PartialComponents; use sp_keyring::Sr25519Keyring; @@ -79,10 +79,6 @@ impl SubstrateCli for Cli { }; Ok(spec) } - - fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion { - &kitchensink_runtime::VERSION - } } /// Parse command line arguments into service configuration. diff --git a/substrate/bin/node/executor/benches/bench.rs b/substrate/bin/node/executor/benches/bench.rs index 6b082744e49..1c9c002492c 100644 --- a/substrate/bin/node/executor/benches/bench.rs +++ b/substrate/bin/node/executor/benches/bench.rs @@ -19,8 +19,8 @@ use codec::{Decode, Encode}; use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use frame_support::Hashable; use kitchensink_runtime::{ - constants::currency::*, Block, BuildStorage, CheckedExtrinsic, GenesisConfig, Header, - RuntimeCall, UncheckedExtrinsic, + constants::currency::*, Block, BuildStorage, CheckedExtrinsic, Header, RuntimeCall, + RuntimeGenesisConfig, UncheckedExtrinsic, }; use node_executor::ExecutorDispatch; use node_primitives::{BlockNumber, Hash}; @@ -67,7 +67,7 @@ fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic { node_testing::keyring::sign(xt, SPEC_VERSION, TRANSACTION_VERSION, GENESIS_HASH) } -fn new_test_ext(genesis_config: &GenesisConfig) -> TestExternalities<BlakeTwo256> { +fn new_test_ext(genesis_config: &RuntimeGenesisConfig) -> TestExternalities<BlakeTwo256> { let mut test_ext = TestExternalities::new_with_code( compact_code_unwrap(), genesis_config.build_storage().unwrap(), @@ -157,7 +157,7 @@ fn construct_block<E: Externalities>( } fn test_blocks( - genesis_config: &GenesisConfig, + genesis_config: &RuntimeGenesisConfig, executor: &NativeElseWasmExecutor<ExecutorDispatch>, ) -> Vec<(Vec<u8>, Hash)> { let mut test_ext = new_test_ext(genesis_config); diff --git a/substrate/client/cli/src/commands/insert_key.rs b/substrate/client/cli/src/commands/insert_key.rs index fa9d125d331..732d874319a 100644 --- a/substrate/client/cli/src/commands/insert_key.rs +++ b/substrate/client/cli/src/commands/insert_key.rs @@ -125,10 +125,6 @@ mod tests { "test".into() } - fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static sp_version::RuntimeVersion { - unimplemented!("Not required in tests") - } - fn load_spec(&self, _: &str) -> std::result::Result<Box<dyn ChainSpec>, String> { Ok(Box::new(GenericChainSpec::from_genesis( "test", diff --git a/substrate/client/cli/src/lib.rs b/substrate/client/cli/src/lib.rs index 5d451bbed65..0ef2ee7b182 100644 --- a/substrate/client/cli/src/lib.rs +++ b/substrate/client/cli/src/lib.rs @@ -248,6 +248,4 @@ pub trait SubstrateCli: Sized { command.init(&Self::support_url(), &Self::impl_version(), logger_hook, &config)?; Runner::new(config, tokio_runtime, signals) } - /// Native runtime version. - fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion; } diff --git a/substrate/client/cli/src/runner.rs b/substrate/client/cli/src/runner.rs index 7b534b37192..66c3fe41b6c 100644 --- a/substrate/client/cli/src/runner.rs +++ b/substrate/client/cli/src/runner.rs @@ -187,23 +187,18 @@ pub fn print_node_infos<C: SubstrateCli>(config: &Configuration) { .path() .map_or_else(|| "<unknown>".to_owned(), |p| p.display().to_string()) ); - info!("⛓ Native runtime: {}", C::native_runtime_version(&config.chain_spec)); } #[cfg(test)] mod tests { + use super::*; + use sc_network::config::NetworkConfiguration; + use sc_service::{Arc, ChainType, GenericChainSpec, NoExtension}; use std::{ path::PathBuf, sync::atomic::{AtomicU64, Ordering}, }; - use sc_network::config::NetworkConfiguration; - use sc_service::{Arc, ChainType, GenericChainSpec, NoExtension}; - use sp_runtime::create_runtime_str; - use sp_version::create_apis_vec; - - use super::*; - struct Cli; impl SubstrateCli for Cli { @@ -237,23 +232,6 @@ mod tests { ) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> { Err("nope".into()) } - - fn native_runtime_version( - _: &Box<dyn sc_service::ChainSpec>, - ) -> &'static sp_version::RuntimeVersion { - const VERSION: sp_version::RuntimeVersion = sp_version::RuntimeVersion { - spec_name: create_runtime_str!("spec"), - impl_name: create_runtime_str!("name"), - authoring_version: 0, - spec_version: 0, - impl_version: 0, - apis: create_apis_vec!([]), - transaction_version: 2, - state_version: 0, - }; - - &VERSION - } } fn create_runner() -> Runner<Cli> { -- GitLab