|
@ -46,15 +46,20 @@ type DuplicateVoteEvidence struct { |
|
|
var _ Evidence = &DuplicateVoteEvidence{} |
|
|
var _ Evidence = &DuplicateVoteEvidence{} |
|
|
|
|
|
|
|
|
// NewDuplicateVoteEvidence creates DuplicateVoteEvidence with right ordering given
|
|
|
// NewDuplicateVoteEvidence creates DuplicateVoteEvidence with right ordering given
|
|
|
// two conflicting votes. If one of the votes is nil, evidence returned is nil as well
|
|
|
|
|
|
func NewDuplicateVoteEvidence(vote1, vote2 *Vote, blockTime time.Time, valSet *ValidatorSet) *DuplicateVoteEvidence { |
|
|
|
|
|
|
|
|
// two conflicting votes. If either of the votes is nil, the val set is nil or the voter is
|
|
|
|
|
|
// not in the val set, an error is returned
|
|
|
|
|
|
func NewDuplicateVoteEvidence(vote1, vote2 *Vote, blockTime time.Time, valSet *ValidatorSet, |
|
|
|
|
|
) (*DuplicateVoteEvidence, error) { |
|
|
var voteA, voteB *Vote |
|
|
var voteA, voteB *Vote |
|
|
if vote1 == nil || vote2 == nil || valSet == nil { |
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
|
if vote1 == nil || vote2 == nil { |
|
|
|
|
|
return nil, errors.New("missing vote") |
|
|
|
|
|
} |
|
|
|
|
|
if valSet == nil { |
|
|
|
|
|
return nil, errors.New("missing validator set") |
|
|
} |
|
|
} |
|
|
idx, val := valSet.GetByAddress(vote1.ValidatorAddress) |
|
|
idx, val := valSet.GetByAddress(vote1.ValidatorAddress) |
|
|
if idx == -1 { |
|
|
if idx == -1 { |
|
|
return nil |
|
|
|
|
|
|
|
|
return nil, errors.New("validator not in validator set") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if strings.Compare(vote1.BlockID.Key(), vote2.BlockID.Key()) == -1 { |
|
|
if strings.Compare(vote1.BlockID.Key(), vote2.BlockID.Key()) == -1 { |
|
@ -70,7 +75,7 @@ func NewDuplicateVoteEvidence(vote1, vote2 *Vote, blockTime time.Time, valSet *V |
|
|
TotalVotingPower: valSet.TotalVotingPower(), |
|
|
TotalVotingPower: valSet.TotalVotingPower(), |
|
|
ValidatorPower: val.VotingPower, |
|
|
ValidatorPower: val.VotingPower, |
|
|
Timestamp: blockTime, |
|
|
Timestamp: blockTime, |
|
|
} |
|
|
|
|
|
|
|
|
}, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ABCI returns the application relevant representation of the evidence
|
|
|
// ABCI returns the application relevant representation of the evidence
|
|
@ -92,7 +97,7 @@ func (dve *DuplicateVoteEvidence) Bytes() []byte { |
|
|
pbe := dve.ToProto() |
|
|
pbe := dve.ToProto() |
|
|
bz, err := pbe.Marshal() |
|
|
bz, err := pbe.Marshal() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
panic(err) |
|
|
|
|
|
|
|
|
panic("marshaling duplicate vote evidence to bytes: " + err.Error()) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return bz |
|
|
return bz |
|
@ -260,11 +265,11 @@ func (l *LightClientAttackEvidence) ABCI() []abci.Evidence { |
|
|
func (l *LightClientAttackEvidence) Bytes() []byte { |
|
|
func (l *LightClientAttackEvidence) Bytes() []byte { |
|
|
pbe, err := l.ToProto() |
|
|
pbe, err := l.ToProto() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
panic(err) |
|
|
|
|
|
|
|
|
panic("converting light client attack evidence to proto: " + err.Error()) |
|
|
} |
|
|
} |
|
|
bz, err := pbe.Marshal() |
|
|
bz, err := pbe.Marshal() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
panic(err) |
|
|
|
|
|
|
|
|
panic("marshaling light client attack evidence to bytes: " + err.Error()) |
|
|
} |
|
|
} |
|
|
return bz |
|
|
return bz |
|
|
} |
|
|
} |
|
@ -684,7 +689,11 @@ func NewMockDuplicateVoteEvidenceWithValidator(height int64, time time.Time, |
|
|
vB := voteB.ToProto() |
|
|
vB := voteB.ToProto() |
|
|
_ = pv.SignVote(context.Background(), chainID, vB) |
|
|
_ = pv.SignVote(context.Background(), chainID, vB) |
|
|
voteB.Signature = vB.Signature |
|
|
voteB.Signature = vB.Signature |
|
|
return NewDuplicateVoteEvidence(voteA, voteB, time, NewValidatorSet([]*Validator{val})) |
|
|
|
|
|
|
|
|
ev, err := NewDuplicateVoteEvidence(voteA, voteB, time, NewValidatorSet([]*Validator{val})) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic("constructing mock duplicate vote evidence: " + err.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
return ev |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func makeMockVote(height int64, round, index int32, addr Address, |
|
|
func makeMockVote(height int64, round, index int32, addr Address, |
|
|