|
@ -122,7 +122,11 @@ func (voteSet *VoteSet) Size() int { |
|
|
// Duplicate votes return added=false, err=nil.
|
|
|
// Duplicate votes return added=false, err=nil.
|
|
|
// Conflicting votes return added=*, err=ErrVoteConflictingVotes.
|
|
|
// Conflicting votes return added=*, err=ErrVoteConflictingVotes.
|
|
|
// NOTE: vote should not be mutated after adding.
|
|
|
// NOTE: vote should not be mutated after adding.
|
|
|
|
|
|
// NOTE: VoteSet must not be nil
|
|
|
func (voteSet *VoteSet) AddVote(vote *Vote) (added bool, err error) { |
|
|
func (voteSet *VoteSet) AddVote(vote *Vote) (added bool, err error) { |
|
|
|
|
|
if voteSet == nil { |
|
|
|
|
|
PanicSanity("AddVote() on nil VoteSet") |
|
|
|
|
|
} |
|
|
voteSet.mtx.Lock() |
|
|
voteSet.mtx.Lock() |
|
|
defer voteSet.mtx.Unlock() |
|
|
defer voteSet.mtx.Unlock() |
|
|
|
|
|
|
|
@ -276,7 +280,11 @@ func (voteSet *VoteSet) addVerifiedVote(vote *Vote, blockKey string, votingPower |
|
|
// NOTE: if there are too many peers, or too much peer churn,
|
|
|
// NOTE: if there are too many peers, or too much peer churn,
|
|
|
// this can cause memory issues.
|
|
|
// this can cause memory issues.
|
|
|
// TODO: implement ability to remove peers too
|
|
|
// TODO: implement ability to remove peers too
|
|
|
|
|
|
// NOTE: VoteSet must not be nil
|
|
|
func (voteSet *VoteSet) SetPeerMaj23(peerID string, blockID BlockID) { |
|
|
func (voteSet *VoteSet) SetPeerMaj23(peerID string, blockID BlockID) { |
|
|
|
|
|
if voteSet == nil { |
|
|
|
|
|
PanicSanity("SetPeerMaj23() on nil VoteSet") |
|
|
|
|
|
} |
|
|
voteSet.mtx.Lock() |
|
|
voteSet.mtx.Lock() |
|
|
defer voteSet.mtx.Unlock() |
|
|
defer voteSet.mtx.Unlock() |
|
|
|
|
|
|
|
@ -332,12 +340,18 @@ func (voteSet *VoteSet) BitArrayByBlockID(blockID BlockID) *BitArray { |
|
|
|
|
|
|
|
|
// NOTE: if validator has conflicting votes, returns "canonical" vote
|
|
|
// NOTE: if validator has conflicting votes, returns "canonical" vote
|
|
|
func (voteSet *VoteSet) GetByIndex(valIndex int) *Vote { |
|
|
func (voteSet *VoteSet) GetByIndex(valIndex int) *Vote { |
|
|
|
|
|
if voteSet == nil { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
voteSet.mtx.Lock() |
|
|
voteSet.mtx.Lock() |
|
|
defer voteSet.mtx.Unlock() |
|
|
defer voteSet.mtx.Unlock() |
|
|
return voteSet.votes[valIndex] |
|
|
return voteSet.votes[valIndex] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (voteSet *VoteSet) GetByAddress(address []byte) *Vote { |
|
|
func (voteSet *VoteSet) GetByAddress(address []byte) *Vote { |
|
|
|
|
|
if voteSet == nil { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
voteSet.mtx.Lock() |
|
|
voteSet.mtx.Lock() |
|
|
defer voteSet.mtx.Unlock() |
|
|
defer voteSet.mtx.Unlock() |
|
|
valIndex, val := voteSet.valSet.GetByAddress(address) |
|
|
valIndex, val := voteSet.valSet.GetByAddress(address) |
|
@ -384,6 +398,9 @@ func (voteSet *VoteSet) HasAll() bool { |
|
|
// Returns either a blockhash (or nil) that received +2/3 majority.
|
|
|
// Returns either a blockhash (or nil) that received +2/3 majority.
|
|
|
// If there exists no such majority, returns (nil, PartSetHeader{}, false).
|
|
|
// If there exists no such majority, returns (nil, PartSetHeader{}, false).
|
|
|
func (voteSet *VoteSet) TwoThirdsMajority() (blockID BlockID, ok bool) { |
|
|
func (voteSet *VoteSet) TwoThirdsMajority() (blockID BlockID, ok bool) { |
|
|
|
|
|
if voteSet == nil { |
|
|
|
|
|
return BlockID{}, false |
|
|
|
|
|
} |
|
|
voteSet.mtx.Lock() |
|
|
voteSet.mtx.Lock() |
|
|
defer voteSet.mtx.Unlock() |
|
|
defer voteSet.mtx.Unlock() |
|
|
if voteSet.maj23 != nil { |
|
|
if voteSet.maj23 != nil { |
|
|