From b7aeb269926f867c1be4b5e5c14e73e75e2a6120 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 14 May 2024 09:42:57 +0200 Subject: [PATCH] imp: add updateClientCheckTx to redunant relayer ante decorator (#6279) * 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 3da483085feaa6bb46144bfc11b2e45a3edcbc52) # Conflicts: # modules/core/ante/ante.go # modules/core/ante/ante_test.go --- modules/core/ante/ante.go | 44 ++++++++++++++++++++++++++++++ modules/core/ante/ante_test.go | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/modules/core/ante/ante.go b/modules/core/ante/ante.go index 7b8cdb326de..ac42d8289a6 100644 --- a/modules/core/ante/ante.go +++ b/modules/core/ante/ante.go @@ -1,11 +1,20 @@ package ante import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +<<<<<<< HEAD clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" "github.com/cosmos/ibc-go/v7/modules/core/keeper" +======= + 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" +>>>>>>> 3da48308 (imp: add updateClientCheckTx to redunant relayer ante decorator (#6279)) ) type RedundantRelayDecorator struct { @@ -70,8 +79,12 @@ func (rrd RedundantRelayDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula packetMsgs++ case *clienttypes.MsgUpdateClient: +<<<<<<< HEAD _, err := rrd.k.UpdateClient(sdk.WrapSDKContext(ctx), msg) if err != nil { +======= + if err := rrd.updateClientCheckTx(ctx, msg); err != nil { +>>>>>>> 3da48308 (imp: add updateClientCheckTx to redunant relayer ante decorator (#6279)) return ctx, err } @@ -90,3 +103,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 { + return errorsmod.Wrapf(clienttypes.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 +} diff --git a/modules/core/ante/ante_test.go b/modules/core/ante/ante_test.go index aca0fefd9a7..fe3a2836e3e 100644 --- a/modules/core/ante/ante_test.go +++ b/modules/core/ante/ante_test.go @@ -3,16 +3,33 @@ package ante_test import ( "testing" +<<<<<<< HEAD +======= + "github.com/stretchr/testify/require" + testifysuite "github.com/stretchr/testify/suite" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" +>>>>>>> 3da48308 (imp: add updateClientCheckTx to redunant relayer ante decorator (#6279)) sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" +<<<<<<< HEAD clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/ante" "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v7/testing" +======= + 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" +>>>>>>> 3da48308 (imp: add updateClientCheckTx to redunant relayer ante decorator (#6279)) ) type AnteTestSuite struct { @@ -386,6 +403,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 {