diff options
Diffstat (limited to 'src/rpc.cpp')
| -rw-r--r-- | src/rpc.cpp | 90 |
1 files changed, 71 insertions, 19 deletions
diff --git a/src/rpc.cpp b/src/rpc.cpp index 9d98a4d..49746ee 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp | |||
| @@ -1745,7 +1745,9 @@ static void FlushMaturePayouts() | |||
| 1745 | } | 1745 | } |
| 1746 | int64 total = 0; | 1746 | int64 total = 0; |
| 1747 | for (auto& kv : it->amounts) total += kv.second; | 1747 | for (auto& kv : it->amounts) total += kv.second; |
| 1748 | LogPrint("payout", "[payout] block %d (%s) was orphaned -- voiding %zu" | 1748 | // Always: one line per voided entry, never a collapsed summary. |
| 1749 | // A reorg voids these in a burst from this one source line. | ||
| 1750 | LogPrintAlways("payout", "[payout] block %d (%s) was orphaned -- voiding %zu" | ||
| 1749 | " payment(s) totalling %s\n", | 1751 | " payment(s) totalling %s\n", |
| 1750 | it->blockHeight, it->blockHash.ToString().substr(0, 14).c_str(), | 1752 | it->blockHeight, it->blockHash.ToString().substr(0, 14).c_str(), |
| 1751 | it->amounts.size(), FormatMoney(total).c_str()); | 1753 | it->amounts.size(), FormatMoney(total).c_str()); |
| @@ -1944,7 +1946,7 @@ static void RecordPayoutTxid(const PayingRecord& r, const std::string& txid) | |||
| 1944 | // disagreeing. | 1946 | // disagreeing. |
| 1945 | static void ForfeitPayoutRecipient(const PayingRecord& r, const std::string& reason) | 1947 | static void ForfeitPayoutRecipient(const PayingRecord& r, const std::string& reason) |
| 1946 | { | 1948 | { |
| 1947 | LogPrint("payout", "[payout] writing off %s owed to %s for block %d: %s\n", | 1949 | LogPrintAlways("payout", "[payout] writing off %s owed to %s for block %d: %s\n", |
| 1948 | FormatMoney(r.amount).c_str(), r.address.c_str(), r.blockHeight, | 1950 | FormatMoney(r.amount).c_str(), r.address.c_str(), r.blockHeight, |
| 1949 | reason.c_str()); | 1951 | reason.c_str()); |
| 1950 | VersionedBlob blob; | 1952 | VersionedBlob blob; |
| @@ -2049,7 +2051,7 @@ static void PayoutThreadFn(void*) | |||
| 2049 | // funding block can land at any point in that window. Upstream has | 2051 | // funding block can land at any point in that window. Upstream has |
| 2050 | // no equivalent -- it decides once, when the entry matures. | 2052 | // no equivalent -- it decides once, when the entry matures. |
| 2051 | if (!PayoutBlockStillOnChain(r.blockHash)) { | 2053 | if (!PayoutBlockStillOnChain(r.blockHash)) { |
| 2052 | LogPrint("payout", "[payout] block %d (%s) orphaned while queued" | 2054 | LogPrintAlways("payout", "[payout] block %d (%s) orphaned while queued" |
| 2053 | " -- dropping %s to %s\n", | 2055 | " -- dropping %s to %s\n", |
| 2054 | r.blockHeight, r.blockHash.ToString().substr(0, 14).c_str(), | 2056 | r.blockHeight, r.blockHash.ToString().substr(0, 14).c_str(), |
| 2055 | FormatMoney(r.amount).c_str(), r.address.c_str()); | 2057 | FormatMoney(r.amount).c_str(), r.address.c_str()); |
| @@ -2093,7 +2095,7 @@ static void PayoutThreadFn(void*) | |||
| 2093 | const std::string reason = | 2095 | const std::string reason = |
| 2094 | strprintf("'%s' is not a valid address, so no transaction" | 2096 | strprintf("'%s' is not a valid address, so no transaction" |
| 2095 | " can pay it", r.address.c_str()); | 2097 | " can pay it", r.address.c_str()); |
| 2096 | LogPrint("payout", "[payout] SKIPPED bad address '%s' --" | 2098 | LogPrintAlways("payout", "[payout] SKIPPED bad address '%s' --" |
| 2097 | " %s owed for block %d cannot be paid\n", | 2099 | " %s owed for block %d cannot be paid\n", |
| 2098 | r.address.c_str(), FormatMoney(r.amount).c_str(), | 2100 | r.address.c_str(), FormatMoney(r.amount).c_str(), |
| 2099 | r.blockHeight); | 2101 | r.blockHeight); |
| @@ -2218,7 +2220,7 @@ static void PayoutThreadFn(void*) | |||
| 2218 | // described by at least one of them at every instant. | 2220 | // described by at least one of them at every instant. |
| 2219 | RecordPayoutTxid(r, wtx.GetHash().GetHex()); | 2221 | RecordPayoutTxid(r, wtx.GetHash().GetHex()); |
| 2220 | ForgetPayment(r); | 2222 | ForgetPayment(r); |
| 2221 | LogPrint("payout", "[payout] paid %s to %s (tx %s)\n", | 2223 | LogPrintAlways("payout", "[payout] paid %s to %s (tx %s)\n", |
| 2222 | FormatMoney(r.amount).c_str(), r.address.c_str(), | 2224 | FormatMoney(r.amount).c_str(), r.address.c_str(), |
| 2223 | wtx.GetHash().ToString().substr(0, 12).c_str()); | 2225 | wtx.GetHash().ToString().substr(0, 12).c_str()); |
| 2224 | } else { | 2226 | } else { |
| @@ -2276,7 +2278,7 @@ static void PayoutThreadFn(void*) | |||
| 2276 | // going away must not turn the log into one line a minute | 2278 | // going away must not turn the log into one line a minute |
| 2277 | // forever, and must not go quiet either. | 2279 | // forever, and must not go quiet either. |
| 2278 | if (r.retries <= 5 || r.retries % 60 == 0) | 2280 | if (r.retries <= 5 || r.retries % 60 == 0) |
| 2279 | LogPrint("payout", "[payout] FAILED to pay %s to %s" | 2281 | LogPrintAlways("payout", "[payout] FAILED to pay %s to %s" |
| 2280 | " (%s spendable, wallet unlocked, block %d on" | 2282 | " (%s spendable, wallet unlocked, block %d on" |
| 2281 | " the main chain) -- attempt %d, retrying in" | 2283 | " the main chain) -- attempt %d, retrying in" |
| 2282 | " 60s; this debt stands until it is paid\n", | 2284 | " 60s; this debt stands until it is paid\n", |
| @@ -5220,13 +5222,19 @@ static void AcceptOneFn(void* arg) | |||
| 5220 | std::string host = relay.substr(0, colon); | 5222 | std::string host = relay.substr(0, colon); |
| 5221 | int port = atoi(relay.substr(colon + 1).c_str()); | 5223 | int port = atoi(relay.substr(colon + 1).c_str()); |
| 5222 | 5224 | ||
| 5223 | LogPrint("pool", "[pool] accept thread started for relay %s\n", relay.c_str()); | 5225 | LogPrint("pool", "[pool] accept thread started for relay %s%s\n", relay.c_str(), |
| 5226 | fBtfRelayPinned ? " (/rvrelay pin)" : ""); | ||
| 5227 | |||
| 5228 | // Registration health for this relay. A pin has no fallback, so a pin that | ||
| 5229 | // never registers means the pool is simply unreachable -- and that has to | ||
| 5230 | // be loud. The 2026-07-30 incident went unnoticed because this loop logged | ||
| 5231 | // failures at one flat line and success not at all, so "which relay is this | ||
| 5232 | // pool actually registered at" could not be answered from the log. | ||
| 5233 | int nConsecFail = 0; | ||
| 5234 | int64 nFirstFail = 0; | ||
| 5235 | bool fEverRegistered = false; | ||
| 5224 | 5236 | ||
| 5225 | while (!fShutdown && gPoolRunning) { | 5237 | while (!fShutdown && gPoolRunning) { |
| 5226 | // Advertise this relay as the pool's meeting node BEFORE registering, | ||
| 5227 | // so that miners which resolve our descriptor find a relay where the | ||
| 5228 | // pool (not the node's peer-accept) holds the registration. | ||
| 5229 | BtfSetActiveRelay(relay); | ||
| 5230 | // Returns as soon as the relay lists us -- registered, not yet paired. | 5238 | // Returns as soon as the relay lists us -- registered, not yet paired. |
| 5231 | btf::RvSocket rv = btf::RvServiceRegister(host.c_str(), (unsigned short)port, pk); | 5239 | btf::RvSocket rv = btf::RvServiceRegister(host.c_str(), (unsigned short)port, pk); |
| 5232 | 5240 | ||
| @@ -5235,12 +5243,36 @@ static void AcceptOneFn(void* arg) | |||
| 5235 | break; | 5243 | break; |
| 5236 | } | 5244 | } |
| 5237 | if (rv == btf::RV_INVALID) { | 5245 | if (rv == btf::RV_INVALID) { |
| 5238 | LogPrint("pool", "[pool] relay %s: RvServiceRegister failed" | 5246 | nConsecFail++; |
| 5239 | " -- backing off 30s before retry\n", relay.c_str()); | 5247 | if (nFirstFail == 0) nFirstFail = GetTime(); |
| 5248 | LogPrint("pool", "[pool] relay %s: registration failed (attempt %d," | ||
| 5249 | " failing for %llds) -- backing off 30s before retry\n", | ||
| 5250 | relay.c_str(), nConsecFail, (long long)(GetTime() - nFirstFail)); | ||
| 5251 | if (fBtfRelayPinned && (nConsecFail == 3 || nConsecFail % 10 == 0)) | ||
| 5252 | LogPrint("pool", "[pool] WARNING: pinned relay %s refused registration" | ||
| 5253 | " %d times running (%llds); /rvrelay leaves no fallback, so" | ||
| 5254 | " miners cannot reach this pool%s\n", | ||
| 5255 | relay.c_str(), nConsecFail, (long long)(GetTime() - nFirstFail), | ||
| 5256 | fEverRegistered ? "" : " -- it has never registered once"); | ||
| 5240 | for (int i = 0; i < 30 && !fShutdown && gPoolRunning; i++) Sleep(1000); | 5257 | for (int i = 0; i < 30 && !fShutdown && gPoolRunning; i++) Sleep(1000); |
| 5241 | continue; | 5258 | continue; |
| 5242 | } | 5259 | } |
| 5243 | 5260 | ||
| 5261 | // Advertise THIS relay only now. Setting it before the call published a | ||
| 5262 | // meeting node we were not yet listed at, so a miner resolving the | ||
| 5263 | // descriptor inside that window burned its dial on a relay holding no | ||
| 5264 | // registration for us. net.cpp's peer-accept has always ordered it this | ||
| 5265 | // way round; the pool had not. | ||
| 5266 | BtfSetActiveRelay(relay); | ||
| 5267 | if (!fEverRegistered || nConsecFail > 0) | ||
| 5268 | LogPrint("pool", "[pool] registered at relay %s%s%s -- advertising it as" | ||
| 5269 | " the pool's meeting node\n", relay.c_str(), | ||
| 5270 | fBtfRelayPinned ? " (/rvrelay pin)" : "", | ||
| 5271 | nConsecFail > 0 ? ", recovered" : ""); | ||
| 5272 | fEverRegistered = true; | ||
| 5273 | nConsecFail = 0; | ||
| 5274 | nFirstFail = 0; | ||
| 5275 | |||
| 5244 | // Block for a miner to actually arrive. RvServiceRegister used to do | 5276 | // Block for a miner to actually arrive. RvServiceRegister used to do |
| 5245 | // this itself and returned with the relay's 0x01 pairing byte already | 5277 | // this itself and returned with the relay's 0x01 pairing byte already |
| 5246 | // consumed; it no longer does. Without waiting here, BtfServiceWrap | 5278 | // consumed; it no longer does. Without waiting here, BtfServiceWrap |
| @@ -5295,9 +5327,21 @@ static void AcceptLoopFn(void*) | |||
| 5295 | LogPrint("pool", "[pool] .btf identity ready after %ds\n", waitSecs * 2); | 5327 | LogPrint("pool", "[pool] .btf identity ready after %ds\n", waitSecs * 2); |
| 5296 | 5328 | ||
| 5297 | std::set<std::string> spawned; // relays we've already started a thread for | 5329 | std::set<std::string> spawned; // relays we've already started a thread for |
| 5330 | std::set<std::string> skipped; // discovered relays the pin excluded, logged once each | ||
| 5298 | 5331 | ||
| 5299 | while (!fShutdown && gPoolRunning) { | 5332 | while (!fShutdown && gPoolRunning) { |
| 5333 | // BtfAllRelays() already honours the pin: with /rvrelay set it returns | ||
| 5334 | // vBtfMeetingRelays alone, so no thread is ever spawned for a | ||
| 5335 | // discovered relay. Name the ones it drops -- a pool registering at a | ||
| 5336 | // stranger's relay is exactly the thing that should not be silent. | ||
| 5300 | vector<string> relays = BtfAllRelays(); | 5337 | vector<string> relays = BtfAllRelays(); |
| 5338 | if (fBtfRelayPinned) { | ||
| 5339 | for (const string& r : BtfDiscoveredRelays()) | ||
| 5340 | if (std::find(relays.begin(), relays.end(), r) == relays.end() && | ||
| 5341 | skipped.insert(r).second) | ||
| 5342 | LogPrint("pool", "[pool] not registering at discovered relay %s" | ||
| 5343 | " -- /rvrelay pins the relay list\n", r.c_str()); | ||
| 5344 | } | ||
| 5301 | if (relays.empty()) { | 5345 | if (relays.empty()) { |
| 5302 | LogPrint("pool", "[pool] no relays available -- miners cannot connect yet\n"); | 5346 | LogPrint("pool", "[pool] no relays available -- miners cannot connect yet\n"); |
| 5303 | } else { | 5347 | } else { |
| @@ -5313,8 +5357,9 @@ static void AcceptLoopFn(void*) | |||
| 5313 | relay.c_str()); | 5357 | relay.c_str()); |
| 5314 | } else { | 5358 | } else { |
| 5315 | spawned.insert(relay); | 5359 | spawned.insert(relay); |
| 5316 | LogPrint("pool", "[pool] accept thread spawned for relay %s" | 5360 | LogPrint("pool", "[pool] accept thread spawned for relay %s%s" |
| 5317 | " (%zu total)\n", relay.c_str(), spawned.size()); | 5361 | " (%zu total)\n", relay.c_str(), |
| 5362 | fBtfRelayPinned ? " (/rvrelay pin)" : "", spawned.size()); | ||
| 5318 | } | 5363 | } |
| 5319 | } | 5364 | } |
| 5320 | } | 5365 | } |
| @@ -5350,10 +5395,17 @@ void ThreadRPCServer(void*) | |||
| 5350 | // armed for its one wallet probe before it is allowed to send. | 5395 | // armed for its one wallet probe before it is allowed to send. |
| 5351 | ReconcilePayouts(); | 5396 | ReconcilePayouts(); |
| 5352 | 5397 | ||
| 5353 | _beginthread(AcceptLoopFn, 0, NULL); | 5398 | // _beginthread cannot throw (it reports -1), but an unchecked failure |
| 5354 | _beginthread(LocalAcceptFn, 0, NULL); | 5399 | // leaves the pool running deaf: nobody accepts, announces, or pays, and |
| 5355 | _beginthread(ThreadBtfPoolAnnouncer, 0, NULL); | 5400 | // nothing in the log says why. |
| 5356 | _beginthread(PayoutThreadFn, 0, NULL); | 5401 | if (_beginthread(AcceptLoopFn, 0, NULL) == (uintptr_t)-1) |
| 5402 | LogPrint("pool", "[pool] FATAL: accept loop thread failed to spawn -- miners cannot connect\n"); | ||
| 5403 | if (_beginthread(LocalAcceptFn, 0, NULL) == (uintptr_t)-1) | ||
| 5404 | LogPrint("pool", "[pool] local accept thread failed to spawn\n"); | ||
| 5405 | if (_beginthread(ThreadBtfPoolAnnouncer, 0, NULL) == (uintptr_t)-1) | ||
| 5406 | LogPrint("pool", "[pool] announcer thread failed to spawn -- pool will not be advertised\n"); | ||
| 5407 | if (_beginthread(PayoutThreadFn, 0, NULL) == (uintptr_t)-1) | ||
| 5408 | LogPrint("pool", "[pool] FATAL: payout thread failed to spawn -- no one gets paid\n"); | ||
| 5357 | 5409 | ||
| 5358 | PoolEventLoop(); // blocks until gPoolRunning = false or fShutdown | 5410 | PoolEventLoop(); // blocks until gPoolRunning = false or fShutdown |
| 5359 | 5411 | ||