From 0dab664d98d4249dcf6cc41168ff291423ac3952 Mon Sep 17 00:00:00 2001 From: zzzckck <152148891+zzzckck@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:02:27 +0800 Subject: [PATCH] txpool: apply miner's gasceil to txpool (#2680) apply `Eth.Miner.GasCeil` to TxPool even the node did not enable `--mine` option Otherwise, there could be accmulated pending transactions in txpool. Take an example: - Currently, BSC testnet's block gaslimit is 70M, as 20M gas is reserved for SystemTxs, the maximum acceptable GasLimit for transaction is 50M. - TxPool recevied a transaction with GasLimit 60M, it would be accepted in TxPool but it will never be accepted by validators. Such kinds of transactions will be kept in txpool and gradually make the txpool overflowed --- cmd/geth/main.go | 11 ++++++----- eth/api_miner.go | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 264f7cb64..e2c277b64 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -450,22 +450,23 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isCon } // Start auxiliary services if enabled + ethBackend, ok := backend.(*eth.EthAPIBackend) + gasCeil := ethBackend.Miner().GasCeil() + if gasCeil > params.SystemTxsGas { + ethBackend.TxPool().SetMaxGas(gasCeil - params.SystemTxsGas) + } if ctx.Bool(utils.MiningEnabledFlag.Name) { // Mining only makes sense if a full Ethereum node is running if ctx.String(utils.SyncModeFlag.Name) == "light" { utils.Fatalf("Light clients do not support mining") } - ethBackend, ok := backend.(*eth.EthAPIBackend) + if !ok { utils.Fatalf("Ethereum service not running") } // Set the gas price to the limits from the CLI and start mining gasprice := flags.GlobalBig(ctx, utils.MinerGasPriceFlag.Name) ethBackend.TxPool().SetGasTip(gasprice) - gasCeil := ethBackend.Miner().GasCeil() - if gasCeil > params.SystemTxsGas { - ethBackend.TxPool().SetMaxGas(gasCeil - params.SystemTxsGas) - } if err := ethBackend.StartMining(); err != nil { utils.Fatalf("Failed to start mining: %v", err) } diff --git a/eth/api_miner.go b/eth/api_miner.go index b8d571a47..56db9e94b 100644 --- a/eth/api_miner.go +++ b/eth/api_miner.go @@ -73,7 +73,7 @@ func (api *MinerAPI) SetGasPrice(gasPrice hexutil.Big) bool { // SetGasLimit sets the gaslimit to target towards during mining. func (api *MinerAPI) SetGasLimit(gasLimit hexutil.Uint64) bool { api.e.Miner().SetGasCeil(uint64(gasLimit)) - if api.e.Miner().Mining() && uint64(gasLimit) > params.SystemTxsGas { + if uint64(gasLimit) > params.SystemTxsGas { api.e.TxPool().SetMaxGas(uint64(gasLimit) - params.SystemTxsGas) } return true