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 -27
View File
@@ -496,7 +496,6 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
// Check amount
if (nValue <= 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
//fprintf(stderr,"nValue %.8f vs curBalance %.8f\n",(double)nValue/COIN,(double)curBalance/COIN);
if (nValue > curBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
@@ -518,9 +517,7 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
for (i=0; i<opretlen; i++)
{
opretpubkey[i] = opretbuf[i];
//printf("%02x",ptr[i]);
}
//printf(" opretbuf[%d]\n",opretlen);
CRecipient opret = { opretpubkey, opretValue, false };
vecSend.push_back(opret);
}
@@ -665,7 +662,6 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
if ( (n= (int32_t)params.size()) >= 3 )
{
flags = atoi(params[2].get_str().c_str());
//printf("flags.%d (%s) n.%d\n",flags,params[2].get_str().c_str(),n);
} else flags = 0;
if ( n >= 4 )
privkey = hush_kvprivkey(&pubkey,(char *)(n >= 4 ? params[3].get_str().c_str() : "password"));
@@ -704,14 +700,11 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
if ( hush_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 )
{
ret.push_back(Pair("error",(char *)"error verifying sig, passphrase is probably wrong"));
printf("VERIFY ERROR\n");
LogPrintf("VERIFY ERROR\n");
return ret;
} // else printf("verified immediately\n");
}
}
}
//for (i=0; i<32; i++)
// printf("%02x",((uint8_t *)&sig)[i]);
//printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize);
ret.push_back(Pair("coin",(char *)(SMART_CHAIN_SYMBOL[0] == 0 ? "HUSH3" : SMART_CHAIN_SYMBOL)));
height = chainActive.LastTip()->GetHeight();
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
@@ -749,9 +742,6 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
}
if ( (opretlen= hush_opreturnscript(opretbuf,'K',keyvalue,coresize)) == 40 )
opretlen++;
//for (i=0; i<opretlen; i++)
// printf("%02x",opretbuf[i]);
//printf(" opretbuf keylen.%d valuesize.%d height.%d (%02x %02x %02x)\n",*(uint16_t *)&keyvalue[0],*(uint16_t *)&keyvalue[2],*(uint32_t *)&keyvalue[4],keyvalue[8],keyvalue[9],keyvalue[10]);
EnsureWalletIsUnlocked();
fee = hush_kvfee(flags,opretlen,keylen);
ret.push_back(Pair("fee",(double)fee/COIN));
@@ -1823,7 +1813,6 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
BOOST_FOREACH(const COutputEntry& r, listReceived)
{
string account;
//fprintf(stderr,"recv iter %s\n",wtx.GetHash().GetHex().c_str());
if (pwalletMain->mapAddressBook.count(r.destination))
account = pwalletMain->mapAddressBook[r.destination].name;
if (fAllAccounts || (account == strAccount))
@@ -1972,9 +1961,8 @@ UniValue listtransactions(const UniValue& params, bool fHelp, const CPubKey& myp
CWalletTx *const pwtx = (*it).second.first;
if (pwtx != 0)
{
//fprintf(stderr,"pwtx iter.%d %s\n",(int32_t)pwtx->nOrderPos,pwtx->GetHash().GetHex().c_str());
ListTransactions(*pwtx, strAccount, 0, true, ret, filter);
} //else fprintf(stderr,"null pwtx\n");
}
CAccountingEntry *const pacentry = (*it).second.second;
if (pacentry != 0)
AcentryToJSON(*pacentry, strAccount, ret);
@@ -2959,7 +2947,6 @@ UniValue listunspent(const UniValue& params, bool fHelp, const CPubKey& mypk)
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
CBlockIndex *tipindex,*pindex = it->second;
uint32_t locktime;
//fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->GetHeight());
}
else if ( chainActive.LastTip() != 0 )
txheight = (chainActive.LastTip()->GetHeight() - out.nDepth - 1);
@@ -4675,7 +4662,6 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp, const CPubK
obj.push_back(Pair("outindex", (int)entry.op.n));
obj.push_back(Pair("rawconfirmations", entry.confirmations));
auto wtx = pwalletMain->mapWallet.at(entry.op.hash); //.ToString());
//fprintf(stderr,"%s: txid=%s not found in wallet!\n", __func__, entry.op.hash.ToString().c_str());
obj.push_back(Pair("time", wtx.GetTxTime()));
obj.push_back(Pair("confirmations", dpowconfs));
@@ -5245,7 +5231,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk)
// select a random address with enough confirmed balance
auto nPotentials = vPotentialAddresses.size();
if (nPotentials > 0) {
fprintf(stderr,"%s: Selecting one of %lu potential source zaddrs\n", __func__, nPotentials);
LogPrintf("%s: Selecting one of %lu potential source zaddrs\n", __func__, nPotentials);
fromaddress = vPotentialAddresses[ GetRandInt(nPotentials) ];
} else {
// Automagic zaddr source selection failed, exit honorably
@@ -5407,7 +5393,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk)
unsigned int MIN_ZOUTS=GetArg("-sietch-min-zouts", DEFAULT_MIN_ZOUTS);
if((MIN_ZOUTS<3) || (MIN_ZOUTS>MAX_ZOUTS)) {
fprintf(stderr,"%s: Sietch min zouts must be >= 3 and <= %d, setting to default value of %d\n", __FUNCTION__, MAX_ZOUTS, DEFAULT_MIN_ZOUTS );
LogPrintf("%s: Sietch min zouts must be >= 3 and <= %d, setting to default value of %d\n", __FUNCTION__, MAX_ZOUTS, DEFAULT_MIN_ZOUTS );
MIN_ZOUTS=DEFAULT_MIN_ZOUTS;
}
@@ -6025,8 +6011,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp, const CPubKey& myp
CAmount nValue = out.tx->vout[out.i].nValue;
if (maximum_utxo_size != 0) {
//fprintf(stderr, "utxo txid.%s vout.%i nValue.%li scriptpubkeylength.%i\n",out.tx->GetHash().ToString().c_str(),out.i,nValue,out.tx->vout[out.i].scriptPubKey.size());
if (nValue > maximum_utxo_size)
if (nValue > maximum_utxo_size)
continue;
if (nValue == 10000 && out.tx->vout[out.i].scriptPubKey.size() == 35)
continue;
@@ -6087,7 +6072,6 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp, const CPubKey& myp
size_t numUtxos = utxoInputs.size();
size_t numNotes = saplingNoteInputs.size();
//fprintf(stderr, "num utxos.%li\n", numUtxos);
if (numUtxos < 2 && numNotes == 0) {
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Could not find any funds to merge.");
}
@@ -6248,7 +6232,6 @@ int32_t hush_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33, void *pT
script = (uint8_t *)&out.tx->vout[out.i].scriptPubKey[0];
if ( out.tx->vout[out.i].scriptPubKey.size() != 35 || script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(notarypub33,script+1,33) != 0 )
{
//fprintf(stderr,"scriptsize.%d [0] %02x\n",(int32_t)out.tx->vout[out.i].scriptPubKey.size(),script[0]);
continue;
}
utxovalue = (uint64_t)nValue;
@@ -6256,7 +6239,6 @@ int32_t hush_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33, void *pT
utxotxid = out.tx->GetHash();
utxovout = out.i;
best_scriptPubKey = out.tx->vout[out.i].scriptPubKey;
//fprintf(stderr,"check %s/v%d %llu\n",(char *)utxotxid.GetHex().c_str(),utxovout,(long long)utxovalue);
txNew.vin.resize(1);
txNew.vout.resize((pTr!=0)+1);
@@ -6277,15 +6259,14 @@ int32_t hush_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33, void *pT
CTransaction txNewConst(txNew);
signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, utxovalue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId);
if (!signSuccess)
fprintf(stderr,"notaryvin failed to create signature\n");
LogPrintf("notaryvin failed to create signature\n");
else
{
UpdateTransaction(txNew,0,sigdata);
ptr = (uint8_t *)&sigdata.scriptSig[0];
siglen = sigdata.scriptSig.size();
for (i=0; i<siglen; i++)
utxosig[i] = ptr[i];//, fprintf(stderr,"%02x",ptr[i]);
//fprintf(stderr," siglen.%d notaryvin %s/v%d\n",siglen,utxotxid.GetHex().c_str(),utxovout);
utxosig[i] = ptr[i];
break;
}
}