perf(core/txpool): pre-filter dynamic fees during pending tx retrieval #29005#2137
perf(core/txpool): pre-filter dynamic fees during pending tx retrieval #29005#2137gzliudan wants to merge 3 commits 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)
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 |
1992b62 to
77a0035
Compare
There was a problem hiding this comment.
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.PendingAPIs 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.
| 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), |
There was a problem hiding this comment.
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.
| 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 | ||
|
|
There was a problem hiding this comment.
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.
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.
77a0035 to
5ec92ed
Compare
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:
PendingAPI fromPending(enforceTips bool)toPending(minTip *uint256.Int, baseFee *uint256.Int)in txpool interfaces.legacypool.Pendingby comparing effective tip against the providedminTip/baseFeefor non-local, non-special txs.miner/worker.go)eth/sync.go)eth/api_backend.go)eth/protocol.go,eth/helper_test.go).Tests:
core/txpool/legacypool/legacypool_test.go, including:Impact:
Ref: ethereum#29005
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