Skip to content

Commit

Permalink
remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed Mar 14, 2024
1 parent b8d8a72 commit 58e3d7d
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 58e3d7d

Please sign in to comment.