Skip to content

Commit

Permalink
provider: rm equivocation evidence handling v50 (#1355)
Browse files Browse the repository at this point in the history
* provider: rm EquivocationEvidence handling

* provider: regenerate mocks without EvidenceKeeper

* provider: fix init module_test.go
  • Loading branch information
MSalopek authored Oct 13, 2023
1 parent 52a1384 commit eed7c10
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 899 deletions.
23 changes: 10 additions & 13 deletions app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ var (
paramsclient.ProposalHandler,
icsproviderclient.ConsumerAdditionProposalHandler,
icsproviderclient.ConsumerRemovalProposalHandler,
icsproviderclient.EquivocationProposalHandler,
icsproviderclient.ChangeRewardDenomsProposalHandler,
},
),
Expand Down Expand Up @@ -433,16 +432,6 @@ func New(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// create evidence keeper with router
app.EvidenceKeeper = *evidencekeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[evidencetypes.StoreKey]),
app.StakingKeeper,
app.SlashingKeeper,
app.AccountKeeper.AddressCodec(),
runtime.ProvideCometInfoService(),
)

app.ProviderKeeper = icsproviderkeeper.NewKeeper(
appCodec,
keys[providertypes.StoreKey],
Expand All @@ -455,7 +444,6 @@ func New(
app.StakingKeeper,
app.SlashingKeeper,
app.AccountKeeper,
app.EvidenceKeeper,
app.DistrKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
Expand All @@ -466,6 +454,16 @@ func New(

providerModule := icsprovider.NewAppModule(&app.ProviderKeeper, app.GetSubspace(providertypes.ModuleName))

// create evidence keeper with router
app.EvidenceKeeper = *evidencekeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[evidencetypes.StoreKey]),
app.StakingKeeper,
app.SlashingKeeper,
app.AccountKeeper.AddressCodec(),
runtime.ProvideCometInfoService(),
)

// register the proposal types
govRouter := govv1beta1.NewRouter()
govRouter.
Expand Down Expand Up @@ -553,7 +551,6 @@ func New(
paramsclient.ProposalHandler,
icsproviderclient.ConsumerAdditionProposalHandler,
icsproviderclient.ConsumerRemovalProposalHandler,
icsproviderclient.EquivocationProposalHandler,
icsproviderclient.ChangeRewardDenomsProposalHandler,
},
),
Expand Down
13 changes: 0 additions & 13 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,6 @@ message ConsumerRemovalProposal {
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
}

// EquivocationProposal is a governance proposal on the provider chain to
// punish a validator for equivocation on a consumer chain.
//
// This type is only used internally to the consumer CCV module.
message EquivocationProposal {
// the title of the proposal
string title = 1;
// the description of the proposal
string description = 2;
// the list of equivocations that will be processed
repeated cosmos.evidence.v1beta1.Equivocation equivocations = 3;
}

// ChangeRewardDenomsProposal is a governance proposal on the provider chain to
// mutate the set of denoms accepted by the provider as rewards.
message ChangeRewardDenomsProposal {
Expand Down
25 changes: 1 addition & 24 deletions testutil/keeper/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ type MockedKeepers struct {
*MockBankKeeper
*MockIBCTransferKeeper
*MockIBCCoreKeeper
*MockEvidenceKeeper
*MockDistributionKeeper
}

Expand All @@ -109,7 +108,6 @@ func NewMockedKeepers(ctrl *gomock.Controller) MockedKeepers {
MockBankKeeper: NewMockBankKeeper(ctrl),
MockIBCTransferKeeper: NewMockIBCTransferKeeper(ctrl),
MockIBCCoreKeeper: NewMockIBCCoreKeeper(ctrl),
MockEvidenceKeeper: NewMockEvidenceKeeper(ctrl),
MockDistributionKeeper: NewMockDistributionKeeper(ctrl),
}
}
Expand All @@ -128,7 +126,6 @@ func NewInMemProviderKeeper(params InMemKeeperParams, mocks MockedKeepers) provi
mocks.MockStakingKeeper,
mocks.MockSlashingKeeper,
mocks.MockAccountKeeper,
mocks.MockEvidenceKeeper,
mocks.MockDistributionKeeper,
mocks.MockBankKeeper,
authtypes.FeeCollectorName,
Expand Down
67 changes: 0 additions & 67 deletions x/ccv/provider/client/proposal_handler.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package client

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -19,7 +17,6 @@ import (
var (
ConsumerAdditionProposalHandler = govclient.NewProposalHandler(SubmitConsumerAdditionPropTxCmd)
ConsumerRemovalProposalHandler = govclient.NewProposalHandler(SubmitConsumerRemovalProposalTxCmd)
EquivocationProposalHandler = govclient.NewProposalHandler(SubmitEquivocationProposalTxCmd)
ChangeRewardDenomsProposalHandler = govclient.NewProposalHandler(SubmitChangeRewardDenomsProposalTxCmd)
)

Expand Down Expand Up @@ -162,70 +159,6 @@ Where proposal.json contains:
}
}

