From a0bc8bbf231c8fdc0d5e3e9564006b710f5cc795 Mon Sep 17 00:00:00 2001 From: agnusmor Date: Thu, 7 Mar 2024 11:39:09 +0100 Subject: [PATCH] fix gasLimit and cumulativeGasUsed for Elderberry txs --- state/convertersV2.go | 1 + state/helper.go | 17 +++++++++-------- state/transaction.go | 7 ++++--- state/types.go | 2 ++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/state/convertersV2.go b/state/convertersV2.go index c68d33db48..b445bad973 100644 --- a/state/convertersV2.go +++ b/state/convertersV2.go @@ -127,6 +127,7 @@ func (s *State) convertToProcessTransactionResponseV2(responses []*executor.Proc result.ReturnValue = response.ReturnValue result.GasLeft = response.GasLeft result.GasUsed = response.GasUsed + result.CumulativeGasUsed = response.CumulativeGasUsed result.GasRefunded = response.GasRefunded result.RomError = executor.RomErr(response.Error) result.CreateAddress = common.HexToAddress(response.CreateAddress) diff --git a/state/helper.go b/state/helper.go index 03759774d9..4d074292bb 100644 --- a/state/helper.go +++ b/state/helper.go @@ -281,19 +281,20 @@ func DecodeTx(encodedTx string) (*types.Transaction, error) { // GenerateReceipt generates a receipt from a processed transaction func GenerateReceipt(blockNumber *big.Int, processedTx *ProcessTransactionResponse, txIndex uint, forkID uint64) *types.Receipt { receipt := &types.Receipt{ - Type: uint8(processedTx.Type), - CumulativeGasUsed: processedTx.GasUsed, - BlockNumber: blockNumber, - GasUsed: processedTx.GasUsed, - TxHash: processedTx.Tx.Hash(), - TransactionIndex: txIndex, - ContractAddress: processedTx.CreateAddress, - Logs: processedTx.Logs, + Type: uint8(processedTx.Type), + BlockNumber: blockNumber, + GasUsed: processedTx.GasUsed, + TxHash: processedTx.Tx.Hash(), + TransactionIndex: txIndex, + ContractAddress: processedTx.CreateAddress, + Logs: processedTx.Logs, } if forkID <= FORKID_ETROG { receipt.PostState = processedTx.StateRoot.Bytes() + receipt.CumulativeGasUsed = processedTx.GasUsed } else { receipt.PostState = ZeroHash.Bytes() + receipt.CumulativeGasUsed = processedTx.CumulativeGasUsed } if processedTx.EffectiveGasPrice != "" { effectiveGasPrice, ok := big.NewInt(0).SetString(processedTx.EffectiveGasPrice, 0) diff --git a/state/transaction.go b/state/transaction.go index 5a66c7e3e2..155786a4fd 100644 --- a/state/transaction.go +++ b/state/transaction.go @@ -211,13 +211,14 @@ func (s *State) StoreL2Block(ctx context.Context, batchNumber uint64, l2Block *P return err } + forkID := s.GetForkIDByBatchNumber(batchNumber) + gasLimit := l2Block.GasLimit - if gasLimit > MaxL2BlockGasLimit { + // We check/set the maximum value of gasLimit for batches <= to ETROG fork. For batches >= to ELDERBERRY fork we use always the value returned by the executor + if forkID <= FORKID_ETROG && gasLimit > MaxL2BlockGasLimit { gasLimit = MaxL2BlockGasLimit } - forkID := s.GetForkIDByBatchNumber(batchNumber) - header := &types.Header{ Number: new(big.Int).SetUint64(l2Block.BlockNumber), ParentHash: prevL2BlockHash, diff --git a/state/types.go b/state/types.go index ea7a0ae289..6b76455a07 100644 --- a/state/types.go +++ b/state/types.go @@ -100,6 +100,8 @@ type ProcessTransactionResponse struct { GasLeft uint64 // GasUsed is the total gas used as result of execution or gas estimation GasUsed uint64 + // CumulativeGasUsed is the accumulated gas used (sum of tx GasUsed and CumulativeGasUsed of the previous tx in the L2 block) + CumulativeGasUsed uint64 // GasRefunded is the total gas refunded as result of execution GasRefunded uint64 // RomError represents any error encountered during the execution