refactor(core/txpool/legacypool): refactor truncatePending #31715#2202
refactor(core/txpool/legacypool): refactor truncatePending #31715#2202gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
Conversation
|
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 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
AddAPIs (drop thelocalflag) and introduceTxPoolhelpers for local submission (SetLocalTracker,AddLocal(s)) plus deterministicTxPool.Sync()for tests/simulators. - Remove “local tx” special-casing from
legacypool(eviction/pricing/journaling) and introducelocals.TxTrackerfor journaling + periodic resubmission. - Wire the local tracker into the
ethservice 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.
| 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 |
| 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. |
eth/api_backend.go
Outdated
| 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] |
6c77e81 to
21bcec3
Compare
21bcec3 to
d3c1c97
Compare
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 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