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
+30 -65
View File
@@ -184,7 +184,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
if(!pblocktemplate.get())
{
fprintf(stderr,"%s: pblocktemplate.get() failure\n", __func__);
LogPrintf("%s: pblocktemplate.get() failure\n", __func__);
return NULL;
}
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
@@ -294,7 +294,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight))
{
fprintf(stderr,"%s: coinbase.%d finaltx.%d expired.%d\n",__func__, tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight));
LogPrint("mempool", "%s: coinbase.%d finaltx.%d expired.%d\n",__func__, tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight));
continue;
}
txvalue = tx.GetValueOut();
@@ -373,9 +373,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
{
// check a notary didnt sign twice (this would be an invalid notarization later on and cause problems)
std::set<int> checkdupes( TMP_NotarizationNotaries.begin(), TMP_NotarizationNotaries.end() );
if ( checkdupes.size() != TMP_NotarizationNotaries.size() )
if ( checkdupes.size() != TMP_NotarizationNotaries.size() )
{
fprintf(stderr, "%s: WTFBBQ! possible notarization is signed multiple times by same notary, passed as normal transaction.\n", __func__);
} else fNotarization = true;
}
nTotalIn += tx.GetShieldedValueIn();
@@ -404,7 +403,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
Notarizations++;
if ( Notarizations > 1 )
{
fprintf(stderr, "%s: skipping notarization.%d\n",__func__, Notarizations);
LogPrint("mempool", "%s: skipping notarization.%d\n",__func__, Notarizations);
// Any attempted notarization needs to be in its own block!
continue;
}
@@ -469,7 +468,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx
{
fprintf(stderr,"%s: nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",__func__, (int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize);
LogPrint("mempool", "%s: nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",__func__, (int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize);
continue;
}
@@ -488,7 +487,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
{
fprintf(stderr,"%s: fee rate skip\n", __func__);
LogPrint("mempool", "%s: fee rate skip\n", __func__);
continue;
}
// Prioritize by fee once past the priority size or we run out of high-priority transactions
@@ -526,7 +525,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
opcodetype op;
std::vector<uint8_t> opretData;
if (txout.scriptPubKey.GetOp(it, op, opretData)) {
//std::cerr << HexStr(opretData.begin(), opretData.end()) << std::endl;
nTxOpretSize += opretData.size();
}
}
@@ -537,7 +535,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
std::cerr << __func__ << ": " << tx.GetHash().ToString() << " nTxSize=" << nTxSize << " nTxOpretSize=" << nTxOpretSize << " feeRate=" << feeRate.ToString() << " opretMinFee=" << opretMinFee << " nTxFees=" << nTxFees <<" fSpamTx=" << fSpamTx << std::endl;
continue;
}
// std::cerr << tx.GetHash().ToString() << " vecPriority.size() = " << vecPriority.size() << std::endl;
}
nTxSigOps += GetP2SHSigOpCount(tx, view);
@@ -552,7 +549,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
PrecomputedTransactionData txdata(tx);
if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId))
{
fprintf(stderr,"%s: ContextualCheckInputs failure\n",__func__);
LogPrint("mempool", "%s: ContextualCheckInputs failure\n",__func__);
continue;
}
UpdateCoins(tx, view, nHeight);
@@ -646,7 +643,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
static bool didinit = false;
if ( !didinit && nHeight > HUSH_EARLYTXID_HEIGHT && HUSH_EARLYTXID != zeroid && hush_appendACscriptpub() )
{
fprintf(stderr, "appended ccopreturn to assetchains_scriptpub.%s\n", assetchains_scriptpub.c_str());
LogPrintf("appended ccopreturn to assetchains_scriptpub.%s\n", assetchains_scriptpub.c_str());
didinit = true;
}
//txNew.vout[1].scriptPubKey = CScript() << ParseHex();
@@ -666,7 +663,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
ptr[34] = OP_CHECKSIG;
}
} else if ( (uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) {
fprintf(stderr,"timelocked chains not supported in this code!\n");
LogPrintf("timelocked chains not supported in this code!\n");
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
return(0);
@@ -679,7 +676,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
uint64_t totalsats = hush_notarypay(txNew, NotarizationNotaries, pblock->nTime, nHeight, script, scriptlen);
if ( totalsats == 0 )
{
fprintf(stderr, "Could not create notary payment, trying again.\n");
LogPrintf("Could not create notary payment, trying again.\n");
if ( !isStake )
{
LEAVE_CRITICAL_SECTION(cs_main);
@@ -687,7 +684,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
}
return(0);
}
} else fprintf(stderr, "vout 2 of notarization is not OP_RETURN scriptlen.%i\n", scriptlen);
} else LogPrintf("vout 2 of notarization is not OP_RETURN scriptlen.%i\n", scriptlen);
}
if ( ASSETCHAINS_CBOPRET != 0 )
{
@@ -734,7 +731,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
}
fprintf(stderr,"%s: TestBlockValidity failed!\n", __func__);
LogPrintf("%s: TestBlockValidity failed!\n", __func__);
//throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); // crashes the node, moved to GetBlockTemplate and issue return.
return(0);
}
@@ -813,7 +810,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight,
// scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
scriptPubKey = GetScriptForDestination(dest);
Getscriptaddress(destaddr,scriptPubKey);
fprintf(stderr,"%s: wallet disabled with mineraddress=%s\n", __func__, destaddr);
LogPrintf("%s: wallet disabled with mineraddress=%s\n", __func__, destaddr);
} else {
return NULL;
}
@@ -853,16 +850,6 @@ static bool ProcessBlockFound(CBlock* pblock)
LOCK(cs_main);
if (pblock->hashPrevBlock != chainActive.LastTip()->GetBlockHash())
{
uint256 hash; int32_t i;
hash = pblock->hashPrevBlock;
for (i=31; i>=0; i--)
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
fprintf(stderr," <- prev (stale)\n");
hash = chainActive.LastTip()->GetBlockHash();
for (i=31; i>=0; i--)
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
fprintf(stderr," <- chainTip (stale)\n");
return error("HushMiner: generated block is stale");
}
}
@@ -954,7 +941,6 @@ CBlockIndex *get_chainactive(int32_t height)
LOCK(cs_main);
return(chainActive[height]);
}
// else fprintf(stderr,"get_chainactive height %d > active.%d\n",height,chainActive.Tip()->GetHeight());
}
return(0);
}
@@ -1280,7 +1266,7 @@ void static RandomXMiner()
// If we don't have a valid chain tip to work from, wait and try again.
if (pindexPrev == nullptr) {
fprintf(stderr,"%s: null pindexPrev, trying again...\n",__func__);
LogPrint("randomx", "%s: null pindexPrev, trying again...\n",__func__);
MilliSleep(1000);
continue;
}
@@ -1341,7 +1327,7 @@ void static RandomXMiner()
}
static uint32_t counter;
if ( counter++ < 10 )
fprintf(stderr,"RandomXMiner: created illegal blockB, retry with counter=%u\n", counter);
LogPrint("randomx", "RandomXMiner: created illegal blockB, retry with counter=%u\n", counter);
sleep(1);
continue;
}
@@ -1366,10 +1352,10 @@ void static RandomXMiner()
{
static uint32_t counter;
if ( counter++ < 10 )
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",SMART_CHAIN_SYMBOL);
LogPrint("randomx", "skip generating %s on-demand block, no tx avail\n",SMART_CHAIN_SYMBOL);
sleep(10);
continue;
} else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",SMART_CHAIN_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT);
} else LogPrint("randomx", "%s vouts.%d mining.%d vs %d\n",SMART_CHAIN_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT);
}
rxdebug("%s: incrementing extra nonce\n");
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
@@ -1388,7 +1374,7 @@ void static RandomXMiner()
while (true)
{
if ( gotinvalid != 0 ) {
fprintf(stderr,"RandomXMiner: gotinvalid=%d\n",gotinvalid);
LogPrint("randomx", "RandomXMiner: gotinvalid=%d\n",gotinvalid);
break;
}
hush_longestchain();
@@ -1402,7 +1388,6 @@ void static RandomXMiner()
// Serialize block header without nSolution but with nNonce for deterministic RandomX input
randomxInput << rxInput;
// std::cerr << "RandomXMiner: randomxInput=" << HexStr(randomxInput) << "\n";
rxdebug("%s: randomxKey=%s randomxInput=%s\n", randomxKey, HexStr(randomxInput).c_str());
rxdebug("%s: calculating randomx hash\n");
@@ -1460,17 +1445,6 @@ void static RandomXMiner()
SetSkipRandomXValidation(false);
if ( !fValid )
{
h = UintToArith256(B.GetHash());
fprintf(stderr,"RandomXMiner: TestBlockValidity FAILED at ht.%d nNonce=%s hash=",
Mining_height, pblock->nNonce.ToString().c_str());
for (z=31; z>=0; z--)
fprintf(stderr,"%02x",((uint8_t *)&h)[z]);
fprintf(stderr," nSolution.size=%lu\n", B.nSolution.size());
// Dump nSolution hex for comparison with validator
fprintf(stderr,"RandomXMiner: nSolution=");
for (unsigned i = 0; i < B.nSolution.size(); i++)
fprintf(stderr,"%02x", B.nSolution[i]);
fprintf(stderr,"\n");
LogPrintf("RandomXMiner: TestBlockValidity FAILED at ht.%d, gotinvalid=1, state=%s\n",
Mining_height, state.GetRejectReason());
gotinvalid = 1;
@@ -1527,13 +1501,13 @@ void static RandomXMiner()
{
if ( Mining_height > ASSETCHAINS_MINHEIGHT )
{
fprintf(stderr,"%s: no nodes, break\n", __func__);
LogPrint("randomx", "%s: no nodes, break\n", __func__);
break;
}
}
if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
{
fprintf(stderr,"%s: nonce & 0xffff == 0xffff, break\n", __func__);
LogPrint("randomx", "%s: nonce & 0xffff == 0xffff, break\n", __func__);
break;
}
// Update nNonce and nTime
@@ -1556,7 +1530,6 @@ void static RandomXMiner()
LogPrintf("%s: destroyed vm via thread interrupt\n", __func__);
} else {
LogPrintf("%s: WARNING myVM already null in thread interrupt handler, skipping destroy (would double-free)\n", __func__);
fprintf(stderr, "%s: WARNING myVM already null in thread interrupt, would have double-freed!\n", __func__);
}
// Dataset and cache are owned by g_rxDatasetManager — do NOT release here
@@ -1565,7 +1538,7 @@ void static RandomXMiner()
} catch (const std::runtime_error &e) {
miningTimer.stop();
c.disconnect();
fprintf(stderr,"RandomXMiner: runtime error: %s\n", e.what());
LogPrintf("RandomXMiner: runtime error: %s\n", e.what());
if (myVM != nullptr) {
randomx_destroy_vm(myVM);
@@ -1624,7 +1597,7 @@ void static BitcoinMiner()
assert(solver == "tromp" || solver == "default");
LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
if ( SMART_CHAIN_SYMBOL[0] != 0 )
fprintf(stderr,"notaryid.%d Mining.%s with %s\n",notaryid,SMART_CHAIN_SYMBOL,solver.c_str());
LogPrintf("notaryid.%d Mining.%s with %s\n",notaryid,SMART_CHAIN_SYMBOL,solver.c_str());
std::mutex m_cs;
bool cancelSolver = false;
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
@@ -1637,7 +1610,7 @@ void static BitcoinMiner()
try {
if ( SMART_CHAIN_SYMBOL[0] != 0 )
fprintf(stderr,"try %s Mining with %s\n",SMART_CHAIN_SYMBOL,solver.c_str());
LogPrintf("try %s Mining with %s\n",SMART_CHAIN_SYMBOL,solver.c_str());
while (true)
{
if (chainparams.MiningRequiresPeers()) {
@@ -1667,7 +1640,7 @@ void static BitcoinMiner()
// If we don't have a valid chain tip to work from, wait and try again.
if (pindexPrev == nullptr) {
fprintf(stderr,"%s: null pindexPrev, trying again...\n",__func__);
LogPrint("pow", "%s: null pindexPrev, trying again...\n",__func__);
MilliSleep(1000);
continue;
}
@@ -1699,7 +1672,7 @@ void static BitcoinMiner()
}
static uint32_t counter;
if ( counter++ < 10 && ASSETCHAINS_STAKED == 0 )
fprintf(stderr,"created illegal blockB, retry\n");
LogPrint("pow", "created illegal blockB, retry\n");
sleep(1);
continue;
}
@@ -1723,10 +1696,10 @@ void static BitcoinMiner()
{
static uint32_t counter;
if ( counter++ < 10 )
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",SMART_CHAIN_SYMBOL);
LogPrint("pow", "skip generating %s on-demand block, no tx avail\n",SMART_CHAIN_SYMBOL);
sleep(10);
continue;
} else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",SMART_CHAIN_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT);
} else LogPrint("pow", "%s vouts.%d mining.%d vs %d\n",SMART_CHAIN_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT);
}
}
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
@@ -1806,7 +1779,7 @@ void static BitcoinMiner()
sleep(1);
if ( chainActive.LastTip()->GetHeight() >= Mining_height )
{
fprintf(stderr,"new block arrived\n");
LogPrint("pow", "new block arrived\n");
return(false);
}
}
@@ -1820,13 +1793,6 @@ void static BitcoinMiner()
MilliSleep((rand() % (r * 1000)) + 1000);
}
}
else
{
uint256 tmp = B.GetHash();
int32_t z; for (z=31; z>=0; z--)
fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]);
fprintf(stderr," mined %s block %d!\n",SMART_CHAIN_SYMBOL,Mining_height);
}
CValidationState state;
//{ LOCK(cs_main);
@@ -1932,14 +1898,14 @@ void static BitcoinMiner()
{
if ( SMART_CHAIN_SYMBOL[0] == 0 || Mining_height > ASSETCHAINS_MINHEIGHT )
{
fprintf(stderr,"no nodes, break\n");
LogPrint("pow", "no nodes, break\n");
break;
}
}
if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
{
//if ( 0 && SMART_CHAIN_SYMBOL[0] != 0 )
fprintf(stderr,"0xffff, break\n");
LogPrint("pow", "0xffff, break\n");
break;
}
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
@@ -2042,7 +2008,6 @@ void static BitcoinMiner()
g_rxDatasetManager = new RandomXDatasetManager();
if (!g_rxDatasetManager->Init()) {
LogPrintf("%s: FATAL - Failed to initialize shared RandomX dataset manager\n", __func__);
fprintf(stderr, "%s: FATAL - Failed to initialize shared RandomX dataset manager\n", __func__);
delete g_rxDatasetManager;
g_rxDatasetManager = nullptr;
delete minerThreads;