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

chore: Change Query/DenomTrace gRPC #1312

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking

* (transfer) [\#1312](https://github.com/cosmos/ibc-go/pull/1312) `DenomTrace` grpc now takes in the whole ibc denom instead of just the hash.
* (transfer) [\#1250](https://github.com/cosmos/ibc-go/pull/1250) Deprecate `GetTransferAccount` since the `transfer` module account is never used.
* (modules/29-fee)[\#1338](https://github.com/cosmos/ibc-go/pull/1338) Renaming `Result` field in `IncentivizedAcknowledgement` to `AppAcknowledgement`.

Expand Down
4 changes: 2 additions & 2 deletions docs/client/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ paths:
format: boolean
tags:
- Query
'/ibc/apps/transfer/v1/denom_traces/{hash}':
'/ibc/apps/transfer/v1/denom_traces/{denom}':
get:
summary: DenomTrace queries a denomination trace information.
operationId: DenomTrace
Expand Down Expand Up @@ -234,7 +234,7 @@ paths:
type: string
format: byte
parameters:
- name: hash
- name: denom
description: hash (in hex format) of the denomination trace information.
in: path
required: true
Expand Down
4 changes: 2 additions & 2 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ method

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `hash` | [string](#string) | | hash (in hex format) of the denomination trace information. |
| `denom` | [string](#string) | | hash (in hex format) of the denomination trace information. |



Expand Down Expand Up @@ -1957,7 +1957,7 @@ Query provides defines the gRPC querier service.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `DenomTrace` | [QueryDenomTraceRequest](#ibc.applications.transfer.v1.QueryDenomTraceRequest) | [QueryDenomTraceResponse](#ibc.applications.transfer.v1.QueryDenomTraceResponse) | DenomTrace queries a denomination trace information. | GET|/ibc/apps/transfer/v1/denom_traces/{hash}|
| `DenomTrace` | [QueryDenomTraceRequest](#ibc.applications.transfer.v1.QueryDenomTraceRequest) | [QueryDenomTraceResponse](#ibc.applications.transfer.v1.QueryDenomTraceResponse) | DenomTrace queries a denomination trace information. | GET|/ibc/apps/transfer/v1/denom_traces/{denom}|
| `DenomTraces` | [QueryDenomTracesRequest](#ibc.applications.transfer.v1.QueryDenomTracesRequest) | [QueryDenomTracesResponse](#ibc.applications.transfer.v1.QueryDenomTracesResponse) | DenomTraces queries all denomination traces. | GET|/ibc/apps/transfer/v1/denom_traces|
| `Params` | [QueryParamsRequest](#ibc.applications.transfer.v1.QueryParamsRequest) | [QueryParamsResponse](#ibc.applications.transfer.v1.QueryParamsResponse) | Params queries all parameters of the ibc-transfer module. | GET|/ibc/apps/transfer/v1/params|
| `DenomHash` | [QueryDenomHashRequest](#ibc.applications.transfer.v1.QueryDenomHashRequest) | [QueryDenomHashResponse](#ibc.applications.transfer.v1.QueryDenomHashResponse) | DenomHash queries a denomination hash information. | GET|/ibc/apps/transfer/v1/denom_hashes/{trace}|
Expand Down
12 changes: 6 additions & 6 deletions modules/apps/transfer/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
)

// GetCmdQueryDenomTrace defines the command to query a a denomination trace from a given hash.
// GetCmdQueryDenomTrace defines the command to query a a denomination trace from a given denom.
func GetCmdQueryDenomTrace() *cobra.Command {
cmd := &cobra.Command{
Use: "denom-trace [hash]",
Short: "Query the denom trace info from a given trace hash",
Long: "Query the denom trace info from a given trace hash",
Example: fmt.Sprintf("%s query ibc-transfer denom-trace [hash]", version.AppName),
Use: "denom-trace [denom]",
Short: "Query the denom trace info from a denom",
Long: "Query the denom trace info from a denom",
Example: fmt.Sprintf("%s query ibc-transfer denom-trace [denom]", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand All @@ -27,7 +27,7 @@ func GetCmdQueryDenomTrace() *cobra.Command {
queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryDenomTraceRequest{
Hash: args[0],
Denom: args[0],
}

res, err := queryClient.DenomTrace(cmd.Context(), req)
Expand Down
11 changes: 8 additions & 3 deletions modules/apps/transfer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -22,17 +23,21 @@ func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest)
return nil, status.Error(codes.InvalidArgument, "empty request")
}

hash, err := types.ParseHexHash(req.Hash)
if !strings.HasPrefix(req.Denom, "ibc/") {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom with no ibc prefix: %s", req.Denom))
}
Comment on lines +26 to +28
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should make this change backwards compatible. We could do so by checking if it has the ibc prefix and then remove the prefix before performing the query. I should have specified this on the original issue (but at the time there was a lot less dependencies on this gRPC

So essentially:

if strings.HasPrefix(denom, "ibc/") {
    denom = denom[4:]
}

Copy link
Contributor Author

@catShaark catShaark May 4, 2022

Choose a reason for hiding this comment

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

If so, how should we name the field in the gRPC request, is it still denom, now that the field means denom or hash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I'll make it like you said and leave the field name still be denom

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good suggestion from @colin-axner. If you make the change backwards compatible, then the changelog entry shouldn't be in the API breaking section, but in the improvements one instead.

Copy link
Contributor Author

@catShaark catShaark May 4, 2022

Choose a reason for hiding this comment

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

I'll apply the change accordingly and I'll change the field back to hash


hash, err := types.ParseHexHash(req.Denom[4:])
if err != nil {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom trace hash %s, %s", req.Hash, err))
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid denom trace hash: %s, error: %s", req.Denom[4:], err))
}

ctx := sdk.UnwrapSDKContext(c)
denomTrace, found := q.GetDenomTrace(ctx, hash)
if !found {
return nil, status.Error(
codes.NotFound,
sdkerrors.Wrap(types.ErrTraceNotFound, req.Hash).Error(),
sdkerrors.Wrap(types.ErrTraceNotFound, req.Denom).Error(),
)
}

Expand Down
24 changes: 12 additions & 12 deletions modules/apps/transfer/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@ func (suite *KeeperTestSuite) TestQueryDenomTrace() {
expPass bool
}{
{
"invalid hex hash",
"success",
func() {
expTrace.Path = "transfer/channelToA/transfer/channelToB"
expTrace.BaseDenom = "uatom"
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), expTrace)

req = &types.QueryDenomTraceRequest{
Hash: "!@#!@#!",
Denom: expTrace.IBCDenom(),
}
},
false,
true,
},
{
"not found denom trace",
"invalid ibc denom",
func() {
expTrace.Path = "transfer/channelToA/transfer/channelToB"
expTrace.BaseDenom = "uatom"
req = &types.QueryDenomTraceRequest{
Hash: expTrace.Hash().String(),
Denom: "!@#!@#!",
}
},
false,
},
{
"success",
"not found denom trace",
func() {
expTrace.Path = "transfer/channelToA/transfer/channelToB"
expTrace.BaseDenom = "uatom"
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), expTrace)

req = &types.QueryDenomTraceRequest{
Hash: expTrace.Hash().String(),
Denom: expTrace.IBCDenom(),
}
},
true,
false,
},
}

Expand Down
95 changes: 47 additions & 48 deletions modules/apps/transfer/types/query.pb.go

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

18 changes: 9 additions & 9 deletions modules/apps/transfer/types/query.pb.gw.go

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

6 changes: 3 additions & 3 deletions proto/ibc/applications/transfer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ option go_package = "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types";
service Query {
// DenomTrace queries a denomination trace information.
rpc DenomTrace(QueryDenomTraceRequest) returns (QueryDenomTraceResponse) {
option (google.api.http).get = "/ibc/apps/transfer/v1/denom_traces/{hash}";
option (google.api.http).get = "/ibc/apps/transfer/v1/denom_traces/{denom}";
}

// DenomTraces queries all denomination traces.
Expand All @@ -35,8 +35,8 @@ service Query {
// QueryDenomTraceRequest is the request type for the Query/DenomTrace RPC
// method
message QueryDenomTraceRequest {
// hash (in hex format) of the denomination trace information.
string hash = 1;
// denom (full denom with ibc prefix) of the denomination trace information.
string denom = 1;
catShaark marked this conversation as resolved.
Show resolved Hide resolved
}

// QueryDenomTraceResponse is the response type for the Query/DenomTrace RPC
Expand Down