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
+28 -28
View File
@@ -929,7 +929,7 @@ static void ZC_LoadParams(const CChainParams& chainparams)
boost::system::error_code ec1, ec2;
boost::uintmax_t spend_size = file_size(sapling_spend, ec1);
boost::uintmax_t output_size = file_size(sapling_output, ec2);
fprintf(stderr,"Sapling spend: %d bytes, output: %d bytes\n", (int)spend_size, (int)output_size);
LogPrintf("Sapling spend: %d bytes, output: %d bytes\n", (int)spend_size, (int)output_size);
// We could check sha hashes, but we mostly want to detect on-disk file corruption
// or people having a full harddrive. Full validation happens in librustzcash_init_zksnark_params
@@ -982,7 +982,7 @@ static void ZC_LoadParams(const CChainParams& chainparams)
bool AppInitServers(boost::thread_group& threadGroup)
{
fprintf(stderr,"%s: start\n",__func__);
LogPrintf("%s: start\n",__func__);
RPCServer::OnStopped(&OnRPCStopped);
RPCServer::OnPreCommand(&OnRPCPreCommand);
if (!InitHTTPServer())
@@ -1191,7 +1191,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// Fail early if user has set experimental options without the global flag
if (!fExperimentalMode) {
if (mapArgs.count("-developerencryptwallet")) {
fprintf(stderr,"%s wallet encryption error\n", __FUNCTION__);
LogPrintf("%s wallet encryption error\n", __FUNCTION__);
return InitError(_("Wallet encryption requires -experimentalfeatures."));
}
}
@@ -1272,33 +1272,33 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if (asmap_path.empty()) {
// Most binaries will have it in PWD
asmap_path = pwd / DEFAULT_ASMAP_FILENAME;
printf("%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
if(fs::exists(asmap_path)) {
printf("%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
} else {
// Debian Packages
asmap_path = fs::path("/usr/share/hush") / DEFAULT_ASMAP_FILENAME;
printf("%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
if(fs::exists(asmap_path)) {
printf("%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
} else {
// Source code
asmap_path = contrib / DEFAULT_ASMAP_FILENAME;
printf("%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
if(fs::exists(asmap_path)) {
printf("%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
} else {
// Last Resort: Check the parent directory
asmap_path = pwd / ".." / DEFAULT_ASMAP_FILENAME;
printf("%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
if(fs::exists(asmap_path)) {
printf("%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
} else {
// Mac SD
asmap_path = fs::path("/Applications/SilentDragon.app/Contents/MacOS/") / DEFAULT_ASMAP_FILENAME;
printf("%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: looking for asmap file at %s\n", __func__, asmap_path.c_str() );
if(fs::exists(asmap_path)) {
printf("%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: found asmap file at %s\n", __func__, asmap_path.c_str() );
} else {
// Shit is fucked up, die an honorable death
InitError(strprintf(_("Could not find any asmap file! Please report this bug to Hush Developers")));
@@ -1312,7 +1312,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if (!asmap_path.is_absolute()) {
asmap_path = GetDataDir() / asmap_path;
}
printf("%s: looking for custom asmap file at %s\n", __func__, asmap_path.c_str() );
LogPrint("net", "%s: looking for custom asmap file at %s\n", __func__, asmap_path.c_str() );
}
//TODO: verify asmap_path is not a directory
@@ -1326,7 +1326,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
return false;
}
const uint256 asmap_version = SerializeHash(asmap);
printf("%s: asmap version=%s with %lu mappings\n", __func__, asmap_version.ToString().c_str(), asmap.size());
LogPrint("net", "%s: asmap version=%s with %lu mappings\n", __func__, asmap_version.ToString().c_str(), asmap.size());
LogPrintf("Using asmap version %s for IP bucketing with %lu mappings\n", asmap_version.ToString(), asmap.size());
addrman.m_asmap = std::move(asmap); // //node.connman->SetAsmap(std::move(asmap));
@@ -1351,7 +1351,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
nMaxConnections = GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
nMaxConnections = std::max(std::min(nMaxConnections, (int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS)), 0);
int nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS);
fprintf(stderr,"nMaxConnections %d FD_SETSIZE.%d nBind.%d expr.%d \n",nMaxConnections,FD_SETSIZE,nBind,(int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS));
LogPrintf("nMaxConnections %d FD_SETSIZE.%d nBind.%d expr.%d \n",nMaxConnections,FD_SETSIZE,nBind,(int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS));
if (nFD < MIN_CORE_FILEDESCRIPTORS)
return InitError(_("Not enough file descriptors available."));
if (nFD - MIN_CORE_FILEDESCRIPTORS < nMaxConnections)
@@ -1401,7 +1401,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
}
if (find(categories.begin(), categories.end(), string("randomx")) != categories.end()) {
fRandomXDebug = true;
fprintf(stderr,"%s: enabled randomx debug\n", __func__);
LogPrintf("%s: enabled randomx debug\n", __func__);
}
// Check for -debugnet
@@ -1651,7 +1651,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if (file) fclose(file);
fprintf(stderr,"Attempting to obtain lock %s\n", pathLockFile.string().c_str());
LogPrintf("Attempting to obtain lock %s\n", pathLockFile.string().c_str());
try {
static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
if (!lock.try_lock())
@@ -2029,7 +2029,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if ( checkval != fAddressIndex && fAddressIndex != 0 )
{
pblocktree->WriteFlag("addressindex", fAddressIndex);
fprintf(stderr,"set addressindex, will reindex. could take a while.\n");
LogPrintf("set addressindex, will reindex. could take a while.\n");
fReindex = true;
}
fSpentIndex = GetBoolArg("-spentindex", DEFAULT_SPENTINDEX);
@@ -2037,7 +2037,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if ( checkval != fSpentIndex && fSpentIndex != 0 )
{
pblocktree->WriteFlag("spentindex", fSpentIndex);
fprintf(stderr,"set spentindex, will reindex. could take a while.\n");
LogPrintf("set spentindex, will reindex. could take a while.\n");
fReindex = true;
}
}
@@ -2090,14 +2090,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
boost::filesystem::remove(GetDataDir() / "hushstate");
boost::filesystem::remove(GetDataDir() / "hushsignedmasks");
pblocktree->WriteReindexing(true);
fprintf(stderr, "%s: Deleted hushstate and hushsignedmasks...\n", __FUNCTION__);
LogPrintf("%s: Deleted hushstate and hushsignedmasks...\n", __FUNCTION__);
//If we're reindexing in prune mode, wipe away unusable block files and all undo data files
if (fPruneMode)
CleanupBlockRevFiles();
}
fprintf(stderr, "%s: Loading block index...\n", __FUNCTION__);
LogPrintf("%s: Loading block index...\n", __FUNCTION__);
if (!LoadBlockIndex()) {
strLoadError = _("Error loading block database");
break;
@@ -2121,7 +2121,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
break;
}
fprintf(stderr, "zindex=%s in block index\n", fZindex ? "enabled" : "disabled");
LogPrintf("zindex=%s in block index\n", fZindex ? "enabled" : "disabled");
if (fZindex != GetBoolArg("-zindex", false)) {
strLoadError = _("You need to rebuild the database using -reindex to change -zindex");
break;
@@ -2176,7 +2176,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if (!fLoaded) {
// first suggest a reindex
if (!fReset) {
fprintf(stderr,"%s: error in hd data\n", __FUNCTION__);
LogPrintf("%s: error in hd data\n", __FUNCTION__);
bool fRet = uiInterface.ThreadSafeMessageBox(
strLoadError + ".\n\n" + _("error in HDD data, might just need to update to latest, if that doesnt work, then you need to resync"),
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
@@ -2382,7 +2382,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
int consolidationInterval = GetArg("-consolidationinterval", 25);
if (consolidationInterval < 5) {
fprintf(stderr,"%s: Invalid consolidation interval of %d < 5, setting to default of 25\n", __func__, consolidationInterval);
LogPrintf("%s: Invalid consolidation interval of %d < 5, setting to default of 25\n", __func__, consolidationInterval);
consolidationInterval = 25;
}
@@ -2407,7 +2407,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if (pwalletMain->fSweepEnabled) {
int sweepInterval = GetArg("-zsweepinterval", 10);
if (sweepInterval < 5) {
fprintf(stderr,"%s: Invalid sweep interval of %d, setting to default of 10\n", __func__, sweepInterval);
LogPrintf("%s: Invalid sweep interval of %d, setting to default of 10\n", __func__, sweepInterval);
sweepInterval = 10;
}
pwalletMain->sweepInterval = sweepInterval;
@@ -2726,7 +2726,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// Advertise willingness to SERVE bulk block streams (full nodes only) when opted in.
if ( fBulkBlockSync )
nLocalServices |= NODE_BULKBLOCKS;
fprintf(stderr,"nLocalServices %llx %d, %d\n",(long long)nLocalServices,GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),GetBoolArg("-spentindex", DEFAULT_SPENTINDEX));
LogPrintf("nLocalServices %llx %d, %d\n",(long long)nLocalServices,GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),GetBoolArg("-spentindex", DEFAULT_SPENTINDEX));
}
// ********************************************************* Step 10: import blocks
@@ -2742,7 +2742,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
if ( !ActivateBestChain(true,state))
strErrors << "Failed to connect best block";
} else {
fprintf(stderr,"HUSH_REWIND < 0\n");
LogPrintf("HUSH_REWIND < 0\n");
}
std::vector<boost::filesystem::path> vImportFiles;
if (mapArgs.count("-loadblock"))