Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit bfef07c

Browse files
authored
Use SpawnTaskHandles for spawning tasks in the tx pool (#8958)
* Remove futures-diagnose * Use `SpawnTaskHandle`s for spawning tasks in the tx pool * Box the spawner * Fix tests * Use the testing task executor
1 parent 408e803 commit bfef07c

File tree

5 files changed

+12
-31
lines changed

5 files changed

+12
-31
lines changed

Cargo.lock

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/transaction-pool/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ targets = ["x86_64-unknown-linux-gnu"]
1616
codec = { package = "parity-scale-codec", version = "2.0.0" }
1717
thiserror = "1.0.21"
1818
futures = { version = "0.3.1", features = ["compat"] }
19-
futures-diagnose = "1.0"
2019
intervalier = "0.4.0"
2120
log = "0.4.8"
2221
parity-util-mem = { version = "0.9.0", default-features = false, features = ["primitive-types"] }

client/transaction-pool/src/api.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use std::{marker::PhantomData, pin::Pin, sync::Arc};
2222
use codec::{Decode, Encode};
2323
use futures::{
24-
channel::oneshot, executor::{ThreadPool, ThreadPoolBuilder}, future::{Future, FutureExt, ready, Ready},
24+
channel::oneshot, future::{Future, FutureExt, ready, Ready},
2525
};
2626

2727
use sc_client_api::{
@@ -31,6 +31,7 @@ use sp_runtime::{
3131
generic::BlockId, traits::{self, Block as BlockT, BlockIdTo, Header as HeaderT, Hash as HashT},
3232
transaction_validity::{TransactionValidity, TransactionSource},
3333
};
34+
use sp_core::traits::SpawnNamed;
3435
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
3536
use sp_api::{ProvideRuntimeApi, ApiExt};
3637
use prometheus_endpoint::Registry as PrometheusRegistry;
@@ -40,7 +41,7 @@ use crate::{metrics::{ApiMetrics, ApiMetricsExt}, error::{self, Error}};
4041
/// The transaction pool logic for full client.
4142
pub struct FullChainApi<Client, Block> {
4243
client: Arc<Client>,
43-
pool: ThreadPool,
44+
spawner: Box<dyn SpawnNamed>,
4445
_marker: PhantomData<Block>,
4546
metrics: Option<Arc<ApiMetrics>>,
4647
}
@@ -50,6 +51,7 @@ impl<Client, Block> FullChainApi<Client, Block> {
5051
pub fn new(
5152
client: Arc<Client>,
5253
prometheus: Option<&PrometheusRegistry>,
54+
spawner: impl SpawnNamed + 'static,
5355
) -> Self {
5456
let metrics = prometheus.map(ApiMetrics::register).and_then(|r| {
5557
match r {
@@ -67,13 +69,9 @@ impl<Client, Block> FullChainApi<Client, Block> {
6769

6870
FullChainApi {
6971
client,
70-
pool: ThreadPoolBuilder::new()
71-
.pool_size(2)
72-
.name_prefix("txpool-verifier")
73-
.create()
74-
.expect("Failed to spawn verifier threads, that are critical for node operation."),
7572
_marker: Default::default(),
7673
metrics,
74+
spawner: Box::new(spawner) ,
7775
}
7876
}
7977
}
@@ -109,9 +107,9 @@ where
109107
let metrics = self.metrics.clone();
110108
metrics.report(|m| m.validations_scheduled.inc());
111109

112-
self.pool.spawn_ok(futures_diagnose::diagnose(
110+
self.spawner.spawn_blocking(
113111
"validate-transaction",
114-
async move {
112+
Box::pin(async move {
115113
let res = validate_transaction_blocking(&*client, &at, source, uxt);
116114
if let Err(e) = tx.send(res) {
117115
log::warn!("Unable to send a validate transaction result: {:?}", e);

client/transaction-pool/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@ where
366366
options: sc_transaction_graph::Options,
367367
is_validator: txpool::IsValidator,
368368
prometheus: Option<&PrometheusRegistry>,
369-
spawner: impl SpawnNamed,
369+
spawner: impl SpawnNamed + Clone + 'static,
370370
client: Arc<Client>,
371371
) -> Arc<Self> {
372-
let pool_api = Arc::new(FullChainApi::new(client.clone(), prometheus));
372+
let pool_api = Arc::new(FullChainApi::new(client.clone(), prometheus, spawner.clone()));
373373
let pool = Arc::new(Self::with_revalidation_type(
374374
options, is_validator, pool_api, prometheus, RevalidationType::Full, spawner
375375
));

client/transaction-pool/src/testing/pool.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use std::collections::BTreeSet;
3535
use sc_client_api::client::BlockchainEvents;
3636
use sc_block_builder::BlockBuilderProvider;
3737
use sp_consensus::BlockOrigin;
38+
use sp_core::testing::TaskExecutor;
3839

3940
fn pool() -> Pool<TestApi> {
4041
Pool::new(Default::default(), true.into(), TestApi::with_alice_nonce(209).into())
@@ -935,7 +936,7 @@ fn should_not_accept_old_signatures() {
935936
let client = Arc::new(substrate_test_runtime_client::new());
936937

937938
let pool = Arc::new(
938-
BasicPool::new_test(Arc::new(FullChainApi::new(client, None))).0
939+
BasicPool::new_test(Arc::new(FullChainApi::new(client, None, TaskExecutor::new()))).0
939940
);
940941

941942
let transfer = Transfer {
@@ -971,7 +972,7 @@ fn import_notification_to_pool_maintain_works() {
971972
let mut client = Arc::new(substrate_test_runtime_client::new());
972973

973974
let pool = Arc::new(
974-
BasicPool::new_test(Arc::new(FullChainApi::new(client.clone(), None))).0
975+
BasicPool::new_test(Arc::new(FullChainApi::new(client.clone(), None, TaskExecutor::new()))).0
975976
);
976977

977978
// Prepare the extrisic, push it to the pool and check that it was added.

0 commit comments

Comments
 (0)