// SubmitEquivocationProposalTxCmd returns a CLI command handler for submitting
// a equivocation proposal via a transaction.
func SubmitEquivocationProposalTxCmd() *cobra.Command {
return &cobra.Command{
Use: "equivocation [proposal-file]",
Args: cobra.ExactArgs(1),
Short: "Submit an equivocation proposal",
Long: fmt.Sprintf(`Submit an equivocation proposal along with an initial deposit.
The proposal details must be supplied via a JSON file.
Example:
$ <appd> tx gov submit-legacy-proposal equivocation <path/to/proposal.json> --from=<key_or_address>
Where proposal.json contains:
{
"title": "Equivoque Foo validator",
"summary": "He double-signs on the Foobar consumer chain",
"equivocations": [
{
"height": 10420042,
"time": "2023-01-27T15:59:50.121607-08:00",
"power": 10,
"consensus_address": "%s1s5afhd6gxevu37mkqcvvsj8qeylhn0rz46zdlq"
}
],
"deposit": "10000stake"
}
`, sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

proposal, err := ParseEquivocationProposalJSON(args[0])
if err != nil {
return err
}

content := types.NewEquivocationProposal(proposal.Title, proposal.Summary, proposal.Equivocations)

from := clientCtx.GetFromAddress()

msgContent, err := govv1.NewLegacyContent(content, authtypes.NewModuleAddress(govtypes.ModuleName).String())
if err != nil {
return err
}

deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}

// @MSalopek: added "expedited" flag to the proposal
msg, err := govv1.NewMsgSubmitProposal([]sdk.Msg{msgContent}, deposit, from.String(), "", content.GetTitle(), proposal.Summary, false)
if err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}

// SubmitChangeRewardDenomsProposalTxCmd returns a CLI command handler for submitting
// a change reward denoms proposal via a transaction.
func SubmitChangeRewardDenomsProposalTxCmd() *cobra.Command {
Expand Down
32 changes: 0 additions & 32 deletions x/ccv/provider/client/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,38 +108,6 @@ func ParseConsumerRemovalProposalJSON(proposalFile string) (ConsumerRemovalPropo
return proposal, nil
}

type EquivocationProposalJSON struct {
// evidencetypes "cosmossdk.io/x/evidence/types"
Summary string `json:"summary"`
types.EquivocationProposal

Deposit string `json:"deposit"`
}

type EquivocationProposalReq struct {
Proposer sdk.AccAddress `json:"proposer"`

// evidencetypes "cosmossdk.io/x/evidence/types"
types.EquivocationProposal

Deposit sdk.Coins `json:"deposit"`
}

func ParseEquivocationProposalJSON(proposalFile string) (EquivocationProposalJSON, error) {
proposal := EquivocationProposalJSON{}

contents, err := os.ReadFile(filepath.Clean(proposalFile))
if err != nil {
return proposal, err
}

if err := json.Unmarshal(contents, &proposal); err != nil {
return proposal, err
}

return proposal, nil
}

type ChangeRewardDenomsProposalJSON struct {
Summary string `json:"summary"`
types.ChangeRewardDenomsProposal
Expand Down
23 changes: 10 additions & 13 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type Keeper struct {
clientKeeper ccv.ClientKeeper
stakingKeeper ccv.StakingKeeper
slashingKeeper ccv.SlashingKeeper
evidenceKeeper ccv.EvidenceKeeper
distributionKeeper ccv.DistributionKeeper
bankKeeper ccv.BankKeeper
feeCollectorName string
Expand All @@ -66,7 +65,7 @@ func NewKeeper(
channelKeeper ccv.ChannelKeeper, portKeeper ccv.PortKeeper,
connectionKeeper ccv.ConnectionKeeper, clientKeeper ccv.ClientKeeper,
stakingKeeper ccv.StakingKeeper, slashingKeeper ccv.SlashingKeeper,
accountKeeper ccv.AccountKeeper, evidenceKeeper ccv.EvidenceKeeper,
accountKeeper ccv.AccountKeeper,
distributionKeeper ccv.DistributionKeeper, bankKeeper ccv.BankKeeper,
feeCollectorName, authority string, validatorAddressCodec,
consensusAddressCodec addresscodec.Codec,
Expand All @@ -89,7 +88,6 @@ func NewKeeper(
stakingKeeper: stakingKeeper,
slashingKeeper: slashingKeeper,
accountKeeper: accountKeeper,
evidenceKeeper: evidenceKeeper,
distributionKeeper: distributionKeeper,
bankKeeper: bankKeeper,
feeCollectorName: feeCollectorName,
Expand Down Expand Up @@ -127,8 +125,8 @@ func (k *Keeper) SetParamSpace(ctx sdk.Context, ps paramtypes.Subspace) {
// non-nil values for all its fields. Otherwise this method will panic.
func (k Keeper) mustValidateFields() {
// Ensures no fields are missed in this validation
if reflect.ValueOf(k).NumField() != 19 {
panic("number of fields in provider keeper is not 19")
if reflect.ValueOf(k).NumField() != 18 {
panic("number of fields in provider keeper is not 18")
}

// TODO: @MSalopek -> validate once connected and AccountKeeper interface is updated
Expand All @@ -152,15 +150,14 @@ func (k Keeper) mustValidateFields() {
ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 9
ccv.PanicIfZeroOrNil(k.stakingKeeper, "stakingKeeper") // 10
ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 11
ccv.PanicIfZeroOrNil(k.evidenceKeeper, "evidenceKeeper") // 12
ccv.PanicIfZeroOrNil(k.distributionKeeper, "distributionKeeper") // 13
ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 14
ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 15
ccv.PanicIfZeroOrNil(k.authority, "authority") // 16
ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 17
ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 18
ccv.PanicIfZeroOrNil(k.distributionKeeper, "distributionKeeper") // 12
ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 13
ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 14
ccv.PanicIfZeroOrNil(k.authority, "authority") // 15
ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 16
ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 17
// TODO: @MSalopek -> validate once connected
// ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 19
// ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 18
}

// Logger returns a module-specific logger.
Expand Down
14 changes: 0 additions & 14 deletions x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,20 +611,6 @@ func (k Keeper) StopConsumerChainInCachedCtx(ctx sdk.Context, p types.ConsumerRe
return
}

// TODO: @MSalopek using consensus addr keeper is probably wrong
// HandleEquivocationProposal handles an equivocation proposal.
// Proposal will be accepted if a record in the SlashLog exists for a given validator address.
func (k Keeper) HandleEquivocationProposal(ctx sdk.Context, p *types.EquivocationProposal) error {
for _, ev := range p.Equivocations {
if !k.GetSlashLog(ctx, types.NewProviderConsAddress(ev.GetConsensusAddress(k.ConsensusAddressCodec()))) {
return fmt.Errorf("no equivocation record found for validator %s", ev.GetConsensusAddress(k.ConsensusAddressCodec()).String())
}
// NOTE: REFACTOR OR REMOVE @MSalopek this is deprecated, or otherwise not aviailable in v50
// k.evidenceKeeper.HandleEquivocationEvidence(ctx, ev)
}
return nil
}

func (k Keeper) HandleConsumerRewardDenomProposal(ctx sdk.Context, p *types.ChangeRewardDenomsProposal) error {
for _, denomToAdd := range p.DenomsToAdd {
// Log error and move on if one of the denoms is already registered
Expand Down
Loading

0 comments on commit eed7c10

Please sign in to comment.