fix(rng): bounded wait for alignment instead of immediate fallback

When peers have published entropySetHash but none match ours yet
(e.g. a subset peer is the only one seen so far), wait for the
bounded deadline instead of immediately falling back to zero.
Other aligned peers may not have published yet — give them time.

Only fall back to zero if no alignment is observed within the
deadline (2x rngREVEAL_TIMEOUT).
This commit is contained in:
Nicholas Dudfield
2026-04-09 17:58:41 +07:00
parent 00f1f7ba30
commit 2a3f0ec923

View File

@@ -667,14 +667,28 @@ extensionsTick(Ext& ext, Ctx const& ctx)
}
else if (!conflict && aligned == 0 && peersSeen > 0)
{
// Peers published but none match ours — this
// shouldn't happen after merge, but treat as
// conflict and fall back.
// Peers published but none match ours yet.
// This can happen when a peer with a subset
// hash is the only one we've seen so far —
// other aligned peers may not have published
// yet. Wait bounded time for alignment.
auto const entropyElapsed =
ctx.nowSteady - ext.revealPhaseStart_;
auto const entropyDeadline =
ctx.parms.rngREVEAL_TIMEOUT * 2;
if (entropyElapsed <= entropyDeadline)
{
JLOG(ext.j_.debug())
<< "RNG: no aligned peers yet "
<< "(peersSeen=" << peersSeen << "), waiting";
logRngDiag("rng-entropy-hash-no-alignment-wait");
return {};
}
ext.setEntropyFailed();
JLOG(ext.j_.warn())
<< "RNG: peers published entropySetHash but "
"none align with ours, falling back";
logRngDiag("rng-entropy-hash-no-alignment");
<< "RNG: no peer alignment within deadline, "
"falling back to zero";
logRngDiag("rng-entropy-hash-no-alignment-timeout");
}
JLOG(ext.j_.debug())