Skip to content

Commit

Permalink
took into account comments
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed May 16, 2024
1 parent f7cd09b commit 156b93a
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 255 deletions.
16 changes: 9 additions & 7 deletions proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ service Query {
"/interchain_security/ccv/provider/oldest_unconfirmed_vsc/{chain_id}";
}

// QueryConsumerChainConsumerValidators returns the latest set consumer-validator set for a given chainID
rpc QueryConsumerChainConsumerValidators(QueryConsumerChainConsumerValidatorsRequest)
returns (QueryConsumerChainConsumerValidatorsResponse) {
// QueryConsumerValidators returns the latest set consumer-validator set for a given chainID
// Note that this does not necessarily mean that the consumer chain is using this validator set at this exact moment
// because a VSCPacket could be delayed to be delivered on the consumer chain.
rpc QueryConsumerValidators(QueryConsumerValidatorsRequest)
returns (QueryConsumerValidatorsResponse) {
option (google.api.http).get =
"/interchain_security/ccv/provider/consumer_validators/{chain_id}";
}
Expand Down Expand Up @@ -265,11 +267,11 @@ message QueryConsumerChainOptedInValidatorsResponse {
repeated string validators_provider_addresses = 1;
}

message QueryConsumerChainConsumerValidatorsRequest {
message QueryConsumerValidatorsRequest {
string chain_id = 1;
}

message QueryConsumerChainConsumerValidator {
message QueryConsumerValidatorsValidator {
// The consensus address of the validator on the provider chain
string provider_address = 1 [ (gogoproto.moretags) = "yaml:\"address\"" ];
// The consumer public key of the validator used on the consumer chain
Expand All @@ -278,8 +280,8 @@ message QueryConsumerChainConsumerValidator {
int64 power = 3;
}

message QueryConsumerChainConsumerValidatorsResponse {
repeated QueryConsumerChainConsumerValidator validators = 1;
message QueryConsumerValidatorsResponse {
repeated QueryConsumerValidatorsValidator validators = 1;
}

message QueryConsumerChainsValidatorHasToValidateRequest {
Expand Down
8 changes: 4 additions & 4 deletions x/ccv/provider/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewQueryCmd() *cobra.Command {
cmd.AddCommand(CmdAllPairsValConAddrByConsumerChainID())
cmd.AddCommand(CmdProviderParameters())
cmd.AddCommand(CmdConsumerChainOptedInValidators())
cmd.AddCommand(CmdConsumerChainConsumerValidators())
cmd.AddCommand(CmdConsumerValidators())
cmd.AddCommand(CmdConsumerChainsValidatorHasToValidate())
cmd.AddCommand(CmdValidatorConsumerCommissionRate())
cmd.AddCommand(CmdOldestUnconfirmedVsc())
Expand Down Expand Up @@ -450,7 +450,7 @@ $ %s consumer-opted-in-validators foochain
}

// Command to query the consumer validators by consumer chain ID
func CmdConsumerChainConsumerValidators() *cobra.Command {
func CmdConsumerValidators() *cobra.Command {
cmd := &cobra.Command{
Use: "consumer-validators [chainid]",
Short: "Query the last set consumer-validator set for a given consumer chain",
Expand All @@ -469,8 +469,8 @@ $ %s consumer-validators foochain
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.QueryConsumerChainConsumerValidators(cmd.Context(),
&types.QueryConsumerChainConsumerValidatorsRequest{ChainId: args[0]})
res, err := queryClient.QueryConsumerValidators(cmd.Context(),
&types.QueryConsumerValidatorsRequest{ChainId: args[0]})
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ func (k Keeper) QueryConsumerChainOptedInValidators(goCtx context.Context, req *
}, nil
}

// QueryConsumerChainConsumerValidators returns all validators that are consumer validators in a given consumer chain
func (k Keeper) QueryConsumerChainConsumerValidators(goCtx context.Context, req *types.QueryConsumerChainConsumerValidatorsRequest) (*types.QueryConsumerChainConsumerValidatorsResponse, error) {
// QueryConsumerValidators returns all validators that are consumer validators in a given consumer chain
func (k Keeper) QueryConsumerValidators(goCtx context.Context, req *types.QueryConsumerValidatorsRequest) (*types.QueryConsumerValidatorsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -270,16 +270,16 @@ func (k Keeper) QueryConsumerChainConsumerValidators(goCtx context.Context, req
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("no started consumer chain: %s", consumerChainID))
}

var validators []*types.QueryConsumerChainConsumerValidator
var validators []*types.QueryConsumerValidatorsValidator
for _, v := range k.GetConsumerValSet(ctx, consumerChainID) {
validators = append(validators, &types.QueryConsumerChainConsumerValidator{
validators = append(validators, &types.QueryConsumerValidatorsValidator{
ProviderAddress: sdk.ConsAddress(v.ProviderConsAddr).String(),
ConsumerKey: v.ConsumerPublicKey,
Power: v.Power,
})
}

return &types.QueryConsumerChainConsumerValidatorsResponse{
return &types.QueryConsumerValidatorsResponse{
Validators: validators,
}, nil
}
Expand Down
12 changes: 6 additions & 6 deletions x/ccv/provider/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ func TestQueryConsumerChainOptedInValidators(t *testing.T) {
require.Equal(t, &expectedResponse, res)
}

func TestQueryConsumerChainConsumerValidators(t *testing.T) {
func TestQueryConsumerValidators(t *testing.T) {
chainID := "chainID"

pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

req := types.QueryConsumerChainConsumerValidatorsRequest{
req := types.QueryConsumerValidatorsRequest{
ChainId: chainID,
}

// error returned from not-started chain
_, err := pk.QueryConsumerChainConsumerValidators(ctx, &req)
_, err := pk.QueryConsumerValidators(ctx, &req)
require.Error(t, err)

providerAddr1 := types.NewProviderConsAddress([]byte("providerAddr1"))
Expand All @@ -157,8 +157,8 @@ func TestQueryConsumerChainConsumerValidators(t *testing.T) {
consumerKey2 := cryptotestutil.NewCryptoIdentityFromIntSeed(2).TMProtoCryptoPublicKey()
consumerValidator2 := types.ConsumerValidator{ProviderConsAddr: providerAddr2.ToSdkConsAddr(), Power: 2, ConsumerPublicKey: &consumerKey2}

expectedResponse := types.QueryConsumerChainConsumerValidatorsResponse{
Validators: []*types.QueryConsumerChainConsumerValidator{
expectedResponse := types.QueryConsumerValidatorsResponse{
Validators: []*types.QueryConsumerValidatorsValidator{
{providerAddr1.String(), &consumerKey1, 1},
{providerAddr2.String(), &consumerKey2, 2},
},
Expand All @@ -168,7 +168,7 @@ func TestQueryConsumerChainConsumerValidators(t *testing.T) {
pk.SetConsumerClientId(ctx, chainID, "clientID")
pk.SetConsumerValSet(ctx, chainID, []types.ConsumerValidator{consumerValidator1, consumerValidator2})

res, err := pk.QueryConsumerChainConsumerValidators(ctx, &req)
res, err := pk.QueryConsumerValidators(ctx, &req)
require.NoError(t, err)
require.Equal(t, &expectedResponse, res)
}
Expand Down
Loading

0 comments on commit 156b93a

Please sign in to comment.