From 7ddef250f7be915059feafa1320e3c1340348884 Mon Sep 17 00:00:00 2001 From: MariusVanDerWijden Date: Thu, 5 Feb 2026 16:46:44 +0100 Subject: [PATCH] core: finally fix miner? --- core/chain_makers.go | 15 +++++++++------ core/state_processor.go | 7 +++---- miner/worker.go | 23 +++++++++++++---------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index 5fb57547d5..4adc56ba25 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -38,11 +38,12 @@ import ( // BlockGen creates blocks for testing. // See GenerateChain for a detailed explanation. type BlockGen struct { - i int - cm *chainMaker - parent *types.Block - header *types.Header - statedb *state.StateDB + i int + cumulativeGas uint64 + cm *chainMaker + parent *types.Block + header *types.Header + statedb *state.StateDB gasPool *GasPool txs []*types.Transaction @@ -115,9 +116,11 @@ func (b *BlockGen) addTx(bc *BlockChain, vmConfig vm.Config, tx *types.Transacti var ( blockContext = NewEVMBlockContext(b.header, bc, &b.header.Coinbase) evm = vm.NewEVM(blockContext, b.statedb, b.cm.config, vmConfig) + receipt *types.Receipt + err error ) b.statedb.SetTxContext(tx.Hash(), len(b.txs)) - receipt, err := ApplyTransaction(evm, b.gasPool, b.statedb, b.header, tx) + receipt, b.cumulativeGas, err = ApplyTransaction(evm, b.gasPool, b.statedb, b.header, tx, b.cumulativeGas) if err != nil { panic(err) } diff --git a/core/state_processor.go b/core/state_processor.go index 2bac65c26a..16bcbff718 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -244,14 +244,13 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b // and uses the input parameters for its environment. It returns the receipt // for the transaction and an error if the transaction failed, // indicating the block was invalid. -func ApplyTransaction(evm *vm.EVM, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction) (*types.Receipt, error) { +func ApplyTransaction(evm *vm.EVM, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, cumulativeGas uint64) (*types.Receipt, uint64, error) { msg, err := TransactionToMessage(tx, types.MakeSigner(evm.ChainConfig(), header.Number, header.Time), header.BaseFee) if err != nil { - return nil, err + return nil, cumulativeGas, err } // Create a new context to be used in the EVM environment - receipt, _, err := ApplyTransactionWithEVM(msg, gp, statedb, header.Number, header.Hash(), header.Time, tx, header.GasUsed, evm) - return receipt, err + return ApplyTransactionWithEVM(msg, gp, statedb, header.Number, header.Hash(), header.Time, tx, cumulativeGas, evm) } // ProcessBeaconBlockRoot applies the EIP-4788 system call to the beacon block root diff --git a/miner/worker.go b/miner/worker.go index 8d109a831c..407baa7ddf 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -19,12 +19,13 @@ package miner import ( "errors" "fmt" - "github.com/ethereum/go-ethereum/core/tracing" - "github.com/ethereum/go-ethereum/core/types/bal" "math/big" "sync/atomic" "time" + "github.com/ethereum/go-ethereum/core/tracing" + "github.com/ethereum/go-ethereum/core/types/bal" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus/misc/eip1559" "github.com/ethereum/go-ethereum/consensus/misc/eip4844" @@ -58,13 +59,14 @@ func (miner *Miner) maxBlobsPerBlock(time uint64) int { // environment is the worker's current environment and holds all // information of the sealing block generation. type environment struct { - signer types.Signer - state *state.StateDB // apply state changes here - tcount int // tx count in cycle - size uint64 // size of the block we are building - gasPool *core.GasPool // available gas used to pack transactions - coinbase common.Address - evm *vm.EVM + signer types.Signer + state *state.StateDB // apply state changes here + tcount int // tx count in cycle + size uint64 // size of the block we are building + gasPool *core.GasPool // available gas used to pack transactions + coinbase common.Address + evm *vm.EVM + cumulativeGas uint64 header *types.Header txs []*types.Transaction @@ -382,12 +384,13 @@ func (miner *Miner) applyTransaction(env *environment, tx *types.Transaction) (* snap = env.state.Snapshot() gp = env.gasPool.Gas() ) - receipt, err := core.ApplyTransaction(env.evm, env.gasPool, env.state, env.header, tx) + receipt, cumulativeGas, err := core.ApplyTransaction(env.evm, env.gasPool, env.state, env.header, tx, env.cumulativeGas) if err != nil { env.state.RevertToSnapshot(snap) env.gasPool.SetGas(gp) return nil, err } + env.cumulativeGas = cumulativeGas env.header.GasUsed += receipt.GasUsed return receipt, nil }