From 2076bcdfd03389e7de7f16f068ce353d2e09af58 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Mon, 12 Jun 2023 12:08:05 +0200 Subject: [PATCH] das: factorize startSampling procedure Signed-off-by: Csaba Kiraly --- das/das.nim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/das/das.nim b/das/das.nim index c1106f7..866ac75 100644 --- a/das/das.nim +++ b/das/das.nim @@ -144,14 +144,20 @@ when isMainModule: info "uploaded to DHT", by = 0, pass, time = Moment.now() - startTime # sample - for n in 1 ..< nodecount: - let startTime = Moment.now() + proc startSampling(n: discv5_protocol.Protocol): seq[Future[DiscResult[seq[byte]]]] = + ## Generate random sample and start the sampling process var futs = newSeq[Future[DiscResult[seq[byte]]]]() let sample = sample(0 ..< blocksize, samplesize) + debug "starting sampling", by = n, sample for s in sample: - let fut = nodes[n][0].getValue(segmentIDs[s]) + let fut = n.getValue(segmentIDs[s]) futs.add(fut) + return futs + + for n in 1 ..< nodecount: + let startTime = Moment.now() + var futs = startSampling(nodes[n][0]) # test is passed if all segments are retrieved in time let pass = await allFutures(futs).withTimeout(sampling_timeout)