From 32560f4a765e990c34481422873a4765df4d61ca Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 20 Sep 2023 13:58:15 +0200 Subject: [PATCH] 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 --- .golangci.yml | 3 + e2e/tests/transfer/localhost_test.go | 1 - e2e/testsuite/testconfig.go | 3 +- modules/core/02-client/proposal_handler.go | 28 ++ .../core/02-client/proposal_handler_test.go | 94 +++++ modules/core/02-client/types/client.pb.go | 376 ++++++++++++++++-- .../core/02-client/types/legacy_proposal.go | 62 +++ .../02-client/types/legacy_proposal_test.go | 85 ++++ modules/core/02-client/types/tx.pb.go | 2 +- .../controller/v1/tx.proto | 2 +- .../interchain_accounts/host/v1/tx.proto | 2 +- proto/ibc/applications/transfer/v1/tx.proto | 2 +- proto/ibc/core/client/v1/client.proto | 24 ++ proto/ibc/core/client/v1/tx.proto | 4 +- proto/ibc/core/connection/v1/tx.proto | 2 +- testing/simapp/app.go | 5 +- 16 files changed, 655 insertions(+), 40 deletions(-) create mode 100644 modules/core/02-client/proposal_handler.go create mode 100644 modules/core/02-client/proposal_handler_test.go create mode 100644 modules/core/02-client/types/legacy_proposal.go create mode 100644 modules/core/02-client/types/legacy_proposal_test.go diff --git a/.golangci.yml b/.golangci.yml index 5550ee25e24..32cd4cb67af 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 diff --git a/e2e/tests/transfer/localhost_test.go b/e2e/tests/transfer/localhost_test.go index 240f3321583..8e50c335bb0 100644 --- a/e2e/tests/transfer/localhost_test.go +++ b/e2e/tests/transfer/localhost_test.go @@ -171,5 +171,4 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() { expected := testvalues.IBCTransferAmount s.Require().Equal(expected, actualBalance.Int64()) }) - } diff --git a/e2e/testsuite/testconfig.go b/e2e/testsuite/testconfig.go index 1c04cefb106..39d73eed36b 100644 --- a/e2e/testsuite/testconfig.go +++ b/e2e/testsuite/testconfig.go @@ -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) diff --git a/modules/core/02-client/proposal_handler.go b/modules/core/02-client/proposal_handler.go new file mode 100644 index 00000000000..a1044bf33fc --- /dev/null +++ b/modules/core/02-client/proposal_handler.go @@ -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) + } + } +} diff --git a/modules/core/02-client/proposal_handler_test.go b/modules/core/02-client/proposal_handler_test.go new file mode 100644 index 00000000000..79e34ceaa85 --- /dev/null +++ b/modules/core/02-client/proposal_handler_test.go @@ -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) + } + }) + } +} diff --git a/modules/core/02-client/types/client.pb.go b/modules/core/02-client/types/client.pb.go index 954b4aba6d6..7a9fdae2289 100644 --- a/modules/core/02-client/types/client.pb.go +++ b/modules/core/02-client/types/client.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + _ "github.com/cosmos/cosmos-proto" types "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" @@ -289,46 +290,109 @@ func (m *Params) GetAllowedClients() []string { return nil } +// ClientUpdateProposal is a legacy governance proposal. If it passes, the substitute +// client's latest consensus state is copied over to the subject client. The proposal +// handler may fail if the subject and the substitute do not match in client and +// chain parameters (with exception to latest height, frozen height, and chain-id). +// +// Deprecated: Please use MsgRecoverClient in favour of this message type. +// +// Deprecated: Do not use. +type ClientUpdateProposal struct { + // the title of the update proposal + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + // the description of the proposal + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + // the client identifier for the client to be updated if the proposal passes + SubjectClientId string `protobuf:"bytes,3,opt,name=subject_client_id,json=subjectClientId,proto3" json:"subject_client_id,omitempty" yaml:"subject_client_id"` + // the substitute client identifier for the client standing in for the subject + // client + SubstituteClientId string `protobuf:"bytes,4,opt,name=substitute_client_id,json=substituteClientId,proto3" json:"substitute_client_id,omitempty" yaml:"substitute_client_id"` +} + +func (m *ClientUpdateProposal) Reset() { *m = ClientUpdateProposal{} } +func (m *ClientUpdateProposal) String() string { return proto.CompactTextString(m) } +func (*ClientUpdateProposal) ProtoMessage() {} +func (*ClientUpdateProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_b6bc4c8185546947, []int{5} +} +func (m *ClientUpdateProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClientUpdateProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClientUpdateProposal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ClientUpdateProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClientUpdateProposal.Merge(m, src) +} +func (m *ClientUpdateProposal) XXX_Size() int { + return m.Size() +} +func (m *ClientUpdateProposal) XXX_DiscardUnknown() { + xxx_messageInfo_ClientUpdateProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_ClientUpdateProposal proto.InternalMessageInfo + func init() { proto.RegisterType((*IdentifiedClientState)(nil), "ibc.core.client.v1.IdentifiedClientState") proto.RegisterType((*ConsensusStateWithHeight)(nil), "ibc.core.client.v1.ConsensusStateWithHeight") proto.RegisterType((*ClientConsensusStates)(nil), "ibc.core.client.v1.ClientConsensusStates") proto.RegisterType((*Height)(nil), "ibc.core.client.v1.Height") proto.RegisterType((*Params)(nil), "ibc.core.client.v1.Params") + proto.RegisterType((*ClientUpdateProposal)(nil), "ibc.core.client.v1.ClientUpdateProposal") } func init() { proto.RegisterFile("ibc/core/client/v1/client.proto", fileDescriptor_b6bc4c8185546947) } var fileDescriptor_b6bc4c8185546947 = []byte{ - // 439 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xcf, 0x8b, 0xd3, 0x40, - 0x14, 0xce, 0x74, 0x97, 0xb2, 0x9d, 0x4a, 0x2b, 0x61, 0x17, 0x62, 0x85, 0xb4, 0xe4, 0x62, 0x0e, - 0xee, 0x8c, 0x8d, 0x07, 0x8b, 0xe0, 0xc1, 0xdd, 0x8b, 0x7b, 0x11, 0x89, 0x07, 0x41, 0x90, 0x92, - 0x4c, 0x66, 0x93, 0x81, 0x64, 0x66, 0xc9, 0x4c, 0x22, 0xfd, 0x0f, 0x3c, 0x0a, 0x5e, 0x3c, 0xee, - 0x9f, 0xb3, 0xc7, 0x3d, 0x7a, 0x12, 0x69, 0xff, 0x11, 0xc9, 0xcc, 0x14, 0x89, 0xbf, 0xd8, 0xdb, - 0xcb, 0xf7, 0xbe, 0x7c, 0xef, 0x7b, 0xdf, 0x3c, 0x38, 0x67, 0x29, 0xc1, 0x44, 0xd4, 0x14, 0x93, - 0x92, 0x51, 0xae, 0x70, 0xbb, 0xb4, 0x15, 0xba, 0xaa, 0x85, 0x12, 0xae, 0xcb, 0x52, 0x82, 0x3a, - 0x02, 0xb2, 0x70, 0xbb, 0x9c, 0x1d, 0xe7, 0x22, 0x17, 0xba, 0x8d, 0xbb, 0xca, 0x30, 0x67, 0x0f, - 0x72, 0x21, 0xf2, 0x92, 0x62, 0xfd, 0x95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0x51, 0x0e, 0xfa, - 0x44, 0xa3, 0xf8, 0xfc, 0xe8, 0xd3, 0xf5, 0xdc, 0xf9, 0x7a, 0x3d, 0x77, 0x82, 0x25, 0x1c, 0xbe, - 0x49, 0xea, 0xa4, 0x92, 0xdd, 0xcf, 0x49, 0x59, 0x8a, 0x8f, 0x34, 0x5b, 0x1b, 0xd3, 0xd2, 0x03, - 0x8b, 0x83, 0x70, 0x14, 0x4f, 0x2c, 0x6c, 0x22, 0x92, 0x67, 0xf1, 0xcd, 0xd6, 0x07, 0xb7, 0x5b, - 0x1f, 0xfc, 0xd8, 0xfa, 0xe0, 0xf3, 0xce, 0x77, 0x6e, 0x77, 0xbe, 0xf3, 0x6d, 0xe7, 0x3b, 0xef, - 0x57, 0x39, 0x53, 0x45, 0x93, 0x22, 0x22, 0x2a, 0x4c, 0x84, 0xac, 0x84, 0xc4, 0x2c, 0x25, 0xa7, - 0xb9, 0xc0, 0xed, 0x0a, 0x57, 0x22, 0x6b, 0x4a, 0x2a, 0xcd, 0x4d, 0x3f, 0x89, 0x4e, 0xed, 0x59, - 0xab, 0xcd, 0x15, 0x95, 0xe9, 0x50, 0x3f, 0xd0, 0xd3, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x17, - 0x37, 0x3f, 0x66, 0xf6, 0x02, 0x00, 0x00, + // 582 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xc1, 0x8a, 0xd3, 0x40, + 0x18, 0x4e, 0xda, 0x5a, 0xb6, 0x53, 0x69, 0x35, 0x74, 0x21, 0xdb, 0x95, 0xa4, 0x04, 0xc1, 0x1e, + 0x6c, 0x62, 0xeb, 0xc1, 0x52, 0xf0, 0x60, 0x7b, 0xd9, 0xbd, 0xc8, 0x1a, 0x11, 0x41, 0x90, 0x92, + 0x4c, 0x66, 0xd3, 0x91, 0x24, 0x53, 0x32, 0x93, 0x48, 0xdf, 0xc0, 0xa3, 0xe2, 0xc5, 0xe3, 0x3e, + 0x84, 0x0f, 0xb1, 0x78, 0xda, 0xa3, 0xa7, 0x22, 0xed, 0x1b, 0xec, 0x13, 0x48, 0x66, 0xa6, 0x76, + 0x6b, 0x55, 0xbc, 0xfd, 0xf3, 0xcd, 0x97, 0xef, 0xff, 0xfe, 0x6f, 0x32, 0x03, 0x4c, 0xec, 0x43, + 0x07, 0x92, 0x14, 0x39, 0x30, 0xc2, 0x28, 0x61, 0x4e, 0xde, 0x97, 0x95, 0x3d, 0x4f, 0x09, 0x23, + 0x9a, 0x86, 0x7d, 0x68, 0x17, 0x04, 0x5b, 0xc2, 0x79, 0xbf, 0x7d, 0x04, 0x09, 0x8d, 0x09, 0x9d, + 0x72, 0x86, 0x23, 0x16, 0x82, 0xde, 0x6e, 0x85, 0x24, 0x24, 0x02, 0x2f, 0x2a, 0x89, 0x1e, 0x85, + 0x84, 0x84, 0x11, 0x72, 0xf8, 0xca, 0xcf, 0xce, 0x1d, 0x2f, 0x59, 0x88, 0x2d, 0x2b, 0x06, 0x87, + 0xa7, 0x01, 0x4a, 0x18, 0x3e, 0xc7, 0x28, 0x98, 0xf0, 0x16, 0x2f, 0x99, 0xc7, 0x90, 0x76, 0x0c, + 0x6a, 0xa2, 0xe3, 0x14, 0x07, 0xba, 0xda, 0x51, 0xbb, 0x35, 0xf7, 0x40, 0x00, 0xa7, 0x81, 0xf6, + 0x04, 0xdc, 0x96, 0x9b, 0xb4, 0x20, 0xeb, 0xa5, 0x8e, 0xda, 0xad, 0x0f, 0x5a, 0xb6, 0xe8, 0x63, + 0x6f, 0xfa, 0xd8, 0xcf, 0x92, 0x85, 0x5b, 0x87, 0x5b, 0x55, 0xeb, 0xb3, 0x0a, 0xf4, 0x09, 0x49, + 0x28, 0x4a, 0x68, 0x46, 0x39, 0xf4, 0x1a, 0xb3, 0xd9, 0x09, 0xc2, 0xe1, 0x8c, 0x69, 0x43, 0x50, + 0x9d, 0xf1, 0x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0xf9, 0xef, 0x10, 0x64, 0xd3, 0x6d, 0xda, + 0xe5, 0x82, 0x37, 0xbe, 0x77, 0xbd, 0x34, 0xf5, 0x85, 0x17, 0x47, 0x23, 0x6b, 0x8f, 0x62, 0xb9, + 0x4d, 0x89, 0x4d, 0x36, 0x47, 0xf2, 0x02, 0xb4, 0x68, 0xe6, 0x53, 0x86, 0x59, 0xc6, 0xd0, 0x0d, + 0xb1, 0x0a, 0x17, 0x33, 0xaf, 0x97, 0xe6, 0xf1, 0x2f, 0xb1, 0x3d, 0x96, 0xe5, 0x6a, 0x5b, 0x78, + 0x23, 0x39, 0xba, 0x5f, 0x44, 0xf5, 0xed, 0x6b, 0xaf, 0x2d, 0x2f, 0x5a, 0x48, 0x72, 0x3b, 0xef, + 0xfb, 0x88, 0x79, 0xfc, 0x48, 0x19, 0x4a, 0x98, 0xae, 0x8e, 0xdd, 0xcb, 0x95, 0xa1, 0x5e, 0xad, + 0x0c, 0xf5, 0xc7, 0xca, 0x50, 0x3f, 0xae, 0x0d, 0xe5, 0x6a, 0x6d, 0x28, 0xdf, 0xd7, 0x86, 0xf2, + 0x66, 0x18, 0x62, 0x36, 0xcb, 0x7c, 0x1b, 0x92, 0x58, 0xde, 0x55, 0x07, 0xfb, 0xb0, 0x17, 0x12, + 0x27, 0x1f, 0x3a, 0x31, 0x09, 0xb2, 0x08, 0x51, 0xf1, 0x04, 0x3c, 0x1a, 0xf4, 0xe4, 0x2b, 0xc0, + 0x16, 0x73, 0x44, 0xfd, 0x2a, 0xff, 0x69, 0x1f, 0xff, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x59, 0x14, + 0xcb, 0xe1, 0x25, 0x04, 0x00, 0x00, } func (m *IdentifiedClientState) Marshal() (dAtA []byte, err error) { @@ -527,6 +591,57 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ClientUpdateProposal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ClientUpdateProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ClientUpdateProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SubstituteClientId) > 0 { + i -= len(m.SubstituteClientId) + copy(dAtA[i:], m.SubstituteClientId) + i = encodeVarintClient(dAtA, i, uint64(len(m.SubstituteClientId))) + i-- + dAtA[i] = 0x22 + } + if len(m.SubjectClientId) > 0 { + i -= len(m.SubjectClientId) + copy(dAtA[i:], m.SubjectClientId) + i = encodeVarintClient(dAtA, i, uint64(len(m.SubjectClientId))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintClient(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintClient(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintClient(dAtA []byte, offset int, v uint64) int { offset -= sovClient(v) base := offset @@ -619,6 +734,31 @@ func (m *Params) Size() (n int) { return n } +func (m *ClientUpdateProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovClient(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovClient(uint64(l)) + } + l = len(m.SubjectClientId) + if l > 0 { + n += 1 + l + sovClient(uint64(l)) + } + l = len(m.SubstituteClientId) + if l > 0 { + n += 1 + l + sovClient(uint64(l)) + } + return n +} + func sovClient(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1148,6 +1288,184 @@ func (m *Params) Unmarshal(dAtA []byte) error { } return nil } +func (m *ClientUpdateProposal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClient + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ClientUpdateProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ClientUpdateProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClient + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthClient + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthClient + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClient + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthClient + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthClient + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubjectClientId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClient + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthClient + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthClient + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SubjectClientId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubstituteClientId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClient + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthClient + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthClient + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SubstituteClientId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipClient(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthClient + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipClient(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/modules/core/02-client/types/legacy_proposal.go b/modules/core/02-client/types/legacy_proposal.go new file mode 100644 index 00000000000..f86724e55ca --- /dev/null +++ b/modules/core/02-client/types/legacy_proposal.go @@ -0,0 +1,62 @@ +// Deprecated: The legacy v1beta1 gov types maintained in this file are deprecated and will be removed in a future release. +// Please use MsgIBCSoftwareUpgrade and MsgRecoverClient in favour of the legacy v1beta1 gov proposal types. +package types + +import ( + errorsmod "cosmossdk.io/errors" + + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" +) + +const ( + // ProposalTypeClientUpdate defines the type for a ClientUpdateProposal + ProposalTypeClientUpdate = "ClientUpdate" +) + +var _ govtypes.Content = &ClientUpdateProposal{} + +func init() { + govtypes.RegisterProposalType(ProposalTypeClientUpdate) +} + +// NewClientUpdateProposal creates a new client update proposal. +func NewClientUpdateProposal(title, description, subjectClientID, substituteClientID string) govtypes.Content { + return &ClientUpdateProposal{ + Title: title, + Description: description, + SubjectClientId: subjectClientID, + SubstituteClientId: substituteClientID, + } +} + +// GetTitle returns the title of a client update proposal. +func (cup *ClientUpdateProposal) GetTitle() string { return cup.Title } + +// GetDescription returns the description of a client update proposal. +func (cup *ClientUpdateProposal) GetDescription() string { return cup.Description } + +// ProposalRoute returns the routing key of a client update proposal. +func (*ClientUpdateProposal) ProposalRoute() string { return RouterKey } + +// ProposalType returns the type of a client update proposal. +func (*ClientUpdateProposal) ProposalType() string { return ProposalTypeClientUpdate } + +// ValidateBasic runs basic stateless validity checks +func (cup *ClientUpdateProposal) ValidateBasic() error { + err := govtypes.ValidateAbstract(cup) + if err != nil { + return err + } + + if cup.SubjectClientId == cup.SubstituteClientId { + return errorsmod.Wrap(ErrInvalidSubstitute, "subject and substitute client identifiers are equal") + } + if _, _, err := ParseClientIdentifier(cup.SubjectClientId); err != nil { + return err + } + if _, _, err := ParseClientIdentifier(cup.SubstituteClientId); err != nil { + return err + } + + return nil +} diff --git a/modules/core/02-client/types/legacy_proposal_test.go b/modules/core/02-client/types/legacy_proposal_test.go new file mode 100644 index 00000000000..1fab3ac9e31 --- /dev/null +++ b/modules/core/02-client/types/legacy_proposal_test.go @@ -0,0 +1,85 @@ +package types_test + +import ( + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + + "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" +) + +func (suite *TypesTestSuite) TestValidateBasic() { + subjectPath := ibctesting.NewPath(suite.chainA, suite.chainB) + suite.coordinator.SetupClients(subjectPath) + subject := subjectPath.EndpointA.ClientID + + substitutePath := ibctesting.NewPath(suite.chainA, suite.chainB) + suite.coordinator.SetupClients(substitutePath) + substitute := substitutePath.EndpointA.ClientID + + testCases := []struct { + name string + proposal govtypes.Content + expPass bool + }{ + { + "success", + types.NewClientUpdateProposal(ibctesting.Title, ibctesting.Description, subject, substitute), + true, + }, + { + "fails validate abstract - empty title", + types.NewClientUpdateProposal("", ibctesting.Description, subject, substitute), + false, + }, + { + "subject and substitute use the same identifier", + types.NewClientUpdateProposal(ibctesting.Title, ibctesting.Description, subject, subject), + false, + }, + { + "invalid subject clientID", + types.NewClientUpdateProposal(ibctesting.Title, ibctesting.Description, ibctesting.InvalidID, substitute), + false, + }, + { + "invalid substitute clientID", + types.NewClientUpdateProposal(ibctesting.Title, ibctesting.Description, subject, ibctesting.InvalidID), + false, + }, + } + + for _, tc := range testCases { + + err := tc.proposal.ValidateBasic() + + if tc.expPass { + suite.Require().NoError(err, tc.name) + } else { + suite.Require().Error(err, tc.name) + } + } +} + +// tests a client update proposal can be marshaled and unmarshaled +func (suite *TypesTestSuite) TestMarshalClientUpdateProposalProposal() { + // create proposal + proposal := types.NewClientUpdateProposal("update IBC client", "description", "subject", "substitute") + + // create codec + ir := codectypes.NewInterfaceRegistry() + types.RegisterInterfaces(ir) + govtypes.RegisterInterfaces(ir) + cdc := codec.NewProtoCodec(ir) + + // marshal message + content := proposal.(*types.ClientUpdateProposal) + bz, err := cdc.MarshalJSON(content) + suite.Require().NoError(err) + + // unmarshal proposal + newProposal := &types.ClientUpdateProposal{} + err = cdc.UnmarshalJSON(bz, newProposal) + suite.Require().NoError(err) +} diff --git a/modules/core/02-client/types/tx.pb.go b/modules/core/02-client/types/tx.pb.go index 4ddcfb55201..5761368d65f 100644 --- a/modules/core/02-client/types/tx.pb.go +++ b/modules/core/02-client/types/tx.pb.go @@ -459,7 +459,7 @@ type MsgIBCSoftwareUpgrade struct { // deprecated in the Cosmos SDK to allow for this logic to exist solely in // the 02-client module. UpgradedClientState *types.Any `protobuf:"bytes,2,opt,name=upgraded_client_state,json=upgradedClientState,proto3" json:"upgraded_client_state,omitempty"` - // signer defaults to the governance account address unless otherwise specified. + // signer address Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` } diff --git a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto index f1830ec787c..1287cfa2d37 100644 --- a/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto +++ b/proto/ibc/applications/interchain_accounts/controller/v1/tx.proto @@ -67,7 +67,7 @@ message MsgUpdateParams { option (gogoproto.goproto_getters) = false; - // signer address + // signer address string signer = 1; // params defines the 27-interchain-accounts/controller parameters to update. diff --git a/proto/ibc/applications/interchain_accounts/host/v1/tx.proto b/proto/ibc/applications/interchain_accounts/host/v1/tx.proto index 01f327292e9..5a8073bc931 100644 --- a/proto/ibc/applications/interchain_accounts/host/v1/tx.proto +++ b/proto/ibc/applications/interchain_accounts/host/v1/tx.proto @@ -22,7 +22,7 @@ message MsgUpdateParams { option (gogoproto.goproto_getters) = false; - // signer address + // signer address string signer = 1; // params defines the 27-interchain-accounts/host parameters to update. diff --git a/proto/ibc/applications/transfer/v1/tx.proto b/proto/ibc/applications/transfer/v1/tx.proto index 144b95898c5..477865f177b 100644 --- a/proto/ibc/applications/transfer/v1/tx.proto +++ b/proto/ibc/applications/transfer/v1/tx.proto @@ -65,7 +65,7 @@ message MsgUpdateParams { option (gogoproto.goproto_getters) = false; - // signer address + // signer address string signer = 1; // params defines the transfer parameters to update. diff --git a/proto/ibc/core/client/v1/client.proto b/proto/ibc/core/client/v1/client.proto index 5da8f86a3a2..27ab04c43bf 100644 --- a/proto/ibc/core/client/v1/client.proto +++ b/proto/ibc/core/client/v1/client.proto @@ -4,6 +4,7 @@ package ibc.core.client.v1; option go_package = "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"; +import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; @@ -61,3 +62,26 @@ message Params { // of this client will be disabled until it is added again to the list. repeated string allowed_clients = 1; } + +// ClientUpdateProposal is a legacy governance proposal. If it passes, the substitute +// client's latest consensus state is copied over to the subject client. The proposal +// handler may fail if the subject and the substitute do not match in client and +// chain parameters (with exception to latest height, frozen height, and chain-id). +// +// Deprecated: Please use MsgRecoverClient in favour of this message type. +message ClientUpdateProposal { + option deprecated = true; + + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + option (gogoproto.goproto_getters) = false; + + // the title of the update proposal + string title = 1; + // the description of the proposal + string description = 2; + // the client identifier for the client to be updated if the proposal passes + string subject_client_id = 3 [(gogoproto.moretags) = "yaml:\"subject_client_id\""]; + // the substitute client identifier for the client standing in for the subject + // client + string substitute_client_id = 4 [(gogoproto.moretags) = "yaml:\"substitute_client_id\""]; +} diff --git a/proto/ibc/core/client/v1/tx.proto b/proto/ibc/core/client/v1/tx.proto index ee32db9158a..b504ab692a4 100644 --- a/proto/ibc/core/client/v1/tx.proto +++ b/proto/ibc/core/client/v1/tx.proto @@ -129,7 +129,7 @@ message MsgRecoverClient { // client string substitute_client_id = 2; - // signer address + // signer address string signer = 3; } @@ -162,7 +162,7 @@ message MsgUpdateParams { option (gogoproto.goproto_getters) = false; - // signer address + // signer address string signer = 1; // params defines the client parameters to update. diff --git a/proto/ibc/core/connection/v1/tx.proto b/proto/ibc/core/connection/v1/tx.proto index 252153b38b1..3ba8ff45660 100644 --- a/proto/ibc/core/connection/v1/tx.proto +++ b/proto/ibc/core/connection/v1/tx.proto @@ -133,7 +133,7 @@ message MsgUpdateParams { option (gogoproto.goproto_getters) = false; - // signer address + // signer address string signer = 1; // params defines the connection parameters to update. diff --git a/testing/simapp/app.go b/testing/simapp/app.go index d258bc8233f..df0d84e034e 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -121,6 +121,8 @@ import ( ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v8/modules/core" + ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client" + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" @@ -411,7 +413,8 @@ func NewSimApp( // See: https://docs.cosmos.network/main/modules/gov#proposal-messages govRouter := govv1beta1.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). - AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)) + AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). + AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)) govConfig := govtypes.DefaultConfig() /* Example of setting gov params: