fix(core/txpool): fix nonce assignment in local tracker #31496#2183
fix(core/txpool): fix nonce assignment in local tracker #31496#2183gzliudan wants to merge 7 commits intoXinFinOrg:dev-upgradefrom
Conversation
…thereum#28837 Improve txpool loop synchronization around background resets. This change: - adds an explicit termination channel to signal pool shutdown - tracks forced-reset intent and a waiter channel inside the reset loop - ensures reset waiters are notified on completion or on pool termination - allows an explicit sync request path to trigger an additional reset round when needed Scope is limited to internal txpool concurrency control in core/txpool/txpool.go, with no protocol or RPC behavior change.
…ereum#29083 * core/txpool: no need to run rotate if no local txs Signed-off-by: jsvisa <delweng@gmail.com> * Revert "core/txpool: no need to run rotate if no local txs" This reverts commit 17fab17. Signed-off-by: jsvisa <delweng@gmail.com> * use Debug if todo is empty Signed-off-by: jsvisa <delweng@gmail.com> --------- Signed-off-by: jsvisa <delweng@gmail.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR refactors local-transaction handling in the txpool to fix incorrect nonce usage in local tracking by separating “chain head nonce” vs “pool (pending-inclusive) nonce”, and introduces a dedicated local tx tracker that can re-submit/journal local submissions.
Changes:
- Update txpool APIs to remove the
localflag fromAdd, introduceAddLocal/AddLocals, and splitNonceintoNonce(chain head) vsPoolNonce(pending-inclusive). - Add a new
core/txpool/localstracker (with journaling + resubmission) and wire it up frometh.Newplus RPC submission paths. - Adjust legacy pool internals/tests to remove local-exemption behavior and align callers/tests with the new
Add(..., sync)signature.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
eth/protocol_test.go |
Updates txpool Add call signature in protocol tests. |
eth/protocol.go |
Updates the protocol manager’s txPool interface Add signature. |
eth/helper_test.go |
Updates mock txpool Add signature for protocol tests. |
eth/handler.go |
Updates inbound network tx insertion to new Add(txs, sync) signature. |
eth/backend.go |
Wires up locals.TxTracker lifecycle and connects it to TxPool when locals are enabled. |
eth/api_backend.go |
Tracks local RPC submissions and switches pending nonce API to PoolNonce. |
core/txpool/txpool.go |
Adds chain-head state caching for nonce lookup, introduces LocalTracker, AddLocal(s), PoolNonce, and Sync(). |
core/txpool/txpool_local_test.go |
New tests ensuring local tracking occurs before subpool Add. |
core/txpool/subpool.go |
Removes local from SubPool.Add and drops Locals() from the interface. |
core/txpool/locals/tx_tracker.go |
New local transaction tracker with periodic recheck/resubmission and optional journaling. |
core/txpool/locals/tx_tracker_test.go |
New tests for tracker resubmission behavior. |
core/txpool/locals/journal.go |
Fixes package name and tweaks logging for empty journal rotations. |
core/txpool/legacypool/list.go |
Exposes SortedMap for use by the locals tracker; removes local-aware pricing/eviction behavior in priced list. |
core/txpool/legacypool/legacypool.go |
Removes local allowlist/journaling/exemptions and adjusts validation/eviction accordingly. |
core/txpool/legacypool/legacypool_test.go |
Updates tests/benchmarks to reflect the removed local exemption semantics and new APIs. |
core/txpool/legacypool/journal_shared.go |
Adds shared journal helpers for order/lending pool journals. |
contracts/utils.go |
Routes contract-created tx insertions through TxPool.AddLocal. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // RemotesBelowTip finds all remote transactions below the given tip threshold. | ||
| func (t *lookup) RemotesBelowTip(threshold *big.Int) types.Transactions { | ||
| // TxsBelowTip finds all remote transactions below the given tip threshold. |
| tracker.journal.load(func(transactions []*types.Transaction) []error { | ||
| tracker.TrackAll(transactions) | ||
| return nil | ||
| }) |
| checkJournal := tracker.journal != nil && time.Since(lastJournal) > tracker.rejournal | ||
| resubmits, rejournal := tracker.recheck(checkJournal) | ||
| if len(resubmits) > 0 { | ||
| tracker.pool.Add(resubmits, false) | ||
| } | ||
| if checkJournal { | ||
| // Lock to prevent journal.rotate <-> journal.insert (via TrackAll) conflicts | ||
| tracker.mu.Lock() | ||
| lastJournal = time.Now() | ||
| if err := tracker.journal.rotate(rejournal); err != nil { | ||
| log.Warn("Transaction journal rotation failed", "err", err) | ||
| } | ||
| tracker.mu.Unlock() |
| // SetLocalTracker configures an optional tracker that will receive all local | ||
| // transaction submissions. | ||
| func (p *TxPool) SetLocalTracker(tracker LocalTracker) { | ||
| p.localTracker = tracker | ||
| } |
| if locals := b.eth.localTxTracker; locals != nil { | ||
| locals.Track(signedTx) | ||
| } | ||
| return b.eth.txPool.Add([]*types.Transaction{signedTx}, false)[0] |
| @@ -671,9 +599,6 @@ func (pool *LegacyPool) validateTxBasics(tx *types.Transaction, local bool) erro | |||
| return pool.isSigner != nil && !pool.isSigner(from) | |||
| }, | |||
| } | |||
Proposed changes
Ref: ethereum#31496
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that