mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Problem: no efficient GetStorageRoot impl in cosmos/evm (#9)
Solution: - create a new method IsStorageEmpty to use in core evm
This commit is contained in:
parent
2fc7571efa
commit
9a3ffad54d
4 changed files with 13 additions and 2 deletions
|
|
@ -335,6 +335,12 @@ func (s *StateDB) GetStorageRoot(addr common.Address) common.Hash {
|
|||
return common.Hash{}
|
||||
}
|
||||
|
||||
// IsStorageEmpty returns if the contract storage is empty
|
||||
func (s *StateDB) IsStorageEmpty(addr common.Address) bool {
|
||||
storageRoot := s.GetStorageRoot(addr)
|
||||
return storageRoot == (common.Hash{}) || storageRoot == types.EmptyRootHash
|
||||
}
|
||||
|
||||
// TxIndex returns the current transaction index set by SetTxContext.
|
||||
func (s *StateDB) TxIndex() int {
|
||||
return s.txIndex
|
||||
|
|
|
|||
|
|
@ -97,6 +97,10 @@ func (s *hookedStateDB) GetStorageRoot(addr common.Address) common.Hash {
|
|||
return s.inner.GetStorageRoot(addr)
|
||||
}
|
||||
|
||||
func (s *hookedStateDB) IsStorageEmpty(addr common.Address) bool {
|
||||
return s.inner.IsStorageEmpty(addr)
|
||||
}
|
||||
|
||||
func (s *hookedStateDB) GetTransientState(addr common.Address, key common.Hash) common.Hash {
|
||||
return s.inner.GetTransientState(addr, key)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -499,10 +499,10 @@ func (evm *EVM) create(caller common.Address, code []byte, gas uint64, value *ui
|
|||
// - the code is non-empty
|
||||
// - the storage is non-empty
|
||||
contractHash := evm.StateDB.GetCodeHash(address)
|
||||
storageRoot := evm.StateDB.GetStorageRoot(address)
|
||||
isStorageEmpty := evm.StateDB.IsStorageEmpty(address)
|
||||
if evm.StateDB.GetNonce(address) != 0 ||
|
||||
(contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) || // non-empty code
|
||||
(storageRoot != (common.Hash{}) && storageRoot != types.EmptyRootHash) { // non-empty storage
|
||||
!isStorageEmpty { // non-empty storage
|
||||
if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil {
|
||||
evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ type StateDB interface {
|
|||
GetState(common.Address, common.Hash) common.Hash
|
||||
SetState(common.Address, common.Hash, common.Hash) common.Hash
|
||||
GetStorageRoot(addr common.Address) common.Hash
|
||||
IsStorageEmpty(addr common.Address) bool
|
||||
|
||||
GetTransientState(addr common.Address, key common.Hash) common.Hash
|
||||
SetTransientState(addr common.Address, key, value common.Hash)
|
||||
|
|
|
|||
Loading…
Reference in a new issue