|
@ -18,12 +18,6 @@ const ( |
|
|
MaxVotesCount = 10000 |
|
|
MaxVotesCount = 10000 |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// UNSTABLE
|
|
|
|
|
|
// XXX: duplicate of p2p.ID to avoid dependence between packages.
|
|
|
|
|
|
// Perhaps we can have a minimal types package containing this (and other things?)
|
|
|
|
|
|
// that both `types` and `p2p` import ?
|
|
|
|
|
|
type P2PID string |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
VoteSet helps collect signatures from validators at each height+round for a |
|
|
VoteSet helps collect signatures from validators at each height+round for a |
|
|
predefined vote type. |
|
|
predefined vote type. |
|
@ -71,7 +65,7 @@ type VoteSet struct { |
|
|
sum int64 // Sum of voting power for seen votes, discounting conflicts
|
|
|
sum int64 // Sum of voting power for seen votes, discounting conflicts
|
|
|
maj23 *BlockID // First 2/3 majority seen
|
|
|
maj23 *BlockID // First 2/3 majority seen
|
|
|
votesByBlock map[string]*blockVotes // string(blockHash|blockParts) -> blockVotes
|
|
|
votesByBlock map[string]*blockVotes // string(blockHash|blockParts) -> blockVotes
|
|
|
peerMaj23s map[P2PID]BlockID // Maj23 for each peer
|
|
|
|
|
|
|
|
|
peerMaj23s map[string]BlockID // Maj23 for each peer
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Constructs a new VoteSet struct used to accumulate votes for given height/round.
|
|
|
// Constructs a new VoteSet struct used to accumulate votes for given height/round.
|
|
@ -91,7 +85,7 @@ func NewVoteSet(chainID string, height int64, round int32, |
|
|
sum: 0, |
|
|
sum: 0, |
|
|
maj23: nil, |
|
|
maj23: nil, |
|
|
votesByBlock: make(map[string]*blockVotes, valSet.Size()), |
|
|
votesByBlock: make(map[string]*blockVotes, valSet.Size()), |
|
|
peerMaj23s: make(map[P2PID]BlockID), |
|
|
|
|
|
|
|
|
peerMaj23s: make(map[string]BlockID), |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -313,7 +307,7 @@ func (voteSet *VoteSet) addVerifiedVote( |
|
|
// 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
|
|
|
// NOTE: VoteSet must not be nil
|
|
|
func (voteSet *VoteSet) SetPeerMaj23(peerID P2PID, blockID BlockID) error { |
|
|
|
|
|
|
|
|
func (voteSet *VoteSet) SetPeerMaj23(peerID string, blockID BlockID) error { |
|
|
if voteSet == nil { |
|
|
if voteSet == nil { |
|
|
panic("SetPeerMaj23() on nil VoteSet") |
|
|
panic("SetPeerMaj23() on nil VoteSet") |
|
|
} |
|
|
} |
|
@ -530,9 +524,9 @@ func (voteSet *VoteSet) MarshalJSON() ([]byte, error) { |
|
|
// NOTE: insufficient for unmarshaling from (compressed votes)
|
|
|
// NOTE: insufficient for unmarshaling from (compressed votes)
|
|
|
// TODO: make the peerMaj23s nicer to read (eg just the block hash)
|
|
|
// TODO: make the peerMaj23s nicer to read (eg just the block hash)
|
|
|
type VoteSetJSON struct { |
|
|
type VoteSetJSON struct { |
|
|
Votes []string `json:"votes"` |
|
|
|
|
|
VotesBitArray string `json:"votes_bit_array"` |
|
|
|
|
|
PeerMaj23s map[P2PID]BlockID `json:"peer_maj_23s"` |
|
|
|
|
|
|
|
|
Votes []string `json:"votes"` |
|
|
|
|
|
VotesBitArray string `json:"votes_bit_array"` |
|
|
|
|
|
PeerMaj23s map[string]BlockID `json:"peer_maj_23s"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Return the bit-array of votes including
|
|
|
// Return the bit-array of votes including
|
|
|