Skip to content

Commit

Permalink
Port: (feat!) [#1435](#1435) Add height-base filter for consumer equi…
Browse files Browse the repository at this point in the history
…vocation evidence.
  • Loading branch information
sainoe committed Nov 21, 2023
1 parent d61f474 commit 1895f87
Show file tree
Hide file tree
Showing 10 changed files with 880 additions and 773 deletions.
49 changes: 47 additions & 2 deletions tests/integration/double_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
blockID1 := testutil.MakeBlockID([]byte("blockhash"), 1000, []byte("partshash"))
blockID2 := testutil.MakeBlockID([]byte("blockhash2"), 1000, []byte("partshash"))

// Set the equivocation evidence min height to the previous block height
equivocationEvidenceMinHeight := uint64(s.consumerCtx().BlockHeight() - 1)
s.providerApp.GetProviderKeeper().SetEquivocationEvidenceMinHeight(
s.providerCtx(),
s.consumerChain.ChainID,
equivocationEvidenceMinHeight,
)

// Note that votes are signed along with the chain ID
// see VoteSignBytes in https://github.com/cometbft/cometbft/blob/v0.37.2/types/vote.go#L93

Expand Down Expand Up @@ -78,6 +86,17 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
s.consumerChain.ChainID,
)

// create a vote using the consumer validator key
// with block height that is smaller than the equivocation evidence min height
consuVoteOld := testutil.MakeAndSignVote(
blockID1,
int64(equivocationEvidenceMinHeight-1),
s.consumerCtx().BlockTime(),
consuValSet,
consuSigner,
s.consumerChain.ChainID,
)

testCases := []struct {
name string
ev *tmtypes.DuplicateVoteEvidence
Expand All @@ -86,7 +105,7 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
expPass bool
}{
{
"invalid consumer chain id - shouldn't pass",
"cannot find consumer chain for the given chain ID - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
VoteA: consuVote,
VoteB: consuBadVote,
Expand All @@ -98,6 +117,32 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
consuVal.PubKey,
false,
},
{
"evidence is older than equivocation evidence min height - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
VoteA: consuVoteOld,
VoteB: consuBadVote,
ValidatorPower: consuVal.VotingPower,
TotalVotingPower: consuVal.VotingPower,
Timestamp: s.consumerCtx().BlockTime(),
},
s.consumerChain.ChainID,
consuVal.PubKey,
false,
},
{
"the votes in the evidence are for different height - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
VoteA: consuVote,
VoteB: consuVoteOld,
ValidatorPower: consuVal.VotingPower,
TotalVotingPower: consuVal.VotingPower,
Timestamp: s.consumerCtx().BlockTime(),
},
s.consumerChain.ChainID,
consuVal.PubKey,
false,
},
{
"wrong public key - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
Expand Down Expand Up @@ -343,7 +388,7 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVotingSlashesUndelegationsAndRele
currentBalance := sdk.NewDecFromInt(unb.Balance)
s.Require().True(initialBalance.Sub(initialBalance.Mul(slashFraction)).Equal(currentBalance))
}
// check that redelegations are slashed
// check that redelegations are slashed
delegations := s.providerApp.GetTestStakingKeeper().Delegation(s.providerCtx(), delAddr, validator2.GetOperator())
s.Require().Equal(delegations.GetShares(), delShares.Add(redelShares).Sub(redelShares.Mul(slashFraction)))
})
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ func (s *CCVTestSuite) TestCheckMisbehaviour() {
altSigners2,
)

// Set the equivocation evidence min height to the previous block height
equivocationEvidenceMinHeight := clientHeight.RevisionHeight + 1
s.providerApp.GetProviderKeeper().SetEquivocationEvidenceMinHeight(
s.providerCtx(),
s.consumerChain.ChainID,
equivocationEvidenceMinHeight,
)

testCases := []struct {
name string
misbehaviour *ibctmtypes.Misbehaviour
Expand Down Expand Up @@ -487,6 +495,24 @@ func (s *CCVTestSuite) TestCheckMisbehaviour() {
},
false,
},
{
"invalid misbehaviour older than the min equivocation evidence height - shouldn't pass",
&ibctmtypes.Misbehaviour{
ClientId: s.path.EndpointA.ClientID,
Header1: s.consumerChain.CreateTMClientHeader(
s.consumerChain.ChainID,
int64(equivocationEvidenceMinHeight-1),
clientHeight,
headerTs,
altValset,
altValset,
clientTMValset,
altSigners,
),
Header2: clientHeader,
},
false,
},
{
"one header of the misbehaviour has insufficient voting power - shouldn't pass",
&ibctmtypes.Misbehaviour{
Expand Down
Loading

0 comments on commit 1895f87

Please sign in to comment.