Skip to content

Commit

Permalink
Slightly refactor CDKGSessionHandler::SleepBeforePhase (dashpay#3224)
Browse files Browse the repository at this point in the history
This should make code a little bit cleaner, should be no changes in the actual behaviour: non-members do not sleep already due to `sleepTime` being negative for them and `phaseTime = 0` does the same on regtest but for everyone.

Signed-off-by: cevap <dev@i2pmail.org>
  • Loading branch information
UdjinM6 authored and cevap committed Apr 5, 2020
1 parent ef40829 commit 00f82ab
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/llmq/quorums_dkgsessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,24 @@ void CDKGSessionHandler::SleepBeforePhase(QuorumPhase curPhase,
double randomSleepFactor,
const WhileWaitFunc& runWhileWaiting)
{
if (!curSession->AreWeMember()) {
// Non-members do not participate and do not create any network load, no need to sleep.
return;
}

if (Params().MineBlocksOnDemand()) {
// On regtest, blocks can be mined on demand without any significant time passing between these.
// We shouldn't wait before phases in this case.
return;
}

// expected time for a full phase
double phaseTime = params.dkgPhaseBlocks * Params().GetConsensus().nPowTargetSpacing * 1000;
// expected time per member
phaseTime = phaseTime / params.size;
// Don't expect perfect block times and thus reduce the phase time to be on the secure side (caller chooses factor)
phaseTime *= randomSleepFactor;

if (Params().MineBlocksOnDemand()) {
// on regtest, blocks can be mined on demand without any significant time passing between these. We shouldn't
// wait before phases in this case
phaseTime = 0;
}

int64_t sleepTime = (int64_t)(phaseTime * curSession->GetMyMemberIndex());
int64_t endTime = GetTimeMillis() + sleepTime;
while (GetTimeMillis() < endTime) {
Expand Down

0 comments on commit 00f82ab

Please sign in to comment.