-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: scalable version queries (#384)
* adding protos for port query interface * adding NegotiateAppVersion method to IBCModule interface * adding grpc port query implementation and module surrounds * adding NegotiateAppVersion implementation to apps/transfer and mocks * updating ErrInvalidVersion error code * adding grpc query tests for 05-port * updating grpc naming, adding godocs, removing redundant query cli * updating grpc query tests * adding changelog entry for #384 app version negotiation * fixing error formatting in transfer version negotiation Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * removing client/cli query * updating grpc query naming, adding new fields and associated surrounds Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
- Loading branch information
1 parent
2fbe682
commit 85b4383
Showing
16 changed files
with
1,196 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/cosmos/ibc-go/modules/core/05-port/types" | ||
host "github.com/cosmos/ibc-go/modules/core/24-host" | ||
) | ||
|
||
var _ types.QueryServer = (*Keeper)(nil) | ||
|
||
// 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") | ||
} | ||
|
||
if err := validategRPCRequest(req.PortId); err != nil { | ||
return nil, err | ||
} | ||
|
||
ctx := sdk.UnwrapSDKContext(c) | ||
module, _, err := q.LookupModuleByPort(ctx, req.PortId) | ||
if err != nil { | ||
return nil, status.Errorf(codes.NotFound, sdkerrors.Wrap(err, "could not retrieve module from port-id").Error()) | ||
} | ||
|
||
ibcModule, found := q.Router.GetRoute(module) | ||
if !found { | ||
return nil, status.Errorf(codes.NotFound, sdkerrors.Wrapf(types.ErrInvalidRoute, "route not found to module: %s", module).Error()) | ||
} | ||
|
||
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.NewQueryAppVersionResponse(req.PortId, version), nil | ||
} | ||
|
||
func validategRPCRequest(portID string) error { | ||
if err := host.PortIdentifierValidator(portID); err != nil { | ||
return status.Error(codes.InvalidArgument, err.Error()) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" | ||
"github.com/cosmos/ibc-go/modules/core/05-port/types" | ||
"github.com/cosmos/ibc-go/testing/mock" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestAppVersion() { | ||
var ( | ||
req *types.QueryAppVersionRequest | ||
expVersion string | ||
) | ||
|
||
testCases := []struct { | ||
msg string | ||
malleate func() | ||
expPass bool | ||
}{ | ||
{ | ||
"empty request", | ||
func() { | ||
req = nil | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid port ID", | ||
func() { | ||
req = &types.QueryAppVersionRequest{ | ||
PortId: "", | ||
} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"module not found", | ||
func() { | ||
req = &types.QueryAppVersionRequest{ | ||
PortId: "mock-port-id", | ||
} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"version negotiation failure", | ||
func() { | ||
|
||
expVersion = mock.Version | ||
|
||
req = &types.QueryAppVersionRequest{ | ||
PortId: "mock", // retrieves the mock testing module | ||
Counterparty: &channeltypes.Counterparty{ | ||
PortId: "mock-port-id", | ||
ChannelId: "mock-channel-id", | ||
}, | ||
ProposedVersion: "invalid-proposed-version", | ||
} | ||
}, | ||
false, | ||
}, | ||
{ | ||
"success", | ||
func() { | ||
|
||
expVersion = mock.Version | ||
|
||
req = &types.QueryAppVersionRequest{ | ||
PortId: "mock", // retrieves the mock testing module | ||
Counterparty: &channeltypes.Counterparty{ | ||
PortId: "mock-port-id", | ||
ChannelId: "mock-channel-id", | ||
}, | ||
ProposedVersion: mock.Version, | ||
} | ||
}, | ||
true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { | ||
suite.SetupTest() // reset | ||
|
||
tc.malleate() | ||
|
||
ctx := sdk.WrapSDKContext(suite.ctx) | ||
res, err := suite.keeper.AppVersion(ctx, req) | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
suite.Require().NotNil(res) | ||
suite.Require().Equal(expVersion, res.Version) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package port | ||
|
||
import ( | ||
"github.com/gogo/protobuf/grpc" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/ibc-go/modules/core/05-port/types" | ||
"github.com/cosmos/ibc-go/modules/core/client/cli" | ||
) | ||
|
||
// Name returns the IBC port ICS name. | ||
func Name() string { | ||
return types.SubModuleName | ||
} | ||
|
||
// GetQueryCmd returns the root query command for IBC ports. | ||
func GetQueryCmd() *cobra.Command { | ||
return cli.GetQueryCmd() | ||
} | ||
|
||
// RegisterQueryService registers the gRPC query service for IBC ports. | ||
func RegisterQueryService(server grpc.Server, queryServer types.QueryServer) { | ||
types.RegisterQueryServer(server, queryServer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package types | ||
|
||
// NewQueryAppVersionResponse creates a new QueryAppVersionResponse instance | ||
func NewQueryAppVersionResponse(portID, version string) *QueryAppVersionResponse { | ||
return &QueryAppVersionResponse{ | ||
PortId: portID, | ||
Version: version, | ||
} | ||
} |
Oops, something went wrong.