Skip to content

perf(core/txpool): pre-filter dynamic fees during pending tx retrieval #29005#2137

Open
gzliudan wants to merge 3 commits intoXinFinOrg:dev-upgradefrom
gzliudan:txpool-pending-filtering
Open

perf(core/txpool): pre-filter dynamic fees during pending tx retrieval #29005#2137
gzliudan wants to merge 3 commits intoXinFinOrg:dev-upgradefrom
gzliudan:txpool-pending-filtering

Conversation

@gzliudan
Copy link
Collaborator

@gzliudan gzliudan commented Mar 6, 2026

Proposed changes

Introduce dynamic-fee pre-filtering in txpool pending retrieval to reduce allocations and downstream processing work during mining and tx propagation.

What changed:

  • Change the Pending API from Pending(enforceTips bool) to Pending(minTip *uint256.Int, baseFee *uint256.Int) in txpool interfaces.
  • Implement pre-filtering in legacypool.Pending by comparing effective tip against the provided minTip/baseFee for non-local, non-special txs.
  • Update call sites to the new API:
  • miner work assembly (miner/worker.go)
  • tx sync (eth/sync.go)
  • pool transaction retrieval (eth/api_backend.go)
  • protocol/test interfaces (eth/protocol.go, eth/helper_test.go).

Tests:

  • Add targeted coverage for pending filtering semantics in core/txpool/legacypool/legacypool_test.go, including:
  • minTip threshold boundary behavior
  • baseFee-aware effective tip filtering
  • local/special transaction exemption behavior
  • dynamic-fee boundary behavior when baseFee is nil.

Impact:

  • Preserves existing behavior while making pending selection cheaper for downstream consumers.
  • Improves confidence in edge-case behavior through dedicated tests.

Ref: ethereum#29005

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 6, 2026 03:21
@coderabbitai
Copy link

coderabbitai bot commented Mar 6, 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: d6f88b47-b243-4eb9-85ec-1af358e344fa

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
  • Post copyable unit tests in a comment

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 updates pending-transaction retrieval to support pre-filtering by EIP-1559 fee parameters (min tip + baseFee) to reduce downstream work during block building, and wires miner configuration/state to drive that filter.

Changes:

  • Extend TxPool.Pending / SubPool.Pending APIs to accept (minTip, baseFee) as *uint256.Int, with legacy pool implementing the filtering logic.
  • Update miner worker to maintain a configurable gas tip threshold and request pre-filtered pending txs during commitNewWork.
  • Refactor mining-related node configuration to ethconfig.Config.Miner (TOML + CLI + backend wiring), plus add/adjust related tests.

Reviewed changes

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

Show a summary per file
File Description
params/protocol_params.go Updates XDC genesis gas limit constant and removes TargetGasLimit global.
miner/worker.go Adds miner-side gas tip state + validation and uses it when pulling pending txs.
miner/miner.go Introduces miner.Config, default miner config, and exposes SetGasTip.
miner/worker_test.go Adds unit tests for worker gas tip validation and pointer-copy semantics.
core/txpool/txpool.go Changes TxPool.Pending signature to accept (minTip, baseFee) in uint256.
core/txpool/subpool.go Updates SubPool.Pending interface to accept (minTip, baseFee) in uint256.
core/txpool/legacypool/legacypool.go Implements pending pre-filtering by effective tip, keeping locals/special txs.
core/txpool/legacypool/legacypool_test.go Adds tests for min-tip/baseFee pending filtering behavior.
eth/protocol.go Updates protocol manager txpool interface to the new Pending signature.
eth/sync.go Adjusts tx sync to call Pending(nil, nil).
eth/api_backend.go Adjusts pool tx retrieval to call Pending(nil, nil).
eth/api_miner.go Ensures miner_setGasPrice updates both txpool tip and miner worker tip.
eth/helper_test.go Updates test txpool mock to satisfy new Pending signature.
eth/ethconfig/config.go Moves mining options under Config.Miner and updates defaults + go:generate.
eth/ethconfig/gen_config.go Regenerates TOML marshal/unmarshal with Miner miner.Config.
eth/backend.go Sanitizes config.Miner fields and wires miner + GPO to config.Miner.GasPrice.
cmd/utils/flags.go Routes miner CLI flags into cfg.Miner and adds setMiner helper.
cmd/XDC/main.go Removes global params.TargetGasLimit mutation on startup.
console/console_test.go Updates console test config to use ethconfig.Config.Miner.Etherbase.
core/chain_makers.go Updates gas limit target constant usage in header construction.
core/bench_test.go Updates gas limit target constant usage in benchmarks.
accounts/abi/bind/v2/util_test.go Adjusts gasPrice in deploy test to add params.GWei to baseFee.

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

