hygiene: Phase 4 — route unconditional debug output through LogPrint

Fourth phase of the code-hygiene remediation, addressing the ~1,082 stray
fprintf(stderr)/printf debug calls so consensus and hot paths stop spewing
to stderr/stdout. Done per-file (18 files) with conservative rules; the tree
builds clean, self-mines, and `verifychain` re-validates the whole chain
(pow/txdb/coins/miner paths) with -debug=1 enabling every converted line —
zero tinyformat/format-arg exceptions.

Net across 18 files: 174 commented-out debug lines deleted, 173 unconditional
live prints converted to LogPrint("<cat>",...)/LogPrintf (net/mining/pow/nspv/
zrpc categories, format strings + args preserved exactly), 40 pure-noise or
sensitive prints deleted, and 194 calls DELIBERATELY LEFT (already behind
fDebug/fZdebug guards, or genuine startup/fatal-error output that must reach
the console before logging init).

Notable:
- Deleted sensitive success-path dumps (nSPV SIG_TXHASH + full tx input/
  output/change amounts; kvupdate privkey/pubkey hex) that were writing key
  and amount material straight to stderr/stdout.
- Removed the raw 32-byte target hex dumps in the zawy adaptive-PoW helpers
  and the legacy one-shot `if(height==340000)` HUSH artifact in pow.cpp.
- Converted per-tx relay + ban/banlist (net), per-setgenerate MININGTHREADS
  (rpc/mining), signrawtransaction TXPOW, and per-message nSPV traces.
- Left format/arg-mismatched lines untouched (flagged) to avoid introducing
  tinyformat runtime throws.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-27 15:02:01 -05:00
co-authored by Claude Opus 4.8
parent 267e6f7ad5
commit cf15b0a399
17 changed files with 197 additions and 489 deletions
+8 -9
View File
@@ -614,7 +614,7 @@ void DumpBanlist()
if (bandb.Write(banmap)) {
SetBannedSetDirty(false);
}
fprintf(stderr,"%s: Dumping banlist with %lu items\n", __func__, banmap.size());
LogPrint("net", "%s: Dumping banlist with %lu items\n", __func__, banmap.size());
LogPrint("net", "Flushed %d banned node ips/subnets to banlist.dat %dms\n",
banmap.size(), GetTimeMillis() - nStart);
@@ -642,7 +642,7 @@ bool CNode::IsBanned(CNetAddr ip)
CBanEntry banEntry = (*it).second;
if(subNet.Match(ip) && GetTime() < banEntry.nBanUntil) {
fprintf(stderr,"%s: found banned subnet %s\n", __func__, subNet.ToString().c_str());
LogPrint("net", "%s: found banned subnet %s\n", __func__, subNet.ToString().c_str());
fResult = true;
}
}
@@ -676,7 +676,7 @@ void CNode::Ban(const CSubNet& subNet, const BanReason &banReason, int64_t banti
if (bantimeoffset > 0)
banEntry.nBanUntil = (sinceUnixEpoch ? 0 : GetTime() )+bantimeoffset;
fprintf(stderr, "%s: banning %s until %ld with bantimeoffset=%ld sinceUnixEpoch=%d\n", __func__, subNet.ToString().c_str(), banEntry.nBanUntil, bantimeoffset, sinceUnixEpoch);
LogPrint("net", "%s: banning %s until %ld with bantimeoffset=%ld sinceUnixEpoch=%d\n", __func__, subNet.ToString().c_str(), banEntry.nBanUntil, bantimeoffset, sinceUnixEpoch);
{
LOCK(cs_setBanned);
if (setBanned[subNet].nBanUntil < banEntry.nBanUntil) {
@@ -690,13 +690,13 @@ void CNode::Ban(const CSubNet& subNet, const BanReason &banReason, int64_t banti
LOCK(cs_vNodes);
for (CNode* pnode : vNodes) {
if (subNet.Match(static_cast<CNetAddr>(pnode->addr)))
fprintf(stderr, "%s: disconnecting from banned node %s\n", __func__, pnode->addr.ToString().c_str() );
LogPrint("net", "%s: disconnecting from banned node %s\n", __func__, pnode->addr.ToString().c_str() );
pnode->fDisconnect = true;
}
}
if(banReason == BanReasonManuallyAdded) {
fprintf(stderr,"%s: dumping banlist after manual ban\n", __func__);
LogPrint("net", "%s: dumping banlist after manual ban\n", __func__);
DumpBanlist(); //store banlist to disk immediately if user requested ban
}
}
@@ -1851,7 +1851,6 @@ void ThreadOpenConnections()
int randsleep = GetRandInt(FEELER_SLEEP_WINDOW * 1000);
MilliSleep(randsleep);
LogPrint("net", "Making feeler connection to %s\n", addrConnect.ToString().c_str());
printf("%s: Making feeler connection to %s\n", __func__, addrConnect.ToString().c_str());
}
//int failures = setConnected.size() >= std::min(nMaxConnections - 1, 2);
@@ -2510,7 +2509,7 @@ void RelayTransaction(const CTransaction& tx, const CDataStream& ss)
// If we have no nodes to relay to, there is nothing to do
if(vNodes.size() == 0) {
if (HUSH_TESTNODE==0) {
fprintf(stderr, "%s: No nodes to relay to!\n", __func__ );
LogPrint("net", "%s: No nodes to relay to!\n", __func__ );
}
return;
}
@@ -2522,10 +2521,10 @@ void RelayTransaction(const CTransaction& tx, const CDataStream& ss)
vRelayNodes.resize(newSize);
if (HUSH_TESTNODE==1 && vNodes.size() == 0) {
fprintf(stderr, "%s: -testnode=1, no peers, not relaying\n", __func__ );
LogPrint("net", "%s: -testnode=1, no peers, not relaying\n", __func__ );
return;
} else {
fprintf(stderr, "%s: Relaying %s to %lu of %lu peers\n", __func__, tx.GetHash().GetHex().c_str(), newSize, vNodes.size() );
LogPrint("net", "%s: Relaying %s to %lu of %lu peers\n", __func__, tx.GetHash().GetHex().c_str(), newSize, vNodes.size() );
}
// Only relay to randomly chosen 50% of peers