Skip to content

refactor(core/txpool/legacypool): refactor truncatePending #31715#2202

Open
gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:truncate-pending
Open

refactor(core/txpool/legacypool): refactor truncatePending #31715#2202
gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:truncate-pending

Conversation

@gzliudan
Copy link
Collaborator

Proposed changes

Ref: ethereum#31715

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 03:49
@coderabbitai
Copy link

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: c4ec17b8-d3f3-43ac-b4e9-9e9f8c6c2650

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
📝 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 transaction pool internals, including LegacyPool.truncatePending, and reworks how “local” transactions are tracked/journaled by moving that responsibility into a new core/txpool/locals tracker that integrates with the aggregated txpool.TxPool.

Changes:

  • Refactor txpool/subpool Add APIs (drop the local flag) and introduce TxPool helpers for local submission (SetLocalTracker, AddLocal(s)) plus deterministic TxPool.Sync() for tests/simulators.
  • Remove “local tx” special-casing from legacypool (eviction/pricing/journaling) and introduce locals.TxTracker for journaling + periodic resubmission.
  • Wire the local tracker into the eth service startup path and update call sites/tests to the new APIs.

Reviewed changes

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

Show a summary per file
File Description
eth/protocol_test.go Updates txpool Add call signature used by protocol tests.
eth/protocol.go Updates txPool interface Add signature (drops local flag).
eth/helper_test.go Updates testTxPool.Add signature to match new protocol interface.
eth/handler.go Updates inbound-tx handling to call Add(txs, sync) signature.
eth/backend.go Wires locals.TxTracker into node lifecycle when locals are enabled; sanitizes Rejournal.
eth/api_backend.go Tracks local txs via localTxTracker before inserting into pool; updates Add call signature.
core/txpool/txpool_local_test.go Adds unit tests asserting local tracking occurs before subpool add.
core/txpool/txpool.go Adds chain/state plumbing, local tracking hooks, and Sync() for deterministic resets; updates Add signature.
core/txpool/subpool.go Updates SubPool interface (Add signature; removes Locals).
core/txpool/locals/tx_tracker_test.go Adds helper scaffolding for tracker tests (currently no Test* functions).
core/txpool/locals/tx_tracker.go Introduces local tx tracker with journaling + periodic recheck/resubmission.
core/txpool/locals/journal.go Moves/renames journal implementation into locals package; tweaks rotate logging verbosity.
core/txpool/legacypool/list.go Exports SortedMap, removes local-specific pricing/eviction paths, and updates lookup interactions.
core/txpool/legacypool/legacypool_test.go Updates tests/benchmarks for removed local semantics and updated APIs.
core/txpool/legacypool/legacypool.go Removes local account/journal machinery, adjusts eviction/pricing flows, and refactors truncatePending.
core/txpool/legacypool/journal_shared.go Adds shared journal helpers for order/lending journals after main local journal moved to locals.
contracts/utils.go Switches to TxPool.AddLocal for submitting locally-signed transactions.

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

Comment on lines +282 to +286
if !config.TxPool.NoLocals {
rejournal := config.TxPool.Rejournal
if rejournal < time.Second {
log.Warn("Sanitizing invalid txpool journal time", "provided", rejournal, "updated", time.Second)
rejournal = time.Second
Comment on lines +51 to +58
type testEnv struct {
chain *core.BlockChain
pool *txpool.TxPool
tracker *TxTracker
genDb ethdb.Database
}

func newTestEnv(t *testing.T, n int, gasTip uint64, journal string) *testEnv {

// 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 +303 to +307
func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
return b.eth.txPool.Add([]*types.Transaction{signedTx}, true, false)[0]
if locals := b.eth.localTxTracker; locals != nil {
locals.Track(signedTx)
}
return b.eth.txPool.Add([]*types.Transaction{signedTx}, false)[0]
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.

3 participants