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

All servers terminate

parent 50f621eb
Pipeline #21818 failed with stages
in 1 minute and 37 seconds
......@@ -40,6 +40,20 @@ func (a *Agreement) AddList(serverID UniqueID, ballotList map[string]uuid.UUID)
return nil
}
func (a *Agreement) TallyList() []uuid.UUID {
for _, ll := range a.ballotLists {
list := make([]uuid.UUID, 0, len(ll))
for _, id := range ll {
list = append(list, id)
}
return list
}
panic("Fuck")
}
type Whitelist map[uuid.UUID]pedersen.Proof
type Judge struct {
......
......@@ -13,19 +13,33 @@ func TestIntersection(t *testing.T) {
elem[i] = uuid.New()
}
superset := [][]uuid.UUID{
[]uuid.UUID{elem[0], elem[1], elem[2], elem[3]},
[]uuid.UUID{elem[0], elem[1], elem[2], elem[4]},
[]uuid.UUID{elem[0], elem[1], elem[2], elem[5]},
[]uuid.UUID{elem[0], elem[1], elem[2], elem[6]},
{elem[0], elem[1], elem[2], elem[3]},
{elem[0], elem[1], elem[2], elem[4]},
{elem[0], elem[1], elem[2], elem[5]},
{elem[0], elem[1], elem[2], elem[6]},
}
subset := Intersection(superset)
if !subset[elem[0]] { t.Fail() }
if !subset[elem[1]] { t.Fail() }
if !subset[elem[2]] { t.Fail() }
if subset[elem[3]] { t.Fail() }
if subset[elem[4]] { t.Fail() }
if subset[elem[5]] { t.Fail() }
if subset[elem[6]] { t.Fail() }
if !subset[elem[0]] {
t.Fail()
}
if !subset[elem[1]] {
t.Fail()
}
if !subset[elem[2]] {
t.Fail()
}
if subset[elem[3]] {
t.Fail()
}
if subset[elem[4]] {
t.Fail()
}
if subset[elem[5]] {
t.Fail()
}
if subset[elem[6]] {
t.Fail()
}
}
func TestMaxSubset(t *testing.T) {
......@@ -35,18 +49,32 @@ func TestMaxSubset(t *testing.T) {
elem[i] = uuid.New()
}
superset := [][]uuid.UUID{
[]uuid.UUID{elem[0], elem[1], elem[2], elem[3]},
[]uuid.UUID{elem[0], elem[1], elem[2], elem[4]},
[]uuid.UUID{elem[0], elem[1], elem[2], elem[5]},
[]uuid.UUID{elem[0], elem[1], elem[2], elem[6]},
[]uuid.UUID{elem[6]},
{elem[0], elem[1], elem[2], elem[3]},
{elem[0], elem[1], elem[2], elem[4]},
{elem[0], elem[1], elem[2], elem[5]},
{elem[0], elem[1], elem[2], elem[6]},
{elem[6]},
}
subset := MaxSubset(4, superset)
if !subset[elem[0]] { t.Fail() }
if !subset[elem[1]] { t.Fail() }
if !subset[elem[2]] { t.Fail() }
if subset[elem[3]] { t.Fail() }
if subset[elem[4]] { t.Fail() }
if subset[elem[5]] { t.Fail() }
if subset[elem[6]] { t.Fail() }
if !subset[elem[0]] {
t.Fail()
}
if !subset[elem[1]] {
t.Fail()
}
if !subset[elem[2]] {
t.Fail()
}
if subset[elem[3]] {
t.Fail()
}
if subset[elem[4]] {
t.Fail()
}
if subset[elem[5]] {
t.Fail()
}
if subset[elem[6]] {
t.Fail()
}
}
......@@ -241,18 +241,15 @@ func (election *Election) nextPhase(reason Reason) {
log.Println("===================== Tallying =====================")
// 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.
election.Status.Phase = PhasePreTally
ballotList := election.ballotBox.ballotList()
_ = election.Agreement.AddList(election.ServerID, ballotList)
election.server.Broadcast(network.NewMessage(MsgBallotList, ballotList))
if election.Config.CloseSleep != 0 {
if len(election.Agreement.ballotLists) < election.Participants.Servers && election.Config.CloseSleep != 0 {
election.Status.Phase = PhasePreTally
log.Printf("Election: waiting %s for ballots lists\n", election.Config.CloseSleep)
go delay(election, time.Now(), ReasonTallyTimeout, ReasonBallotList, PhaseTally)
break
} else {
// Skip PhasePreTally
election.Status.Phase = PhaseTallying
}
fallthrough
case PhaseTally:
......@@ -260,7 +257,8 @@ func (election *Election) nextPhase(reason Reason) {
// Only tally if we have ballots
if election.ballotBox.Size() != 0 {
tally := election.ballotBox.Tally(nil)
list := election.Agreement.TallyList()
tally := election.ballotBox.Tally(list)
election.Status.TalliedServers[election.ServerID] = true
err := election.tallyBox.Put(tally)
if err != nil {
......@@ -276,6 +274,8 @@ func (election *Election) nextPhase(reason Reason) {
election.Status.Phase = PhaseResult
result := election.createResults()
election.resultCallback(result)
default:
return // No new phase
}
log.Println("Election: new phase:", election.Status.Phase)
......
......@@ -398,6 +398,9 @@ func TestCloseTimeoutTally(t *testing.T) {
// This should start a go-routine waiting for late ballots
e.nextPhase(ReasonAgreement)
// This prevent us from wait for ballot lists
e.Config.CloseSleep = 0
e.handleClosing("4")
if e.Status.Phase != PhaseCloseWait {
t.Errorf("Not waiting for late ballots")
......@@ -417,6 +420,8 @@ func TestCloseTimeoutSkipTally(t *testing.T) {
// This should start a go-routine waiting for late ballots
e.nextPhase(ReasonAgreement)
e.Config.CloseSleep = 0
e.handleClosing("4")
if e.Status.Phase != PhaseCloseWait {
t.Errorf("Not waiting for late ballots")
......
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