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

fix(light client): adds tests and check to disable misbehavior update for canon client #1212

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions x/lightclient/ante/ibc_msg_update_client.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ante

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/dymensionxyz/dymension/v3/x/lightclient/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

func (i IBCMessagesDecorator) HandleMsgUpdateClient(ctx sdk.Context, msg *ibcclienttypes.MsgUpdateClient) error {
Expand All @@ -23,10 +25,15 @@ func (i IBCMessagesDecorator) HandleMsgUpdateClient(ctx sdk.Context, msg *ibccli
if canonicalClient != msg.ClientId {
return nil // The client is not a rollapp's canonical client. Continue with default behaviour.
}

clientMessage, err := ibcclienttypes.UnpackClientMessage(msg.ClientMessage)
if err != nil {
return nil
}
_, ok = clientMessage.(*ibctm.Misbehaviour)
if ok {
return errorsmod.Wrap(gerrc.ErrFailedPrecondition, "misbehavior evidence is disabled for canonical clients")
}
header, ok := clientMessage.(*ibctm.Header)
if !ok {
return nil
Expand Down
36 changes: 36 additions & 0 deletions x/lightclient/ante/ibc_msg_update_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,42 @@ func TestHandleMsgUpdateClient(t *testing.T) {
require.NoError(t, err)
},
},
{
name: "Client is not a known canonical client of a rollapp",
prepare: func(ctx sdk.Context, k keeper.Keeper) testInput {
return testInput{
msg: &ibcclienttypes.MsgUpdateClient{
ClientId: "canon-client-id",
},
}
},
assert: func(ctx sdk.Context, k keeper.Keeper, err error) {
require.NoError(t, err)
},
},
{
name: "SubmitMisbehavior for a canonical chain",
prepare: func(ctx sdk.Context, k keeper.Keeper) testInput {
k.SetCanonicalClient(ctx, "rollapp-has-canon-client", "canon-client-id")
m := &ibctm.Misbehaviour{}
mAny, _ := ibcclienttypes.PackClientMessage(m)

return testInput{
msg: &ibcclienttypes.MsgUpdateClient{
ClientId: "canon-client-id",
ClientMessage: mAny,
},
rollapps: map[string]rollapptypes.Rollapp{
"rollapp-has-canon-client": {
RollappId: "rollapp-has-canon-client",
},
},
}
},
assert: func(ctx sdk.Context, k keeper.Keeper, err error) {
require.Error(t, err)
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
Loading