diff --git a/consensus/reactor.go b/consensus/reactor.go index 7208f397a..80e87efd8 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -584,6 +584,8 @@ OUTER_LOOP: } } +// NOTE: `queryMaj23Routine` has a simple crude design since it only comes +// into play for liveness when there's a signature DDoS attack happening. func (conR *ConsensusReactor) queryMaj23Routine(peer *p2p.Peer, ps *PeerState) { log := log.New("peer", peer) diff --git a/types/vote_set.go b/types/vote_set.go index a1a2bf394..de853a5e7 100644 --- a/types/vote_set.go +++ b/types/vote_set.go @@ -122,7 +122,11 @@ func (voteSet *VoteSet) Size() int { // Duplicate votes return added=false, err=nil. // Conflicting votes return added=*, err=ErrVoteConflictingVotes. // NOTE: vote should not be mutated after adding. +// NOTE: VoteSet must not be nil func (voteSet *VoteSet) AddVote(vote *Vote) (added bool, err error) { + if voteSet == nil { + PanicSanity("AddVote() on nil VoteSet") + } voteSet.mtx.Lock() 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, // this can cause memory issues. // TODO: implement ability to remove peers too +// NOTE: VoteSet must not be nil func (voteSet *VoteSet) SetPeerMaj23(peerID string, blockID BlockID) { + if voteSet == nil { + PanicSanity("SetPeerMaj23() on nil VoteSet") + } voteSet.mtx.Lock() defer voteSet.mtx.Unlock() @@ -332,12 +340,18 @@ func (voteSet *VoteSet) BitArrayByBlockID(blockID BlockID) *BitArray { // NOTE: if validator has conflicting votes, returns "canonical" vote func (voteSet *VoteSet) GetByIndex(valIndex int) *Vote { + if voteSet == nil { + return nil + } voteSet.mtx.Lock() defer voteSet.mtx.Unlock() return voteSet.votes[valIndex] } func (voteSet *VoteSet) GetByAddress(address []byte) *Vote { + if voteSet == nil { + return nil + } voteSet.mtx.Lock() defer voteSet.mtx.Unlock() 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. // If there exists no such majority, returns (nil, PartSetHeader{}, false). func (voteSet *VoteSet) TwoThirdsMajority() (blockID BlockID, ok bool) { + if voteSet == nil { + return BlockID{}, false + } voteSet.mtx.Lock() defer voteSet.mtx.Unlock() if voteSet.maj23 != nil {