perf: txpool parallel stateless validation and pre-read state before promotion#9
Open
beamuu wants to merge 5 commits intokub-chain:mainfrom
Open
perf: txpool parallel stateless validation and pre-read state before promotion#9beamuu wants to merge 5 commits intokub-chain:mainfrom
beamuu wants to merge 5 commits intokub-chain:mainfrom
Conversation
…allel stateless validation and pre-read account state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TxPool Optimization
Background
The transaction pool (
core/tx_pool.go) processes incoming transactions from the network. Under distributed traffic — many unique sender addresses each sending one transaction — two bottlenecks emerged:Stateless checks run under the write lock. Checks like size, transaction type, gas price floor, and fee cap validation do not touch shared pool state, but they execute sequentially inside
pool.mu.Lock()along with every other validation step.Cold statedb reads hold the write lock during promotion.
promoteExecutablescallsGetNonceandGetBalancefor every queued account whilepool.muis held. For N unique senders with uncached state this means N sequential disk/trie reads inside the critical section, blocking all concurrent transaction submissions for the full duration.Changes
Change A — Parallel stateless validation (
validateTxStateless)File:
core/tx_pool.goA new
validateTxStatelessfunction extracts all checks fromvalidateTxthat do not requirepool.currentState:pool.currentMaxGaspool.gasPricesenderCacher)addTxsnow runsvalidateTxStatelessconcurrently across all incoming transactions before acquiringpool.mu. Transactions that fail are rejected early. Only survivors reach the locked phase where stateful checks (nonce ordering, balance sufficiency) and insertion happen.Change B — Pre-read account state before promotion (
runReorg)File:
core/tx_pool.gorunReorgnow reads nonces and balances for all queued addresses outsidepool.mubefore callingpromoteExecutables. The results are passed as a pre-fetched map, andpromoteExecutablesuses those values instead of calling statedb directly.The total number of statedb reads is unchanged. The write lock hold time drops from
O(N × disk_latency)toO(N × map_lookup).What Was Not Changed
txNoncercaching logictxPricedListheap operationsBenchmark
Running the benchmarks
Scenarios
SingleSenderManyUniqueSendersMixedLoadComparing before and after
The
ManyUniqueSendersscenario shows the largest improvement because it maximises cold statedb reads — exactly the path targeted by both optimizations.