Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update Paginate to use FilterPaginate in ClientStates and ConnectionChannels grpc queries #3010

Merged
merged 21 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 19 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: 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) {
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
// 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) {
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
// 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