diff --git a/api/results.go b/api/results.go index 7d4b2555fb77ad90e317311ab4c0d8f5a8eeb836..f2358f366b26b1f5a0efb9b1599387b2fb566519 100644 --- a/api/results.go +++ b/api/results.go @@ -93,17 +93,18 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration, oldestRound := networkInstance.GetOldestRoundID() + roundEventTimeout := 7 * time.Second + if timeout < roundEventTimeout { + roundEventTimeout = timeout + } + // Parse and adjudicate every round for _, rnd := range roundList { // Every round is timed out by default, until proven to have finished roundsResults[rnd] = TimeOut roundInfo, err := networkInstance.GetRound(rnd) - if err != nil && rnd < oldestRound { - // If round is older that oldest round in our buffer - // Add it to the historical round request (performed later) - historicalRequest.Rounds = append(historicalRequest.Rounds, uint64(rnd)) - numResults++ - } else { + // If we have the round in the buffer + if err == nil { // Check if the round is done (completed or failed) or in progress if states.Round(roundInfo.State) == states.COMPLETED { roundsResults[rnd] = Succeeded @@ -113,7 +114,20 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration, } else { // If in progress, add a channel monitoring its state roundEvents.AddRoundEventChan(rnd, sendResults, - timeout/2, states.COMPLETED, states.FAILED) + roundEventTimeout, states.COMPLETED, states.FAILED) + numResults++ + } + } else { + // Update the oldest round (buffer may have updated externally) + if rnd < oldestRound { + // If round is older that oldest round in our buffer + // Add it to the historical round request (performed later) + historicalRequest.Rounds = append(historicalRequest.Rounds, uint64(rnd)) + numResults++ + } else { + // Otherwise, monitor its progress + roundEvents.AddRoundEventChan(rnd, sendResults, + roundEventTimeout, states.COMPLETED, states.FAILED) numResults++ } }