diff --git a/core/vm/evm.go b/core/vm/evm.go index 63600ed279..3e83f476cc 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -248,10 +248,9 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas if len(code) == 0 { ret, err = nil, nil // gas is unchanged } else { - optimized := false addrCopy := addr codeHash := evm.StateDB.GetCodeHash(addrCopy) - optimized, code = tryGetOptimizedCode(evm, addrCopy, codeHash) + optimized, code := tryGetOptimizedCode(evm, codeHash) // If the account has no code, we can abort here // The depth-check is already done, and precompiles handled above contract := NewContract(caller, AccountRef(addrCopy), value, gas) @@ -315,7 +314,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, contract := NewContract(caller, AccountRef(caller.Address()), value, gas) // try get from cache codeHash := evm.StateDB.GetCodeHash(addrCopy) - optimized, code := tryGetOptimizedCode(evm, addrCopy, codeHash) + optimized, code := tryGetOptimizedCode(evm, codeHash) contract.optimized = optimized contract.SetCallCode(&addrCopy, codeHash, code) @@ -364,7 +363,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by contract := NewContract(caller, AccountRef(caller.Address()), nil, gas).AsDelegate() // try get from cache codeHash := evm.StateDB.GetCodeHash(addrCopy) - optimized, code := tryGetOptimizedCode(evm, addrCopy, codeHash) + optimized, code := tryGetOptimizedCode(evm, codeHash) contract.optimized = optimized contract.SetCallCode(&addrCopy, codeHash, code) ret, err = evm.interpreter.Run(contract, input, false) @@ -422,7 +421,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte contract := NewContract(caller, AccountRef(addrCopy), new(big.Int), gas) // try get from cache codeHash := evm.StateDB.GetCodeHash(addrCopy) - optimized, code := tryGetOptimizedCode(evm, addrCopy, codeHash) + optimized, code := tryGetOptimizedCode(evm, codeHash) contract.optimized = optimized contract.SetCallCode(&addrCopy, codeHash, code) // When an error was returned by the EVM or when setting the creation code @@ -440,17 +439,9 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte return ret, gas, err } -func tryGetOptimizedCode(evm *EVM, addrCopy common.Address, codeHash common.Hash) (bool, []byte) { +func tryGetOptimizedCode(evm *EVM, codeHash common.Hash) (bool, []byte) { var code []byte // In case the code is not in stateDB. skip the optimization - // TODO - this is a must to avoid the case that code has required to be delete but not yet processed by the codecache, - // but at the same some other tx (afterward but processed before request of deletion) are processed by code cache. - // Another way is to identify all possible way for code delete in stateDB, and to invalid any opti request related to - // the contract, which is complicated so maybe considered when GetCode here is heavy. - code = evm.StateDB.GetCode(addrCopy) - if len(code) == 0 { - return false, nil - } optimized := false if evm.Config.EnableOpcodeOptimizations { optCode := compiler.LoadOptimizedCode(codeHash)