fix eip-7778 in the miner and BAL parallel state processor

This commit is contained in:
Jared Wasinger 2026-02-04 14:40:13 -05:00
parent 022e460d1e
commit bf0f959751
5 changed files with 18 additions and 16 deletions

View file

@ -76,12 +76,16 @@ func (p *ParallelStateProcessor) prepareExecResult(block *types.Block, allStateR
return cmp.Compare(a.TransactionIndex, b.TransactionIndex) return cmp.Compare(a.TransactionIndex, b.TransactionIndex)
}) })
var cumulativeGasUsed uint64 var (
cumulativeGasUsed uint64
cumulativeBlockGasUsed uint64
)
var allLogs []*types.Log var allLogs []*types.Log
for _, receipt := range receipts { for _, receipt := range receipts {
receipt.CumulativeGasUsed = cumulativeGasUsed + receipt.GasUsed receipt.CumulativeGasUsed = cumulativeGasUsed + receipt.GasUsed
cumulativeGasUsed += receipt.GasUsed cumulativeGasUsed += receipt.GasUsed
if receipt.CumulativeGasUsed > header.GasLimit { cumulativeBlockGasUsed += receipt.BlockGasUsed
if cumulativeBlockGasUsed > header.GasLimit {
return &ProcessResultWithMetrics{ return &ProcessResultWithMetrics{
ProcessResult: &ProcessResult{Error: fmt.Errorf("gas limit exceeded")}, ProcessResult: &ProcessResult{Error: fmt.Errorf("gas limit exceeded")},
} }
@ -184,7 +188,7 @@ func (p *ParallelStateProcessor) resultHandler(block *types.Block, preTxStateRea
if res.err != nil { if res.err != nil {
execErr = res.err execErr = res.err
} else { } else {
if err := gp.SubGas(res.receipt.GasUsed); err != nil { if err := gp.SubGas(res.receipt.BlockGasUsed); err != nil {
execErr = err execErr = err
} else { } else {
receipts = append(receipts, res.receipt) receipts = append(receipts, res.receipt)

View file

@ -108,16 +108,9 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
if err != nil { if err != nil {
return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
} }
usedGas += receipt.GasUsed usedGas += receipt.BlockGasUsed
receipts = append(receipts, receipt) receipts = append(receipts, receipt)
allLogs = append(allLogs, receipt.Logs...) allLogs = append(allLogs, receipt.Logs...)
/*
enc, _ := json.MarshalIndent(receipt, "", " ")
fmt.Printf("receipt json %s\n", string(enc))
encRLP, _ := rlp.EncodeToBytes(receipt)
fmt.Printf("receipt rlp %x\n", encRLP)
*/
} }
// Read requests if Prague is enabled. // Read requests if Prague is enabled.
@ -210,10 +203,11 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b
receipt.Status = types.ReceiptStatusSuccessful receipt.Status = types.ReceiptStatusSuccessful
} }
receipt.TxHash = tx.Hash() receipt.TxHash = tx.Hash()
receipt.GasUsed = result.UsedGas
if evm.ChainConfig().IsAmsterdam(blockNumber, blockTime) { if evm.ChainConfig().IsAmsterdam(blockNumber, blockTime) {
receipt.GasUsed = result.MaxUsedGas receipt.BlockGasUsed = result.MaxUsedGas
} else { } else {
receipt.GasUsed = result.UsedGas receipt.BlockGasUsed = result.UsedGas
} }
if tx.Type() == types.BlobTxType { if tx.Type() == types.BlobTxType {

View file

@ -33,7 +33,7 @@ import (
// ExecutionResult includes all output after executing given evm // ExecutionResult includes all output after executing given evm
// message no matter the execution itself is successful or not. // message no matter the execution itself is successful or not.
type ExecutionResult struct { type ExecutionResult struct {
UsedGas uint64 // Total used gas, not including the refunded gas UsedGas uint64 // Total gas used, with refunds subtracted
MaxUsedGas uint64 // Maximum gas consumed during execution, excluding gas refunds. MaxUsedGas uint64 // Maximum gas consumed during execution, excluding gas refunds.
Err error // Any error encountered during the execution(listed in core/vm/errors.go) Err error // Any error encountered during the execution(listed in core/vm/errors.go)
ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode) ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode)

View file

@ -63,6 +63,7 @@ type Receipt struct {
TxHash common.Hash `json:"transactionHash" gencodec:"required"` TxHash common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress common.Address `json:"contractAddress"` ContractAddress common.Address `json:"contractAddress"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"` GasUsed uint64 `json:"gasUsed" gencodec:"required"`
BlockGasUsed uint64 `json:"blockGasUsed"`
EffectiveGasPrice *big.Int `json:"effectiveGasPrice"` // required, but tag omitted for backwards compatibility EffectiveGasPrice *big.Int `json:"effectiveGasPrice"` // required, but tag omitted for backwards compatibility
BlobGasUsed uint64 `json:"blobGasUsed,omitempty"` BlobGasUsed uint64 `json:"blobGasUsed,omitempty"`
BlobGasPrice *big.Int `json:"blobGasPrice,omitempty"` BlobGasPrice *big.Int `json:"blobGasPrice,omitempty"`

View file

@ -66,7 +66,9 @@ type environment struct {
coinbase common.Address coinbase common.Address
evm *vm.EVM evm *vm.EVM
header *types.Header header *types.Header
blockGasUsed uint64 // block gas used incl refunds
txs []*types.Transaction txs []*types.Transaction
receipts []*types.Receipt receipts []*types.Receipt
sidecars []*types.BlobTxSidecar sidecars []*types.BlobTxSidecar
@ -382,11 +384,12 @@ func (miner *Miner) applyTransaction(env *environment, tx *types.Transaction) (*
snap = env.state.Snapshot() snap = env.state.Snapshot()
gp = env.gasPool.Gas() gp = env.gasPool.Gas()
) )
receipt, err := core.ApplyTransaction(env.evm, env.gasPool, env.state, env.header, tx, &env.header.GasUsed) receipt, err := core.ApplyTransaction(env.evm, env.gasPool, env.state, env.header, tx, &env.blockGasUsed)
if err != nil { if err != nil {
env.state.RevertToSnapshot(snap) env.state.RevertToSnapshot(snap)
env.gasPool.SetGas(gp) env.gasPool.SetGas(gp)
} }
env.header.GasUsed += receipt.BlockGasUsed
return receipt, err return receipt, err
} }