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 7 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.

23 changes: 15 additions & 8 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,26 +29,34 @@ 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
} else if err != nil {
return ctx, err
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
}
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
} else if err != nil {
return ctx, err
}
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
} else if err != nil {
return ctx, err
}
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
} else if err != nil {
return ctx, err
}
packetMsgs += 1

Expand All @@ -61,7 +69,6 @@ func (ad AnteDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
// even if they get batched with redundant packet messages.
return next(ctx, tx, simulate)
}

}

// only return error if all packet messages are redundant
Expand Down
Loading