Reduce time taken to collect VerifiedTransactions #1563
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The original
execute_block()
collected verified transactions transactions from the Proposal block by re-verifying each transaction in the Proposal block. This triggers therecover_signer()
library call for each transaction in the Proposal. It then fills up any missing ones from the mempool by cloning.This PR flips this behaviour around to collect verified transactions first from the mempool, which already contains pre-verified transactions. It then fills up any missing ones from the Proposal block by only re-verifying those missing from the mempool.
This speeds things up by several orders of magnitude, when the transactions are already pre-verified and present in the mempool, with the worst case scenario being similar in timing to the previous behaviour e.g.
before
after
The time taken to collect about ~95 VerifiedTransactions is about 325ms across all nodes (before) and is about 200us (if already present in the pool) to ~325ms (if not present in the pool).
As this is a small change that makes a measurable impact, with the worst case similar as before, I thought it would be good to merge this one first.