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

feat: add provider info query #1164

Merged
merged 21 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
18 changes: 18 additions & 0 deletions proto/interchain_security/ccv/consumer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ service Query {
rpc QueryParams(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/interchain_security/ccv/consumer/params";
}

rpc QueryProviderChainInfo(QueryProviderInfoRequest) returns (QueryProviderInfoResponse) {
option (google.api.http).get = "/interchain_security/ccv/consumer/provider-info";
}
}

// NextFeeDistributionEstimate holds information about next fee distribution
Expand Down Expand Up @@ -52,3 +56,17 @@ message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [ (gogoproto.nullable) = false ];
}

message QueryProviderInfoRequest {}
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved

message QueryProviderInfoResponse {
ChainInfo consumer = 1 [ (gogoproto.nullable) = false ];
ChainInfo provider = 2 [ (gogoproto.nullable) = false ];
}

message ChainInfo {
string ChainID = 1;
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
string ClientID = 2;
string ConnectionID = 3;
string ChannelID = 4;
}
10 changes: 10 additions & 0 deletions testutil/keeper/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion x/ccv/consumer/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func NewQueryCmd() *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdNextFeeDistribution())
cmd.AddCommand(
CmdNextFeeDistribution(),
CmdProviderInfo(),
)

return cmd
}
Expand Down Expand Up @@ -50,3 +53,30 @@ func CmdNextFeeDistribution() *cobra.Command {

return cmd
}

func CmdProviderInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "provider-info",
Short: "Query provider info",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryProviderInfoRequest{}
res, err := queryClient.QueryProviderChainInfo(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
12 changes: 11 additions & 1 deletion x/ccv/consumer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

sdk "github.com/cosmos/cosmos-sdk/types"

Check failure on line 9 in x/ccv/consumer/keeper/grpc_query.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard,default,blank,dot,prefix(cosmossdk.io),prefix(github.com/cosmos/cosmos-sdk),prefix(github.com/cometbft/cometbft),prefix(github.com/cosmos/interchain-security) (gci)

"github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
)

Expand Down Expand Up @@ -40,3 +39,14 @@

return &types.QueryParamsResponse{Params: p}, nil
}

func (k Keeper) QueryProviderChainInfo(c context.Context,
req *types.QueryProviderInfoRequest,
) (*types.QueryProviderInfoResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

return k.GetProviderChainInfo(ctx)
}
54 changes: 54 additions & 0 deletions x/ccv/consumer/keeper/provider_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

Check failure on line 4 in x/ccv/consumer/keeper/provider_info.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard,default,blank,dot,prefix(cosmossdk.io),prefix(github.com/cosmos/cosmos-sdk),prefix(github.com/cometbft/cometbft),prefix(github.com/cosmos/interchain-security) (gci)
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"

Check failure on line 5 in x/ccv/consumer/keeper/provider_info.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard,default,blank,dot,prefix(cosmossdk.io),prefix(github.com/cosmos/cosmos-sdk),prefix(github.com/cometbft/cometbft),prefix(github.com/cosmos/interchain-security) (gci)
"github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
)

func (k Keeper) GetProviderChainInfo(ctx sdk.Context) (*types.QueryProviderInfoResponse, error) {
// get the channelID for the channel to the provider.
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
consumerChannelID, found := k.GetProviderChannel(ctx)
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
if !found {
return nil, nil
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
}
consumerChannel, found := k.channelKeeper.GetChannel(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
if !found {
return nil, nil
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
}

// from channel get connection
consumerConnectionID, consumerConnection, err := k.channelKeeper.GetChannelConnection(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
if err != nil {
return nil, err
}

providerChannelID := consumerChannel.GetCounterparty().GetChannelID()
providerConnection := consumerConnection.GetCounterparty()

consumerClientState, found := k.clientKeeper.GetClientState(ctx, consumerConnection.GetClientID())
if !found {
// todo if return err?
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
return nil, nil
}
providerChainID := consumerClientState.(*ibctm.ClientState).ChainId

resp := types.QueryProviderInfoResponse{
Consumer: types.ChainInfo{
ChainID: "",
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
ClientID: consumerConnection.GetClientID(),
ConnectionID: consumerConnectionID,
ChannelID: consumerChannelID,
},

Provider: types.ChainInfo{
ChainID: providerChainID,
ClientID: providerConnection.GetClientID(),
ConnectionID: providerConnection.GetConnectionID(),
ChannelID: providerChannelID,
},
}

return &resp, nil
}
Loading
Loading