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: enable pagination and introduce new response data in queries #2398

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 bug in query for listing the consumer chains.
([\#2398](https://github.com/cosmos/interchain-security/pull/2398))
5 changes: 3 additions & 2 deletions docs/docs/build/modules/02-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,7 @@ Output:

#### List Consumer Chains

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

```bash
Expand Down Expand Up @@ -2873,7 +2873,8 @@ grpcurl -plaintext -d '{"consumer_id": "0"}' localhost:9090 interchain_security.
"validatorSetCap": 50,
"minStake": "1000",
"allowInactiveVals": true
}
},
"clientId": "07-tendermint-28"
}
```

Expand Down
3 changes: 3 additions & 0 deletions proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ message QueryConsumerChainResponse {
ConsumerMetadata metadata = 5 [ (gogoproto.nullable) = false ];
ConsumerInitializationParameters init_params = 6;
PowerShapingParameters power_shaping_params = 7;

// corresponds to the id of the client that is created during launch
string client_id = 8;
}

message QueryConsumerGenesisTimeRequest {
Expand Down
22 changes: 11 additions & 11 deletions x/ccv/provider/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"

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

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

if len(args) == 2 && args[1] != "" {
limit, err := strconv.ParseInt(args[1], 10, 32)
if err != nil {
return err
}
req.Pagination = &query.PageRequest{
Limit: uint64(limit),
}
fs, err := client.FlagSetWithPageKeyDecoded(cmd.Flags())
if err != nil {
return err
}

req.Pagination, err = client.ReadPageRequest(fs)
if err != nil {
return err
}

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

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "consumer chains")

return cmd
}
Expand Down
7 changes: 6 additions & 1 deletion x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ func (k Keeper) QueryConsumerChain(goCtx context.Context, req *types.QueryConsum
initParams, _ := k.GetConsumerInitializationParameters(ctx, consumerId)
powerParams, _ := k.GetConsumerPowerShapingParameters(ctx, consumerId)

// The client id might not exist in case the consumer chain has not yet launched or in case the chain has been deleted.
// That's why we do not check if the client id is found.
clientId, _ := k.GetConsumerClientId(ctx, consumerId)

return &types.QueryConsumerChainResponse{
ChainId: chainId,
ConsumerId: consumerId,
Expand All @@ -626,10 +630,11 @@ func (k Keeper) QueryConsumerChain(goCtx context.Context, req *types.QueryConsum
Metadata: metadata,
InitParams: &initParams,
PowerShapingParams: &powerParams,
ClientId: clientId,
}, nil
}

// QueryConsumerGenesisTime returns the genesis time
// QueryConsumerGenesisTime returns the genesis time
// of the consumer chain associated with the provided consumer id
func (k Keeper) QueryConsumerGenesisTime(goCtx context.Context, req *types.QueryConsumerGenesisTimeRequest) (*types.QueryConsumerGenesisTimeResponse, error) {
if req == nil {
Expand Down
4 changes: 4 additions & 0 deletions x/ccv/provider/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ func TestQueryConsumerChain(t *testing.T) {

consumerId := "0"
chainId := "consumer"
clientId := "client-0"

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

providerKeeper.SetConsumerClientId(ctx, consumerId, clientId)

expRes := types.QueryConsumerChainResponse{
ChainId: chainId,
ConsumerId: consumerId,
Expand All @@ -595,6 +598,7 @@ func TestQueryConsumerChain(t *testing.T) {
Phase: types.CONSUMER_PHASE_REGISTERED.String(),
InitParams: &types.ConsumerInitializationParameters{},
PowerShapingParams: &types.PowerShapingParameters{},
ClientId: clientId,
}

// expect no error when neither the consumer init and power shaping params are set
Expand Down
Loading
Loading