From ef574456384bd1e149f59bbab7a3ac9519b4056b Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Mon, 6 Nov 2023 09:13:18 +0100 Subject: [PATCH] add codec and content for equivo proposal msg --- .../ccv/provider/v1/provider.proto | 2 +- x/ccv/provider/types/codec.go | 11 ++--- x/ccv/provider/types/proposal.go | 40 ++++++++++++++++++- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/proto/interchain_security/ccv/provider/v1/provider.proto b/proto/interchain_security/ccv/provider/v1/provider.proto index 0fcec166f3..0ea0106d83 100644 --- a/proto/interchain_security/ccv/provider/v1/provider.proto +++ b/proto/interchain_security/ccv/provider/v1/provider.proto @@ -96,7 +96,7 @@ message EquivocationProposal { option deprecated = true; // the title of the proposal string title = 1; - // the description of the proposal +// the description of the proposal string description = 2; // the list of equivocations that will be processed repeated cosmos.evidence.v1beta1.Equivocation equivocations = 3; diff --git a/x/ccv/provider/types/codec.go b/x/ccv/provider/types/codec.go index 53654d129d..5d2c51b62e 100644 --- a/x/ccv/provider/types/codec.go +++ b/x/ccv/provider/types/codec.go @@ -27,25 +27,22 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { (*sdk.Msg)(nil), &MsgAssignConsumerKey{}, ) + registry.RegisterImplementations( + (*govtypes.Content)(nil), + &EquivocationProposal{}, + ) registry.RegisterImplementations( (*govtypes.Content)(nil), &ChangeRewardDenomsProposal{}, ) - registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgSubmitConsumerMisbehaviour{}, ) - registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgSubmitConsumerDoubleVoting{}, ) - registry.RegisterImplementations( - (*govtypes.Content)(nil), - &ChangeRewardDenomsProposal{}, - ) - msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/ccv/provider/types/proposal.go b/x/ccv/provider/types/proposal.go index d77be8591e..e318671f82 100644 --- a/x/ccv/provider/types/proposal.go +++ b/x/ccv/provider/types/proposal.go @@ -1,13 +1,14 @@ package types import ( + "errors" "fmt" "strings" time "time" errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types" ccvtypes "github.com/cosmos/interchain-security/v2/x/ccv/types" @@ -16,18 +17,21 @@ import ( const ( ProposalTypeConsumerAddition = "ConsumerAddition" ProposalTypeConsumerRemoval = "ConsumerRemoval" + ProposalTypeEquivocation = "Equivocation" ProposalTypeChangeRewardDenoms = "ChangeRewardDenoms" ) var ( _ govtypes.Content = &ConsumerAdditionProposal{} _ govtypes.Content = &ConsumerRemovalProposal{} + _ govtypes.Content = &EquivocationProposal{} _ govtypes.Content = &ChangeRewardDenomsProposal{} ) func init() { govtypes.RegisterProposalType(ProposalTypeConsumerAddition) govtypes.RegisterProposalType(ProposalTypeConsumerRemoval) + govtypes.RegisterProposalType(ProposalTypeEquivocation) govtypes.RegisterProposalType(ProposalTypeChangeRewardDenoms) } @@ -196,6 +200,40 @@ func (sccp *ConsumerRemovalProposal) ValidateBasic() error { return nil } +// NewEquivocationProposal creates a new equivocation proposal. +// [DEPRECATED]: do not use +func NewEquivocationProposal(title, description string, equivocations []*evidencetypes.Equivocation) govtypes.Content { + return &EquivocationProposal{ + Title: title, + Description: description, + Equivocations: equivocations, + } +} + +// ProposalRoute returns the routing key of an equivocation proposal. +func (sp *EquivocationProposal) ProposalRoute() string { return RouterKey } + +// ProposalType returns the type of a equivocation proposal. +func (sp *EquivocationProposal) ProposalType() string { + return ProposalTypeEquivocation +} + +// ValidateBasic runs basic stateless validity checks +func (sp *EquivocationProposal) ValidateBasic() error { + if err := govtypes.ValidateAbstract(sp); err != nil { + return err + } + if len(sp.Equivocations) == 0 { + return errors.New("invalid equivocation proposal: empty equivocations") + } + for i := 0; i < len(sp.Equivocations); i++ { + if err := sp.Equivocations[i].ValidateBasic(); err != nil { + return err + } + } + return nil +} + func NewChangeRewardDenomsProposal(title, description string, denomsToAdd, denomsToRemove []string, ) govtypes.Content {