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: fix consumer chains list pagination #2377

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[x/provider]` Fixed pagination in the list consumer chains query.
freak12techno marked this conversation as resolved.
Show resolved Hide resolved
([\#2378](https://github.com/cosmos/interchain-security/pull/2378))
15 changes: 9 additions & 6 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,26 @@ func (k Keeper) QueryConsumerChains(goCtx context.Context, req *types.QueryConsu
store := ctx.KVStore(k.storeKey)
storePrefix := types.ConsumerIdToPhaseKeyPrefix()
consumerPhaseStore := prefix.NewStore(store, []byte{storePrefix})
pageRes, err := query.Paginate(consumerPhaseStore, req.Pagination, func(key, value []byte) error {
pageRes, err := query.FilteredPaginate(consumerPhaseStore, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) {
consumerId, err := types.ParseStringIdWithLenKey(storePrefix, append([]byte{storePrefix}, key...))
if err != nil {
return status.Error(codes.Internal, err.Error())
return false, status.Error(codes.Internal, err.Error())
}

phase := types.ConsumerPhase(binary.BigEndian.Uint32(value))
if req.Phase != types.CONSUMER_PHASE_UNSPECIFIED && req.Phase != phase {
return nil
return false, nil
}

c, err := k.GetConsumerChain(ctx, consumerId)
if err != nil {
return status.Error(codes.Internal, err.Error())
return false, status.Error(codes.Internal, err.Error())
}
chains = append(chains, &c)
return nil

if accumulate {
chains = append(chains, &c)
}
return true, nil
})

if err != nil {
Expand Down
Loading