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 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Add an entry to the unreleased section whenever merging a PR to main that is not
* (fix!) revert consumer packet data changes from #1037 [#1150](https://github.com/cosmos/interchain-security/pull/1150)
* (fix!) proper deletion of pending packets [#1146](https://github.com/cosmos/interchain-security/pull/1146)
* (feat!) optimize pending packets storage on consumer, with migration! [#1037](https://github.com/cosmos/interchain-security/pull/1037)
* (feat) introduce the gRPC query `/interchain_security/ccv/consumer/provider-info` and CLI command `interchain-security-cd q ccvconsumer provider-info`to retrieve provider info from the consumer chain.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaruwangway please include a PR link next time


## v3.1.0

Expand Down
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 QueryProviderInfo(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;
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.QueryProviderInfo(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
17 changes: 14 additions & 3 deletions x/ccv/consumer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
)

var _ types.QueryServer = Keeper{}
var _ types.QueryServer = Keeper{} //nolint:golint

func (k Keeper) QueryNextFeeDistribution(c context.Context,
func (k Keeper) QueryNextFeeDistribution(c context.Context, //nolint:golint
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
req *types.QueryNextFeeDistributionEstimateRequest,
) (*types.QueryNextFeeDistributionEstimateResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
Expand All @@ -27,7 +27,7 @@ func (k Keeper) QueryNextFeeDistribution(c context.Context,
return &types.QueryNextFeeDistributionEstimateResponse{Data: &nextDist}, nil
}

func (k Keeper) QueryParams(c context.Context,
func (k Keeper) QueryParams(c context.Context, //nolint:golint
req *types.QueryParamsRequest,
) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
Expand All @@ -40,3 +40,14 @@ func (k Keeper) QueryParams(c context.Context,

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

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

return k.GetProviderInfo(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 (
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" //nolint:golint

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

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

func (k Keeper) GetProviderInfo(ctx sdk.Context) (*types.QueryProviderInfoResponse, error) { //nolint:golint
consumerChannelID, found := k.GetProviderChannel(ctx)
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
if !found {
return nil, ccvtypes.ErrChannelNotFound
}
consumerChannel, found := k.channelKeeper.GetChannel(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
if !found {
return nil, ccvtypes.ErrChannelNotFound
}

// 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 {
return nil, ccvtypes.ErrClientNotFound
}
providerChainID := consumerClientState.(*ibctm.ClientState).ChainId

resp := types.QueryProviderInfoResponse{
Consumer: types.ChainInfo{
ChainID: ctx.ChainID(),
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