Skip to content

Commit

Permalink
add codec and content for equivo proposal msg
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Nov 6, 2023
1 parent 03471e1 commit ef57445
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions x/ccv/provider/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
40 changes: 39 additions & 1 deletion x/ccv/provider/types/proposal.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ef57445

Please sign in to comment.