cmd/XDC: fix txpool gasPrice being overridden at checkpoints (#1878)

This commit removes two redundant SetGasPrice() calls in the startNode function that were causing multiple issues:

1. Overriding txpool's configured price limit with the miner's gas price setting, mixing two independent configurations:

- cfg.Eth.GasPrice (from --miner-gasprice --gasprice flag)
- cfg.TxPool.PriceLimit (from --txpool-pricelimit flag)

2. Reverting runtime gasPrice changes made via RPC. When users call miner_setGasPrice RPC method to adjust the gasPrice dynamically, the changes would be unexpectedly reverted at the next checkpoint when startNode re-applies cfg.Eth.GasPrice.

The txpool already initializes its gasPrice from config.PriceLimit during construction (core/txpool/txpool.go:333):

```go
func NewTxPool(config Config, chainconfig *params.ChainConfig, chain blockChain) *TxPool {
	pool := &TxPool{
		gasPrice:         new(big.Int).SetUint64(config.PriceLimit),
	}
```

When mining is started via RPC (miner_start), the MinerAPI.Start() method handles gasPrice propagation correctly.

This change ensures:

- The txpool respects its own configuration
- Runtime gasPrice adjustments via RPC persist across checkpoints
- No unexpected overriding of user-configured values
This commit is contained in:
Daniel Liu 2025-12-22 14:31:38 +08:00 committed by GitHub
parent 1dd09427ed
commit 1a9935625f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -361,8 +361,6 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, cfg X
th.SetThreads(threads)
}
}
// Set the gas price to the limits from the CLI and start mining
ethBackend.TxPool().SetGasPrice(cfg.Eth.GasPrice)
if err := ethBackend.StartStaking(true); err != nil {
utils.Fatalf("Failed to start staking: %v", err)
}
@ -398,8 +396,6 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, cfg X
th.SetThreads(threads)
}
}
// Set the gas price to the limits from the CLI and start mining
ethBackend.TxPool().SetGasPrice(cfg.Eth.GasPrice)
if err := ethBackend.StartStaking(true); err != nil {
utils.Fatalf("Failed to start staking: %v", err)
}