evm: ForEachStorage semantic not compatible with go-ethereum (#798)

* Problem: ForEachStorage sematic not compatible with go-ethereum

Solution:
- reversed the semantic of return value of the callback function.

* changelog

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
yihuang 2021-11-30 18:34:33 +08:00 committed by GitHub
parent 91b042b653
commit e6d0eff957
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 9 deletions

View File

@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [tharsis#769](https://github.com/tharsis/ethermint/pull/769) Fix default Ethereum signer for JSON-RPC.
* (rpc) [tharsis#781](https://github.com/tharsis/ethermint/pull/781) Fix get block invalid transactions filter.
* (rpc) [tharsis#782](https://github.com/tharsis/ethermint/pull/782) Fix wrong block gas limit returned by JSON-RPC.
* (evm) [tharsis#798](https://github.com/tharsis/ethermint/pull/798) Fix the semantic of `ForEachStorage` callback's return value
## [v0.8.0] - 2021-11-17

View File

@ -251,10 +251,9 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance
}
func WriteFile(name string, dir string, contents []byte) error {
writePath := filepath.Join(dir)
file := filepath.Join(writePath, name)
file := filepath.Join(dir, name)
err := tmos.EnsureDir(writePath, 0o755)
err := tmos.EnsureDir(dir, 0o755)
if err != nil {
return err
}

View File

@ -295,7 +295,7 @@ func (k Keeper) GetAccountStorage(ctx sdk.Context, address common.Address) (type
err := k.ForEachStorage(address, func(key, value common.Hash) bool {
storage = append(storage, types.NewState(key, value))
return false
return true
})
if err != nil {
return types.Storage{}, err
@ -317,7 +317,7 @@ func (k Keeper) DeleteState(addr common.Address, key common.Hash) {
func (k Keeper) DeleteAccountStorage(addr common.Address) {
_ = k.ForEachStorage(addr, func(key, _ common.Hash) bool {
k.DeleteState(addr, key)
return false
return true
})
}

View File

@ -795,6 +795,7 @@ func (k *Keeper) AddPreimage(_ common.Hash, _ []byte) {}
// ForEachStorage uses the store iterator to iterate over all the state keys and perform a callback
// function on each of them.
// The callback should return `true` to continue, return `false` to break early.
func (k *Keeper) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool) error {
if k.HasStateError() {
return k.stateErr
@ -814,7 +815,7 @@ func (k *Keeper) ForEachStorage(addr common.Address, cb func(key, value common.H
value := common.BytesToHash(iterator.Value())
// check if iteration stops
if cb(key, value) {
if !cb(key, value) {
return nil
}
}

View File

@ -747,7 +747,7 @@ func (suite *KeeperTestSuite) TestForEachStorage() {
},
func(key, value common.Hash) bool {
storage = append(storage, types.NewState(key, value))
return false
return true
},
[]common.Hash{
common.BytesToHash([]byte("value0")),
@ -766,9 +766,9 @@ func (suite *KeeperTestSuite) TestForEachStorage() {
func(key, value common.Hash) bool {
if value == common.BytesToHash([]byte("filtervalue")) {
storage = append(storage, types.NewState(key, value))
return true
return false
}
return false
return true
},
[]common.Hash{
common.BytesToHash([]byte("filtervalue")),