-
Notifications
You must be signed in to change notification settings - Fork 886
Simplify retired IBC transaction rejection #4010
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,92 +1,33 @@ | ||
| package ante | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types" | ||
|
|
||
| clienttypes "github.com/sei-protocol/sei-chain/sei-ibc-go/modules/core/02-client/types" | ||
| channeltypes "github.com/sei-protocol/sei-chain/sei-ibc-go/modules/core/04-channel/types" | ||
| "github.com/sei-protocol/sei-chain/sei-ibc-go/modules/core/keeper" | ||
| coretypes "github.com/sei-protocol/sei-chain/sei-ibc-go/modules/core/types" | ||
| ) | ||
|
|
||
| type AnteDecorator struct { | ||
| k *keeper.Keeper | ||
| } | ||
| // AnteDecorator rejects retired IBC messages before they enter the mempool. | ||
| type AnteDecorator struct{} | ||
|
|
||
| func NewAnteDecorator(k *keeper.Keeper) AnteDecorator { | ||
| return AnteDecorator{k: k} | ||
| func NewAnteDecorator() AnteDecorator { | ||
| return AnteDecorator{} | ||
| } | ||
|
|
||
| // AnteDecorator returns an error if a multiMsg tx only contains packet messages (Recv, Ack, Timeout) and additional update messages | ||
| // and all packet messages 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 and continues processing to ensure these transactions | ||
| // are included. 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. | ||
| func (ad AnteDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { | ||
| // do not run redundancy check on DeliverTx or simulate | ||
| if (ctx.IsCheckTx() || ctx.IsReCheckTx()) && !simulate { | ||
| // keep track of total packet messages and number of redundancies across `RecvPacket`, `AcknowledgePacket`, and `TimeoutPacket/OnClose` | ||
| redundancies := 0 | ||
| packetMsgs := 0 | ||
| for _, m := range tx.GetMsgs() { | ||
| switch msg := m.(type) { | ||
| case *channeltypes.MsgRecvPacket: | ||
| response, err := ad.k.RecvPacket(sdk.WrapSDKContext(ctx), msg) | ||
| if err != nil { | ||
| return ctx, err | ||
| } | ||
| if response.Result == channeltypes.NOOP { | ||
| redundancies += 1 | ||
| } | ||
| packetMsgs += 1 | ||
|
|
||
| case *channeltypes.MsgAcknowledgement: | ||
| response, err := ad.k.Acknowledgement(sdk.WrapSDKContext(ctx), msg) | ||
| if err != nil { | ||
| return ctx, err | ||
| } | ||
| if response.Result == channeltypes.NOOP { | ||
| redundancies += 1 | ||
| } | ||
| packetMsgs += 1 | ||
|
|
||
| case *channeltypes.MsgTimeout: | ||
| response, err := ad.k.Timeout(sdk.WrapSDKContext(ctx), msg) | ||
| if err != nil { | ||
| return ctx, err | ||
| } | ||
| if response.Result == channeltypes.NOOP { | ||
| redundancies += 1 | ||
| } | ||
| packetMsgs += 1 | ||
|
|
||
| case *channeltypes.MsgTimeoutOnClose: | ||
| response, err := ad.k.TimeoutOnClose(sdk.WrapSDKContext(ctx), msg) | ||
| if err != nil { | ||
| return ctx, err | ||
| } | ||
| if response.Result == channeltypes.NOOP { | ||
| redundancies += 1 | ||
| } | ||
| packetMsgs += 1 | ||
|
|
||
| case *clienttypes.MsgUpdateClient: | ||
| _, err := ad.k.UpdateClient(sdk.WrapSDKContext(ctx), msg) | ||
| if err != nil { | ||
| return ctx, err | ||
| } | ||
|
|
||
| default: | ||
| // if the multiMsg tx has a msg that is not a packet msg or update msg, then we will not return error | ||
| // regardless of if all packet messages are redundant. This ensures that non-packet messages get processed | ||
| // even if they get batched with redundant packet messages. | ||
| return next(ctx, tx, simulate) | ||
| } | ||
| // RejectMessages returns the retirement error when a transaction contains an IBC message. | ||
| func RejectMessages(tx sdk.Tx) error { | ||
| for _, msg := range tx.GetMsgs() { | ||
| if strings.HasPrefix(sdk.MsgTypeURL(msg), "/ibc.") { | ||
| return coretypes.ErrIBCDeprecated | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // only return error if all packet messages are redundant | ||
| if redundancies == packetMsgs && packetMsgs > 0 { | ||
| return ctx, channeltypes.ErrRedundantTx | ||
| } | ||
| func (AnteDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { | ||
| if err := RejectMessages(tx); err != nil { | ||
| return ctx, err | ||
| } | ||
| return next(ctx, tx, simulate) | ||
| } | ||
This file contains hidden or 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,50 @@ | ||
| package ante | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types" | ||
| banktypes "github.com/sei-protocol/sei-chain/sei-cosmos/x/bank/types" | ||
| channeltypes "github.com/sei-protocol/sei-chain/sei-ibc-go/modules/core/04-channel/types" | ||
| coretypes "github.com/sei-protocol/sei-chain/sei-ibc-go/modules/core/types" | ||
| ) | ||
|
|
||
| type testTx struct { | ||
| msgs []sdk.Msg | ||
| } | ||
|
|
||
| func (tx testTx) GetMsgs() []sdk.Msg { return tx.msgs } | ||
| func (testTx) ValidateBasic() error { return nil } | ||
| func (testTx) GetGasEstimate() uint64 { return 0 } | ||
|
|
||
| func TestAnteDecorator(t *testing.T) { | ||
| decorator := NewAnteDecorator() | ||
|
|
||
| t.Run("rejects IBC messages", func(t *testing.T) { | ||
| nextCalled := false | ||
| _, err := decorator.AnteHandle(sdk.Context{}, testTx{msgs: []sdk.Msg{ | ||
| &channeltypes.MsgChannelCloseInit{}, | ||
| }}, false, func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) { | ||
| nextCalled = true | ||
| return ctx, nil | ||
| }) | ||
|
|
||
| require.ErrorIs(t, err, coretypes.ErrIBCDeprecated) | ||
| require.False(t, nextCalled) | ||
| }) | ||
|
|
||
| t.Run("passes non-IBC messages", func(t *testing.T) { | ||
| nextCalled := false | ||
| _, err := decorator.AnteHandle(sdk.Context{}, testTx{msgs: []sdk.Msg{ | ||
| &banktypes.MsgSend{}, | ||
| }}, false, func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) { | ||
| nextCalled = true | ||
| return ctx, nil | ||
| }) | ||
|
|
||
| require.NoError(t, err) | ||
| require.True(t, nextCalled) | ||
| }) | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion]
RejectMessagesonly walkstx.GetMsgs(), so an IBC message wrapped inauthz.MsgExechas type URL/cosmos.authz.v1beta1.MsgExecand passes the prefix check. Such a tx enters the mempool and can be included in a block, only failing later at the retainedMsgServertombstone — which undercuts the stated goal of rejecting retired IBC traffic "before they enter the mempool."The codebase already has the recursion this needs:
CheckAuthzContainsEvm(app/ante/cosmos_checktx.go:569, called from the same CheckTx path at line 216, andapp/antedecorators/authz_nested_message.go:40) descends through nestedMsgExecwith amaxNestedMsgsdepth cap. Extending that walk — or mirroring it here — would close the hole at the single choke point every path passes through, and deserves a regression test with an IBC message nested insideMsgExec.