From ca03f8e9416837acfac825f02a6c592e07e0c4df Mon Sep 17 00:00:00 2001 From: bitflash-maintainer Date: Wed, 2 Sep 2026 17:13:06 +0000 Subject: worker: count a session as productive only if the pool sent a job PoolParticipantMiner returned true from its normal cleanup path whether or not the pool had ever sent work, so a pool that completed the tunnel and then dropped was indistinguishable from a healthy one. The caller reset nRetrySecs to 10 on every such "session", pinning the reconnect at a flat 10s and defeating the backoff in precisely the case it was added for. It cleared nFailingSince as well, so the "failing for N minutes" line never printed either -- the worker went back to idling silently. Return true only once at least one well-formed mining.notify has arrived. The existing early returns are unaffected: they already mean "no session", which stays the right answer for any path that leaves the worker without work, a failed hash-thread spawn included. --- src/main.cpp | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index b0cdab2..b0bdb8c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3662,6 +3662,14 @@ static void ParticipantHashWorker(ParticipantJobShared* sh, int idx, int nWorker RandomXDestroyMinerVM(vm); } +// Run one participant session: resolve the pool, open the tunnel, subscribe, +// hash, submit shares. Returns true only if the pool actually handed out work +// -- at least one well-formed mining.notify arrived. Everything else is false, +// including a tunnel that opened and was dropped before any job. +// +// The caller's reconnect backoff keys off this return value, so any path added +// here that leaves the session without work MUST return false. "The session +// ended tidily" is not the question being asked. static bool PoolParticipantMiner() { // ------------------------------------------------------------------ @@ -3944,6 +3952,7 @@ connected: uint256 target; double currentDifficulty = 1.0; // updated by mining.set_difficulty from pool bool haveJob = false; + bool gotAnyJob = false; // any job at all this session -- the return value bool gotSubscribeAck = false; bool gotAuthorizeAck = false; int64 authWaitStart = 0; @@ -4060,8 +4069,9 @@ connected: jobId = newJobId; memcpy(header, hdrBytes.data(), 80); memcpy(&target, tgtBytes.data(), 32); - haveJob = true; - nNonce = 1; + haveJob = true; + gotAnyJob = true; + nNonce = 1; { std::lock_guard lk(jobShared.mtx); memcpy(jobShared.header, header, 80); @@ -4197,7 +4207,11 @@ connected: (unsigned long long)hashesSinceSample, (unsigned long long)sessionSharesSent, (unsigned long long)sessionSharesAccepted); - return true; + // Not "we got here", which is true of a tunnel the pool accepted and then + // dropped without ever sending a job -- exactly the case the caller's + // backoff exists for. Reaching the end of the session is not evidence the + // session was worth anything; a job is. + return gotAnyJob; } // --------------------------------------------------------------------------- @@ -4394,17 +4408,23 @@ bool BitcoinMiner(int nThreadId) // Participant mode: connect to external pool instead of mining solo/operator if (nMineMode == MINE_PARTICIPANT) { - // An attempt that never got a session backs off (10s doubling to - // 120s) instead of hammering the same path every flat 10s, and a - // streak lasting minutes is said at printf level: the identical - // once-per-10s LogPrint line is how a worker idled all night - // unnoticed (issue #17). A completed session resets both. + // An attempt that never got work backs off (10s doubling to 120s) + // instead of hammering the same path every flat 10s, and a streak + // lasting minutes is said at printf level: the identical once-per-10s + // LogPrint line is how a worker idled all night unnoticed (issue #17). + // + // Only a session the pool actually sent a job to resets either. The + // weaker test -- "the session returned" -- was gameable: a pool that + // completes the tunnel and drops without ever sending work leaves by + // the same tidy cleanup path a healthy one does, which would pin the + // retry at 10s forever and defeat the backoff in exactly the scenario + // it exists for. int nRetrySecs = 10; int64 nFailingSince = 0; while (fGenerateBitcoins && nMineMode == MINE_PARTICIPANT && !fShutdown) { - bool fHadSession = PoolParticipantMiner(); + bool fGotWork = PoolParticipantMiner(); if (fGenerateBitcoins && nMineMode == MINE_PARTICIPANT && !fShutdown) { - if (fHadSession) { + if (fGotWork) { nRetrySecs = 10; nFailingSince = 0; } else { @@ -4428,7 +4448,7 @@ bool BitcoinMiner(int nThreadId) for (int i = 0; i < nRetrySecs && !fShutdown && fGenerateBitcoins && nMineMode == MINE_PARTICIPANT; i++) Sleep(1000); - if (!fHadSession && nRetrySecs < 120) { + if (!fGotWork && nRetrySecs < 120) { nRetrySecs *= 2; if (nRetrySecs > 120) nRetrySecs = 120; -- cgit v1.2.3