Skip to content

feat(core/txpool/legacypool): sweep underpriced transactions on gas tier forks - #2532

Open
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:sweep-low-price-tx
Open

feat(core/txpool/legacypool): sweep underpriced transactions on gas tier forks#2532
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:sweep-low-price-tx

Conversation

@gzliudan

Copy link
Copy Markdown
Collaborator

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.

  • Both halves of the pool are swept. promoteExecutables does not check price, so leaving the queue untouched would promote those transactions straight back into pending.
  • The baseline is the pool's actual head, not the requested one. A reset that bails out on a missing head or state leaves currentHead in place, so an aborted reset never sweeps, and the reset that follows still catches the fork even though the pool driver already moved past it.
  • Boundary triggered. A reset that does not raise the floor costs two floor lookups and one comparison; a reorg that lowers the floor never triggers the scan.
  • Special transactions are exempt, exactly as during admission: they are consensus critical and generated with a zero gas price.
  • The price heap is charged once for the whole sweep rather than once per removal, the way SetGasTip charges its own.

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

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

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 Plus

Run ID: 57ccec67-b7c4-42b9-9b0d-91079c1d0593

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

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AccountSlots value 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.

Comment thread core/txpool/legacypool/legacypool_test.go Outdated
@gzliudan
gzliudan force-pushed the sweep-low-price-tx branch 2 times, most recently from fb1f432 to 2a747ce Compare August 22, 2026 02:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

…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.
@gzliudan
gzliudan force-pushed the sweep-low-price-tx branch from 6c78a34 to 25725cb Compare August 24, 2026 10:20
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