Skip to content

Commit

Permalink
Merge PR: fix query eth_getStorageAt by watchdb bug (#2929)
Browse files Browse the repository at this point in the history
* fix the eth_getStorageAt from watchdb bug

* modify the sim call affect

---------

Co-authored-by: KamiD <[email protected]>
  • Loading branch information
lyh169 and KamiD authored Jan 28, 2023
1 parent 177e2e2 commit 1db8ed5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,18 @@ func (api *PublicEthereumAPI) GetAccount(address common.Address) (*ethermint.Eth
func (api *PublicEthereumAPI) getStorageAt(address common.Address, key []byte, blockNum rpctypes.BlockNumber, directlyKey bool) (hexutil.Bytes, error) {
clientCtx := api.clientCtx.WithHeight(blockNum.Int64())
useWatchBackend := api.useWatchBackend(blockNum)

qWatchdbKey := key
if useWatchBackend {
res, err := api.wrappedBackend.MustGetState(address, key)
if !directlyKey {
qWatchdbKey = evmtypes.GetStorageByAddressKey(address.Bytes(), key).Bytes()
}
res, err := api.wrappedBackend.MustGetState(address, qWatchdbKey)
if err == nil {
return res, nil
}
}

var queryStr = ""
if !directlyKey {
queryStr = fmt.Sprintf("custom/%s/storage/%s/%X", evmtypes.ModuleName, address.Hex(), key)
Expand All @@ -479,7 +485,7 @@ func (api *PublicEthereumAPI) getStorageAt(address common.Address, key []byte, b
var out evmtypes.QueryResStorage
api.clientCtx.Codec.MustUnmarshalJSON(res, &out)
if useWatchBackend {
api.watcherBackend.CommitStateToRpcDb(address, key, out.Value)
api.watcherBackend.CommitStateToRpcDb(address, qWatchdbKey, out.Value)
}
return out.Value, nil
}
Expand Down

0 comments on commit 1db8ed5

Please sign in to comment.