feat(core/txpool/legacypool): sweep underpriced transactions on gas tier forks - #2532
feat(core/txpool/legacypool): sweep underpriced transactions on gas tier forks#2532gzliudan wants to merge 1 commit into
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 Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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
Sweeps transactions invalidated by raised gas-price floors after txpool resets.
Changes:
- Detects gas-tier floor increases and removes underpriced pending/queued transactions.
- Adds sweep metrics and batched price-heap updates.
- Adds fork, reset, propagation, and exemption tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
core/txpool/legacypool/legacypool.go |
Implements floor detection and transaction sweeping. |
core/txpool/legacypool/legacypool_test.go |
Adds sweep tests and adjusts shared-config tests. |
Suppressed comments (1)
core/txpool/legacypool/legacypool_test.go:2322
- This test says it covers executable transactions above the per-account threshold, but 10 is below the pool's configured
AccountSlotsvalue of 16. The loop therefore exercises only the ordinary below-threshold path. Derive the count from the pool configuration so the test actually crosses the boundary.
const accountQueue = uint64(10)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
fb1f432 to
2a747ce
Compare
2a747ce to
6c78a34
Compare
…ier forks A gas schedule fork raises the pool's minimum gas price above transactions admitted under the previous tier. No node admits or relays them any more, yet they stay in the pending list and keep pendingNonces past them, so wallets reading the pending nonce keep building on top of a transaction the network has priced out. After a reset, compare the floor of the block pending on the head the pool landed on with the one its previous head implied, and on a rise drop every non-special transaction priced below the new floor from both the pending list and the queue. The queue is swept as well because promoteExecutables does not check price and would otherwise promote those transactions straight back into pending. The price heap is charged once for the whole sweep rather than once per removal, the way SetGasTip charges its own. The scan is boundary triggered, so a reset that does not raise the floor costs two floor lookups and one comparison, and a reorg that lowers the floor never triggers it. Special transactions are exempt exactly as they are during admission, being consensus critical and generated with a zero gas price. A swept transaction does not come back. A reorg below the fork restores the floor but not the pool, so resubmitting the transaction is accepted again only until the chain re-crosses the fork and the next reset prices it out; its sender has to resign at the new price for the transaction to stick.
6c78a34 to
25725cb
Compare
Proposed changes
Problem
A gas schedule fork (e.g. gas2500x) raises the pool's minimum gas price above transactions admitted under the previous tier. No node admits or relays them any more, yet they stay in the pending list and keep pendingNonces past them, so wallets reading the pending nonce keep building on top of a transaction the network has priced out — those follow-up transactions can never be included.
Solution
After a pool reset, compare the minimum gas price of the block pending on top of the head the pool landed on (pool.currentHead) with the one implied by its previous head. On a rise, drop every non-special transaction priced below the new floor from both the pending list and the queue.
Behavioural notes
A swept transaction does not come back. A reorg below the fork restores the floor but not the pool; the sender has to re-sign at the new price for the transaction to stick.
Announcements already queued for a swept transaction are still sent, matching upstream behaviour: announcements are hints, and peers that request the transaction simply get nothing back.
Metrics: txpool/pending/belowfloor and txpool/queued/belowfloor count swept transactions, alongside a log.Warn on every non-empty sweep.
Tests
Floor detection: within a tier, onto the fork block, reorg lowering the floor, reorg back across the fork, crossing one tier, crossing both tiers at once, nil head numbers.
Sweep semantics: pending and queued halves, still-valid transactions demoted to the queue, pending nonce rolled back, special transactions exempt.
Reset edge cases: aborted reset does not sweep; the reset after an abort still catches the fork.
Propagation: stale announcements for swept transactions kept, demoted transactions still announced, swept queued transactions never announced.
dropBatch skips already-removed hashes and does not charge the price heap.
Existing tests no longer mutate the global pool config so the new parallel tests can read its defaults without racing.
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