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: ics29 counterparty address grpc query and CLI #1224

Merged
merged 9 commits into from
Apr 7, 2022
34 changes: 34 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
- [Metadata](#ibc.applications.fee.v1.Metadata)

- [ibc/applications/fee/v1/query.proto](#ibc/applications/fee/v1/query.proto)
- [QueryCounterpartyAddressRequest](#ibc.applications.fee.v1.QueryCounterpartyAddressRequest)
- [QueryCounterpartyAddressResponse](#ibc.applications.fee.v1.QueryCounterpartyAddressResponse)
- [QueryIncentivizedPacketRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketRequest)
- [QueryIncentivizedPacketResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketResponse)
- [QueryIncentivizedPacketsForChannelRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketsForChannelRequest)
Expand Down Expand Up @@ -906,6 +908,37 @@ See ICS004: https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-



<a name="ibc.applications.fee.v1.QueryCounterpartyAddressRequest"></a>

### QueryCounterpartyAddressRequest
QueryCounterpartyAddressRequest defines the request type for the CounterpartyAddress rpc


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `channel_id` | [string](#string) | | unique channel identifier |
| `relayer_address` | [string](#string) | | the relayer address to which the counterparty is registered |






<a name="ibc.applications.fee.v1.QueryCounterpartyAddressResponse"></a>

### QueryCounterpartyAddressResponse
QueryCounterpartyAddressResponse defines the response type for the CounterpartyAddress rpc


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `counterparty_address` | [string](#string) | | the counterparty address used to compensate forward relaying |






<a name="ibc.applications.fee.v1.QueryIncentivizedPacketRequest"></a>

### QueryIncentivizedPacketRequest
Expand Down Expand Up @@ -1111,6 +1144,7 @@ Query defines the ICS29 gRPC querier service.
| `TotalRecvFees` | [QueryTotalRecvFeesRequest](#ibc.applications.fee.v1.QueryTotalRecvFeesRequest) | [QueryTotalRecvFeesResponse](#ibc.applications.fee.v1.QueryTotalRecvFeesResponse) | TotalRecvFees returns the total receive fees for a packet given its identifier | GET|/ibc/apps/fee/v1/total_recv_fees/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
| `TotalAckFees` | [QueryTotalAckFeesRequest](#ibc.applications.fee.v1.QueryTotalAckFeesRequest) | [QueryTotalAckFeesResponse](#ibc.applications.fee.v1.QueryTotalAckFeesResponse) | TotalAckFees returns the total acknowledgement fees for a packet given its identifier | GET|/ibc/apps/fee/v1/total_ack_fees/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
| `TotalTimeoutFees` | [QueryTotalTimeoutFeesRequest](#ibc.applications.fee.v1.QueryTotalTimeoutFeesRequest) | [QueryTotalTimeoutFeesResponse](#ibc.applications.fee.v1.QueryTotalTimeoutFeesResponse) | TotalTimeoutFees returns the total timeout fees for a packet given its identifier | GET|/ibc/apps/fee/v1/total_timeout_fees/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
| `CounterpartyAddress` | [QueryCounterpartyAddressRequest](#ibc.applications.fee.v1.QueryCounterpartyAddressRequest) | [QueryCounterpartyAddressResponse](#ibc.applications.fee.v1.QueryCounterpartyAddressResponse) | CounterpartyAddress returns the registered counterparty address for forward relaying | GET|/ibc/apps/fee/v1/counterparty_address/{relayer_address}/channel/{channel_id}|

<!-- end services -->

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/gateway v1.1.0 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
Expand Down
120 changes: 1 addition & 119 deletions go.sum

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion modules/apps/29-fee/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func GetQueryCmd() *cobra.Command {
queryCmd := &cobra.Command{
Use: "ibc-fee",
Short: "", // TODO
Short: "Query subcommand for IBC relayer incentivization",
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that we currently have:

ibc                      Querying commands for the IBC module
ibc-transfer             IBC fungible token transfer query subcommands

Should we choose one format that's closer to one of these?

  1. Querying commands for IBC relayer incentivization
  2. IBC relayer incentivization query subcommands

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I like option 2! Will push an update

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Updated both descriptions for queries and txs

DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
}
Expand All @@ -18,6 +18,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdTotalRecvFees(),
GetCmdTotalAckFees(),
GetCmdTotalTimeoutFees(),
GetCmdCounterpartyAddress(),
)

return queryCmd
Expand Down
40 changes: 40 additions & 0 deletions modules/apps/29-fee/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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/version"
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
Expand Down Expand Up @@ -149,3 +150,42 @@ func GetCmdTotalTimeoutFees() *cobra.Command {

return cmd
}

// GetCmdCounterpartyAddress returns the command handler for the Query/CounterpartyAddress rpc.
func GetCmdCounterpartyAddress() *cobra.Command {
cmd := &cobra.Command{
Use: "counterparty-address [channel-id] [address]",
Short: "Query the relayer counterparty address on a given channel",
Long: "Query the relayer counterparty address on a given channel",
Args: cobra.ExactArgs(2),
Example: fmt.Sprintf("%s query ibc-fee counterparty-address channel-5 cosmos1layxcsmyye0dc0har9sdfzwckaz8sjwlfsj8zs", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

if _, err := sdk.AccAddressFromBech32(args[1]); err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryCounterpartyAddressRequest{
ChannelId: args[0],
RelayerAddress: args[1],
}

res, err := queryClient.CounterpartyAddress(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
18 changes: 18 additions & 0 deletions modules/apps/29-fee/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,21 @@ func (k Keeper) TotalTimeoutFees(goCtx context.Context, req *types.QueryTotalTim
TimeoutFees: timeoutFees,
}, nil
}

// CounterpartyAddress implements the Query/CounterpartyAddress gRPC method
Copy link
Contributor

Choose a reason for hiding this comment

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

I know the proto file describes what this gRPC endpoint does but I think it would be good to have an explanation here as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you want to open a doc issue for that separately? I think most if not all query handlers across the codebase use this godoc format. But I agree, we could keep this and add second line with a similar description to that in the proto files.

I think that would be a good general improvement to all godocs for query handlers

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah good idea I'll open an issue for the other godoc comments but I think we can start by updating this one if we are in agreement :D

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

func (k Keeper) CounterpartyAddress(goCtx context.Context, req *types.QueryCounterpartyAddressRequest) (*types.QueryCounterpartyAddressResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

counterpartyAddr, found := k.GetCounterpartyAddress(ctx, req.RelayerAddress, req.ChannelId)
if !found {
return nil, status.Errorf(codes.NotFound, "counterparty address not found for address: %s on channel: %s", req.RelayerAddress, req.ChannelId)
}

return &types.QueryCounterpartyAddressResponse{
CounterpartyAddress: counterpartyAddr,
}, nil
}
67 changes: 67 additions & 0 deletions modules/apps/29-fee/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package keeper_test

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/tendermint/tendermint/crypto/secp256k1"

"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
Expand Down Expand Up @@ -426,3 +428,68 @@ func (suite *KeeperTestSuite) TestQueryTotalTimeoutFees() {
})
}
}

func (suite *KeeperTestSuite) TestQueryCounterpartyAddress() {
var (
req *types.QueryCounterpartyAddressRequest
)

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success",
func() {},
true,
},
{
"counterparty address not found: invalid channel",
func() {
req.ChannelId = "invalid-channel-id"
},
false,
},
{
"counterparty address not found: invalid address",
func() {
req.RelayerAddress = "invalid-addr"
},
false,
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

pk := secp256k1.GenPrivKey().PubKey()
expectedCounterpartyAddr := sdk.AccAddress(pk.Address())

suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(
suite.chainA.GetContext(),
suite.chainA.SenderAccount.GetAddress().String(),
expectedCounterpartyAddr.String(),
suite.path.EndpointA.ChannelID,
)

req = &types.QueryCounterpartyAddressRequest{
ChannelId: suite.path.EndpointA.ChannelID,
RelayerAddress: suite.chainA.SenderAccount.GetAddress().String(),
}

tc.malleate()

ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
res, err := suite.queryClient.CounterpartyAddress(ctx, req)

if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(expectedCounterpartyAddr.String(), res.CounterpartyAddress)
} else {
suite.Require().Error(err)
}
})
}
}
Loading