From faeb40c5d1dbcb6548c9825b14fa3b72f6497d86 Mon Sep 17 00:00:00 2001 From: bitflash-maintainer Date: Sat, 8 Aug 2026 04:37:52 +0000 Subject: nostr: make /rvrelay a true pin -- never merge discovered relays A pool started with /rvrelay=ONE still spawned an accept thread for every Nostr-discovered relay (BtfAllRelays always merged g_discoveredRelays), and each thread optimistically overwrote the advertised meeting node before registering -- so a discovered Tailscale-only relay (a mesh host) flapped the published .btf descriptor and public miners could not connect. fBtfRelayPinned (set only when /rvrelay parses) makes BtfAllRelays return exactly the pinned list. Also validate the /rvrelay value at parse time: with the pin in place no discovered relay can mask a typo. (cherry picked from commit 0a4d2b02fa5382c5e788b5f0e2f8a844695dec47) --- src/main_gui.cpp | 16 ++++++++++++++-- src/nostr.cpp | 10 +++++++++- src/nostr.h | 8 ++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 0b4e091..d0969b5 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -261,8 +261,20 @@ static void ParseStartupArguments(int argc, char* argv[]) string rvRelay = argval2(argc, argv, "/rvrelay", "-rvrelay"); if (!rvRelay.empty()) { - vBtfMeetingRelays.clear(); - vBtfMeetingRelays.push_back(rvRelay); + if (!LooksLikeRelay(rvRelay)) + { + // A malformed pin must not replace the seed list: with the pin + // set, no discovered relay can ever mask the typo, and the pool + // would publish a garbage (or no) meeting node forever. + fprintf(stderr, "Ignoring /rvrelay=%s: expected host:port\n", + rvRelay.c_str()); + } + else + { + vBtfMeetingRelays.clear(); + vBtfMeetingRelays.push_back(rvRelay); + fBtfRelayPinned = true; + } } string announceRelay = argval2(argc, argv, "/announcerelay", "-announcerelay"); diff --git a/src/nostr.cpp b/src/nostr.cpp index 21104bc..6d85bf6 100644 --- a/src/nostr.cpp +++ b/src/nostr.cpp @@ -110,6 +110,12 @@ vector vBtfMeetingRelays = { "31.44.4.249:8434", // New Jersey, US "90.156.222.107:8434", // Almaty, KZ }; +// True when the operator pinned the relay list with /rvrelay: discovered +// relays must NOT be merged in (BtfAllRelays), otherwise one accept thread +// per discovered relay is spawned and each one optimistically overwrites the +// advertised meeting node (BtfSetActiveRelay) before registering -- a +// discovered but unreachable relay then flaps the published .btf descriptor. +bool fBtfRelayPinned = false; string strBtfActiveRelay; static CCriticalSection cs_activeRelay; @@ -144,7 +150,7 @@ static map g_discoveredPools; static CCriticalSection cs_discoveredPools; // Basic sanity: "host:port" with a numeric 1..65535 port and a plausible host. -static bool LooksLikeRelay(const string& r) +bool LooksLikeRelay(const string& r) { size_t colon = r.rfind(':'); if (colon == string::npos || colon == 0 || colon + 1 >= r.size()) @@ -172,6 +178,8 @@ static bool LooksLikeRelay(const string& r) vector BtfAllRelays() { vector all = vBtfMeetingRelays; + if (fBtfRelayPinned) + return all; CRITICAL_BLOCK(cs_discoveredRelays) foreach(const string& r, g_discoveredRelays) if (find(all.begin(), all.end(), r) == all.end()) diff --git a/src/nostr.h b/src/nostr.h index b5eb5e3..827b2f3 100644 --- a/src/nostr.h +++ b/src/nostr.h @@ -43,6 +43,14 @@ void BtfSetActiveRelay(const std::string& relay); // If set (via /announcerelay=host:port), this node announces that relay on // Nostr so other nodes discover it automatically -- no manual seed-list edit. extern std::string strBtfAnnounceRelay; +// True when /rvrelay pinned the meeting relay list: BtfAllRelays then returns +// ONLY vBtfMeetingRelays, never Nostr-discovered volunteer relays. Without +// this, a pool that pins one public relay still spawns an accept thread per +// discovered relay, and each thread's optimistic BtfSetActiveRelay makes the +// published descriptor flap to relays the pool may not be reachable at. +extern bool fBtfRelayPinned; +// Basic sanity check on a "host:port" relay address (numeric port 1..65535). +bool LooksLikeRelay(const std::string& r); // Every relay to try: curated seeds + relays discovered from Nostr announcements. std::vector BtfAllRelays(); -- cgit v1.2.3