From 9a409d8ba97251f29ba80913a4014b8a369c52c0 Mon Sep 17 00:00:00 2001 From: bitflash-maintainer Date: Wed, 2 Sep 2026 14:46:38 +0000 Subject: pool: advertise a rendezvous only once registered, and log the pin Issue #2 reported that /rvrelay does not govern registration. It does: BtfAllRelays() returns vBtfMeetingRelays alone when fBtfRelayPinned, and every relay-choosing site -- the pool's AcceptLoopFn, the node's ThreadBtfAccept, and the dial path -- draws from it. vBtfMeetingRelays has exactly one writer, the pin itself. A pinned pool therefore spawns one accept thread, at the pin, and no discovered relay is registered at. The registration the incident actually caught was not the pool's. The "registered at" line it quotes exists only in ThreadBtfAccept, and 90.156.222.107:8434 is not a stranger's relay -- it is the third hardcoded seed, one of the three ThreadBtfAccept picks between at random when no pin is in force. That relay is only reachable with the pin absent, so the binary that logged it did not have one; both the pin and the operator-mode skip that keeps a pool out of that thread landed two days before the observation. What was genuinely wrong is that none of this could be read off a log. The pool announced no successful registration at all, and retried failures at one flat line, so "is this pool registered where its descriptor says" had no answer. So: - Advertise the relay after registering at it, not before. The optimistic order published a meeting node we were not yet listed at, and a miner resolving the descriptor inside that window spent its dial on a relay holding no registration for us. ThreadBtfAccept has always ordered it this way; the pool had not. - Log the relay registration succeeds at, name the pin when one is in force, and name each discovered relay the pin excludes. - Escalate when a pinned relay keeps refusing: a pin has no fallback, so an unregistered pin means the pool is unreachable, and that now says so instead of scrolling past. - Refuse to advertise a non-pinned relay in BtfSetActiveRelay. No caller can reach it today, but the descriptor is the one thing a miner obeys, so the invariant is enforced at the sink rather than retrusted to every future caller. Does not touch the registration-consumption race: the pool still gives up its registration on each pairing and re-registers after wrap-and-push. Moving the advertise call inside that loop does not widen the window, it only stops the descriptor naming a relay we never reached. --- src/rpc.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 9 deletions(-) (limited to 'src/rpc.cpp') diff --git a/src/rpc.cpp b/src/rpc.cpp index a4b53ca..a3560ff 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -4947,13 +4947,19 @@ static void AcceptOneFn(void* arg) std::string host = relay.substr(0, colon); int port = atoi(relay.substr(colon + 1).c_str()); - LogPrint("pool", "[pool] accept thread started for relay %s\n", relay.c_str()); + LogPrint("pool", "[pool] accept thread started for relay %s%s\n", relay.c_str(), + fBtfRelayPinned ? " (/rvrelay pin)" : ""); + + // Registration health for this relay. A pin has no fallback, so a pin that + // never registers means the pool is simply unreachable -- and that has to + // be loud. The 2026-07-30 incident went unnoticed because this loop logged + // failures at one flat line and success not at all, so "which relay is this + // pool actually registered at" could not be answered from the log. + int nConsecFail = 0; + int64 nFirstFail = 0; + bool fEverRegistered = false; while (!fShutdown && gPoolRunning) { - // Advertise this relay as the pool's meeting node BEFORE registering, - // so that miners which resolve our descriptor find a relay where the - // pool (not the node's peer-accept) holds the registration. - BtfSetActiveRelay(relay); // Returns as soon as the relay lists us -- registered, not yet paired. btf::RvSocket rv = btf::RvServiceRegister(host.c_str(), (unsigned short)port, pk); @@ -4962,12 +4968,36 @@ static void AcceptOneFn(void* arg) break; } if (rv == btf::RV_INVALID) { - LogPrint("pool", "[pool] relay %s: RvServiceRegister failed" - " -- backing off 30s before retry\n", relay.c_str()); + nConsecFail++; + if (nFirstFail == 0) nFirstFail = GetTime(); + LogPrint("pool", "[pool] relay %s: registration failed (attempt %d," + " failing for %llds) -- backing off 30s before retry\n", + relay.c_str(), nConsecFail, (long long)(GetTime() - nFirstFail)); + if (fBtfRelayPinned && (nConsecFail == 3 || nConsecFail % 10 == 0)) + LogPrint("pool", "[pool] WARNING: pinned relay %s refused registration" + " %d times running (%llds); /rvrelay leaves no fallback, so" + " miners cannot reach this pool%s\n", + relay.c_str(), nConsecFail, (long long)(GetTime() - nFirstFail), + fEverRegistered ? "" : " -- it has never registered once"); for (int i = 0; i < 30 && !fShutdown && gPoolRunning; i++) Sleep(1000); continue; } + // Advertise THIS relay only now. Setting it before the call published a + // meeting node we were not yet listed at, so a miner resolving the + // descriptor inside that window burned its dial on a relay holding no + // registration for us. net.cpp's peer-accept has always ordered it this + // way round; the pool had not. + BtfSetActiveRelay(relay); + if (!fEverRegistered || nConsecFail > 0) + LogPrint("pool", "[pool] registered at relay %s%s%s -- advertising it as" + " the pool's meeting node\n", relay.c_str(), + fBtfRelayPinned ? " (/rvrelay pin)" : "", + nConsecFail > 0 ? ", recovered" : ""); + fEverRegistered = true; + nConsecFail = 0; + nFirstFail = 0; + // Block for a miner to actually arrive. RvServiceRegister used to do // this itself and returned with the relay's 0x01 pairing byte already // consumed; it no longer does. Without waiting here, BtfServiceWrap @@ -5022,9 +5052,21 @@ static void AcceptLoopFn(void*) LogPrint("pool", "[pool] .btf identity ready after %ds\n", waitSecs * 2); std::set spawned; // relays we've already started a thread for + std::set skipped; // discovered relays the pin excluded, logged once each while (!fShutdown && gPoolRunning) { + // BtfAllRelays() already honours the pin: with /rvrelay set it returns + // vBtfMeetingRelays alone, so no thread is ever spawned for a + // discovered relay. Name the ones it drops -- a pool registering at a + // stranger's relay is exactly the thing that should not be silent. vector relays = BtfAllRelays(); + if (fBtfRelayPinned) { + for (const string& r : BtfDiscoveredRelays()) + if (std::find(relays.begin(), relays.end(), r) == relays.end() && + skipped.insert(r).second) + LogPrint("pool", "[pool] not registering at discovered relay %s" + " -- /rvrelay pins the relay list\n", r.c_str()); + } if (relays.empty()) { LogPrint("pool", "[pool] no relays available -- miners cannot connect yet\n"); } else { @@ -5040,8 +5082,9 @@ static void AcceptLoopFn(void*) relay.c_str()); } else { spawned.insert(relay); - LogPrint("pool", "[pool] accept thread spawned for relay %s" - " (%zu total)\n", relay.c_str(), spawned.size()); + LogPrint("pool", "[pool] accept thread spawned for relay %s%s" + " (%zu total)\n", relay.c_str(), + fBtfRelayPinned ? " (/rvrelay pin)" : "", spawned.size()); } } } -- cgit v1.2.3