Skip to content

Commit

Permalink
imp: add updateClientCheckTx to redunant relayer ante decorator (#6279)
Browse files Browse the repository at this point in the history
* imp: add checkTxUpdateClient to redunant relayer ante decorator

* chore: update godoc and duplicate imports

* test: add coverage for checkTxUpdateClient func

* chore: rename ante func to updateClientCheckTx

(cherry picked from commit 3da4830)
  • Loading branch information
damiannolan authored and mergify[bot] committed May 14, 2024
1 parent 0b10c11 commit 21afd16
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
37 changes: 35 additions & 2 deletions modules/core/ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package ante

Check failure on line 1 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

: # github.com/cosmos/ibc-go/v8/modules/core/ante

Check failure on line 1 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

: # github.com/cosmos/ibc-go/v8/modules/core/ante

import (
errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"

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

Expand Down Expand Up @@ -70,8 +73,7 @@ func (rrd RedundantRelayDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
packetMsgs++

case *clienttypes.MsgUpdateClient:
_, err := rrd.k.UpdateClient(ctx, msg)
if err != nil {
if err := rrd.updateClientCheckTx(ctx, msg); err != nil {
return ctx, err
}

Expand All @@ -90,3 +92,34 @@ func (rrd RedundantRelayDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
}
return next(ctx, tx, simulate)
}

// updateClientCheckTx runs a subset of ibc client update logic to be used specifically within the RedundantRelayDecorator AnteHandler.
// The following function performs ibc client message verification for CheckTx only and state updates in both CheckTx and ReCheckTx.
// Note that misbehaviour checks are omitted.
func (rrd RedundantRelayDecorator) updateClientCheckTx(ctx sdk.Context, msg *clienttypes.MsgUpdateClient) error {
clientMsg, err := clienttypes.UnpackClientMessage(msg.ClientMessage)
if err != nil {
return err
}

if status := rrd.k.ClientKeeper.GetClientStatus(ctx, msg.ClientId); status != exported.Active {

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / build (arm)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / build (amd64)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / build (arm64)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (03)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (03)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (03)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (03)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (00)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (01)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (01)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (01)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (01)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (02)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (02)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (02)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (02)

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus

Check failure on line 105 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to rrd.k.ClientKeeper.GetClientStatus
return errorsmod.Wrapf(clienttypes.ErrClientNotActive, "cannot update client (%s) with status %s", msg.ClientId, status)
}

clientModule, found := rrd.k.ClientKeeper.Route(msg.ClientId)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / build (arm)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / build (amd64)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / build (arm64)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (03)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (03)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (03)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (00)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (01)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (01)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (01)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (02)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (02)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (02)

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)

Check failure on line 109 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

rrd.k.ClientKeeper.Route undefined (type "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper".Keeper has no field or method Route)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, msg.ClientId)

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / build (arm)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / build (amd64)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / build (arm64)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: clienttypes.ErrRouteNotFound

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

undefined: clienttypes.ErrRouteNotFound (typecheck)

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

undefined: clienttypes.ErrRouteNotFound) (typecheck)

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

undefined: clienttypes.ErrRouteNotFound (typecheck)

Check failure on line 111 in modules/core/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

undefined: clienttypes.ErrRouteNotFound) (typecheck)
}

if !ctx.IsReCheckTx() {
if err := clientModule.VerifyClientMessage(ctx, msg.ClientId, clientMsg); err != nil {
return err
}
}

heights := clientModule.UpdateState(ctx, msg.ClientId, clientMsg)

ctx.Logger().With("module", "x/"+exported.ModuleName).Debug("ante ibc client update", "consensusHeights", heights)

return nil
}
35 changes: 35 additions & 0 deletions modules/core/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"github.com/stretchr/testify/require"
testifysuite "github.com/stretchr/testify/suite"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"

clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
"github.com/cosmos/ibc-go/v8/modules/core/ante"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

Expand Down Expand Up @@ -387,6 +389,39 @@ func (suite *AnteTestSuite) TestAnteDecorator() {
},
false,
},
{
"no success on one new UpdateClient message: invalid client identifier",
func(suite *AnteTestSuite) []sdk.Msg {
clientMsg, err := codectypes.NewAnyWithValue(&ibctm.Header{})
suite.Require().NoError(err)

msgs := []sdk.Msg{&clienttypes.MsgUpdateClient{ClientId: ibctesting.InvalidID, ClientMessage: clientMsg}}
return msgs
},
false,
},
{
"no success on one new UpdateClient message: client module not found",
func(suite *AnteTestSuite) []sdk.Msg {
clientMsg, err := codectypes.NewAnyWithValue(&ibctm.Header{})
suite.Require().NoError(err)

msgs := []sdk.Msg{&clienttypes.MsgUpdateClient{ClientId: clienttypes.FormatClientIdentifier("08-wasm", 1), ClientMessage: clientMsg}}
return msgs
},
false,
},
{
"no success on one new UpdateClient message: no consensus state for trusted height",
func(suite *AnteTestSuite) []sdk.Msg {
clientMsg, err := codectypes.NewAnyWithValue(&ibctm.Header{TrustedHeight: clienttypes.NewHeight(1, 10000)})
suite.Require().NoError(err)

msgs := []sdk.Msg{&clienttypes.MsgUpdateClient{ClientId: suite.path.EndpointA.ClientID, ClientMessage: clientMsg}}
return msgs
},
false,
},
{
"no success on three new UpdateClient messages and three redundant messages of each type",
func(suite *AnteTestSuite) []sdk.Msg {
Expand Down

0 comments on commit 21afd16

Please sign in to comment.