Skip to content

Commit 9b4cfe6

Browse files
fatxpool: report_invalid is now aync (#8836)
[`TransactionPool::report_invalid`](https://github.com/paritytech/polkadot-sdk/blob/74dafaee5c600fd2c8a59a280f647f94ccf0a755/substrate/client/transaction-pool/api/src/lib.rs#L314) is now `async`, function was typically used in async context, seems right to be fully async. _Note_: expected to be merged after: #8596 --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 45cc86a commit 9b4cfe6

File tree

12 files changed

+53
-29
lines changed

12 files changed

+53
-29
lines changed

prdoc/pr_8836.prdoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
title: '`fatxpool`: `report_invalid` is now aync'
2+
doc:
3+
- audience: Node Dev
4+
description: '[`TransactionPool::report_invalid`](https://github.com/paritytech/polkadot-sdk/blob/74dafaee5c600fd2c8a59a280f647f94ccf0a755/substrate/client/transaction-pool/api/src/lib.rs#L314)
5+
is now `async`, function was typically used in async context, seems right to be
6+
fully async.'
7+
crates:
8+
- name: sc-basic-authorship
9+
bump: major
10+
- name: sc-rpc-api
11+
bump: major
12+
- name: sc-rpc-spec-v2
13+
bump: major
14+
- name: sc-rpc
15+
bump: major
16+
- name: sc-transaction-pool-api
17+
bump: major
18+
- name: sc-transaction-pool
19+
bump: major

substrate/bin/node/bench/src/construct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl sc_transaction_pool_api::TransactionPool for Transactions {
271271
unimplemented!()
272272
}
273273

274-
fn report_invalid(
274+
async fn report_invalid(
275275
&self,
276276
_at: Option<Self::Hash>,
277277
_invalid_tx_errors: TxInvalidityReportMap<TxHash<Self>>,

substrate/client/basic-authorship/src/basic_authorship.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,9 @@ where
530530
);
531531
}
532532

533-
self.transaction_pool.report_invalid(Some(self.parent_hash), unqueue_invalid);
533+
self.transaction_pool
534+
.report_invalid(Some(self.parent_hash), unqueue_invalid)
535+
.await;
534536
Ok(end_reason)
535537
}
536538

substrate/client/rpc-api/src/author/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub trait AuthorApi<Hash, BlockHash> {
6161

6262
/// Remove given extrinsic from the pool and temporarily ban it to prevent reimporting.
6363
#[method(name = "author_removeExtrinsic", with_extensions)]
64-
fn remove_extrinsic(
64+
async fn remove_extrinsic(
6565
&self,
6666
bytes_or_hash: Vec<hash::ExtrinsicOrHash<Hash>>,
6767
) -> Result<Vec<Hash>, Error>;

substrate/client/rpc-spec-v2/src/transaction/tests/middleware_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ impl TransactionPool for MiddlewarePool {
137137
Ok(watcher.boxed())
138138
}
139139

140-
fn report_invalid(
140+
async fn report_invalid(
141141
&self,
142142
at: Option<<Self::Block as BlockT>::Hash>,
143143
invalid_tx_errors: TxInvalidityReportMap<TxHash<Self>>,
144144
) -> Vec<Arc<Self::InPoolTransaction>> {
145-
self.inner_pool.report_invalid(at, invalid_tx_errors)
145+
self.inner_pool.report_invalid(at, invalid_tx_errors).await
146146
}
147147

148148
fn status(&self) -> PoolStatus {

substrate/client/rpc-spec-v2/src/transaction/transaction_broadcast.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,22 @@ where
226226
let pool = self.pool.clone();
227227
// The future expected by the executor must be `Future<Output = ()>` instead of
228228
// `Future<Output = Result<(), Aborted>>`.
229-
let fut = fut.map(move |result| {
230-
// Connection space is cleaned when this object is dropped.
231-
drop(reserved_identifier);
229+
let fut = fut.then(move |result| {
230+
async move {
231+
// Connection space is cleaned when this object is dropped.
232+
drop(reserved_identifier);
232233

233-
// Remove the entry from the broadcast IDs map.
234-
let Some(broadcast_state) = broadcast_ids.write().remove(&drop_id) else { return };
234+
// Remove the entry from the broadcast IDs map.
235+
let Some(broadcast_state) = broadcast_ids.write().remove(&drop_id) else { return };
235236

236-
// The broadcast was not stopped.
237-
if result.is_ok() {
238-
return
239-
}
237+
// The broadcast was not stopped.
238+
if result.is_ok() {
239+
return
240+
}
240241

241-
// Best effort pool removal (tx can already be finalized).
242-
pool.report_invalid(None, [(broadcast_state.tx_hash, None)].into());
242+
// Best effort pool removal (tx can already be finalized).
243+
pool.report_invalid(None, [(broadcast_state.tx_hash, None)].into()).await;
244+
}
243245
});
244246

245247
// Keep track of this entry and the abortable handle.

substrate/client/rpc/src/author/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ where
153153
Ok(self.pool.ready().map(|tx| tx.data().encode().into()).collect())
154154
}
155155

156-
fn remove_extrinsic(
156+
async fn remove_extrinsic(
157157
&self,
158158
ext: &Extensions,
159159
bytes_or_hash: Vec<hash::ExtrinsicOrHash<TxHash<P>>>,
@@ -173,6 +173,7 @@ where
173173
Ok(self
174174
.pool
175175
.report_invalid(None, hashes)
176+
.await
176177
.into_iter()
177178
.map(|tx| tx.hash().clone())
178179
.collect())

substrate/client/transaction-pool/api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub trait TransactionPool: Send + Sync {
311311
/// occurred.
312312
///
313313
/// Function returns the transactions actually removed from the pool.
314-
fn report_invalid(
314+
async fn report_invalid(
315315
&self,
316316
at: Option<<Self::Block as BlockT>::Hash>,
317317
invalid_tx_errors: TxInvalidityReportMap<TxHash<Self>>,

substrate/client/transaction-pool/src/fork_aware_txpool/fork_aware_txpool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ where
10051005
/// The transaction pool implementation will determine which transactions should be
10061006
/// removed from the pool. Transactions that depend on invalid transactions will also
10071007
/// be removed.
1008-
fn report_invalid(
1008+
async fn report_invalid(
10091009
&self,
10101010
at: Option<<Self::Block as BlockT>::Hash>,
10111011
invalid_tx_errors: TxInvalidityReportMap<TxHash<Self>>,
@@ -1018,7 +1018,7 @@ where
10181018
let removed = self.view_store.report_invalid(at, invalid_tx_errors);
10191019

10201020
let removed_hashes = removed.iter().map(|tx| tx.hash).collect::<Vec<_>>();
1021-
self.mempool.clone().remove_transactions_sync(removed_hashes.clone());
1021+
self.mempool.remove_transactions(&removed_hashes).await;
10221022
self.import_notification_sink.clean_notified_items(&removed_hashes);
10231023

10241024
self.metrics

substrate/client/transaction-pool/src/single_state_txpool/single_state_txpool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ where
334334
.map(|mut outcome| outcome.expect_watcher().into_stream().boxed())
335335
}
336336

337-
fn report_invalid(
337+
async fn report_invalid(
338338
&self,
339339
_at: Option<<Self::Block as BlockT>::Hash>,
340340
invalid_tx_errors: TxInvalidityReportMap<TxHash<Self>>,

0 commit comments

Comments
 (0)