From 3d12e68d247c3b8d170d4d1311dd85a02f27b7c7 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Mon, 8 Jul 2024 21:49:19 +0200 Subject: [PATCH] Fix block num --- cmd/evm/internal/t8ntool/execution.go | 2 +- core/state_processor.go | 2 +- core/state_processor_test.go | 4 ++-- miner/worker.go | 11 ++++++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index b166d3ff88..d39d3641f5 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -202,7 +202,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, prevHash = pre.Env.BlockHashes[math.HexOrDecimal64(prevNumber)] evm = vm.NewEVM(vmContext, vm.TxContext{}, statedb, chainConfig, vmConfig) ) - core.ProcessParentBlockHash(statedb, evm, prevHash, prevNumber) + core.ProcessParentBlockHash(statedb, evm, prevHash) } for i := 0; txIt.Next(); i++ { tx, err := txIt.Tx() diff --git a/core/state_processor.go b/core/state_processor.go index b2f97ca5ce..09feb79965 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -82,7 +82,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg } if p.config.IsPrague(block.Number(), block.Time()) { // This should not underflow as genesis block is not processed. - ProcessParentBlockHash(statedb, vmenv, block.ParentHash(), block.NumberU64()-1) + ProcessParentBlockHash(statedb, vmenv, block.ParentHash()) } // Iterate over and process the individual transactions for i, tx := range block.Transactions() { diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 2ce4698966..a4d6b47e96 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -549,11 +549,11 @@ func TestProcessParentBlockHash(t *testing.T) { vmContext := NewEVMBlockContext(header, nil, &coinbase) evm := vm.NewEVM(vmContext, vm.TxContext{}, statedb, chainConfig, vm.Config{}) - ProcessParentBlockHash(statedb, evm, header.ParentHash, parent.Number.Uint64()) + ProcessParentBlockHash(statedb, evm, header.ParentHash) vmContext = NewEVMBlockContext(parent, nil, &coinbase) evm = vm.NewEVM(vmContext, vm.TxContext{}, statedb, chainConfig, vm.Config{}) - ProcessParentBlockHash(statedb, evm, parent.ParentHash, genesis.Number.Uint64()) + ProcessParentBlockHash(statedb, evm, parent.ParentHash) // make sure that the state is correct if have := getParentBlockHash(statedb, 1); have != hashA { diff --git a/miner/worker.go b/miner/worker.go index da72685422..9653a4a826 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -195,13 +195,18 @@ func (miner *Miner) prepareWork(genParams *generateParams) (*environment, error) log.Error("Failed to create sealing context", "err", err) return nil, err } + var ( + context vm.BlockContext + vmenv *vm.EVM + ) if header.ParentBeaconRoot != nil { - context := core.NewEVMBlockContext(header, miner.chain, nil) - vmenv := vm.NewEVM(context, vm.TxContext{}, env.state, miner.chainConfig, vm.Config{}) + context = core.NewEVMBlockContext(header, miner.chain, nil) + vmenv = vm.NewEVM(context, vm.TxContext{}, env.state, miner.chainConfig, vm.Config{}) core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state) } if miner.chainConfig.IsPrague(header.Number, header.Time) { - core.ProcessParentBlockHash(env.state, header.ParentHash, header.Number.Uint64()-1) + // Prague is enabled after Cancun so vmenv should be initalized. + core.ProcessParentBlockHash(env.state, vmenv, header.ParentHash) } return env, nil }