core: finally fix miner?

This commit is contained in:
MariusVanDerWijden 2026-02-05 16:46:44 +01:00
parent 8182ab0b06
commit 7ddef250f7
3 changed files with 25 additions and 20 deletions

View file

@ -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)
}

View file

@ -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

View file

@ -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
}