Skip to content

Commit

Permalink
chore: improve DenomTrace grpc (backport #1342) (#1500)
Browse files Browse the repository at this point in the history
* chore: improve DenomTrace grpc (#1342)

* change DenomTrace grpc

* update CHANGELOG.md

* minor

* minor

* minor

* minor

* minor

* minor

* Update modules/apps/transfer/keeper/grpc_query_test.go

Co-authored-by: Carlos Rodriguez <[email protected]>

* Update modules/apps/transfer/keeper/grpc_query_test.go

Co-authored-by: Carlos Rodriguez <[email protected]>

* Update CHANGELOG.md

Co-authored-by: Damian Nolan <[email protected]>

* use TrimPrefix() in DenomTrace()

* update migration doc

Co-authored-by: Carlos Rodriguez <[email protected]>
Co-authored-by: Damian Nolan <[email protected]>
(cherry picked from commit 23e7e7d)

# Conflicts:
#	CHANGELOG.md
#	docs/ibc/proto-docs.md
#	docs/migrations/v3-to-v4.md
#	modules/apps/transfer/client/cli/query.go

* fix conflict

Co-authored-by: khanh <[email protected]>
Co-authored-by: crodriguezvega <[email protected]>
  • Loading branch information
3 people committed Jun 9, 2022
1 parent c76e1e1 commit 291c730
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (modules/core/04-channel) [\#1130](https://github.com/cosmos/ibc-go/pull/1130) Call `packet.GetSequence()` rather than passing func in `WriteAcknowledgement` log output
* (transfer) [\#1342](https://github.com/cosmos/ibc-go/pull/1342) `DenomTrace` grpc now takes in either an `ibc denom` or a `hash` instead of only accepting a `hash`.
* (modules/core/keeper) [\#1284](https://github.com/cosmos/ibc-go/pull/1284) Add sanity check for the keepers passed into `ibckeeper.NewKeeper`. `ibckeeper.NewKeeper` now panics if any of the keepers passed in is empty.
* (transfer) [\#1414](https://github.com/cosmos/ibc-go/pull/1414) Emitting Sender address from `fungible_token_packet` events in `OnRecvPacket` and `OnAcknowledgementPacket`.
* (modules/core/04-channel) [\#1464](https://github.com/cosmos/ibc-go/pull/1464) Emit a channel close event when an ordered channel is closed.
Expand Down
4 changes: 3 additions & 1 deletion docs/client/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ paths:
format: byte
parameters:
- name: hash
description: hash (in hex format) of the denomination trace information.
description: >-
hash (in hex format) or denom (full denom with ibc prefix) of the
denomination trace information.
in: path
required: true
type: string
Expand Down
2 changes: 1 addition & 1 deletion docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ method

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



Expand Down
31 changes: 31 additions & 0 deletions docs/migrations/v3-to-v4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Migrating from ibc-go v3 to v4

This document is intended to highlight significant changes which may require more information than presented in the CHANGELOG.
Any changes that must be done by a user of ibc-go should be documented here.

There are four sections based on the four potential user groups of this document:
- Chains
- IBC Apps
- Relayers
- IBC Light Clients

**Note:** ibc-go supports golang semantic versioning and therefore all imports must be updated to bump the version number on major releases.
```go
github.com/cosmos/ibc-go/v3 -> github.com/cosmos/ibc-go/v4
```

No genesis or in-place migrations required when upgrading from v1 or v2 of ibc-go.

## Chains

### IS04 - Channel

The `WriteAcknowledgement` API now takes the `exported.Acknowledgement` type instead of passing in the acknowledgement byte array directly.
This is an API breaking change and as such IBC application developers will have to update any calls to `WriteAcknowledgement`.

The `OnChanOpenInit` application callback has been modified.
The return signature now includes the application version as detailed in the latest IBC [spec changes](https://github.com/cosmos/ibc/pull/629).

## Relayers

When using the `DenomTrace` gRPC, the full IBC denomination with the `ibc/` prefix may now be passed in.
8 changes: 4 additions & 4 deletions modules/apps/transfer/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/cosmos/ibc-go/v2/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 trace hash or ibc 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",
Use: "denom-trace [hash/denom]",
Short: "Query the denom trace info from a given trace hash or ibc denom",
Long: "Query the denom trace info from a given trace hash or ibc denom",
Example: fmt.Sprintf("%s query ibc-transfer denom-trace 27A6394C3F9FF9C9DCF5DFFADF9BB5FE9A37C7E92B006199894CF1824DF9AC7C", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
6 changes: 4 additions & 2 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"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -22,9 +23,10 @@ func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest)
return nil, status.Error(codes.InvalidArgument, "empty request")
}

hash, err := types.ParseHexHash(req.Hash)
hash, err := types.ParseHexHash(strings.TrimPrefix(req.Hash, "ibc/"))

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", hash.String(), err))
}

ctx := sdk.UnwrapSDKContext(c)
Expand Down
31 changes: 22 additions & 9 deletions modules/apps/transfer/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,50 @@ func (suite *KeeperTestSuite) TestQueryDenomTrace() {
expPass bool
}{
{
"invalid hex hash",
"success: correct ibc denom",
func() {
expTrace.Path = "transfer/channelToA/transfer/channelToB"
expTrace.BaseDenom = "uatom"
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), expTrace)

req = &types.QueryDenomTraceRequest{
Hash: "!@#!@#!",
Hash: expTrace.IBCDenom(),
}
},
false,
true,
},
{
"not found denom trace",
"success: correct hex hash",
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(),
}
},
true,
},
{
"failure: invalid hash",
func() {
req = &types.QueryDenomTraceRequest{
Hash: "!@#!@#!",
}
},
false,
},
{
"success",
"failure: 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(),
Hash: expTrace.IBCDenom(),
}
},
true,
false,
},
}

Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/query.pb.go

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

2 changes: 1 addition & 1 deletion proto/ibc/applications/transfer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ service Query {
// QueryDenomTraceRequest is the request type for the Query/DenomTrace RPC
// method
message QueryDenomTraceRequest {
// hash (in hex format) of the denomination trace information.
// hash (in hex format) or denom (full denom with ibc prefix) of the denomination trace information.
string hash = 1;
}

Expand Down

0 comments on commit 291c730

Please sign in to comment.