Comment on lines +170 to 180
func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, announceTxs bool) *worker {
worker := &worker{
config: config,
chainConfig: chainConfig,
engine: engine,
eth: eth,
mux: mux,
coinbase: config.Etherbase,
extra: config.ExtraData,
tip: config.GasPrice,
txsCh: make(chan core.NewTxsEvent, txChanSize),
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

newWorker assigns tip: config.GasPrice directly, which both (a) defeats the new pointer-copying safety you added in setGasTip (external mutation of config.GasPrice would mutate w.tip), and (b) can lead to a panic later in commitNewWork when calling uint256.MustFromBig(w.tip) if config.GasPrice is nil. Consider validating config/config.GasPrice here and initializing w.tip with a defensive copy (or a sane default) so the worker never holds a shared or nil tip pointer.

Copilot uses AI. Check for mistakes.
Comment on lines 27 to 31
MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be.
MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1).
GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block.
XDCGenesisGasLimit uint64 = 84000000
XDCGenesisGasLimit uint64 = 42000000

Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

The PR title/description is about txpool pending-fee prefiltering, but this hunk also changes the network-wide XDCGenesisGasLimit constant (84,000,000 -> 42,000,000) and removes the TargetGasLimit variable. Since XDCGenesisGasLimit is now used as the default miner gas ceiling (and in tests/benchmarks), this is a significant default behavior change that should be explicitly justified in the PR description (or split into a dedicated PR) to avoid accidental operational changes for node operators.

Copilot uses AI. Check for mistakes.
gzliudan added 3 commits March 9, 2026 19:46
Miner configuration is unified under [Eth.Miner] (GasCeil/GasPrice/Etherbase/ExtraData), replacing legacy top-level [Eth] miner keys.

Operational impact: existing config files using [Eth].GasPrice/[Eth].Etherbase/[Eth].ExtraData must be migrated before upgrade.

Behavior update: gasprice=0 remains valid; only negative gas prices are sanitized at startup.

Default change: XDCGenesisGasLimit is reduced to 42,000,000 and now feeds miner default GasCeil (including default --miner-gaslimit), so nodes relying on defaults should review capacity expectations.
Synchronize miner gas tip updates across subsystems when RPC updates gas price.

- update eth miner API to apply gas tip changes to both txpool and miner
- add miner/worker SetGasTip path and initialize worker tip from config
- adjust bind util test to use params.GWei over base fee

Ref: ethereum#28933
…ethereum#29005

Introduce dynamic-fee pre-filtering in txpool pending retrieval to reduce
allocations and downstream processing work during mining and tx propagation.

What changed:
- Change the `Pending` API from `Pending(enforceTips bool)` to
  `Pending(minTip *uint256.Int, baseFee *uint256.Int)` in txpool interfaces.
- Implement pre-filtering in `legacypool.Pending` by comparing effective tip
  against the provided `minTip/baseFee` for non-local, non-special txs.
- Update call sites to the new API:
  - miner work assembly (`miner/worker.go`)
  - tx sync (`eth/sync.go`)
  - pool transaction retrieval (`eth/api_backend.go`)
  - protocol/test interfaces (`eth/protocol.go`, `eth/helper_test.go`).

Tests:
- Add targeted coverage for pending filtering semantics in
  `core/txpool/legacypool/legacypool_test.go`, including:
  - minTip threshold boundary behavior
  - baseFee-aware effective tip filtering
  - local/special transaction exemption behavior
  - dynamic-fee boundary behavior when baseFee is nil.

Impact:
- Preserves existing behavior while making pending selection cheaper for
  downstream consumers.
- Improves confidence in edge-case behavior through dedicated tests.
@gzliudan gzliudan force-pushed the txpool-pending-filtering branch from 77a0035 to 5ec92ed Compare March 9, 2026 11:53
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