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

Commit fa23b18

Browse files
authored
Revert "Use SpawnTaskHandles for spawning tasks in the tx pool (#8958)" (#8983)
This reverts commit bfef07c.
1 parent 24750ea commit fa23b18

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

Cargo.lock

Lines changed: 17 additions & 0 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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"
1920
intervalier = "0.4.0"
2021
log = "0.4.8"
2122
parity-util-mem = { version = "0.9.0", default-features = false, features = ["primitive-types"] }

client/transaction-pool/src/api.rs

Lines changed: 9 additions & 7 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, future::{Future, FutureExt, ready, Ready},
24+
channel::oneshot, executor::{ThreadPool, ThreadPoolBuilder}, future::{Future, FutureExt, ready, Ready},
2525
};
2626

2727
use sc_client_api::{
@@ -31,7 +31,6 @@ 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;
3534
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
3635
use sp_api::{ProvideRuntimeApi, ApiExt};
3736
use prometheus_endpoint::Registry as PrometheusRegistry;
@@ -41,7 +40,7 @@ use crate::{metrics::{ApiMetrics, ApiMetricsExt}, error::{self, Error}};
4140
/// The transaction pool logic for full client.
4241
pub struct FullChainApi<Client, Block> {
4342
client: Arc<Client>,
44-
spawner: Box<dyn SpawnNamed>,
43+
pool: ThreadPool,
4544
_marker: PhantomData<Block>,
4645
metrics: Option<Arc<ApiMetrics>>,
4746
}
@@ -51,7 +50,6 @@ impl<Client, Block> FullChainApi<Client, Block> {
5150
pub fn new(
5251
client: Arc<Client>,
5352
prometheus: Option<&PrometheusRegistry>,
54-
spawner: impl SpawnNamed + 'static,
5553
) -> Self {
5654
let metrics = prometheus.map(ApiMetrics::register).and_then(|r| {
5755
match r {
@@ -69,9 +67,13 @@ impl<Client, Block> FullChainApi<Client, Block> {
6967

7068
FullChainApi {
7169
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."),
7275
_marker: Default::default(),
7376
metrics,
74-
spawner: Box::new(spawner) ,
7577
}
7678
}
7779
}
@@ -107,9 +109,9 @@ where
107109
let metrics = self.metrics.clone();
108110
metrics.report(|m| m.validations_scheduled.inc());
109111

110-
self.spawner.spawn_blocking(
112+
self.pool.spawn_ok(futures_diagnose::diagnose(
111113
"validate-transaction",
112-
Box::pin(async move {
114+
async move {
113115
let res = validate_transaction_blocking(&*client, &at, source, uxt);
114116
if let Err(e) = tx.send(res) {
115117
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 + Clone + 'static,
369+
spawner: impl SpawnNamed,
370370
client: Arc<Client>,
371371
) -> Arc<Self> {
372-
let pool_api = Arc::new(FullChainApi::new(client.clone(), prometheus, spawner.clone()));
372+
let pool_api = Arc::new(FullChainApi::new(client.clone(), prometheus));
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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ 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;
3938

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

938937
let pool = Arc::new(
939-
BasicPool::new_test(Arc::new(FullChainApi::new(client, None, TaskExecutor::new()))).0
938+
BasicPool::new_test(Arc::new(FullChainApi::new(client, None))).0
940939
);
941940

942941
let transfer = Transfer {
@@ -972,7 +971,7 @@ fn import_notification_to_pool_maintain_works() {
972971
let mut client = Arc::new(substrate_test_runtime_client::new());
973972

974973
let pool = Arc::new(
975-
BasicPool::new_test(Arc::new(FullChainApi::new(client.clone(), None, TaskExecutor::new()))).0
974+
BasicPool::new_test(Arc::new(FullChainApi::new(client.clone(), None))).0
976975
);
977976

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

0 commit comments

Comments
 (0)