From 5c44597f403ebe6b3f2747471af17d98a3ca1d3e Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 31 May 2021 15:15:51 +0200 Subject: [PATCH 1/5] Remove futures-diagnose --- Cargo.lock | 17 ----------------- client/transaction-pool/Cargo.toml | 1 - client/transaction-pool/src/api.rs | 17 +++++++---------- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e954a76d0ba2..0d07bcef8af6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2052,22 +2052,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "futures-diagnose" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdcef58a173af8148b182684c9f2d5250875adbcaff7b5794073894f9d8634a9" -dependencies = [ - "futures 0.1.31", - "futures 0.3.13", - "lazy_static", - "log", - "parking_lot 0.9.0", - "pin-project 0.4.27", - "serde", - "serde_json", -] - [[package]] name = "futures-executor" version = "0.3.13" @@ -8097,7 +8081,6 @@ version = "3.0.0" dependencies = [ "assert_matches", "futures 0.3.13", - "futures-diagnose", "hex", "intervalier", "log", diff --git a/client/transaction-pool/Cargo.toml b/client/transaction-pool/Cargo.toml index d457d709d122..6b105520baec 100644 --- a/client/transaction-pool/Cargo.toml +++ b/client/transaction-pool/Cargo.toml @@ -16,7 +16,6 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { package = "parity-scale-codec", version = "2.0.0" } thiserror = "1.0.21" futures = { version = "0.3.1", features = ["compat"] } -futures-diagnose = "1.0" intervalier = "0.4.0" log = "0.4.8" parity-util-mem = { version = "0.9.0", default-features = false, features = ["primitive-types"] } diff --git a/client/transaction-pool/src/api.rs b/client/transaction-pool/src/api.rs index 2ebf038844fa..67d75ca7cbef 100644 --- a/client/transaction-pool/src/api.rs +++ b/client/transaction-pool/src/api.rs @@ -109,16 +109,13 @@ where let metrics = self.metrics.clone(); metrics.report(|m| m.validations_scheduled.inc()); - self.pool.spawn_ok(futures_diagnose::diagnose( - "validate-transaction", - async move { - let res = validate_transaction_blocking(&*client, &at, source, uxt); - if let Err(e) = tx.send(res) { - log::warn!("Unable to send a validate transaction result: {:?}", e); - } - metrics.report(|m| m.validations_finished.inc()); - }, - )); + self.pool.spawn_ok(async move { + let res = validate_transaction_blocking(&*client, &at, source, uxt); + if let Err(e) = tx.send(res) { + log::warn!("Unable to send a validate transaction result: {:?}", e); + } + metrics.report(|m| m.validations_finished.inc()); + }); Box::pin(async move { match rx.await { From b2d59530260def493585ced1680ee6c8e84e7f89 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 31 May 2021 16:17:04 +0200 Subject: [PATCH 2/5] Use `SpawnTaskHandle`s for spawning tasks in the tx pool --- bin/node-template/node/src/service.rs | 4 +-- bin/node/cli/src/service.rs | 5 +-- client/transaction-pool/src/api.rs | 45 ++++++++++++++------------- client/transaction-pool/src/lib.rs | 18 ++++++----- 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index f50490410076..f8f0f6e32397 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -3,7 +3,7 @@ use std::{sync::Arc, time::Duration}; use sc_client_api::{ExecutorProvider, RemoteBackend}; use node_template_runtime::{self, opaque::Block, RuntimeApi}; -use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; +use sc_service::{error::Error as ServiceError, Configuration, TaskManager, SpawnTaskHandle}; use sc_executor::native_executor_instance; pub use sc_executor::NativeExecutor; use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; @@ -28,7 +28,7 @@ type FullSelectChain = sc_consensus::LongestChain; pub fn new_partial(config: &Configuration) -> Result, - sc_transaction_pool::FullPool, + sc_transaction_pool::FullPool, ( sc_finality_grandpa::GrandpaBlockImport, sc_finality_grandpa::LinkHalf, diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 42020e6668e4..00386331b80a 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -26,6 +26,7 @@ use node_primitives::Block; use node_runtime::RuntimeApi; use sc_service::{ config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager, + SpawnTaskHandle, }; use sc_network::{Event, NetworkService}; use sp_runtime::traits::Block as BlockT; @@ -47,7 +48,7 @@ pub fn new_partial( ) -> Result, - sc_transaction_pool::FullPool, + sc_transaction_pool::FullPool, ( impl Fn( node_rpc::DenyUnsafe, @@ -204,7 +205,7 @@ pub struct NewFullBase { pub task_manager: TaskManager, pub client: Arc, pub network: Arc::Hash>>, - pub transaction_pool: Arc>, + pub transaction_pool: Arc>, } /// Creates a full service from the configuration. diff --git a/client/transaction-pool/src/api.rs b/client/transaction-pool/src/api.rs index 67d75ca7cbef..e310a0d39a16 100644 --- a/client/transaction-pool/src/api.rs +++ b/client/transaction-pool/src/api.rs @@ -21,7 +21,7 @@ use std::{marker::PhantomData, pin::Pin, sync::Arc}; use codec::{Decode, Encode}; use futures::{ - channel::oneshot, executor::{ThreadPool, ThreadPoolBuilder}, future::{Future, FutureExt, ready, Ready}, + channel::oneshot, future::{Future, FutureExt, ready, Ready}, }; use sc_client_api::{ @@ -38,18 +38,19 @@ use prometheus_endpoint::Registry as PrometheusRegistry; use crate::{metrics::{ApiMetrics, ApiMetricsExt}, error::{self, Error}}; /// The transaction pool logic for full client. -pub struct FullChainApi { +pub struct FullChainApi { client: Arc, - pool: ThreadPool, + spawner: Spawner, _marker: PhantomData, metrics: Option>, } -impl FullChainApi { +impl FullChainApi { /// Create new transaction pool logic. pub fn new( client: Arc, prometheus: Option<&PrometheusRegistry>, + spawner: Spawner, ) -> Self { let metrics = prometheus.map(ApiMetrics::register).and_then(|r| { match r { @@ -67,23 +68,20 @@ impl FullChainApi { FullChainApi { client, - pool: ThreadPoolBuilder::new() - .pool_size(2) - .name_prefix("txpool-verifier") - .create() - .expect("Failed to spawn verifier threads, that are critical for node operation."), _marker: Default::default(), metrics, + spawner, } } } -impl sc_transaction_graph::ChainApi for FullChainApi +impl sc_transaction_graph::ChainApi for FullChainApi where Block: BlockT, Client: ProvideRuntimeApi + BlockBackend + BlockIdTo, Client: Send + Sync + 'static, Client::Api: TaggedTransactionQueue, + Spawner: sp_core::traits::SpawnNamed, { type Block = Block; type Error = error::Error; @@ -109,13 +107,16 @@ where let metrics = self.metrics.clone(); metrics.report(|m| m.validations_scheduled.inc()); - self.pool.spawn_ok(async move { - let res = validate_transaction_blocking(&*client, &at, source, uxt); - if let Err(e) = tx.send(res) { - log::warn!("Unable to send a validate transaction result: {:?}", e); - } - metrics.report(|m| m.validations_finished.inc()); - }); + self.spawner.spawn_blocking( + "validate-transaction", + Box::pin(async move { + let res = validate_transaction_blocking::<_, _, Spawner>(&*client, &at, source, uxt); + if let Err(e) = tx.send(res) { + log::warn!("Unable to send a validate transaction result: {:?}", e); + } + metrics.report(|m| m.validations_finished.inc()); + }, + )); Box::pin(async move { match rx.await { @@ -151,17 +152,18 @@ where /// Helper function to validate a transaction using a full chain API. /// This method will call into the runtime to perform the validation. -fn validate_transaction_blocking( +fn validate_transaction_blocking( client: &Client, at: &BlockId, source: TransactionSource, - uxt: sc_transaction_graph::ExtrinsicFor>, + uxt: sc_transaction_graph::ExtrinsicFor>, ) -> error::Result where Block: BlockT, Client: ProvideRuntimeApi + BlockBackend + BlockIdTo, Client: Send + Sync + 'static, Client::Api: TaggedTransactionQueue, + Spawner: sp_core::traits::SpawnNamed, { sp_tracing::within_span!(sp_tracing::Level::TRACE, "validate_transaction"; { @@ -187,12 +189,13 @@ where }) } -impl FullChainApi +impl FullChainApi where Block: BlockT, Client: ProvideRuntimeApi + BlockBackend + BlockIdTo, Client: Send + Sync + 'static, Client::Api: TaggedTransactionQueue, + Spawner: sp_core::traits::SpawnNamed, { /// Validates a transaction by calling into the runtime, same as /// `validate_transaction` but blocks the current thread when performing @@ -204,7 +207,7 @@ where source: TransactionSource, uxt: sc_transaction_graph::ExtrinsicFor, ) -> error::Result { - validate_transaction_blocking(&*self.client, at, source, uxt) + validate_transaction_blocking::<_, _, Spawner>(&*self.client, at, source, uxt) } } diff --git a/client/transaction-pool/src/lib.rs b/client/transaction-pool/src/lib.rs index efd5a7a14342..b81288ff9b9c 100644 --- a/client/transaction-pool/src/lib.rs +++ b/client/transaction-pool/src/lib.rs @@ -65,7 +65,7 @@ type ReadyIteratorFor = BoxedReadyIterator< type PolledIterator = Pin> + Send>>; /// A transaction pool for a full node. -pub type FullPool = BasicPool, Block>; +pub type FullPool = BasicPool, Block>; /// A transaction pool for a light node. pub type LightPool = BasicPool, Block>; @@ -352,7 +352,7 @@ where } } -impl FullPool +impl FullPool where Block: BlockT, Client: sp_api::ProvideRuntimeApi @@ -360,16 +360,17 @@ where + sp_runtime::traits::BlockIdTo, Client: sc_client_api::ExecutorProvider + Send + Sync + 'static, Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue, + Spawner: SpawnNamed + Clone + 'static, { /// Create new basic transaction pool for a full node with the provided api. pub fn new_full( options: sc_transaction_graph::Options, is_validator: txpool::IsValidator, prometheus: Option<&PrometheusRegistry>, - spawner: impl SpawnNamed, + spawner: Spawner, client: Arc, ) -> Arc { - let pool_api = Arc::new(FullChainApi::new(client.clone(), prometheus)); + let pool_api = Arc::new(FullChainApi::new(client.clone(), prometheus, spawner.clone())); let pool = Arc::new(Self::with_revalidation_type( options, is_validator, pool_api, prometheus, RevalidationType::Full, spawner )); @@ -381,8 +382,8 @@ where } } -impl sp_transaction_pool::LocalTransactionPool - for BasicPool, Block> +impl sp_transaction_pool::LocalTransactionPool + for BasicPool, Block> where Block: BlockT, Client: sp_api::ProvideRuntimeApi @@ -390,10 +391,11 @@ where + sp_runtime::traits::BlockIdTo, Client: Send + Sync + 'static, Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue, + Spawner: SpawnNamed, { type Block = Block; - type Hash = sc_transaction_graph::ExtrinsicHash>; - type Error = as ChainApi>::Error; + type Hash = sc_transaction_graph::ExtrinsicHash>; + type Error = as ChainApi>::Error; fn submit_local( &self, From 5d3468af0ce493e84ddab155efece88e713668fc Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 31 May 2021 17:12:58 +0200 Subject: [PATCH 3/5] Box the spawner --- bin/node-template/node/src/service.rs | 4 ++-- bin/node/cli/src/service.rs | 5 ++--- client/transaction-pool/src/api.rs | 26 ++++++++++++-------------- client/transaction-pool/src/lib.rs | 16 +++++++--------- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index f8f0f6e32397..f50490410076 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -3,7 +3,7 @@ use std::{sync::Arc, time::Duration}; use sc_client_api::{ExecutorProvider, RemoteBackend}; use node_template_runtime::{self, opaque::Block, RuntimeApi}; -use sc_service::{error::Error as ServiceError, Configuration, TaskManager, SpawnTaskHandle}; +use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; use sc_executor::native_executor_instance; pub use sc_executor::NativeExecutor; use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; @@ -28,7 +28,7 @@ type FullSelectChain = sc_consensus::LongestChain; pub fn new_partial(config: &Configuration) -> Result, - sc_transaction_pool::FullPool, + sc_transaction_pool::FullPool, ( sc_finality_grandpa::GrandpaBlockImport, sc_finality_grandpa::LinkHalf, diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 00386331b80a..42020e6668e4 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -26,7 +26,6 @@ use node_primitives::Block; use node_runtime::RuntimeApi; use sc_service::{ config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager, - SpawnTaskHandle, }; use sc_network::{Event, NetworkService}; use sp_runtime::traits::Block as BlockT; @@ -48,7 +47,7 @@ pub fn new_partial( ) -> Result, - sc_transaction_pool::FullPool, + sc_transaction_pool::FullPool, ( impl Fn( node_rpc::DenyUnsafe, @@ -205,7 +204,7 @@ pub struct NewFullBase { pub task_manager: TaskManager, pub client: Arc, pub network: Arc::Hash>>, - pub transaction_pool: Arc>, + pub transaction_pool: Arc>, } /// Creates a full service from the configuration. diff --git a/client/transaction-pool/src/api.rs b/client/transaction-pool/src/api.rs index e310a0d39a16..fe1f99e0a3c2 100644 --- a/client/transaction-pool/src/api.rs +++ b/client/transaction-pool/src/api.rs @@ -31,6 +31,7 @@ use sp_runtime::{ generic::BlockId, traits::{self, Block as BlockT, BlockIdTo, Header as HeaderT, Hash as HashT}, transaction_validity::{TransactionValidity, TransactionSource}, }; +use sp_core::traits::SpawnNamed; use sp_transaction_pool::runtime_api::TaggedTransactionQueue; use sp_api::{ProvideRuntimeApi, ApiExt}; use prometheus_endpoint::Registry as PrometheusRegistry; @@ -38,19 +39,19 @@ use prometheus_endpoint::Registry as PrometheusRegistry; use crate::{metrics::{ApiMetrics, ApiMetricsExt}, error::{self, Error}}; /// The transaction pool logic for full client. -pub struct FullChainApi { +pub struct FullChainApi { client: Arc, - spawner: Spawner, + spawner: Box, _marker: PhantomData, metrics: Option>, } -impl FullChainApi { +impl FullChainApi { /// Create new transaction pool logic. pub fn new( client: Arc, prometheus: Option<&PrometheusRegistry>, - spawner: Spawner, + spawner: impl SpawnNamed + 'static, ) -> Self { let metrics = prometheus.map(ApiMetrics::register).and_then(|r| { match r { @@ -70,18 +71,17 @@ impl FullChainApi { client, _marker: Default::default(), metrics, - spawner, + spawner: Box::new(spawner) , } } } -impl sc_transaction_graph::ChainApi for FullChainApi +impl sc_transaction_graph::ChainApi for FullChainApi where Block: BlockT, Client: ProvideRuntimeApi + BlockBackend + BlockIdTo, Client: Send + Sync + 'static, Client::Api: TaggedTransactionQueue, - Spawner: sp_core::traits::SpawnNamed, { type Block = Block; type Error = error::Error; @@ -110,7 +110,7 @@ where self.spawner.spawn_blocking( "validate-transaction", Box::pin(async move { - let res = validate_transaction_blocking::<_, _, Spawner>(&*client, &at, source, uxt); + let res = validate_transaction_blocking(&*client, &at, source, uxt); if let Err(e) = tx.send(res) { log::warn!("Unable to send a validate transaction result: {:?}", e); } @@ -152,18 +152,17 @@ where /// Helper function to validate a transaction using a full chain API. /// This method will call into the runtime to perform the validation. -fn validate_transaction_blocking( +fn validate_transaction_blocking( client: &Client, at: &BlockId, source: TransactionSource, - uxt: sc_transaction_graph::ExtrinsicFor>, + uxt: sc_transaction_graph::ExtrinsicFor>, ) -> error::Result where Block: BlockT, Client: ProvideRuntimeApi + BlockBackend + BlockIdTo, Client: Send + Sync + 'static, Client::Api: TaggedTransactionQueue, - Spawner: sp_core::traits::SpawnNamed, { sp_tracing::within_span!(sp_tracing::Level::TRACE, "validate_transaction"; { @@ -189,13 +188,12 @@ where }) } -impl FullChainApi +impl FullChainApi where Block: BlockT, Client: ProvideRuntimeApi + BlockBackend + BlockIdTo, Client: Send + Sync + 'static, Client::Api: TaggedTransactionQueue, - Spawner: sp_core::traits::SpawnNamed, { /// Validates a transaction by calling into the runtime, same as /// `validate_transaction` but blocks the current thread when performing @@ -207,7 +205,7 @@ where source: TransactionSource, uxt: sc_transaction_graph::ExtrinsicFor, ) -> error::Result { - validate_transaction_blocking::<_, _, Spawner>(&*self.client, at, source, uxt) + validate_transaction_blocking(&*self.client, at, source, uxt) } } diff --git a/client/transaction-pool/src/lib.rs b/client/transaction-pool/src/lib.rs index b81288ff9b9c..39c58b96738a 100644 --- a/client/transaction-pool/src/lib.rs +++ b/client/transaction-pool/src/lib.rs @@ -65,7 +65,7 @@ type ReadyIteratorFor = BoxedReadyIterator< type PolledIterator = Pin> + Send>>; /// A transaction pool for a full node. -pub type FullPool = BasicPool, Block>; +pub type FullPool = BasicPool, Block>; /// A transaction pool for a light node. pub type LightPool = BasicPool, Block>; @@ -352,7 +352,7 @@ where } } -impl FullPool +impl FullPool where Block: BlockT, Client: sp_api::ProvideRuntimeApi @@ -360,14 +360,13 @@ where + sp_runtime::traits::BlockIdTo, Client: sc_client_api::ExecutorProvider + Send + Sync + 'static, Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue, - Spawner: SpawnNamed + Clone + 'static, { /// Create new basic transaction pool for a full node with the provided api. pub fn new_full( options: sc_transaction_graph::Options, is_validator: txpool::IsValidator, prometheus: Option<&PrometheusRegistry>, - spawner: Spawner, + spawner: impl SpawnNamed + Clone + 'static, client: Arc, ) -> Arc { let pool_api = Arc::new(FullChainApi::new(client.clone(), prometheus, spawner.clone())); @@ -382,8 +381,8 @@ where } } -impl sp_transaction_pool::LocalTransactionPool - for BasicPool, Block> +impl sp_transaction_pool::LocalTransactionPool + for BasicPool, Block> where Block: BlockT, Client: sp_api::ProvideRuntimeApi @@ -391,11 +390,10 @@ where + sp_runtime::traits::BlockIdTo, Client: Send + Sync + 'static, Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue, - Spawner: SpawnNamed, { type Block = Block; - type Hash = sc_transaction_graph::ExtrinsicHash>; - type Error = as ChainApi>::Error; + type Hash = sc_transaction_graph::ExtrinsicHash>; + type Error = as ChainApi>::Error; fn submit_local( &self, From 5d863991d3999ffa80deb27512192647ab50a394 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 31 May 2021 17:26:12 +0200 Subject: [PATCH 4/5] Fix tests --- client/transaction-pool/src/testing/pool.rs | 24 +++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/client/transaction-pool/src/testing/pool.rs b/client/transaction-pool/src/testing/pool.rs index 063947b383d0..51ca5fa7ccd2 100644 --- a/client/transaction-pool/src/testing/pool.rs +++ b/client/transaction-pool/src/testing/pool.rs @@ -19,6 +19,7 @@ use crate::*; use sp_transaction_pool::TransactionStatus; use futures::executor::{block_on, block_on_stream}; +use futures::future::BoxFuture; use txpool::{self, Pool}; use sp_runtime::{ generic::BlockId, @@ -36,6 +37,25 @@ use sc_client_api::client::BlockchainEvents; use sc_block_builder::BlockBuilderProvider; use sp_consensus::BlockOrigin; +#[derive(Clone)] +struct ThreadPoolSpawner(futures::executor::ThreadPool); + +impl ThreadPoolSpawner { + fn new() -> Self { + Self(futures::executor::ThreadPool::new().unwrap()) + } +} + +impl sp_core::traits::SpawnNamed for ThreadPoolSpawner { + fn spawn_blocking(&self, _: &'static str, future: BoxFuture<'static, ()>) { + self.0.spawn_ok(future); + } + + fn spawn(&self, _: &'static str, future: BoxFuture<'static, ()>) { + self.0.spawn_ok(future); + } +} + fn pool() -> Pool { Pool::new(Default::default(), true.into(), TestApi::with_alice_nonce(209).into()) } @@ -935,7 +955,7 @@ fn should_not_accept_old_signatures() { let client = Arc::new(substrate_test_runtime_client::new()); let pool = Arc::new( - BasicPool::new_test(Arc::new(FullChainApi::new(client, None))).0 + BasicPool::new_test(Arc::new(FullChainApi::new(client, None, ThreadPoolSpawner::new()))).0 ); let transfer = Transfer { @@ -971,7 +991,7 @@ fn import_notification_to_pool_maintain_works() { let mut client = Arc::new(substrate_test_runtime_client::new()); let pool = Arc::new( - BasicPool::new_test(Arc::new(FullChainApi::new(client.clone(), None))).0 + BasicPool::new_test(Arc::new(FullChainApi::new(client.clone(), None, ThreadPoolSpawner::new()))).0 ); // Prepare the extrisic, push it to the pool and check that it was added. From f6334fcbe5c283ba53206b110fed5543371f4efb Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Tue, 1 Jun 2021 14:05:36 +0200 Subject: [PATCH 5/5] Use the testing task executor --- client/transaction-pool/src/testing/pool.rs | 25 +++------------------ 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/client/transaction-pool/src/testing/pool.rs b/client/transaction-pool/src/testing/pool.rs index 51ca5fa7ccd2..da6f9278a929 100644 --- a/client/transaction-pool/src/testing/pool.rs +++ b/client/transaction-pool/src/testing/pool.rs @@ -19,7 +19,6 @@ use crate::*; use sp_transaction_pool::TransactionStatus; use futures::executor::{block_on, block_on_stream}; -use futures::future::BoxFuture; use txpool::{self, Pool}; use sp_runtime::{ generic::BlockId, @@ -36,25 +35,7 @@ use std::collections::BTreeSet; use sc_client_api::client::BlockchainEvents; use sc_block_builder::BlockBuilderProvider; use sp_consensus::BlockOrigin; - -#[derive(Clone)] -struct ThreadPoolSpawner(futures::executor::ThreadPool); - -impl ThreadPoolSpawner { - fn new() -> Self { - Self(futures::executor::ThreadPool::new().unwrap()) - } -} - -impl sp_core::traits::SpawnNamed for ThreadPoolSpawner { - fn spawn_blocking(&self, _: &'static str, future: BoxFuture<'static, ()>) { - self.0.spawn_ok(future); - } - - fn spawn(&self, _: &'static str, future: BoxFuture<'static, ()>) { - self.0.spawn_ok(future); - } -} +use sp_core::testing::TaskExecutor; fn pool() -> Pool { Pool::new(Default::default(), true.into(), TestApi::with_alice_nonce(209).into()) @@ -955,7 +936,7 @@ fn should_not_accept_old_signatures() { let client = Arc::new(substrate_test_runtime_client::new()); let pool = Arc::new( - BasicPool::new_test(Arc::new(FullChainApi::new(client, None, ThreadPoolSpawner::new()))).0 + BasicPool::new_test(Arc::new(FullChainApi::new(client, None, TaskExecutor::new()))).0 ); let transfer = Transfer { @@ -991,7 +972,7 @@ fn import_notification_to_pool_maintain_works() { let mut client = Arc::new(substrate_test_runtime_client::new()); let pool = Arc::new( - BasicPool::new_test(Arc::new(FullChainApi::new(client.clone(), None, ThreadPoolSpawner::new()))).0 + BasicPool::new_test(Arc::new(FullChainApi::new(client.clone(), None, TaskExecutor::new()))).0 ); // Prepare the extrisic, push it to the pool and check that it was added.