Fix block num

This commit is contained in:
Sina Mahmoodi 2024-07-08 21:49:19 +02:00
parent dddd593c77
commit 3d12e68d24
4 changed files with 12 additions and 7 deletions

View file

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

View file

@ -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() {

View file

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

View file

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