mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 22:44:24 +00:00
check if we already have evidence
This commit is contained in:
+11
-4
@@ -1338,10 +1338,7 @@ func (cs *ConsensusState) tryAddVote(vote *types.Vote, peerKey string) error {
|
||||
cs.Logger.Error("Found conflicting vote from ourselves. Did you unsafe_reset a validator?", "height", vote.Height, "round", vote.Round, "type", vote.Type)
|
||||
return err
|
||||
}
|
||||
cs.Logger.Error("Found conflicting vote. Recording evidence in the RoundState", "height", vote.Height, "round", vote.Round, "type", vote.Type, "valAddr", vote.ValidatorAddress, "valIndex", vote.ValidatorIndex)
|
||||
|
||||
// TODO: ensure we haven't seen this evidence already !
|
||||
cs.Evidence = append(cs.Evidence, voteErr.DuplicateVoteEvidence)
|
||||
cs.addEvidence(voteErr.DuplicateVoteEvidence)
|
||||
return err
|
||||
} else {
|
||||
// Probably an invalid signature / Bad peer.
|
||||
@@ -1353,6 +1350,16 @@ func (cs *ConsensusState) tryAddVote(vote *types.Vote, peerKey string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cs *ConsensusState) addEvidence(ev types.Evidence) {
|
||||
if cs.Evidence.Has(ev) {
|
||||
return
|
||||
}
|
||||
|
||||
cs.Logger.Error("Found conflicting vote. Recording evidence in the RoundState", "evidence", ev)
|
||||
|
||||
cs.Evidence = append(cs.Evidence, ev)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
func (cs *ConsensusState) addVote(vote *types.Vote, peerKey string) (added bool, err error) {
|
||||
|
||||
@@ -86,7 +86,6 @@ func (b *Block) FillHeader() {
|
||||
// Hash computes and returns the block hash.
|
||||
// If the block is incomplete, block hash is nil for safety.
|
||||
func (b *Block) Hash() data.Bytes {
|
||||
// fmt.Println(">>", b.Data)
|
||||
if b == nil || b.Header == nil || b.Data == nil || b.LastCommit == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ type Evidence interface {
|
||||
Address() []byte
|
||||
Hash() []byte
|
||||
Verify(chainID string) error
|
||||
Equal(Evidence) bool
|
||||
|
||||
String() string
|
||||
}
|
||||
@@ -61,6 +62,15 @@ func (evs Evidences) String() string {
|
||||
return s
|
||||
}
|
||||
|
||||
func (evs Evidences) Has(evidence Evidence) bool {
|
||||
for _, ev := range evs {
|
||||
if ev.Equal(evidence) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
// DuplicateVoteEvidence contains evidence a validator signed two conflicting votes.
|
||||
@@ -120,3 +130,13 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Equal checks if two pieces of evidence are equal.
|
||||
func (dve *DuplicateVoteEvidence) Equal(ev Evidence) bool {
|
||||
if _, ok := ev.(*DuplicateVoteEvidence); !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
// just check their hashes
|
||||
return bytes.Equal(merkle.SimpleHashFromBinary(dve), merkle.SimpleHashFromBinary(ev))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user