Substrate Companion #9737 (#3830)

Co-authored-by: parity-processbot <>
Co-authored-by: kianenigma <kian@parity.io>
This commit is contained in:
Bastian Köcher
2021-09-12 15:25:58 +02:00
committed by GitHub
parent 3693eb8744
commit a2cea3a314
8 changed files with 187 additions and 186 deletions
+157 -155
View File
File diff suppressed because it is too large Load Diff
+2 -3
View File
@@ -410,9 +410,8 @@ pub fn run() -> Result<()> {
use sc_service::TaskManager; use sc_service::TaskManager;
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry); let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager = let task_manager = TaskManager::new(runner.config().tokio_handle.clone(), *registry)
TaskManager::new(runner.config().task_executor.clone(), *registry) .map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?;
.map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?;
ensure_dev(chain_spec).map_err(Error::Other)?; ensure_dev(chain_spec).map_err(Error::Other)?;
@@ -33,8 +33,7 @@ use sp_runtime::{app_crypto::sp_core::H256, generic::Era, AccountId32};
use std::{error::Error, future::Future, str::FromStr}; use std::{error::Error, future::Future, str::FromStr};
use support::{weights::Weight, StorageValue}; use support::{weights::Weight, StorageValue};
use test_runner::{ use test_runner::{
build_runtime, client_parts, task_executor, ChainInfo, ConfigOrChainSpec, Node, build_runtime, client_parts, ChainInfo, ConfigOrChainSpec, Node, SignatureVerificationOverride,
SignatureVerificationOverride,
}; };
type BlockImport<B, BE, C, SC> = BabeBlockImport<B, C, GrandpaBlockImport<BE, B, C, SC>>; type BlockImport<B, BE, C, SC> = BabeBlockImport<B, C, GrandpaBlockImport<BE, B, C, SC>>;
@@ -360,7 +359,6 @@ where
use structopt::StructOpt; use structopt::StructOpt;
let tokio_runtime = build_runtime()?; let tokio_runtime = build_runtime()?;
let task_executor = task_executor(tokio_runtime.handle().clone());
// parse cli args // parse cli args
let cmd = <polkadot_cli::Cli as StructOpt>::from_args(); let cmd = <polkadot_cli::Cli as StructOpt>::from_args();
// set up logging // set up logging
@@ -369,7 +367,7 @@ where
logger.init()?; logger.init()?;
// set up the test-runner // set up the test-runner
let config = cmd.create_configuration(&cmd.run.base, task_executor)?; let config = cmd.create_configuration(&cmd.run.base, tokio_runtime.handle().clone())?;
sc_cli::print_node_infos::<polkadot_cli::Cli>(&config); sc_cli::print_node_infos::<polkadot_cli::Cli>(&config);
let (rpc, task_manager, client, pool, command_sink, backend) = let (rpc, task_manager, client, pool, command_sink, backend) =
client_parts::<PolkadotChainInfo>(ConfigOrChainSpec::Config(config))?; client_parts::<PolkadotChainInfo>(ConfigOrChainSpec::Config(config))?;
@@ -392,11 +390,10 @@ mod tests {
#[test] #[test]
fn test_runner() { fn test_runner() {
let runtime = build_runtime().unwrap(); let runtime = build_runtime().unwrap();
let task_executor = task_executor(runtime.handle().clone());
let (rpc, task_manager, client, pool, command_sink, backend) = let (rpc, task_manager, client, pool, command_sink, backend) =
client_parts::<PolkadotChainInfo>(ConfigOrChainSpec::ChainSpec( client_parts::<PolkadotChainInfo>(ConfigOrChainSpec::ChainSpec(
Box::new(polkadot_development_config().unwrap()), Box::new(polkadot_development_config().unwrap()),
task_executor, runtime.handle().clone(),
)) ))
.unwrap(); .unwrap();
let node = let node =
+1
View File
@@ -11,6 +11,7 @@ hex = "0.4.3"
tracing = "0.1.26" tracing = "0.1.26"
rand = "0.8.3" rand = "0.8.3"
tempfile = "3.2.0" tempfile = "3.2.0"
tokio = "1.10.0"
# Polkadot dependencies # Polkadot dependencies
polkadot-overseer = { path = "../../overseer" } polkadot-overseer = { path = "../../overseer" }
+7 -9
View File
@@ -41,8 +41,7 @@ use sc_network::{
}; };
use service::{ use service::{
config::{DatabaseSource, KeystoreConfig, MultiaddrWithPeerId, WasmExecutionMethod}, config::{DatabaseSource, KeystoreConfig, MultiaddrWithPeerId, WasmExecutionMethod},
BasePath, Configuration, KeepBlocks, Role, RpcHandlers, TaskExecutor, TaskManager, BasePath, Configuration, KeepBlocks, Role, RpcHandlers, TaskManager, TransactionStorageMode,
TransactionStorageMode,
}; };
use sp_arithmetic::traits::SaturatedConversion; use sp_arithmetic::traits::SaturatedConversion;
use sp_blockchain::HeaderBackend; use sp_blockchain::HeaderBackend;
@@ -112,7 +111,7 @@ impl ClientHandle for TestClient {
/// and can be used to make adjustments to the runtime genesis storage. /// and can be used to make adjustments to the runtime genesis storage.
pub fn node_config( pub fn node_config(
storage_update_func: impl Fn(), storage_update_func: impl Fn(),
task_executor: TaskExecutor, tokio_handle: tokio::runtime::Handle,
key: Sr25519Keyring, key: Sr25519Keyring,
boot_nodes: Vec<MultiaddrWithPeerId>, boot_nodes: Vec<MultiaddrWithPeerId>,
is_validator: bool, is_validator: bool,
@@ -149,7 +148,7 @@ pub fn node_config(
impl_name: "polkadot-test-node".to_string(), impl_name: "polkadot-test-node".to_string(),
impl_version: "0.1".to_string(), impl_version: "0.1".to_string(),
role, role,
task_executor, tokio_handle,
transaction_pool: Default::default(), transaction_pool: Default::default(),
network: network_config, network: network_config,
keystore: KeystoreConfig::InMemory, keystore: KeystoreConfig::InMemory,
@@ -171,7 +170,6 @@ pub fn node_config(
offchain_worker: sc_client_api::ExecutionStrategy::NativeWhenPossible, offchain_worker: sc_client_api::ExecutionStrategy::NativeWhenPossible,
other: sc_client_api::ExecutionStrategy::NativeWhenPossible, other: sc_client_api::ExecutionStrategy::NativeWhenPossible,
}, },
rpc_http_threads: None,
rpc_http: None, rpc_http: None,
rpc_ws: None, rpc_ws: None,
rpc_ipc: None, rpc_ipc: None,
@@ -204,13 +202,13 @@ pub fn node_config(
/// The `storage_update_func` function will be executed in an externalities provided environment /// The `storage_update_func` function will be executed in an externalities provided environment
/// and can be used to make adjustments to the runtime genesis storage. /// and can be used to make adjustments to the runtime genesis storage.
pub fn run_validator_node( pub fn run_validator_node(
task_executor: TaskExecutor, tokio_handle: tokio::runtime::Handle,
key: Sr25519Keyring, key: Sr25519Keyring,
storage_update_func: impl Fn(), storage_update_func: impl Fn(),
boot_nodes: Vec<MultiaddrWithPeerId>, boot_nodes: Vec<MultiaddrWithPeerId>,
worker_program_path: Option<PathBuf>, worker_program_path: Option<PathBuf>,
) -> PolkadotTestNode { ) -> PolkadotTestNode {
let config = node_config(storage_update_func, task_executor, key, boot_nodes, true); let config = node_config(storage_update_func, tokio_handle, key, boot_nodes, true);
let multiaddr = config.network.listen_addresses[0].clone(); let multiaddr = config.network.listen_addresses[0].clone();
let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } = let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } =
new_full(config, IsCollator::No, worker_program_path) new_full(config, IsCollator::No, worker_program_path)
@@ -236,13 +234,13 @@ pub fn run_validator_node(
/// The collator functionality still needs to be registered at the node! This can be done using /// The collator functionality still needs to be registered at the node! This can be done using
/// [`PolkadotTestNode::register_collator`]. /// [`PolkadotTestNode::register_collator`].
pub fn run_collator_node( pub fn run_collator_node(
task_executor: TaskExecutor, tokio_handle: tokio::runtime::Handle,
key: Sr25519Keyring, key: Sr25519Keyring,
storage_update_func: impl Fn(), storage_update_func: impl Fn(),
boot_nodes: Vec<MultiaddrWithPeerId>, boot_nodes: Vec<MultiaddrWithPeerId>,
collator_pair: CollatorPair, collator_pair: CollatorPair,
) -> PolkadotTestNode { ) -> PolkadotTestNode {
let config = node_config(storage_update_func, task_executor, key, boot_nodes, false); let config = node_config(storage_update_func, tokio_handle, key, boot_nodes, false);
let multiaddr = config.network.listen_addresses[0].clone(); let multiaddr = config.network.listen_addresses[0].clone();
let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } = let NewFull { task_manager, client, network, rpc_handlers, overseer_handle, .. } =
new_full(config, IsCollator::Yes(collator_pair), None) new_full(config, IsCollator::Yes(collator_pair), None)
@@ -14,21 +14,25 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. // along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use futures::{future, pin_mut, select}; use futures::{future, pin_mut, select, FutureExt};
use polkadot_test_service::*; use polkadot_test_service::*;
use service::TaskExecutor;
use sp_keyring::Sr25519Keyring; use sp_keyring::Sr25519Keyring;
#[substrate_test_utils::test] #[substrate_test_utils::test]
async fn ensure_test_service_build_blocks(task_executor: TaskExecutor) { async fn ensure_test_service_build_blocks() {
let mut builder = sc_cli::LoggerBuilder::new(""); let mut builder = sc_cli::LoggerBuilder::new("");
builder.with_colors(false); builder.with_colors(false);
builder.init().expect("Sets up logger"); builder.init().expect("Sets up logger");
let mut alice = let mut alice = run_validator_node(
run_validator_node(task_executor.clone(), Sr25519Keyring::Alice, || {}, Vec::new(), None); tokio::runtime::Handle::current(),
Sr25519Keyring::Alice,
|| {},
Vec::new(),
None,
);
let mut bob = run_validator_node( let mut bob = run_validator_node(
task_executor.clone(), tokio::runtime::Handle::current(),
Sr25519Keyring::Bob, Sr25519Keyring::Bob,
|| {}, || {},
vec![alice.addr.clone()], vec![alice.addr.clone()],
@@ -15,12 +15,12 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. // along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use polkadot_test_service::*; use polkadot_test_service::*;
use service::TaskExecutor;
use sp_keyring::Sr25519Keyring::{Alice, Bob}; use sp_keyring::Sr25519Keyring::{Alice, Bob};
#[substrate_test_utils::test] #[substrate_test_utils::test]
async fn call_function_actually_work(task_executor: TaskExecutor) { async fn call_function_actually_work() {
let alice = run_validator_node(task_executor, Alice, || {}, Vec::new(), None); let alice =
run_validator_node(tokio::runtime::Handle::current(), Alice, || {}, Vec::new(), None);
let function = polkadot_test_runtime::Call::Balances(pallet_balances::Call::transfer( let function = polkadot_test_runtime::Call::Balances(pallet_balances::Call::transfer(
Default::default(), Default::default(),
@@ -21,7 +21,7 @@ const PUPPET_EXE: &str = env!("CARGO_BIN_EXE_adder_collator_puppet_worker");
// If this test is failing, make sure to run all tests with the `real-overseer` feature being enabled. // If this test is failing, make sure to run all tests with the `real-overseer` feature being enabled.
#[substrate_test_utils::test] #[substrate_test_utils::test]
async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor) { async fn collating_using_adder_collator() {
use futures::join; use futures::join;
use polkadot_primitives::v1::Id as ParaId; use polkadot_primitives::v1::Id as ParaId;
use sp_keyring::AccountKeyring::*; use sp_keyring::AccountKeyring::*;
@@ -34,7 +34,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
// start alice // start alice
let alice = polkadot_test_service::run_validator_node( let alice = polkadot_test_service::run_validator_node(
task_executor.clone(), tokio::runtime::Handle::current(),
Alice, Alice,
|| {}, || {},
vec![], vec![],
@@ -43,7 +43,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
// start bob // start bob
let bob = polkadot_test_service::run_validator_node( let bob = polkadot_test_service::run_validator_node(
task_executor.clone(), tokio::runtime::Handle::current(),
Bob, Bob,
|| {}, || {},
vec![alice.addr.clone()], vec![alice.addr.clone()],
@@ -60,7 +60,7 @@ async fn collating_using_adder_collator(task_executor: sc_service::TaskExecutor)
// run the collator node // run the collator node
let mut charlie = polkadot_test_service::run_collator_node( let mut charlie = polkadot_test_service::run_collator_node(
task_executor.clone(), tokio::runtime::Handle::current(),
Charlie, Charlie,
|| {}, || {},
vec![alice.addr.clone(), bob.addr.clone()], vec![alice.addr.clone(), bob.addr.clone()],