Skip to content

Commit

Permalink
imp: add checkTxUpdateClient to redunant relayer ante decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed May 8, 2024
1 parent edd41da commit 12b939a
Showing 1 changed file with 35 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,14 @@
package ante

import (
errorsmod "cosmossdk.io/errors"

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

"github.com/cosmos/ibc-go/v8/modules/core/02-client/types"

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

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" is being imported more than once (stylecheck)
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"

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

View workflow job for this annotation

GitHub Actions / lint

duplicated-imports: Package "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" already imported (revive)
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 +74,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.checkTxUpdateClient(ctx, msg); err != nil {
return ctx, err
}

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

// checkTxUpdateClient runs a subset of ibc client update logic to be used in within the RedunantRelayerDecorator AnteHandler.
// The following function performs client message verification and state updates only. Note that misbehaviour checks are ommited.

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

View workflow job for this annotation

GitHub Actions / lint

`ommited` is a misspelling of `omitted` (misspell)
func (rrd RedundantRelayDecorator) checkTxUpdateClient(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 {
return errorsmod.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", msg.ClientId, status)
}

clientModule, found := rrd.k.ClientKeeper.Route(msg.ClientId)
if !found {
return errorsmod.Wrap(clienttypes.ErrRouteNotFound, msg.ClientId)
}

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
}

0 comments on commit 12b939a

Please sign in to comment.