Skip to content

feat(core/txpool): reject stale transaction for local tracking #31473#2182

Open
gzliudan wants to merge 6 commits intoXinFinOrg:dev-upgradefrom
gzliudan:fix-txpool-localtracker
Open

feat(core/txpool): reject stale transaction for local tracking #31473#2182
gzliudan wants to merge 6 commits intoXinFinOrg:dev-upgradefrom
gzliudan:fix-txpool-localtracker

Conversation

@gzliudan
Copy link
Collaborator

Proposed changes

Ref: ethereum#31473

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 6 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 09:31
@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: 55fa5659-d88f-4de9-b018-166bd481b0db

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 across the txpool stack by removing the local flag from txpool/subpool APIs and introducing a dedicated locals.TxTracker for tracking/journaling/resubmitting local submissions. It wires the tracker into the Ethereum service startup and updates callers/tests accordingly.

Changes:

  • Remove local bool from TxPool.Add/SubPool.Add (and related interfaces/call sites), keeping only the sync flag.
  • Introduce core/txpool/locals tracker + journaling and wire it in eth.New when TxPool.NoLocals is false.
  • Simplify legacypool by removing local-account exemptions/journaling paths and update tests/benchmarks for the new semantics.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
eth/protocol.go Updates txpool interface to new Add(txs, sync) signature.
eth/protocol_test.go Updates protocol tests for new txpool Add signature.
eth/helper_test.go Updates test txpool implementation signature.
eth/handler.go Updates inbound-tx handling to call Add(txs, sync) without local flag.
eth/backend.go Wires locals.TxTracker into node lifecycle and txpool when locals enabled.
eth/api_backend.go Updates RPC submission path to track locals and call txpool Add.
core/txpool/txpool.go Adds local-tracker plumbing (AddLocal(s)), pool termination/sync helper, and internal state tracking.
core/txpool/txpool_local_test.go Adds tests asserting local tracking happens before add and propagates sync.
core/txpool/subpool.go Updates subpool interface to new Add signature; removes Locals() API.
core/txpool/locals/tx_tracker.go New local transaction tracker (track/recheck/resubmit + journaling).
core/txpool/locals/tx_tracker_test.go Adds a test harness for locals tracker integration tests.
core/txpool/locals/journal.go Fixes package name and adjusts regen logging verbosity when empty.
core/txpool/legacypool/list.go Exports SortedMap/constructor; removes local-aware pricing/eviction hooks.
core/txpool/legacypool/legacypool.go Removes legacy local-account exemptions/journaling and unifies tx lookup handling.
core/txpool/legacypool/legacypool_test.go Updates tests/benchmarks for unified (non-local-exempt) semantics.
core/txpool/legacypool/journal_shared.go Adds shared journal helpers for legacypool journals.
contracts/utils.go Switches contract helpers to TxPool.AddLocal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +304 to 309
if locals := b.eth.localTxTracker; locals != nil {
locals.Track(signedTx)
}
return b.eth.txPool.Add([]*types.Transaction{signedTx}, false)[0]
}


// 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.
Comment on lines +500 to +503
sync := make(chan error)
select {
case p.sync <- sync:
return <-sync
// Sync is a helper method for unit tests or simulator runs where the chain events
// are arriving in quick succession, without any time in between them to run the
// internal background reset operations. This method will run an explicit reset
// operation to ensure the pool stabilises, thus avoiding flakey behavior.
Comment on lines 619 to 623
// Discard finds a number of most underpriced transactions, removes them from the
// priced list and returns them for further removal from the entire pool.
// If noPending is set to true, we will only consider the floating list
//
// Note local transaction won't be considered for eviction.
func (l *pricedList) Discard(slots int, force bool) (types.Transactions, bool) {
func (l *pricedList) Discard(slots int) (types.Transactions, bool) {
drop := make(types.Transactions, 0, slots) // Remote underpriced transactions to drop
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