Skip to content

Commit deea6fb

Browse files
authored
fix: enable pagination and introduce new response data in queries (#2398)
* init commit * added changelog and changed docs
1 parent fb598fc commit deea6fb

File tree

7 files changed

+236
-169
lines changed

7 files changed

+236
-169
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `[x/provider]` Fixed pagination bug in query for listing the consumer chains.
2+
([\#2398](https://github.com/cosmos/interchain-security/pull/2398))

docs/docs/build/modules/02-provider.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ Output:
23362336

23372337
#### List Consumer Chains
23382338

2339-
The `QueryConsumerChains` endpoint queries consumer chains supported by the provider chain.
2339+
The `QueryConsumerChains` endpoint queries consumer chains supported by the provider chain and supports pagination for managing a large number of chains.
23402340
An optional integer parameter can be passed for phase filtering of consumer chains, (Registered=1|Initialized=2|Launched=3|Stopped=4|Deleted=5).`
23412341

23422342
```bash
@@ -2873,7 +2873,8 @@ grpcurl -plaintext -d '{"consumer_id": "0"}' localhost:9090 interchain_security.
28732873
"validatorSetCap": 50,
28742874
"minStake": "1000",
28752875
"allowInactiveVals": true
2876-
}
2876+
},
2877+
"clientId": "07-tendermint-28"
28772878
}
28782879
```
28792880

proto/interchain_security/ccv/provider/v1/query.proto

+3
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ message QueryConsumerChainResponse {
397397
ConsumerMetadata metadata = 5 [ (gogoproto.nullable) = false ];
398398
ConsumerInitializationParameters init_params = 6;
399399
PowerShapingParameters power_shaping_params = 7;
400+
401+
// corresponds to the id of the client that is created during launch
402+
string client_id = 8;
400403
}
401404

402405
message QueryConsumerGenesisTimeRequest {

x/ccv/provider/client/cli/query.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/cosmos/cosmos-sdk/client"
1111
"github.com/cosmos/cosmos-sdk/client/flags"
1212
sdk "github.com/cosmos/cosmos-sdk/types"
13-
"github.com/cosmos/cosmos-sdk/types/query"
1413
"github.com/cosmos/cosmos-sdk/version"
1514

1615
"github.com/cosmos/interchain-security/v6/x/ccv/provider/types"
@@ -76,12 +75,12 @@ func CmdConsumerGenesis() *cobra.Command {
7675

7776
func CmdConsumerChains() *cobra.Command {
7877
cmd := &cobra.Command{
79-
Use: "list-consumer-chains [phase] [limit]",
78+
Use: "list-consumer-chains [phase]",
8079
Short: "Query consumer chains for provider chain.",
8180
Long: `Query consumer chains for provider chain. An optional
8281
integer parameter can be passed for phase filtering of consumer chains,
8382
(Registered=1|Initialized=2|Launched=3|Stopped=4|Deleted=5).`,
84-
Args: cobra.MaximumNArgs(2),
83+
Args: cobra.MaximumNArgs(1),
8584
RunE: func(cmd *cobra.Command, args []string) (err error) {
8685
clientCtx, err := client.GetClientQueryContext(cmd)
8786
if err != nil {
@@ -99,14 +98,14 @@ func CmdConsumerChains() *cobra.Command {
9998
req.Phase = types.ConsumerPhase(phase)
10099
}
101100

102-
if len(args) == 2 && args[1] != "" {
103-
limit, err := strconv.ParseInt(args[1], 10, 32)
104-
if err != nil {
105-
return err
106-
}
107-
req.Pagination = &query.PageRequest{
108-
Limit: uint64(limit),
109-
}
101+
fs, err := client.FlagSetWithPageKeyDecoded(cmd.Flags())
102+
if err != nil {
103+
return err
104+
}
105+
106+
req.Pagination, err = client.ReadPageRequest(fs)
107+
if err != nil {
108+
return err
110109
}
111110

112111
res, err := queryClient.QueryConsumerChains(cmd.Context(), req)
@@ -119,6 +118,7 @@ func CmdConsumerChains() *cobra.Command {
119118
}
120119

121120
flags.AddQueryFlagsToCmd(cmd)
121+
flags.AddPaginationFlagsToCmd(cmd, "consumer chains")
122122

123123
return cmd
124124
}

x/ccv/provider/keeper/grpc_query.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@ func (k Keeper) QueryConsumerChain(goCtx context.Context, req *types.QueryConsum
618618
initParams, _ := k.GetConsumerInitializationParameters(ctx, consumerId)
619619
powerParams, _ := k.GetConsumerPowerShapingParameters(ctx, consumerId)
620620

621+
// The client id might not exist in case the consumer chain has not yet launched or in case the chain has been deleted.
622+
// That's why we do not check if the client id is found.
623+
clientId, _ := k.GetConsumerClientId(ctx, consumerId)
624+
621625
return &types.QueryConsumerChainResponse{
622626
ChainId: chainId,
623627
ConsumerId: consumerId,
@@ -626,10 +630,11 @@ func (k Keeper) QueryConsumerChain(goCtx context.Context, req *types.QueryConsum
626630
Metadata: metadata,
627631
InitParams: &initParams,
628632
PowerShapingParams: &powerParams,
633+
ClientId: clientId,
629634
}, nil
630635
}
631636

632-
// QueryConsumerGenesisTime returns the genesis time
637+
// QueryConsumerGenesisTime returns the genesis time
633638
// of the consumer chain associated with the provided consumer id
634639
func (k Keeper) QueryConsumerGenesisTime(goCtx context.Context, req *types.QueryConsumerGenesisTimeRequest) (*types.QueryConsumerGenesisTimeResponse, error) {
635640
if req == nil {

x/ccv/provider/keeper/grpc_query_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ func TestQueryConsumerChain(t *testing.T) {
557557

558558
consumerId := "0"
559559
chainId := "consumer"
560+
clientId := "client-0"
560561

561562
req := types.QueryConsumerChainRequest{
562563
ConsumerId: consumerId,
@@ -587,6 +588,8 @@ func TestQueryConsumerChain(t *testing.T) {
587588
err = providerKeeper.SetConsumerMetadata(ctx, consumerId, types.ConsumerMetadata{Name: chainId})
588589
require.NoError(t, err)
589590

591+
providerKeeper.SetConsumerClientId(ctx, consumerId, clientId)
592+
590593
expRes := types.QueryConsumerChainResponse{
591594
ChainId: chainId,
592595
ConsumerId: consumerId,
@@ -595,6 +598,7 @@ func TestQueryConsumerChain(t *testing.T) {
595598
Phase: types.CONSUMER_PHASE_REGISTERED.String(),
596599
InitParams: &types.ConsumerInitializationParameters{},
597600
PowerShapingParams: &types.PowerShapingParameters{},
601+
ClientId: clientId,
598602
}
599603

600604
// expect no error when neither the consumer init and power shaping params are set

0 commit comments

Comments
 (0)