core, all: split vm.Context into BlockContext and TxContext (#21672)

* all: core: split vm.Config into BlockConfig and TxConfig

* core: core/vm: reset EVM between tx in block instead of creating new

* core/vm: added docs
This commit is contained in:
Marius van der Wijden
2020-11-13 13:42:19 +01:00
committed by GitHub
parent 6f4cccf8d2
commit 2045a2bba3
24 changed files with 183 additions and 139 deletions

View File

@ -138,20 +138,22 @@ func (t *VMTest) newEVM(statedb *state.StateDB, vmconfig vm.Config) *vm.EVM {
return core.CanTransfer(db, address, amount)
}
transfer := func(db vm.StateDB, sender, recipient common.Address, amount *big.Int) {}
context := vm.Context{
txContext := vm.TxContext{
Origin: t.json.Exec.Origin,
GasPrice: t.json.Exec.GasPrice,
}
context := vm.BlockContext{
CanTransfer: canTransfer,
Transfer: transfer,
GetHash: vmTestBlockHash,
Origin: t.json.Exec.Origin,
Coinbase: t.json.Env.Coinbase,
BlockNumber: new(big.Int).SetUint64(t.json.Env.Number),
Time: new(big.Int).SetUint64(t.json.Env.Timestamp),
GasLimit: t.json.Env.GasLimit,
Difficulty: t.json.Env.Difficulty,
GasPrice: t.json.Exec.GasPrice,
}
vmconfig.NoRecursion = true
return vm.NewEVM(context, statedb, params.MainnetChainConfig, vmconfig)
return vm.NewEVM(context, txContext, statedb, params.MainnetChainConfig, vmconfig)
}
func vmTestBlockHash(n uint64) common.Hash {