diff --git a/cmd/geth/main.go b/cmd/geth/main.go index a2e48c7465..1325957cb1 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -25,6 +25,8 @@ import ( "strings" "time" + "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" @@ -456,6 +458,10 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isCon // 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/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 792f851ee2..a30f0e1417 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -27,6 +27,7 @@ import ( "path/filepath" "sort" "sync" + "sync/atomic" "time" "github.com/ethereum/go-ethereum/common" @@ -305,6 +306,7 @@ type BlobPool struct { head *types.Header // Current head of the chain state *state.StateDB // Current state at the head of the chain gasTip *uint256.Int // Currently accepted minimum gas tip + maxGas atomic.Uint64 // Currently accepted max gas, it will be modified by MinerAPI lookup map[common.Hash]uint64 // Lookup table mapping hashes to tx billy entries index map[common.Address][]*blobTxMeta // Blob transactions grouped by accounts, sorted by nonce @@ -1098,6 +1100,7 @@ func (p *BlobPool) validateTx(tx *types.Transaction) error { Accept: 1 << types.BlobTxType, MaxSize: txMaxSize, MinTip: p.gasTip.ToBig(), + MaxGas: p.GetMaxGas(), } if err := txpool.ValidateTransaction(tx, p.head, p.signer, baseOpts); err != nil { return err @@ -1671,3 +1674,11 @@ func (p *BlobPool) Status(hash common.Hash) txpool.TxStatus { } return txpool.TxStatusUnknown } + +func (p *BlobPool) SetMaxGas(maxGas uint64) { + p.maxGas.Store(maxGas) +} + +func (p *BlobPool) GetMaxGas() uint64 { + return p.maxGas.Load() +} diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 0f3ce8d049..91cd01e7b4 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -219,6 +219,7 @@ type LegacyPool struct { scope event.SubscriptionScope signer types.Signer mu sync.RWMutex + maxGas atomic.Uint64 // Currently accepted max gas, it will be modified by MinerAPI currentHead atomic.Pointer[types.Header] // Current head of the blockchain currentState *state.StateDB // Current state in the blockchain head @@ -670,6 +671,7 @@ func (pool *LegacyPool) validateTxBasics(tx *types.Transaction, local bool) erro 1< 0 && opts.MaxGas < tx.Gas() { + return ErrGasLimit + } + // Sanity check for extremely large numbers (supported by RLP or RPC) if tx.GasFeeCap().BitLen() > 256 { return core.ErrFeeCapVeryHigh diff --git a/eth/api_miner.go b/eth/api_miner.go index 764d0ae5e2..76398435c5 100644 --- a/eth/api_miner.go +++ b/eth/api_miner.go @@ -20,6 +20,8 @@ import ( "math/big" "time" + "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" ) @@ -71,6 +73,9 @@ 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 { + api.e.TxPool().SetMaxGas(uint64(gasLimit) - params.SystemTxsGas) + } return true } diff --git a/miner/miner.go b/miner/miner.go index 665e409462..40503eb473 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -295,3 +295,7 @@ func (miner *Miner) SubscribePendingLogs(ch chan<- []*types.Log) event.Subscript func (miner *Miner) BuildPayload(args *BuildPayloadArgs) (*Payload, error) { return miner.worker.buildPayload(args) } + +func (miner *Miner) GasCeil() uint64 { + return miner.worker.getGasCeil() +} diff --git a/miner/worker.go b/miner/worker.go index ca866bc6e1..1677dc12b4 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -329,6 +329,12 @@ func (w *worker) setGasCeil(ceil uint64) { w.config.GasCeil = ceil } +func (w *worker) getGasCeil() uint64 { + w.mu.Lock() + defer w.mu.Unlock() + return w.config.GasCeil +} + // setExtra sets the content used to initialize the block extra field. func (w *worker) setExtra(extra []byte) { w.mu.Lock()