Skip to content

Commit 2b587f0

Browse files
authored
Slightly refactor CDKGSessionHandler::SleepBeforePhase (#3224)
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.
1 parent fdb0586 commit 2b587f0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/llmq/quorums_dkgsessionhandler.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,24 @@ void CDKGSessionHandler::SleepBeforePhase(QuorumPhase curPhase,
225225
double randomSleepFactor,
226226
const WhileWaitFunc& runWhileWaiting)
227227
{
228+
if (!curSession->AreWeMember()) {
229+
// Non-members do not participate and do not create any network load, no need to sleep.
230+
return;
231+
}
232+
233+
if (Params().MineBlocksOnDemand()) {
234+
// On regtest, blocks can be mined on demand without any significant time passing between these.
235+
// We shouldn't wait before phases in this case.
236+
return;
237+
}
238+
228239
// expected time for a full phase
229240
double phaseTime = params.dkgPhaseBlocks * Params().GetConsensus().nPowTargetSpacing * 1000;
230241
// expected time per member
231242
phaseTime = phaseTime / params.size;
232243
// Don't expect perfect block times and thus reduce the phase time to be on the secure side (caller chooses factor)
233244
phaseTime *= randomSleepFactor;
234245

235-
if (Params().MineBlocksOnDemand()) {
236-
// on regtest, blocks can be mined on demand without any significant time passing between these. We shouldn't
237-
// wait before phases in this case
238-
phaseTime = 0;
239-
}
240-
241246
int64_t sleepTime = (int64_t)(phaseTime * curSession->GetMyMemberIndex());
242247
int64_t endTime = GetTimeMillis() + sleepTime;
243248
while (GetTimeMillis() < endTime) {

0 commit comments

Comments
 (0)