Skip to content

refactor(txpool,eth,miner): use pending filter struct #29026#2160

Open
gzliudan wants to merge 5 commits intoXinFinOrg:dev-upgradefrom
gzliudan:blob-plain-split
Open

refactor(txpool,eth,miner): use pending filter struct #29026#2160
gzliudan wants to merge 5 commits intoXinFinOrg:dev-upgradefrom
gzliudan:blob-plain-split

Conversation

@gzliudan
Copy link
Collaborator

Proposed changes

Introduce txpool.PendingFilter and migrate Pending(...) signatures from positional params to a typed struct.

  • Add core/txpool.PendingFilter with MinTip/BaseFee fields for cheap call-site filtering
  • Update txpool subpool interface and all call sites in eth/miner to pass the filter struct
  • Keep behavior unchanged for empty filter (equivalent to previous nil,nil usage)
  • Refresh legacypool tests to use the new API shape

This is a refactor-only change intended to improve API clarity and future extensibility without changing consensus or RPC semantics.

Ref: ethereum#29026

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

gzliudan added 5 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.
…int256 ethereum#29008

Switch LazyTransaction gas caps from *big.Int to *uint256.Int and convert once at pending retrieval time.

In miner ordering, keep fee comparisons on uint256 and precompute TRC21 gas price in uint256 form to avoid repeated big-int conversions in heap comparisons.

Also update affected tests and call sites in legacypool/worker/helper paths.

Compatibility: LazyTransaction exported field types changed (GasFeeCap/GasTipCap).
Introduce txpool.PendingFilter and migrate Pending(...) signatures from positional params to a typed struct.

- Add core/txpool.PendingFilter with MinTip/BaseFee fields for cheap call-site filtering
- Update txpool subpool interface and all call sites in eth/miner to pass the filter struct
- Keep behavior unchanged for empty filter (equivalent to previous nil,nil usage)
- Refresh legacypool tests to use the new API shape

This is a refactor-only change intended to improve API clarity and future extensibility without changing consensus or RPC semantics.
Copilot AI review requested due to automatic review settings March 10, 2026 02:51
@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 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: a545bcbf-c344-4a1e-a728-8779e23c5975

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

Refactors transaction selection plumbing by introducing a typed txpool.PendingFilter (instead of positional args) and propagating it through txpool → eth → miner, while also migrating fee-cap fields on txpool.LazyTransaction to uint256.Int for cheaper comparisons.

Changes:

  • Add txpool.PendingFilter and update TxPool.Pending / SubPool.Pending signatures and call sites to accept the struct.
  • Update miner transaction ordering/selection to use uint256.Int fee fields and pass a PendingFilter (MinTip/BaseFee) when collecting pending txs for block production.
  • Move mining runtime options under ethconfig.Config.Miner (miner.Config) and update CLI/config marshalling + service initialization accordingly.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
params/protocol_params.go Adjusts XDC gas-limit constants and removes TargetGasLimit global.
core/txpool/subpool.go Introduces PendingFilter; changes LazyTransaction fee fields to *uint256.Int.
core/txpool/txpool.go Updates TxPool.Pending to accept PendingFilter and forwards it to subpools.
core/txpool/legacypool/legacypool.go Implements Pending(filter) by translating filter to legacy big.Int comparisons.
core/txpool/legacypool/legacypool_test.go Adds/updates tests for pending filtering (MinTip/BaseFee) behavior.
eth/protocol.go Updates txPool interface to Pending(filter) shape.
eth/sync.go Updates tx sync path to call Pending(txpool.PendingFilter{}).
eth/api_backend.go Updates pool-tx retrieval to call Pending(txpool.PendingFilter{}).
eth/helper_test.go Updates test txpool implementation to the new Pending(filter) signature.
miner/worker.go Adds miner gas tip state + filter-based pending retrieval; switches LazyTx fee fields to uint256.
miner/worker_test.go Updates worker setup and adds setGasTip validation/copying tests.
miner/ordering.go Migrates ordering logic to uint256-based fee comparisons and baseFee conversion.
miner/ordering_test.go Updates tests to populate LazyTx fee fields as uint256.
miner/miner.go Introduces miner.Config + defaults and adds Miner.SetGasTip.
eth/backend.go Sanitizes config.Miner values and wires miner construction to config.Miner.
eth/ethconfig/config.go Moves mining options under Config.Miner and updates defaults/go:generate.
eth/ethconfig/gen_config.go Regenerates TOML marshal/unmarshal using nested Miner config.
cmd/utils/flags.go Routes CLI miner flags into cfg.Miner via new setMiner.
cmd/XDC/main.go Removes runtime mutation of params.TargetGasLimit (now config-driven).
console/console_test.go Updates console test config to set Miner.Etherbase.
core/chain_makers.go Updates header gas-limit targeting to use XDCGenesisGasLimit.
core/bench_test.go Updates benchmark gas-limit targeting to use XDCGenesisGasLimit.
accounts/abi/bind/v2/util_test.go Adjusts deployment gasPrice calculation to be baseFee + 1 gwei.
eth/api_miner.go Updates SetGasPrice to update both txpool and miner gas-tip threshold.

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

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 10, 2026

Choose a reason for hiding this comment

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

This PR is described as a txpool Pending(...) API refactor with unchanged semantics, but this hunk changes XDCGenesisGasLimit from 84,000,000 to 42,000,000 and removes the global TargetGasLimit. That alters default gas limit behavior (e.g., default mining/config/bench helpers) and should be explicitly justified or split into a separate PR to avoid accidentally changing network defaults.

Copilot uses AI. Check for mistakes.
Comment on lines +63 to +67
// DefaultConfig contains default settings for miner.
var DefaultConfig = Config{
GasCeil: params.XDCGenesisGasLimit,
GasPrice: big.NewInt(1),
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

miner.DefaultConfig sets GasPrice to 1 wei, which is far below the chain’s configured minimum gas price (common.MinGasPrice defaults to 250,000,000). Since this value feeds both txpool tip enforcement and the miner’s pending-tx filter, it changes which transactions are mined by default. Consider preserving the previous default (or setting it to common.MinGasPrice) to keep default mining/txpool behavior consistent.

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +67
type PendingFilter struct {
MinTip *uint256.Int // Minimum miner tip required to include a transaction
BaseFee *uint256.Int // Minimum 1559 basefee needed to include a transaction
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The PendingFilter.BaseFee field comment says "Minimum 1559 basefee needed", but call sites (e.g. mining) pass the current execution base fee to compute effective tips. Consider rewording this to avoid misuse (e.g., treat it as the baseFee context for effectiveTip = min(tipCap, feeCap-baseFee)).

Copilot uses AI. Check for mistakes.
Comment on lines 90 to 101
// This is the number of blocks for which logs will be cached in the filter system.
FilterLogCacheSize int

// Mining options
Miner miner.Config

// This is the maximum number of addresses or topics allowed in filter criteria
// for eth_getLogs.
LogQueryLimit int

// Mining-related options
Etherbase common.Address `toml:",omitempty"`
MinerThreads int `toml:",omitempty"`
ExtraData []byte `toml:",omitempty"`
GasPrice *big.Int

// Transaction pool options
TxPool legacypool.Config
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Moving Etherbase/ExtraData/GasPrice into the nested Miner struct changes the TOML schema and will break existing config files that still use the old top-level keys. If backward compatibility is required, consider supporting both shapes during TOML unmarshalling (e.g., accept the legacy fields and map them into Config.Miner when Miner is unset).

Copilot uses AI. Check for mistakes.
@AnilChinchawale
Copy link
Member

@gzliudan conflict

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.

6 participants