Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Problem: ForEachStorage sematic not compatible with go-ethereum #798

Merged
merged 4 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
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
}
Expand Down
4 changes: 2 additions & 2 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
})
}

Expand Down
3 changes: 2 additions & 1 deletion x/evm/keeper/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down
6 changes: 3 additions & 3 deletions x/evm/keeper/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand All @@ -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")),
Expand Down