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

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

Merged

Conversation

michalkucharczyk
Copy link
Contributor

@michalkucharczyk michalkucharczyk commented Dec 19, 2022

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.

Part of: #12903

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
@michalkucharczyk michalkucharczyk added B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Dec 19, 2022
@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Dec 19, 2022
@michalkucharczyk michalkucharczyk requested review from a team and arkpar December 19, 2022 12:26
Copy link
Contributor

@lexnv lexnv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@arkpar
Copy link
Member

arkpar commented Dec 19, 2022

I'd prefer this check to be earlier in the event handling flow. This skips validation but there's still unnecessary work done to read potentially thousands of extrinsics from all blocks since the last notification into memory.

I think the root of the issue is the way the tree route is queried here:

match self.api.tree_route(from, to) {

This code seems to calculate the route from a previous notification, expecting it to be short. In reality notifications are not guaranteed to be sent for all blocks. I.e. if a node goes offline for a few days, then reconnects and catches up the route may be huge. The fact that we send a finality notification on each session end even when doing a full sync is not something the tx pool should rely on. There should be a reasonable maximum of blocks that are queried here.

@michalkucharczyk
Copy link
Contributor Author

michalkucharczyk commented Dec 19, 2022

I agree this solution is not a perfect solution of original problem. Please refer to: #12903 (comment) for my other proposal.

I.e. if a node goes offline for a few days, then reconnects and catches up the route may be huge.

  • Just a thought - the local node being offline for long time, could have non-propagate transactions in its txpool. It could build a local fork. To handle this case correctly and notify txs' listeners, the complete tree route must be computed, and all transaction from enacted/retracted blocks should be processed. Not sure if this can be avoided.
  • question: is there any indication of this state (catching up after being offline) in the client (sth like is_major_syncing)

@arkpar
Copy link
Member

arkpar commented Dec 20, 2022

Just a thought - the local node being offline for long time, could have non-propagate transactions in its txpool. It could build a local fork. To handle this case correctly and notify txs' listeners, the complete tree route must be computed, and all transaction from enacted/retracted blocks should be processed. Not sure if this can be avoided.

The simplest solution I see is to simply clear the pool if the period between notifications is too large.

question: is there any indication of this state (catching up after being offline) in the client (sth like is_major_syncing)

IIRC major syncing state indicates not just the initial sync, but also covers this case.

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this doesn't solve the issue properly as @arkpar mentioned, this is still a good optimization.

client/transaction-pool/src/graph/pool.rs Outdated Show resolved Hide resolved
client/transaction-pool/src/graph/pool.rs Outdated Show resolved Hide resolved
@bkchr
Copy link
Member

bkchr commented Dec 22, 2022

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot paritytech-processbot bot merged commit 9443052 into master Dec 22, 2022
@paritytech-processbot paritytech-processbot bot deleted the mku-txpool-avoid-cpu-high-load-during-sync branch December 22, 2022 22:33
ltfschoen pushed a commit to ltfschoen/substrate that referenced this pull request Feb 22, 2023
…ytech#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: paritytech#12903

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
…ytech#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: paritytech#12903

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

4 participants