forked from cerc-io/laconicd-deprecated
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:
parent
91b042b653
commit
e6d0eff957
@ -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#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#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.
|
* (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
|
## [v0.8.0] - 2021-11-17
|
||||||
|
|
||||||
|
@ -251,10 +251,9 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance
|
|||||||
}
|
}
|
||||||
|
|
||||||
func WriteFile(name string, dir string, contents []byte) error {
|
func WriteFile(name string, dir string, contents []byte) error {
|
||||||
writePath := filepath.Join(dir)
|
file := filepath.Join(dir, name)
|
||||||
file := filepath.Join(writePath, name)
|
|
||||||
|
|
||||||
err := tmos.EnsureDir(writePath, 0o755)
|
err := tmos.EnsureDir(dir, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
err := k.ForEachStorage(address, func(key, value common.Hash) bool {
|
||||||
storage = append(storage, types.NewState(key, value))
|
storage = append(storage, types.NewState(key, value))
|
||||||
return false
|
return true
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.Storage{}, err
|
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) {
|
func (k Keeper) DeleteAccountStorage(addr common.Address) {
|
||||||
_ = k.ForEachStorage(addr, func(key, _ common.Hash) bool {
|
_ = k.ForEachStorage(addr, func(key, _ common.Hash) bool {
|
||||||
k.DeleteState(addr, key)
|
k.DeleteState(addr, key)
|
||||||
return false
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
// ForEachStorage uses the store iterator to iterate over all the state keys and perform a callback
|
||||||
// function on each of them.
|
// 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 {
|
func (k *Keeper) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool) error {
|
||||||
if k.HasStateError() {
|
if k.HasStateError() {
|
||||||
return k.stateErr
|
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())
|
value := common.BytesToHash(iterator.Value())
|
||||||
|
|
||||||
// check if iteration stops
|
// check if iteration stops
|
||||||
if cb(key, value) {
|
if !cb(key, value) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -747,7 +747,7 @@ func (suite *KeeperTestSuite) TestForEachStorage() {
|
|||||||
},
|
},
|
||||||
func(key, value common.Hash) bool {
|
func(key, value common.Hash) bool {
|
||||||
storage = append(storage, types.NewState(key, value))
|
storage = append(storage, types.NewState(key, value))
|
||||||
return false
|
return true
|
||||||
},
|
},
|
||||||
[]common.Hash{
|
[]common.Hash{
|
||||||
common.BytesToHash([]byte("value0")),
|
common.BytesToHash([]byte("value0")),
|
||||||
@ -766,9 +766,9 @@ func (suite *KeeperTestSuite) TestForEachStorage() {
|
|||||||
func(key, value common.Hash) bool {
|
func(key, value common.Hash) bool {
|
||||||
if value == common.BytesToHash([]byte("filtervalue")) {
|
if value == common.BytesToHash([]byte("filtervalue")) {
|
||||||
storage = append(storage, types.NewState(key, value))
|
storage = append(storage, types.NewState(key, value))
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
return false
|
return true
|
||||||
},
|
},
|
||||||
[]common.Hash{
|
[]common.Hash{
|
||||||
common.BytesToHash([]byte("filtervalue")),
|
common.BytesToHash([]byte("filtervalue")),
|
||||||
|
Loading…
Reference in New Issue
Block a user