Skip to content

Commit

Permalink
provider: rm EquivocationEvidence handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Oct 13, 2023
1 parent 52a1384 commit 44caa0b
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 872 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
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
60 changes: 0 additions & 60 deletions x/ccv/provider/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1094,63 +1094,3 @@ func TestBeginBlockCCR(t *testing.T) {
ctx, invalidProp.ChainId, invalidProp.StopTime)
require.False(t, found)
}

// func TestHandleEquivocationProposal(t *testing.T) {
// equivocations := []*evidencetypes.Equivocation{
// {
// Time: time.Now(),
// Height: 1,
// Power: 1,
// ConsensusAddress: "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk",
// },
// {
// Time: time.Now(),
// Height: 1,
// Power: 1,
// ConsensusAddress: "cosmosvalcons1ezyrq65s3gshhx5585w6mpusq3xsj3ayzf4uv6",
// },
// }

// prop := &providertypes.EquivocationProposal{
// Equivocations: []*evidencetypes.Equivocation{equivocations[0], equivocations[1]},
// }

// testCases := []struct {
// name string
// setSlashLogs bool
// expectEquivsHandled bool
// expectErr bool
// }{
// {name: "slash logs not set", setSlashLogs: false, expectEquivsHandled: false, expectErr: true},
// {name: "slash logs set", setSlashLogs: true, expectEquivsHandled: true, expectErr: false},
// }
// for _, tc := range testCases {

// keeperParams := testkeeper.NewInMemKeeperParams(t)
// keeper, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, keeperParams)

// if tc.setSlashLogs {
// // Set slash logs according to cons addrs in equivocations
// consAddr := equivocations[0].GetConsensusAddress(keeper.ConsensusAddressCodec())
// require.NotNil(t, consAddr, "consensus address could not be parsed")
// keeper.SetSlashLog(ctx, providertypes.NewProviderConsAddress(consAddr))
// consAddr = equivocations[1].GetConsensusAddress(keeper.ConsensusAddressCodec())
// require.NotNil(t, consAddr, "consensus address could not be parsed")
// keeper.SetSlashLog(ctx, providertypes.NewProviderConsAddress(consAddr))
// }

// if tc.expectEquivsHandled {
// mocks.MockEvidenceKeeper.EXPECT().HandleEquivocationEvidence(ctx, equivocations[0])
// mocks.MockEvidenceKeeper.EXPECT().HandleEquivocationEvidence(ctx, equivocations[1])
// }

// err := keeper.HandleEquivocationProposal(ctx, prop)

// if tc.expectErr {
// require.Error(t, err)
// } else {
// require.NoError(t, err)
// }
// ctrl.Finish()
// }
// }
5 changes: 1 addition & 4 deletions x/ccv/provider/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
)

// NewProviderProposalHandler defines the handler for consumer addition,
// consumer removal and equivocation proposals.
// NewProviderProposalHandler defines the handler for consumer addition and removal proposals.
// Passed proposals are executed during EndBlock.
func NewProviderProposalHandler(k keeper.Keeper) govv1beta1.Handler {
return func(ctx sdk.Context, content govv1beta1.Content) error {
Expand All @@ -21,8 +20,6 @@ func NewProviderProposalHandler(k keeper.Keeper) govv1beta1.Handler {
return k.HandleConsumerAdditionProposal(ctx, c)
case *types.ConsumerRemovalProposal:
return k.HandleConsumerRemovalProposal(ctx, c)
case *types.EquivocationProposal:
return k.HandleEquivocationProposal(ctx, c)
case *types.ChangeRewardDenomsProposal:
return k.HandleConsumerRewardDenomProposal(ctx, c)
default:
Expand Down
Loading

0 comments on commit 44caa0b

Please sign in to comment.