Commit b9914b0c authored by Anders Jensen Løvig's avatar Anders Jensen Løvig
Browse files

Fix Agreement

parent 21377379
Pipeline #21848 failed with stages
in 1 minute and 48 seconds
......@@ -44,21 +44,26 @@ func (a *Agreement) AddList(serverID UniqueID, ballotList map[string]uuid.UUID)
func (a *Agreement) TallyList() ([]uuid.UUID, error) {
a.Lock()
defer a.Unlock()
// First create a list of received ballot lists
bls := make([]BallotList, 0, len(a.ballotLists))
for _, b := range a.ballotLists {
bls = append(bls, b)
}
// Find the maximum subset
hashes := MaxSubset(a.required, bls)
// We know create a list of ballots we have in the subset.
list := make([]uuid.UUID, 0, len(a.ourList))
for h := range hashes {
if id, ok := a.ourList[h]; ok {
list = append(list, id)
delete(hashes, h)
delete(hashes, h) // Delete hashes that we have.
}
}
// If hashes is non-empty then we are not part of the max-subset.
if len(hashes) != 0 {
return nil, fmt.Errorf("missing %d ballots to tally", len(hashes))
}
......
......@@ -242,6 +242,7 @@ func (election *Election) nextPhase(reason Reason) {
// Tallying is two phased. First we wait for servers to sent ballot lists.
// Then we find the largest intersection of ballot lists and tally this intersection.
ballotList := election.ballotBox.ballotList()
election.Agreement.ourList = ballotList
_ = election.Agreement.AddList(election.ServerID, ballotList)
election.server.Broadcast(network.NewMessage(MsgBallotList, ballotList))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment