Skip to content

Commit 16c65c6

Browse files
replace channel keeper with IBC keeper in AnteDecorator (#950) (#1096)
* replace channel keeper with IBC keeper in AnteDecorator and pass message to rpc handler * fix error checking condition * fix for proper way of getting go context * refactor tests for ante handler * review comment * review comments and some fixes * review comments * execute message for update client as well * add migration Co-authored-by: Carlos Rodriguez <[email protected]> (cherry picked from commit f0b94df) Co-authored-by: Carlos Rodriguez <[email protected]>
1 parent 45fdb81 commit 16c65c6

File tree

11 files changed

+683
-401
lines changed

11 files changed

+683
-401
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
5858
* (testing) [\#776](https://github.com/cosmos/ibc-go/pull/776) Adding helper fn to generate capability name for testing callbacks
5959
* (testing) [\#892](https://github.com/cosmos/ibc-go/pull/892) IBC Mock modules store the scoped keeper and portID within the IBCMockApp. They also maintain reference to the AppModule to update the AppModule's list of IBC applications it references. Allows for the mock module to be reused as a base application in middleware stacks.
6060
* (channel) [\#882](https://github.com/cosmos/ibc-go/pull/882) The `WriteAcknowledgement` API now takes `exported.Acknowledgement` instead of a byte array
61+
* (modules/core/ante) [\#950](https://github.com/cosmos/ibc-go/pull/950) Replaces the channel keeper with the IBC keeper in the IBC `AnteDecorator` in order to execute the entire message and be able to reject redundant messages that are in the same block as the non-redundant messages.
6162

6263
### State Machine Breaking
6364

docs/ibc/proto-docs.md

+35
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127
- [MsgTimeoutOnCloseResponse](#ibc.core.channel.v1.MsgTimeoutOnCloseResponse)
128128
- [MsgTimeoutResponse](#ibc.core.channel.v1.MsgTimeoutResponse)
129129

130+
- [ResponseResultType](#ibc.core.channel.v1.ResponseResultType)
131+
130132
- [Msg](#ibc.core.channel.v1.Msg)
131133

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

17401742

1743+
| Field | Type | Label | Description |
1744+
| ----- | ---- | ----- | ----------- |
1745+
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |
1746+
1747+
17411748

17421749

17431750

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

19561963

1964+
| Field | Type | Label | Description |
1965+
| ----- | ---- | ----- | ----------- |
1966+
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |
1967+
1968+
19571969

19581970

19591971

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

20052017

2018+
| Field | Type | Label | Description |
2019+
| ----- | ---- | ----- | ----------- |
2020+
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |
2021+
2022+
20062023

20072024

20082025

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

20152032

2033+
| Field | Type | Label | Description |
2034+
| ----- | ---- | ----- | ----------- |
2035+
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |
2036+
2037+
20162038

20172039

20182040

20192041
<!-- end messages -->
20202042

2043+
2044+
<a name="ibc.core.channel.v1.ResponseResultType"></a>
2045+
2046+
### ResponseResultType
2047+
ResponseResultType defines the possible outcomes of the execution of a message
2048+
2049+
| Name | Number | Description |
2050+
| ---- | ------ | ----------- |
2051+
| RESPONSE_RESULT_UNSPECIFIED | 0 | Default zero value enumeration |
2052+
| RESPONSE_RESULT_NOOP | 1 | The message did not call the IBC application callbacks (because, for example, the packet had already been relayed) |
2053+
| RESPONSE_RESULT_SUCCESS | 2 | The message was executed successfully |
2054+
2055+
20212056
<!-- end enums -->
20222057

20232058
<!-- end HasExtensions -->

docs/migrations/v2-to-v3.md

+16
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ The migration code required may look like:
109109
appState[icatypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(icaGenesisState)
110110
```
111111

112+
### Ante decorator
113+
114+
The field of type `channelkeeper.Keeper` in the `AnteDecorator` structure has been replaced with a field of type `*keeper.Keeper`:
115+
116+
```diff
117+
type AnteDecorator struct {
118+
- k channelkeeper.Keeper
119+
+ k *keeper.Keeper
120+
}
121+
122+
- func NewAnteDecorator(k channelkeeper.Keeper) AnteDecorator {
123+
+ func NewAnteDecorator(k *keeper.Keeper) AnteDecorator {
124+
return AnteDecorator{k: k}
125+
}
126+
```
127+
112128
## IBC Apps
113129

114130

modules/core/04-channel/types/tx.pb.go

+226-73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/core/ante/ante.go

+32-13
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
55

66
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
7-
channelkeeper "github.com/cosmos/ibc-go/v3/modules/core/04-channel/keeper"
87
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
8+
"github.com/cosmos/ibc-go/v3/modules/core/keeper"
99
)
1010

1111
type AnteDecorator struct {
12-
k channelkeeper.Keeper
12+
k *keeper.Keeper
1313
}
1414

15-
func NewAnteDecorator(k channelkeeper.Keeper) AnteDecorator {
15+
func NewAnteDecorator(k *keeper.Keeper) AnteDecorator {
1616
return AnteDecorator{k: k}
1717
}
1818

19-
// AnteDecorator returns an error if a multiMsg tx only contains packet messages (Recv, Ack, Timeout) and additional update messages and all packet messages
20-
// are redundant. If the transaction is just a single UpdateClient message, or the multimsg transaction contains some other message type, then the antedecorator returns no error
21-
// and continues processing to ensure these transactions are included.
22-
// This will ensure that relayers do not waste fees on multiMsg transactions when another relayer has already submitted all packets, by rejecting the tx at the mempool layer.
19+
// AnteDecorator returns an error if a multiMsg tx only contains packet messages (Recv, Ack, Timeout) and additional update messages
20+
// and all packet messages are redundant. If the transaction is just a single UpdateClient message, or the multimsg transaction
21+
// contains some other message type, then the antedecorator returns no error and continues processing to ensure these transactions
22+
// are included. This will ensure that relayers do not waste fees on multiMsg transactions when another relayer has already submitted
23+
// all packets, by rejecting the tx at the mempool layer.
2324
func (ad AnteDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
2425
// do not run redundancy check on DeliverTx or simulate
2526
if (ctx.IsCheckTx() || ctx.IsReCheckTx()) && !simulate {
@@ -29,39 +30,57 @@ func (ad AnteDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
2930
for _, m := range tx.GetMsgs() {
3031
switch msg := m.(type) {
3132
case *channeltypes.MsgRecvPacket:
32-
if _, found := ad.k.GetPacketReceipt(ctx, msg.Packet.GetDestPort(), msg.Packet.GetDestChannel(), msg.Packet.GetSequence()); found {
33+
response, err := ad.k.RecvPacket(sdk.WrapSDKContext(ctx), msg)
34+
if err != nil {
35+
return ctx, err
36+
}
37+
if response.Result == channeltypes.NOOP {
3338
redundancies += 1
3439
}
3540
packetMsgs += 1
3641

3742
case *channeltypes.MsgAcknowledgement:
38-
if commitment := ad.k.GetPacketCommitment(ctx, msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), msg.Packet.GetSequence()); len(commitment) == 0 {
43+
response, err := ad.k.Acknowledgement(sdk.WrapSDKContext(ctx), msg)
44+
if err != nil {
45+
return ctx, err
46+
}
47+
if response.Result == channeltypes.NOOP {
3948
redundancies += 1
4049
}
4150
packetMsgs += 1
4251

4352
case *channeltypes.MsgTimeout:
44-
if commitment := ad.k.GetPacketCommitment(ctx, msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), msg.Packet.GetSequence()); len(commitment) == 0 {
53+
response, err := ad.k.Timeout(sdk.WrapSDKContext(ctx), msg)
54+
if err != nil {
55+
return ctx, err
56+
}
57+
if response.Result == channeltypes.NOOP {
4558
redundancies += 1
4659
}
4760
packetMsgs += 1
4861

4962
case *channeltypes.MsgTimeoutOnClose:
50-
if commitment := ad.k.GetPacketCommitment(ctx, msg.Packet.GetSourcePort(), msg.Packet.GetSourceChannel(), msg.Packet.GetSequence()); len(commitment) == 0 {
63+
response, err := ad.k.TimeoutOnClose(sdk.WrapSDKContext(ctx), msg)
64+
if err != nil {
65+
return ctx, err
66+
}
67+
if response.Result == channeltypes.NOOP {
5168
redundancies += 1
5269
}
5370
packetMsgs += 1
5471

5572
case *clienttypes.MsgUpdateClient:
56-
// do nothing here, as we want to avoid updating clients if it is batched with only redundant messages
73+
_, err := ad.k.UpdateClient(sdk.WrapSDKContext(ctx), msg)
74+
if err != nil {
75+
return ctx, err
76+
}
5777

5878
default:
5979
// if the multiMsg tx has a msg that is not a packet msg or update msg, then we will not return error
6080
// regardless of if all packet messages are redundant. This ensures that non-packet messages get processed
6181
// even if they get batched with redundant packet messages.
6282
return next(ctx, tx, simulate)
6383
}
64-
6584
}
6685

6786
// only return error if all packet messages are redundant

0 commit comments

Comments
 (0)