txpool: don't validate block transactions if the pool is empty (#12973)

* txpool: don't validate block transactions if the pool is empty

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

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Michal Kucharczyk
2022-12-22 23:33:01 +01:00
committed by GitHub
parent 614cd04df0
commit 8b57471221
@@ -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;
// Avoid validating block txs if the pool is empty
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);
if let Ok(Ok(validity)) = validity {
future_tags.extend(validity.provides);
}
} else {
log::trace!(target: "txpool", "txpool is empty, skipping validation for block {at:?}");
}
},
}