Skip to content

fix(core/txpool): fix nonce assignment in local tracker #31496#2183

Open
gzliudan wants to merge 7 commits intoXinFinOrg:dev-upgradefrom
gzliudan:fix-localtracker-nonce
Open

fix(core/txpool): fix nonce assignment in local tracker #31496#2183
gzliudan wants to merge 7 commits intoXinFinOrg:dev-upgradefrom
gzliudan:fix-localtracker-nonce

Conversation

@gzliudan
Copy link
Collaborator

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 apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

gzliudan and others added 7 commits March 13, 2026 15:06
…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>
Copilot AI review requested due to automatic review settings March 13, 2026 10:03
@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8762d75f-69c2-4b4f-be3a-b13821585374

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 local flag from Add, introduce AddLocal/AddLocals, and split Nonce into Nonce (chain head) vs PoolNonce (pending-inclusive).
  • Add a new core/txpool/locals tracker (with journaling + resubmission) and wire it up from eth.New plus 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
})
Comment on lines +195 to +207
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()
Comment on lines +361 to +365
// SetLocalTracker configures an optional tracker that will receive all local
// transaction submissions.
func (p *TxPool) SetLocalTracker(tracker LocalTracker) {
p.localTracker = tracker
}
Comment on lines +304 to +307
if locals := b.eth.localTxTracker; locals != nil {
locals.Track(signedTx)
}
return b.eth.txPool.Add([]*types.Transaction{signedTx}, false)[0]
Comment on lines 584 to 601
@@ -671,9 +599,6 @@ func (pool *LegacyPool) validateTxBasics(tx *types.Transaction, local bool) erro
return pool.isSigner != nil && !pool.isSigner(from)
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants