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

replace channel keeper with IBC keeper in AnteDecorator #950

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
- [MsgTimeoutOnCloseResponse](#ibc.core.channel.v1.MsgTimeoutOnCloseResponse)
- [MsgTimeoutResponse](#ibc.core.channel.v1.MsgTimeoutResponse)

- [ResponseResultType](#ibc.core.channel.v1.ResponseResultType)

- [Msg](#ibc.core.channel.v1.Msg)

- [ibc/core/client/v1/genesis.proto](#ibc/core/client/v1/genesis.proto)
Expand Down Expand Up @@ -1738,6 +1740,11 @@ MsgAcknowledgement receives incoming IBC acknowledgement
MsgAcknowledgementResponse defines the Msg/Acknowledgement response type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |





Expand Down Expand Up @@ -1954,6 +1961,11 @@ MsgRecvPacket receives incoming IBC packet
MsgRecvPacketResponse defines the Msg/RecvPacket response type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |





Expand Down Expand Up @@ -2003,6 +2015,11 @@ MsgTimeoutOnClose timed-out packet upon counterparty channel closure.
MsgTimeoutOnCloseResponse defines the Msg/TimeoutOnClose response type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |





Expand All @@ -2013,11 +2030,29 @@ MsgTimeoutOnCloseResponse defines the Msg/TimeoutOnClose response type.
MsgTimeoutResponse defines the Msg/Timeout response type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |





<!-- end messages -->


<a name="ibc.core.channel.v1.ResponseResultType"></a>

### ResponseResultType
ResponseResultType defines the possible outcomes of the execution of a message

| Name | Number | Description |
| ---- | ------ | ----------- |
| RESPONSE_RESULT_UNSPECIFIED | 0 | Default zero value enumeration |
| RESPONSE_RESULT_NOOP | 1 | The message was not executed (because, for example, the packet had already been relayed) |
| RESPONSE_RESULT_SUCCESS | 2 | The message was executed successfully |


<!-- end enums -->

<!-- end HasExtensions -->
Expand Down
299 changes: 226 additions & 73 deletions modules/core/04-channel/types/tx.pb.go

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions modules/core/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
channelkeeper "github.com/cosmos/ibc-go/v3/modules/core/04-channel/keeper"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/v3/modules/core/keeper"
)

type AnteDecorator struct {
k channelkeeper.Keeper
k *keeper.Keeper
}

func NewAnteDecorator(k channelkeeper.Keeper) AnteDecorator {
func NewAnteDecorator(k *keeper.Keeper) AnteDecorator {
return AnteDecorator{k: k}
}

Expand All @@ -29,25 +29,25 @@ func (ad AnteDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
for _, m := range tx.GetMsgs() {
switch msg := m.(type) {
case *channeltypes.MsgRecvPacket:
if _, found := ad.k.GetPacketReceipt(ctx, msg.Packet.GetDestPort(), msg.Packet.GetDestChannel(), msg.Packet.GetSequence()); found {
if response, err := ad.k.RecvPacket(sdk.WrapSDKContext(ctx), msg); err == nil && response.Result == channeltypes.NOOP {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
redundancies += 1
}
packetMsgs += 1

case *channeltypes.MsgAcknowledgement:
if commitment := ad.k.GetPacketCommitment(ctx, msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), msg.Packet.GetSequence()); len(commitment) == 0 {
if response, err := ad.k.Acknowledgement(sdk.WrapSDKContext(ctx), msg); err == nil && response.Result == channeltypes.NOOP {
redundancies += 1
}
packetMsgs += 1

case *channeltypes.MsgTimeout:
if commitment := ad.k.GetPacketCommitment(ctx, msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), msg.Packet.GetSequence()); len(commitment) == 0 {
if response, err := ad.k.Timeout(sdk.WrapSDKContext(ctx), msg); err == nil && response.Result == channeltypes.NOOP {
redundancies += 1
}
packetMsgs += 1

case *channeltypes.MsgTimeoutOnClose:
if commitment := ad.k.GetPacketCommitment(ctx, msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), msg.Packet.GetSequence()); len(commitment) == 0 {
if response, err := ad.k.TimeoutOnClose(sdk.WrapSDKContext(ctx), msg); err == nil && response.Result == channeltypes.NOOP {
redundancies += 1
}
packetMsgs += 1
Expand Down
2 changes: 1 addition & 1 deletion modules/core/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
// reset suite
suite.SetupTest()

k := suite.chainB.App.GetIBCKeeper().ChannelKeeper
k := suite.chainB.App.GetIBCKeeper()
decorator := ante.NewAnteDecorator(k)

msgs := tc.malleate(suite)
Expand Down
36 changes: 32 additions & 4 deletions proto/ibc/core/channel/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ service Msg {
rpc Acknowledgement(MsgAcknowledgement) returns (MsgAcknowledgementResponse);
}

// ResponseResultType defines the possible outcomes of the execution of a message
enum ResponseResultType {
option (gogoproto.goproto_enum_prefix) = false;

// Default zero value enumeration
RESPONSE_RESULT_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNSPECIFIED"];
// The message was not executed (because, for example, the packet had already been relayed)
RESPONSE_RESULT_NOOP = 1 [(gogoproto.enumvalue_customname) = "NOOP"];
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
// The message was executed successfully
RESPONSE_RESULT_SUCCESS = 2 [(gogoproto.enumvalue_customname) = "SUCCESS"];
}

// MsgChannelOpenInit defines an sdk.Msg to initialize a channel handshake. It
// is called by a relayer on Chain A.
message MsgChannelOpenInit {
Expand Down Expand Up @@ -163,7 +175,11 @@ message MsgRecvPacket {
}

// MsgRecvPacketResponse defines the Msg/RecvPacket response type.
message MsgRecvPacketResponse {}
message MsgRecvPacketResponse {
option (gogoproto.goproto_getters) = false;

ResponseResultType result = 1;
}

// MsgTimeout receives timed-out packet
message MsgTimeout {
Expand All @@ -179,7 +195,11 @@ message MsgTimeout {
}

// MsgTimeoutResponse defines the Msg/Timeout response type.
message MsgTimeoutResponse {}
message MsgTimeoutResponse {
option (gogoproto.goproto_getters) = false;

ResponseResultType result = 1;
}

// MsgTimeoutOnClose timed-out packet upon counterparty channel closure.
message MsgTimeoutOnClose {
Expand All @@ -196,7 +216,11 @@ message MsgTimeoutOnClose {
}

// MsgTimeoutOnCloseResponse defines the Msg/TimeoutOnClose response type.
message MsgTimeoutOnCloseResponse {}
message MsgTimeoutOnCloseResponse {
option (gogoproto.goproto_getters) = false;

ResponseResultType result = 1;
}

// MsgAcknowledgement receives incoming IBC acknowledgement
message MsgAcknowledgement {
Expand All @@ -212,4 +236,8 @@ message MsgAcknowledgement {
}

// MsgAcknowledgementResponse defines the Msg/Acknowledgement response type.
message MsgAcknowledgementResponse {}
message MsgAcknowledgementResponse {
option (gogoproto.goproto_getters) = false;

ResponseResultType result = 1;
}
9 changes: 4 additions & 5 deletions testing/simapp/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"

channelkeeper "github.com/cosmos/ibc-go/v3/modules/core/04-channel/keeper"
ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante"
"github.com/cosmos/ibc-go/v3/modules/core/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC keeper.
type HandlerOptions struct {
ante.HandlerOptions

IBCChannelkeeper channelkeeper.Keeper
IBCkeeper *keeper.Keeper
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
}

// NewAnteHandler creates a new ante handler
Expand Down Expand Up @@ -49,7 +48,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCChannelkeeper),
ibcante.NewAnteDecorator(options.IBCkeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
2 changes: 1 addition & 1 deletion testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func NewSimApp(
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
IBCChannelkeeper: app.IBCKeeper.ChannelKeeper,
IBCkeeper: app.IBCKeeper,
},
)
if err != nil {
Expand Down