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

Commit

Permalink
txpool: don't validate block transactions if the pool is empty
Browse files Browse the repository at this point in the history
Fix shall prevent from wasting the CPU during the major sync. Block
transaction don't need to be re-validated when the txpool is empty.

Fixes: #12903
  • Loading branch information
michalkucharczyk committed Dec 19, 2022
1 parent 2a0eeff commit ed357df
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions client/transaction-pool/src/graph/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,23 @@ impl<B: ChainApi> Pool<B> {
// if it's not found in the pool query the runtime at parent block
// to get validity info and tags that the extrinsic provides.
None => {
let validity = self
.validated_pool
.api()
.validate_transaction(parent, TransactionSource::InBlock, extrinsic.clone())
.await;

if let Ok(Ok(validity)) = validity {
future_tags.extend(validity.provides);
// Avoid validating block txs if the pool is empty (substrate/issues #12903)
if !self.validated_pool.status().is_empty() {
let validity = self
.validated_pool
.api()
.validate_transaction(
parent,
TransactionSource::InBlock,
extrinsic.clone(),
)
.await;

if let Ok(Ok(validity)) = validity {
future_tags.extend(validity.provides);
}
} else {
log::trace!( target: "txpool", "txpool is empty, skipping validation for block {:?}", at);
}
},
}
Expand Down

0 comments on commit ed357df

Please sign in to comment.