From 687dbd00c882e21569101e758d508159070f80d6 Mon Sep 17 00:00:00 2001 From: David Florness Date: Mon, 15 Feb 2021 10:45:51 -0500 Subject: [PATCH] Slightly optimize onSumMessage loop --- election/msg.go | 12 +++++------- election/result.go | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/election/msg.go b/election/msg.go index d7a5e82..f35d140 100644 --- a/election/msg.go +++ b/election/msg.go @@ -503,17 +503,15 @@ func (elections *ElectionsMap) onSumMessage(evt *event.Event) (success bool) { voter.SumID = &evt.ID voter.Sum = new(big.Int).SetBytes(bytes) - // once we've recieved all sums, calculate the election result! - receivedAllSums := true + // if we've recieved all sums, calculate the election result! for _, voterID := range *el.FinalJoinIDs { if el.Joins[voterID].SumID == nil { - receivedAllSums = false - break + // still need at least one voter's sum, but this event + // was processed successfully + return true } } - if receivedAllSums { - el.CalculateResult() - } + el.calculateResult() return true } diff --git a/election/result.go b/election/result.go index d85cfc0..679735c 100644 --- a/election/result.go +++ b/election/result.go @@ -10,7 +10,7 @@ import ( "tallyard.xyz/math" ) -func (el *Election) CalculateResult() { +func (el *Election) calculateResult() { // this assumes all sums have been received and successfully validated // and processed M := constructPolyMatrix(el) -- 2.38.4