fix(overlay): draw fault drops through rand_int

The four direct uniform_int_distribution calls on this lineage were still
stdlib-defined. Peer send drop and delay jitter, and the RNG claim and
reveal drops, now use rand_int. A zero jitter adds nothing, because
rand_int rejects a zero-width range.
This commit is contained in:
Nicholas Dudfield
2026-09-23 13:19:01 +07:00
parent 2a3f9ebae2
commit 39c83950f5
2 changed files with 6 additions and 7 deletions

View File

@@ -3067,8 +3067,7 @@ ConsensusExtensions::harvestRngData(
if (cfg->rngClaimDropPctX100 && *cfg->rngClaimDropPctX100 > 0)
{
static thread_local std::mt19937 rng{std::random_device{}()};
if (std::uniform_int_distribution<int>{0, 9999}(rng) <
*cfg->rngClaimDropPctX100)
if (rand_int(rng, 0, 9999) < *cfg->rngClaimDropPctX100)
{
JLOG(j_.warn())
<< "RNG: TESTING dropping claim"
@@ -3131,8 +3130,7 @@ ConsensusExtensions::harvestRngData(
{
static thread_local std::mt19937 rng{
std::random_device{}()};
if (std::uniform_int_distribution<int>{0, 9999}(rng) <
*cfg->rngRevealDropPctX100)
if (rand_int(rng, 0, 9999) < *cfg->rngRevealDropPctX100)
{
JLOG(j_.warn())
<< "RNG: TESTING dropping reveal claim"

View File

@@ -325,7 +325,7 @@ PeerImp::send(std::shared_ptr<Message> const& m)
if (dropPct > 0)
{
static thread_local std::mt19937 rng{std::random_device{}()};
if (std::uniform_int_distribution<int>{0, 9999}(rng) < dropPct)
if (rand_int(rng, 0, 9999) < dropPct)
return; // silently dropped
}
@@ -333,12 +333,13 @@ PeerImp::send(std::shared_ptr<Message> const& m)
if (delayMs > 0 || jitterMs > 0)
{
int totalMs = delayMs;
// jitterMs == 0 adds nothing. rand_int rejects a zero-width
// range, so the draw is only taken when the jitter is positive.
if (jitterMs > 0)
{
static thread_local std::mt19937 rng{
std::random_device{}()};
totalMs +=
std::uniform_int_distribution<int>{0, jitterMs}(rng);
totalMs += rand_int(rng, 0, jitterMs);
}
auto self = shared_from_this();