Skip to content

Commit 32560f4

Browse files
authored
chore: adding legacy gov proposal handler for client updates (cosmos#4729)
* 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
1 parent 8baeb7f commit 32560f4

File tree

16 files changed

+655
-40
lines changed

16 files changed

+655
-40
lines changed

.golangci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ issues:
3838
- text: 'Use of weak random number generator'
3939
linters:
4040
- gosec
41+
- linters:
42+
- staticcheck
43+
text: "SA1019:" # silence errors on usage of deprecated funcs
4144

4245
max-issues-per-linter: 10000
4346
max-same-issues: 10000

e2e/tests/transfer/localhost_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,4 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() {
171171
expected := testvalues.IBCTransferAmount
172172
s.Require().Equal(expected, actualBalance.Int64())
173173
})
174-
175174
}

e2e/testsuite/testconfig.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,8 @@ func getGenesisModificationFunction(cc ChainConfig) func(ibc.ChainConfig, []byte
434434
// defaultGovv1ModifyGenesis will only modify governance params to ensure the voting period and minimum deposit
435435
// are functional for e2e testing purposes.
436436
func defaultGovv1ModifyGenesis(version string) func(ibc.ChainConfig, []byte) ([]byte, error) {
437-
var stdlibJSONMarshalling = semverutil.FeatureReleases{MajorVersion: "v8"}
437+
stdlibJSONMarshalling := semverutil.FeatureReleases{MajorVersion: "v8"}
438438
return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) {
439-
440439
appGenesis, err := genutiltypes.AppGenesisFromReader(bytes.NewReader(genbz))
441440
if err != nil {
442441
return nil, fmt.Errorf("failed to unmarshal genesis bytes into genesis doc: %w", err)
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package client
2+
3+
import (
4+
errorsmod "cosmossdk.io/errors"
5+
6+
sdk "github.com/cosmos/cosmos-sdk/types"
7+
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
8+
9+
"github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
10+
"github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
11+
ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors"
12+
)
13+
14+
// NewClientProposalHandler defines the 02-client legacy proposal handler.
15+
//
16+
// Deprecated: This function is deprecated and will be removed in a future release.
17+
// Please use MsgRecoverClient and MsgIBCSoftwareUpgrade in favour of this legacy Handler.
18+
func NewClientProposalHandler(k keeper.Keeper) govtypes.Handler { //nolint:staticcheck
19+
return func(ctx sdk.Context, content govtypes.Content) error {
20+
switch c := content.(type) {
21+
case *types.ClientUpdateProposal:
22+
// NOTE: RecoverClient is called in favour of the deprecated ClientUpdateProposal function.
23+
return k.RecoverClient(ctx, c.SubjectClientId, c.SubstituteClientId)
24+
default:
25+
return errorsmod.Wrapf(ibcerrors.ErrUnknownRequest, "unrecognized ibc proposal content type: %T", c)
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package client_test
2+
3+
import (
4+
sdkmath "cosmossdk.io/math"
5+
6+
sdk "github.com/cosmos/cosmos-sdk/types"
7+
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
8+
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
9+
10+
client "github.com/cosmos/ibc-go/v8/modules/core/02-client"
11+
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
12+
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
13+
ibctesting "github.com/cosmos/ibc-go/v8/testing"
14+
)
15+
16+
func (suite *ClientTestSuite) TestNewClientUpdateProposalHandler() {
17+
var (
18+
content govtypes.Content
19+
err error
20+
)
21+
22+
testCases := []struct {
23+
name string
24+
malleate func()
25+
expPass bool
26+
}{
27+
{
28+
"valid update client proposal", func() {
29+
subjectPath := ibctesting.NewPath(suite.chainA, suite.chainB)
30+
suite.coordinator.SetupClients(subjectPath)
31+
subjectClientState := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID)
32+
33+
substitutePath := ibctesting.NewPath(suite.chainA, suite.chainB)
34+
suite.coordinator.SetupClients(substitutePath)
35+
36+
// update substitute twice
37+
err = substitutePath.EndpointA.UpdateClient()
38+
suite.Require().NoError(err)
39+
err = substitutePath.EndpointA.UpdateClient()
40+
suite.Require().NoError(err)
41+
substituteClientState := suite.chainA.GetClientState(substitutePath.EndpointA.ClientID)
42+
43+
tmClientState, ok := subjectClientState.(*ibctm.ClientState)
44+
suite.Require().True(ok)
45+
tmClientState.AllowUpdateAfterMisbehaviour = true
46+
tmClientState.FrozenHeight = tmClientState.LatestHeight
47+
suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID, tmClientState)
48+
49+
// replicate changes to substitute (they must match)
50+
tmClientState, ok = substituteClientState.(*ibctm.ClientState)
51+
suite.Require().True(ok)
52+
tmClientState.AllowUpdateAfterMisbehaviour = true
53+
suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), substitutePath.EndpointA.ClientID, tmClientState)
54+
55+
content = clienttypes.NewClientUpdateProposal(ibctesting.Title, ibctesting.Description, subjectPath.EndpointA.ClientID, substitutePath.EndpointA.ClientID)
56+
}, true,
57+
},
58+
{
59+
"nil proposal", func() {
60+
content = nil
61+
}, false,
62+
},
63+
{
64+
"unsupported proposal type", func() {
65+
content = &distributiontypes.CommunityPoolSpendProposal{ //nolint:staticcheck
66+
Title: ibctesting.Title,
67+
Description: ibctesting.Description,
68+
Recipient: suite.chainA.SenderAccount.GetAddress().String(),
69+
Amount: sdk.NewCoins(sdk.NewCoin("communityfunds", sdkmath.NewInt(10))),
70+
}
71+
}, false,
72+
},
73+
}
74+
75+
for _, tc := range testCases {
76+
tc := tc
77+
78+
suite.Run(tc.name, func() {
79+
suite.SetupTest() // reset
80+
81+
tc.malleate()
82+
83+
proposalHandler := client.NewClientProposalHandler(suite.chainA.App.GetIBCKeeper().ClientKeeper)
84+
85+
err = proposalHandler(suite.chainA.GetContext(), content)
86+
87+
if tc.expPass {
88+
suite.Require().NoError(err)
89+
} else {
90+
suite.Require().Error(err)
91+
}
92+
})
93+
}
94+
}

0 commit comments

Comments
 (0)