Skip to content

fix(core/txpool/legacypool): fix data race of pricedList access #31758#2203

Merged
AnilChinchawale merged 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:fix-data-race-pricedList-access
Mar 24, 2026
Merged

fix(core/txpool/legacypool): fix data race of pricedList access #31758#2203
AnilChinchawale merged 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:fix-data-race-pricedList-access

Conversation

@gzliudan
Copy link
Copy Markdown
Collaborator

Proposed changes

Ref: ethereum#31758

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

Copilot AI review requested due to automatic review settings March 17, 2026 04:28
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 17, 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: 7066db7a-9a25-4435-8549-46454872c1d7

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

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
Copy Markdown

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 transaction-pool “local transaction” handling by removing the local flag from the txpool/subpool APIs and introducing a dedicated locals.TxTracker for journaling/resubmission, while also adding a deterministic TxPool.Sync() helper for simulator/tests.

Changes:

  • Simplify txpool/subpool Add APIs by removing the local parameter; add TxPool.AddLocal(s) wrappers that feed a pluggable local tracker.
  • Introduce core/txpool/locals.TxTracker with journaling + periodic recheck/resubmit, wired from eth.New() when locals are enabled.
  • Update legacy pool internals/tests to drop local/remote distinctions (pricing/eviction/journaling) and adjust eth protocol/tests call sites.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
eth/protocol.go Updates protocol manager’s txpool interface to the new Add(txs, sync) signature.
eth/protocol_test.go Updates protocol tests to use the new txpool Add signature.
eth/helper_test.go Updates the test txpool mock to match the new Add signature.
eth/handler.go Updates p2p tx ingestion to call Add(txs, sync) without a local flag.
eth/backend.go Wires locals.TxTracker into TxPool and node lifecycle; sanitizes Rejournal.
eth/api_backend.go Adjusts RPC tx submission path to track locals + submit into txpool under new API.
core/txpool/txpool.go Adds LocalTracker, SetLocalTracker, AddLocal(s), termination marker, and Sync() for deterministic resets; updates Add/loop logic.
core/txpool/txpool_local_test.go Adds tests ensuring local tracking happens before pool insertion.
core/txpool/subpool.go Updates SubPool interface by removing the local parameter and removing Locals().
core/txpool/locals/tx_tracker.go Adds local tx tracker with periodic recheck/resubmit and optional journaling.
core/txpool/locals/journal.go Fixes package name and adjusts logging verbosity when journal is empty.
core/txpool/legacypool/list.go Renames sortedMap to SortedMap and removes local-aware pricing/eviction code paths.
core/txpool/legacypool/legacypool.go Removes legacy local-account semantics/journaling; collapses local/remote lookup into a single map; updates add/evict/clear flows accordingly.
core/txpool/legacypool/legacypool_test.go Updates tests/benchmarks to match the new semantics and APIs (no local exemptions).
core/txpool/legacypool/journal_shared.go Adds shared journal helpers for legacypool journals.
contracts/utils.go Switches contract helper submissions to TxPool.AddLocal for local tracking.

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

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]
}
}
return migrated
t.slots = 0
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
Comment on lines +1934 to 1938
// TxsBelowTip finds all remote transactions below the given tip threshold.
func (t *lookup) TxsBelowTip(threshold *big.Int) types.Transactions {
found := make(types.Transactions, 0, 128)
t.Range(func(hash common.Hash, tx *types.Transaction, local bool) bool {
t.Range(func(hash common.Hash, tx *types.Transaction) bool {
if tx.GasTipCapIntCmp(threshold) < 0 {
@gzliudan gzliudan force-pushed the fix-data-race-pricedList-access branch 2 times, most recently from 7128100 to 17d0484 Compare March 18, 2026 06:51
@gzliudan gzliudan force-pushed the fix-data-race-pricedList-access branch from 17d0484 to 13d5504 Compare March 24, 2026 11:15
@gzliudan gzliudan force-pushed the fix-data-race-pricedList-access branch from 13d5504 to 1bc881d Compare March 24, 2026 14:32
@AnilChinchawale AnilChinchawale merged commit 83d644b into XinFinOrg:dev-upgrade Mar 24, 2026
13 checks passed
@gzliudan gzliudan deleted the fix-data-race-pricedList-access branch March 24, 2026 14:57
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.

6 participants