diff --git a/cmd/geth/main.go b/cmd/geth/main.go index e7a61f8254..483b2aca7c 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -466,8 +466,8 @@ 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 gasCeil > params.SystemTxsGasSoftLimit { + ethBackend.TxPool().SetMaxGas(gasCeil - params.SystemTxsGasSoftLimit) } if ctx.Bool(utils.MiningEnabledFlag.Name) { // Mining only makes sense if a full Ethereum node is running diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index 64b4b12a3c..322d387840 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -1258,6 +1258,44 @@ func (p *Parlia) distributeFinalityReward(chain consensus.ChainHeaderReader, sta return p.applyTransaction(msg, state, header, cx, txs, receipts, systemTxs, usedGas, mining, tracer) } +func (p *Parlia) EstimateGasReservedForSystemTxs(chain consensus.ChainHeaderReader, header *types.Header) uint64 { + parent := chain.GetHeaderByHash(header.ParentHash) + if parent != nil { + // Mainnet and Chapel have both passed Feynman. Now, simplify the logic before and during the Feynman hard fork. + if p.chainConfig.IsFeynman(header.Number, header.Time) && + !p.chainConfig.IsOnFeynman(header.Number, parent.Time, header.Time) { + // const ( + // the following values represent the maximum values found in the most recent blocks on the mainnet + // depositTxGas = uint64(60_000) + // slashTxGas = uint64(140_000) + // finalityRewardTxGas = uint64(350_000) + // updateValidatorTxGas = uint64(12_160_000) + // ) + // suggestReservedGas := depositTxGas + // if header.Difficulty.Cmp(diffInTurn) != 0 { + // snap, err := p.snapshot(chain, header.Number.Uint64()-1, header.ParentHash, nil) + // if err != nil || !snap.SignRecently(snap.inturnValidator()) { + // suggestReservedGas += slashTxGas + // } + // } + // if header.Number.Uint64()%p.config.Epoch == 0 { + // suggestReservedGas += finalityRewardTxGas + // } + // if isBreatheBlock(parent.Time, header.Time) { + // suggestReservedGas += updateValidatorTxGas + // } + // return suggestReservedGas * 150 / 100 + if !isBreatheBlock(parent.Time, header.Time) { + // params.SystemTxsGasSoftLimit > (depositTxGas+slashTxGas+finalityRewardTxGas)*150/100 + return params.SystemTxsGasSoftLimit + } + } + } + + // params.SystemTxsGasHardLimit > (depositTxGas+slashTxGas+finalityRewardTxGas+updateValidatorTxGas)*150/100 + return params.SystemTxsGasHardLimit +} + // Finalize implements consensus.Engine, ensuring no uncles are set, nor block // rewards given. func (p *Parlia) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state vm.StateDB, txs *[]*types.Transaction, diff --git a/eth/api_miner.go b/eth/api_miner.go index 56db9e94b1..64b3130dae 100644 --- a/eth/api_miner.go +++ b/eth/api_miner.go @@ -73,8 +73,8 @@ 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 uint64(gasLimit) > params.SystemTxsGas { - api.e.TxPool().SetMaxGas(uint64(gasLimit) - params.SystemTxsGas) + if uint64(gasLimit) > params.SystemTxsGasSoftLimit { + api.e.TxPool().SetMaxGas(uint64(gasLimit) - params.SystemTxsGasSoftLimit) } return true } diff --git a/miner/bid_simulator.go b/miner/bid_simulator.go index a48407b7e2..baa2c9c1c5 100644 --- a/miner/bid_simulator.go +++ b/miner/bid_simulator.go @@ -17,6 +17,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/bidutil" "github.com/ethereum/go-ethereum/consensus" + "github.com/ethereum/go-ethereum/consensus/parlia" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/txpool" "github.com/ethereum/go-ethereum/core/types" @@ -582,7 +583,9 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) { gasLimit := bidRuntime.env.header.GasLimit if bidRuntime.env.gasPool == nil { bidRuntime.env.gasPool = new(core.GasPool).AddGas(gasLimit) - bidRuntime.env.gasPool.SubGas(params.SystemTxsGas) + if p, ok := b.engine.(*parlia.Parlia); ok { + bidRuntime.env.gasPool.SubGas(p.EstimateGasReservedForSystemTxs(b.chain, bidRuntime.env.header)) + } bidRuntime.env.gasPool.SubGas(params.PayBidTxGasLimit) } diff --git a/miner/worker.go b/miner/worker.go index e23b0eced0..f84e862b55 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -790,7 +790,11 @@ func (w *worker) commitTransactions(env *environment, plainTxs, blobTxs *transac gasLimit := env.header.GasLimit if env.gasPool == nil { env.gasPool = new(core.GasPool).AddGas(gasLimit) - env.gasPool.SubGas(params.SystemTxsGas) + if p, ok := w.engine.(*parlia.Parlia); ok { + gasReserved := p.EstimateGasReservedForSystemTxs(w.chain, env.header) + env.gasPool.SubGas(gasReserved) + log.Debug("commitTransactions", "number", env.header.Number.Uint64(), "time", env.header.Time, "EstimateGasReservedForSystemTxs", gasReserved) + } } var coalescedLogs []*types.Log diff --git a/params/protocol_params.go b/params/protocol_params.go index c83e330a8c..800c8578cd 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -38,7 +38,8 @@ const ( CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero. CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior. TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions. - SystemTxsGas uint64 = 20000000 // The gas reserved for system txs; only for parlia consensus + SystemTxsGasHardLimit uint64 = 20000000 // Maximum gas reserved for system transactions (Parlia consensus only) + SystemTxsGasSoftLimit uint64 = 1000000 // Maximum gas reserved for system transactions, excluding validator update transactions (Parlia consensus only) TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions. TxDataZeroGas uint64 = 4 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. QuadCoeffDiv uint64 = 512 // Divisor for the quadratic particle of the memory cost equation.