Skip to content

Commit

Permalink
updating grpc query naming, adding new fields and associated surrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Sep 10, 2021
1 parent 5f0a231 commit 52989a7
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 130 deletions.
20 changes: 11 additions & 9 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@
- [Msg](#ibc.core.connection.v1.Msg)

- [ibc/core/port/v1/query.proto](#ibc/core/port/v1/query.proto)
- [NegotiateAppVersionRequest](#ibc.core.port.v1.NegotiateAppVersionRequest)
- [NegotiateAppVersionResponse](#ibc.core.port.v1.NegotiateAppVersionResponse)
- [QueryAppVersionRequest](#ibc.core.port.v1.QueryAppVersionRequest)
- [QueryAppVersionResponse](#ibc.core.port.v1.QueryAppVersionResponse)

- [Query](#ibc.core.port.v1.Query)

Expand Down Expand Up @@ -2887,15 +2887,17 @@ Msg defines the ibc/connection Msg service.



<a name="ibc.core.port.v1.NegotiateAppVersionRequest"></a>
<a name="ibc.core.port.v1.QueryAppVersionRequest"></a>

### NegotiateAppVersionRequest
NegotiateAppVersionRequest is the request type for the Query/NegotiateAppVersion RPC method
### QueryAppVersionRequest
QueryAppVersionRequest is the request type for the Query/AppVersion RPC method


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `port_id` | [string](#string) | | port unique identifier |
| `connection_id` | [string](#string) | | connection unique identifier |
| `ordering` | [ibc.core.channel.v1.Order](#ibc.core.channel.v1.Order) | | whether the channel is ordered or unordered |
| `counterparty` | [ibc.core.channel.v1.Counterparty](#ibc.core.channel.v1.Counterparty) | | counterparty channel end |
| `proposed_version` | [string](#string) | | proposed version |

Expand All @@ -2904,10 +2906,10 @@ NegotiateAppVersionRequest is the request type for the Query/NegotiateAppVersion



<a name="ibc.core.port.v1.NegotiateAppVersionResponse"></a>
<a name="ibc.core.port.v1.QueryAppVersionResponse"></a>

### NegotiateAppVersionResponse
NegotiateAppVersionResponse is the response type for the Query/NegotiateAppVersion RPC method.
### QueryAppVersionResponse
QueryAppVersionResponse is the response type for the Query/AppVersion RPC method.


| Field | Type | Label | Description |
Expand All @@ -2933,7 +2935,7 @@ Query defines the gRPC querier service

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `NegotiateAppVersion` | [NegotiateAppVersionRequest](#ibc.core.port.v1.NegotiateAppVersionRequest) | [NegotiateAppVersionResponse](#ibc.core.port.v1.NegotiateAppVersionResponse) | NegotiateAppVersion queries an IBC Port and determines the appropriate application version to be used | |
| `AppVersion` | [QueryAppVersionRequest](#ibc.core.port.v1.QueryAppVersionRequest) | [QueryAppVersionResponse](#ibc.core.port.v1.QueryAppVersionResponse) | AppVersion queries an IBC Port and determines the appropriate application version to be used | |

<!-- end services -->

Expand Down
4 changes: 3 additions & 1 deletion modules/apps/transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,12 @@ func (am AppModule) OnTimeoutPacket(
// NegotiateAppVersion implements the IBCModule interface
func (am AppModule) NegotiateAppVersion(
ctx sdk.Context,
order channeltypes.Order,
connectionID string,
portID string,
counterparty channeltypes.Counterparty,
proposedVersion string,
) (version string, err error) {
) (string, error) {
if proposedVersion != types.Version {
return "", sdkerrors.Wrapf(types.ErrInvalidVersion, "failed to negotiate app version: expected %s, got %s", types.Version, proposedVersion)
}
Expand Down
8 changes: 4 additions & 4 deletions modules/core/05-port/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

var _ types.QueryServer = (*Keeper)(nil)

// NegotiateAppVersion implements the Query/NegotiateAppVersion gRPC method
func (q Keeper) NegotiateAppVersion(c context.Context, req *types.NegotiateAppVersionRequest) (*types.NegotiateAppVersionResponse, error) {
// AppVersion implements the Query/AppVersion gRPC method
func (q Keeper) AppVersion(c context.Context, req *types.QueryAppVersionRequest) (*types.QueryAppVersionResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -35,12 +35,12 @@ func (q Keeper) NegotiateAppVersion(c context.Context, req *types.NegotiateAppVe
return nil, status.Errorf(codes.NotFound, sdkerrors.Wrapf(types.ErrInvalidRoute, "route not found to module: %s", module).Error())
}

version, err := ibcModule.NegotiateAppVersion(ctx, req.PortId, *req.Counterparty, req.ProposedVersion)
version, err := ibcModule.NegotiateAppVersion(ctx, req.Ordering, req.ConnectionId, req.PortId, *req.Counterparty, req.ProposedVersion)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, sdkerrors.Wrap(err, "version negotation failed").Error())
}

return types.NewNegotiateAppVersionResponse(req.PortId, version), nil
return types.NewQueryAppVersionResponse(req.PortId, version), nil
}

func validategRPCRequest(portID string) error {
Expand Down
14 changes: 7 additions & 7 deletions modules/core/05-port/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/cosmos/ibc-go/testing/mock"
)

func (suite *KeeperTestSuite) TestNegotiateAppVersion() {
func (suite *KeeperTestSuite) TestAppVersion() {
var (
req *types.NegotiateAppVersionRequest
req *types.QueryAppVersionRequest
expVersion string
)

Expand All @@ -31,7 +31,7 @@ func (suite *KeeperTestSuite) TestNegotiateAppVersion() {
{
"invalid port ID",
func() {
req = &types.NegotiateAppVersionRequest{
req = &types.QueryAppVersionRequest{
PortId: "",
}
},
Expand All @@ -40,7 +40,7 @@ func (suite *KeeperTestSuite) TestNegotiateAppVersion() {
{
"module not found",
func() {
req = &types.NegotiateAppVersionRequest{
req = &types.QueryAppVersionRequest{
PortId: "mock-port-id",
}
},
Expand All @@ -52,7 +52,7 @@ func (suite *KeeperTestSuite) TestNegotiateAppVersion() {

expVersion = mock.Version

req = &types.NegotiateAppVersionRequest{
req = &types.QueryAppVersionRequest{
PortId: "mock", // retrieves the mock testing module
Counterparty: &channeltypes.Counterparty{
PortId: "mock-port-id",
Expand All @@ -69,7 +69,7 @@ func (suite *KeeperTestSuite) TestNegotiateAppVersion() {

expVersion = mock.Version

req = &types.NegotiateAppVersionRequest{
req = &types.QueryAppVersionRequest{
PortId: "mock", // retrieves the mock testing module
Counterparty: &channeltypes.Counterparty{
PortId: "mock-port-id",
Expand All @@ -89,7 +89,7 @@ func (suite *KeeperTestSuite) TestNegotiateAppVersion() {
tc.malleate()

ctx := sdk.WrapSDKContext(suite.ctx)
res, err := suite.keeper.NegotiateAppVersion(ctx, req)
res, err := suite.keeper.AppVersion(ctx, req)

if tc.expPass {
suite.Require().NoError(err)
Expand Down
4 changes: 3 additions & 1 deletion modules/core/05-port/types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ type IBCModule interface {
relayer sdk.AccAddress,
) error

// NegotiateAppVersion performs application version negotiation given the provided port ID, counterparty and proposed version.
// NegotiateAppVersion performs application version negotiation given the provided channel ordering, connectionID, portID, counterparty and proposed version.
// An error is returned if version negotiation cannot be performed. For example, an application module implementing this interface
// may decide to return an error in the event of the proposed version being incompatible with it's own
NegotiateAppVersion(
ctx sdk.Context,
order channeltypes.Order,
connectionID string,
portID string,
counterparty channeltypes.Counterparty,
proposedVersion string,
Expand Down
6 changes: 3 additions & 3 deletions modules/core/05-port/types/query.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package types

// NewNegotiateAppVersionResponse creates a new NegotiateAppVersionResponse instance
func NewNegotiateAppVersionResponse(portID, version string) *NegotiateAppVersionResponse {
return &NegotiateAppVersionResponse{
// NewQueryAppVersionResponse creates a new QueryAppVersionResponse instance
func NewQueryAppVersionResponse(portID, version string) *QueryAppVersionResponse {
return &QueryAppVersionResponse{
PortId: portID,
Version: version,
}
Expand Down
Loading

0 comments on commit 52989a7

Please sign in to comment.