~edwargix/tallyard

687dbd00c882e21569101e758d508159070f80d6 — David Florness 4 years ago d9f5c80
Slightly optimize onSumMessage loop
2 files changed, 6 insertions(+), 8 deletions(-)

M election/msg.go
M election/result.go
M election/msg.go => election/msg.go +5 -7
@@ 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
}

M election/result.go => election/result.go +1 -1
@@ 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)