From 90a98f0f99321135590c571bf782bcfebcce9173 Mon Sep 17 00:00:00 2001 From: ckoopmann Date: Mon, 4 Dec 2023 21:01:57 +0800 Subject: [PATCH] Assume default gas limit of 30 mil if registered limit is zero --- core/blockchain.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 469076db1..ad2613079 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2521,12 +2521,12 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad log.Debug("GetHeader(Parent) succeeded", "time_elapsed", time.Since(start), "requestId", requestId) } - calculatedGasLimit := utils.CalcGasLimit(parent.GasLimit, registeredGasLimit) - if calculatedGasLimit != header.GasLimit { - log.Debug("CalcGasLimit failed", "time_elapsed", time.Since(start), "error", err, "requestId", requestId) - return errors.New("incorrect gas limit set") + err = CheckGasLimit(parent.GasLimit, registeredGasLimit, header.GasLimit) + if err != nil { + log.Debug("CheckGasLimit failed", "time_elapsed", time.Since(start), "error", err) + return err } else { - log.Debug("CalcGasLimit succeeded", "time_elapsed", time.Since(start), "requestId", requestId) + log.Debug("CheckGasLimit succeeded", "time_elapsed", time.Since(start)) } statedb, err := bc.StateAt(parent.Root) @@ -2604,6 +2604,22 @@ func (bc *BlockChain) ValidatePayload(block *types.Block, feeRecipient common.Ad return nil } +func CheckGasLimit(parentGasLimit uint64, registeredGasLimit uint64, headerGasLimit uint64) error { + if registeredGasLimit == 0 && headerGasLimit == utils.CalcGasLimit(parentGasLimit, 30_000_000) { + // Prysm has a bug where it registers validators with a desired gas limit + // of 0. Some builders treat these as desiring gas limit 30_000_000. As a + // workaround, whenever the desired gas limit is 0, we accept both the + // limit as calculated with a desired limit of 0, and builders which fall + // back to calculating with the default 30_000_000. + } else { + calculatedGasLimit := utils.CalcGasLimit(parentGasLimit, registeredGasLimit) + if calculatedGasLimit != headerGasLimit { + return fmt.Errorf("incorrect gas limit set, expected: %d, got: %d", calculatedGasLimit, headerGasLimit) + } + } + return nil +} + func CheckProposerPayment(expectedProfit *big.Int, feeRecipient common.Address, feeRecipientDiff *big.Int, receipts types.Receipts, block *types.Block) error { // If diff is sufficiently large, just return success. if feeRecipientDiff.Cmp(expectedProfit) >= 0 {