Skip to content

Commit

Permalink
fix: update Paginate to use FilterPaginate in ClientStates and …
Browse files Browse the repository at this point in the history
…`ConnectionChannels` grpc queries (#3010)

* update paginate to use filter paginate
  • Loading branch information
charleenfei authored Jan 25, 2023
1 parent e093d85 commit e92aefe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
1 change: 0 additions & 1 deletion e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ func (b *broadcastUser) FormattedAddressWithPrefix(prefix string) string {
// BroadcastMessages broadcasts the provided messages to the given chain and signs them on behalf of the provided user.
// Once the broadcast response is returned, we wait for a few blocks to be created on both chain A and chain B.
func (s *E2ETestSuite) BroadcastMessages(ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, msgs ...sdk.Msg) (sdk.TxResponse, error) {

// wrap the user so it is a valid implementation of broadcast user.
b := broadcastUser{Wallet: user}

Expand Down
11 changes: 6 additions & 5 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,26 @@ func (q Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequ
clientStates := types.IdentifiedClientStates{}
store := prefix.NewStore(ctx.KVStore(q.storeKey), host.KeyClientStorePrefix)

pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) {
// filter any metadata stored under client state key
keySplit := strings.Split(string(key), "/")
if keySplit[len(keySplit)-1] != "clientState" {
return nil
return false, nil
}

clientState, err := q.UnmarshalClientState(value)
if err != nil {
return err
return false, err
}

clientID := keySplit[1]
if err := host.ClientIdentifierValidator(clientID); err != nil {
return err
return false, err
}

identifiedClient := types.NewIdentifiedClientState(clientID, clientState)
clientStates = append(clientStates, identifiedClient)
return nil
return true, nil
})
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions modules/core/02-client/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ func (suite *KeeperTestSuite) TestQueryClientStates() {
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())

res, err := suite.chainA.QueryServer.ClientStates(ctx, req)

if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(expClientStates.Sort(), res.ClientStates)
suite.Require().Equal(len(expClientStates), int(res.Pagination.Total))
} else {
suite.Require().Error(err)
}
Expand Down Expand Up @@ -381,7 +381,6 @@ func (suite *KeeperTestSuite) TestQueryConsensusStates() {
for i := range expConsensusStates {
suite.Require().NotNil(res.ConsensusStates[i])
suite.Require().Equal(expConsensusStates[i], res.ConsensusStates[i])

// ensure UnpackInterfaces is defined
cachedValue := res.ConsensusStates[i].ConsensusState.GetCachedValue()
suite.Require().NotNil(cachedValue)
Expand Down
11 changes: 6 additions & 5 deletions modules/core/04-channel/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,27 @@ func (q Keeper) ConnectionChannels(c context.Context, req *types.QueryConnection
channels := []*types.IdentifiedChannel{}
store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.KeyChannelEndPrefix))

pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) {
// filter any metadata stored under channel key
var result types.Channel
if err := q.cdc.Unmarshal(value, &result); err != nil {
return err
return false, err
}

// ignore channel and continue to the next item if the connection is
// different than the requested one
if result.ConnectionHops[0] != req.Connection {
return nil
return false, nil
}

portID, channelID, err := host.ParseChannelPath(string(key))
if err != nil {
return err
return false, err
}

identifiedChannel := types.NewIdentifiedChannel(portID, channelID, result)
channels = append(channels, &identifiedChannel)
return nil
return true, nil
})
if err != nil {
return nil, err
Expand Down

0 comments on commit e92aefe

Please sign in to comment.