Skip to content

Commit

Permalink
chore: adding legacy gov proposal handler for client updates (#4729)
Browse files Browse the repository at this point in the history
* chore: re-adding ClientUpdateProposal types and interface impl

* chore: re-adding legacy proposal handler and surrounds

* chore: remove dead code and route to RecoverClient, adding deprecation comments inline

* chore: remove unused event emission func

* chore: remove unused event type and error

* make format

* chore: adding deprecation notice to legacy_proposal.go, attempt to fix linter

* chore: attempt to silence deprecation linter

* chore: adding comment in golangci.yml
  • Loading branch information
damiannolan authored Sep 20, 2023
1 parent 8baeb7f commit 32560f4
Show file tree
Hide file tree
Showing 16 changed files with 655 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ issues:
- text: 'Use of weak random number generator'
linters:
- gosec
- linters:
- staticcheck
text: "SA1019:" # silence errors on usage of deprecated funcs

max-issues-per-linter: 10000
max-same-issues: 10000
Expand Down
1 change: 0 additions & 1 deletion e2e/tests/transfer/localhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,4 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() {
expected := testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance.Int64())
})

}
3 changes: 1 addition & 2 deletions e2e/testsuite/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,8 @@ func getGenesisModificationFunction(cc ChainConfig) func(ibc.ChainConfig, []byte
// defaultGovv1ModifyGenesis will only modify governance params to ensure the voting period and minimum deposit
// are functional for e2e testing purposes.
func defaultGovv1ModifyGenesis(version string) func(ibc.ChainConfig, []byte) ([]byte, error) {
var stdlibJSONMarshalling = semverutil.FeatureReleases{MajorVersion: "v8"}
stdlibJSONMarshalling := semverutil.FeatureReleases{MajorVersion: "v8"}
return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) {

appGenesis, err := genutiltypes.AppGenesisFromReader(bytes.NewReader(genbz))
if err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis bytes into genesis doc: %w", err)
Expand Down
28 changes: 28 additions & 0 deletions modules/core/02-client/proposal_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package client

import (
errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

"github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
"github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors"
)

// NewClientProposalHandler defines the 02-client legacy proposal handler.
//
// Deprecated: This function is deprecated and will be removed in a future release.
// Please use MsgRecoverClient and MsgIBCSoftwareUpgrade in favour of this legacy Handler.
func NewClientProposalHandler(k keeper.Keeper) govtypes.Handler { //nolint:staticcheck
return func(ctx sdk.Context, content govtypes.Content) error {
switch c := content.(type) {
case *types.ClientUpdateProposal:
// NOTE: RecoverClient is called in favour of the deprecated ClientUpdateProposal function.
return k.RecoverClient(ctx, c.SubjectClientId, c.SubstituteClientId)
default:
return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "unrecognized ibc proposal content type: %T", c)
}
}
}
94 changes: 94 additions & 0 deletions modules/core/02-client/proposal_handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package client_test

import (
sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

client "github.com/cosmos/ibc-go/v8/modules/core/02-client"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

func (suite *ClientTestSuite) TestNewClientUpdateProposalHandler() {
var (
content govtypes.Content
err error
)

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"valid update client proposal", func() {
subjectPath := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupClients(subjectPath)
subjectClientState := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID)

substitutePath := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupClients(substitutePath)

// update substitute twice
err = substitutePath.EndpointA.UpdateClient()
suite.Require().NoError(err)
err = substitutePath.EndpointA.UpdateClient()
suite.Require().NoError(err)
substituteClientState := suite.chainA.GetClientState(substitutePath.EndpointA.ClientID)

tmClientState, ok := subjectClientState.(*ibctm.ClientState)
suite.Require().True(ok)
tmClientState.AllowUpdateAfterMisbehaviour = true
tmClientState.FrozenHeight = tmClientState.LatestHeight
suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID, tmClientState)

// replicate changes to substitute (they must match)
tmClientState, ok = substituteClientState.(*ibctm.ClientState)
suite.Require().True(ok)
tmClientState.AllowUpdateAfterMisbehaviour = true
suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), substitutePath.EndpointA.ClientID, tmClientState)

content = clienttypes.NewClientUpdateProposal(ibctesting.Title, ibctesting.Description, subjectPath.EndpointA.ClientID, substitutePath.EndpointA.ClientID)
}, true,
},
{
"nil proposal", func() {
content = nil
}, false,
},
{
"unsupported proposal type", func() {
content = &distributiontypes.CommunityPoolSpendProposal{ //nolint:staticcheck
Title: ibctesting.Title,
Description: ibctesting.Description,
Recipient: suite.chainA.SenderAccount.GetAddress().String(),
Amount: sdk.NewCoins(sdk.NewCoin("communityfunds", sdkmath.NewInt(10))),
}
}, false,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

tc.malleate()

proposalHandler := client.NewClientProposalHandler(suite.chainA.App.GetIBCKeeper().ClientKeeper)

err = proposalHandler(suite.chainA.GetContext(), content)

if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
}
}
Loading

0 comments on commit 32560f4

Please sign in to comment.