Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gaslimit and cumulativeGasUsed for Elderberry transactions #3428

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions state/convertersV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions state/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions state/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions state/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading