From be63e83d79e7e00e6b8ca889a70e6a19886aa1d8 Mon Sep 17 00:00:00 2001 From: bitflash-maintainer Date: Wed, 19 Aug 2026 22:46:53 +0000 Subject: mine: one pool session in participant mode, not one per core StartMinerThreads() sizes its pool with MinerThreadCount(), which is right for solo mining -- each thread hashes a template of its own -- and wrong for participant mode, where every thread entering BitcoinMiner() is a whole miner: its own Stratum session, its own payout address off the rotation, its own pool of /hashthreads workers. The two counts multiplied instead of dividing. Measured on the pool box with /hashthreads=2: a container with no cpuset logged "Mining with 11 thread(s) of 12 core(s)" -- 11 sessions, 22 hash threads on 12 cores, 1058% CPU, load 22.68 -- while the same binary under --cpuset-cpus 10,11 logged one session and 199%. The second miner (8 cores, /hashthreads=1) ran 7 sessions and went 74C to 89C. No code differed between those runs. Only the cpuset did, which means the cpuset was holding the thread count down by accident and every deployment without one was oversubscribed. Participant mode now starts exactly one session, so /hashthreads means what it says instead of being multiplied by the core count. The worker count moves to ParticipantHashThreadCount(), next to MinerThreadCount() where the two are easy to confuse, so what is printed at startup and what actually hashes cannot drift apart -- and it IS printed now. It was only ever visible under -debug, which is how eleven sessions ran unnoticed. Same host, same cpuset (0-3), same arguments, measured as a delta over 20 s more than four minutes after start: before 399% CPU, 6-7 threads hot, 3 sessions after 201% CPU, exactly 2 threads at 99.9%, 1 session Solo mining is untouched: /gen without /participant still starts MinerThreadCount() threads. (cherry picked from commit 45bc9ed5bc132712092f3e7902fef746c6cae898) --- src/net.cpp | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'src/net.cpp') diff --git a/src/net.cpp b/src/net.cpp index e08f6f7..34c608c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1801,7 +1801,21 @@ void ThreadBitcoinMiner(void* parg) // Start the miners. Returns how many actually got off the ground. int StartMinerThreads() { - int nThreads = MinerThreadCount(); + // MinerThreadCount() sizes the SOLO miner, where each thread hashes a + // template of its own and more threads is simply more hashrate. + // + // Participant mode is not that shape. Every thread that enters + // BitcoinMiner() takes the MINE_PARTICIPANT branch, and that branch is a + // whole miner: its own Stratum session to the pool, its own payout address + // from the rotation, and its own pool of /hashthreads worker threads. So + // the two counts multiply instead of dividing, and the machine ends up + // running MinerThreadCount() x nHashThreads hashing threads plus one pool + // connection each. On a 12-core host with /hashthreads=2 that is 11 + // sessions and 22 hash threads -- roughly 2x the cores, which is not more + // work done, only more contention -- and with /hashthreads unset it is 11 + // sessions of 11 workers. One session is the entirety of participant mode; + // /hashthreads is what sizes it, and it can then mean what it says. + int nThreads = (nMineMode == MINE_PARTICIPANT) ? 1 : MinerThreadCount(); int nStarted = 0; for (int i = 0; i < nThreads; i++) { @@ -1813,9 +1827,24 @@ int StartMinerThreads() // The dataset is one allocation shared by all of them; only the 2 MB // scratchpads multiply. Printed because "why is it using 2 GB" is the first // question anyone asks. - printf("Mining with %d thread(s) of %u core(s) -- about %d MB " - "(~2080 MB shared RandomX dataset + ~2 MB per thread)\n", - nStarted, AvailableCoreCount(), 2080 + 2 * nStarted); + // + // Participant mode reports the workers that session will run, not the one + // thread that runs it: the hash thread count is the number an operator + // watches, and it is the number that was wrong here. It is otherwise only + // logged under -debug, which is how 11 sessions ran unnoticed. + if (nMineMode == MINE_PARTICIPANT) + { + int nWorkers = ParticipantHashThreadCount(); + printf("Mining for the pool with %d hash thread(s) of %u core(s) -- about %d MB " + "(~2080 MB shared RandomX dataset + ~2 MB per thread)\n", + nWorkers, AvailableCoreCount(), 2080 + 2 * nWorkers); + } + else + { + printf("Mining with %d thread(s) of %u core(s) -- about %d MB " + "(~2080 MB shared RandomX dataset + ~2 MB per thread)\n", + nStarted, AvailableCoreCount(), 2080 + 2 * nStarted); + } return nStarted; } -- cgit v1.2.3