-
Notifications
You must be signed in to change notification settings - Fork 2.6k
txpool: don't validate block transactions if the pool is empty #12973
txpool: don't validate block transactions if the pool is empty #12973
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
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: substrate/client/transaction-pool/src/lib.rs Line 727 in cad470b
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. |
I agree this solution is not a perfect solution of original problem. Please refer to: #12903 (comment) for my other proposal.
|
The simplest solution I see is to simply clear the pool if the period between notifications is too large.
IIRC major syncing state indicates not just the initial sync, but also covers this case. |
There was a problem hiding this 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.
bot merge |
Waiting for commit status. |
…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 <[email protected]>
…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 <[email protected]>
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