-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adding legacy gov proposal handler for client updates (#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
- Loading branch information
1 parent
8baeb7f
commit 32560f4
Showing
16 changed files
with
655 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.