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:
+3
-70
@@ -637,9 +637,6 @@ void CustomizeWork(const StratumClient& client, const StratumWork& current_work,
|
||||
nonce.insert(nonce.end(), extranonce2.begin(), extranonce2.end());
|
||||
|
||||
// nonce = extranonce1 + extranonce2
|
||||
// if (instance_of_cstratumparams.fstdErrDebugOutput) {
|
||||
// std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << " nonce = " << HexStr(nonce) << std::endl;
|
||||
// }
|
||||
|
||||
if (cb.vin.empty()) {
|
||||
const std::string msg = strprintf("%s: first transaction is missing coinbase input; unable to customize work to miner", __func__);
|
||||
@@ -737,14 +734,11 @@ std::string GetWorkUnit(StratumClient& client)
|
||||
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
|
||||
}
|
||||
|
||||
// if (instance_of_cstratumparams.fstdErrDebugOutput) std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << "hashMerkleRoot = " << new_work->block.hashMerkleRoot.ToString() << std::endl;
|
||||
|
||||
// So that block.GetHash() is correct
|
||||
//new_work->block.hashMerkleRoot = BlockMerkleRoot(new_work->block);
|
||||
new_work->block.hashMerkleRoot = new_work->block.BuildMerkleTree();
|
||||
|
||||
// NB! here we have merkle with scriptDummy script in coinbase, after CustomizeWork we should recalculate it (!)
|
||||
// if (instance_of_cstratumparams.fstdErrDebugOutput) std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << "hashMerkleRoot = " << new_work->block.hashMerkleRoot.ToString() << std::endl;
|
||||
|
||||
job_id = new_work->block.GetHash();
|
||||
//work_templates[job_id] = StratumWork(*new_work, new_work->block.vtx[0]->HasWitness());
|
||||
@@ -851,12 +845,6 @@ std::string GetWorkUnit(StratumClient& client)
|
||||
CMutableTransaction cb, bf;
|
||||
std::vector<uint256> cb_branch;
|
||||
|
||||
// if (instance_of_cstratumparams.fstdErrDebugOutput)
|
||||
// {
|
||||
// std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << " [1] cb = " << CTransaction(cb).ToString() << std::endl;
|
||||
// std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << " [1] current_work.GetBlock().vtx[0] = " << current_work.GetBlock().vtx[0].ToString() << std::endl;
|
||||
// }
|
||||
|
||||
{
|
||||
std::vector<unsigned char> extranonce1 = client.ExtraNonce1(job_id);
|
||||
|
||||
@@ -873,12 +861,6 @@ std::string GetWorkUnit(StratumClient& client)
|
||||
|
||||
}
|
||||
|
||||
// if (instance_of_cstratumparams.fstdErrDebugOutput)
|
||||
// {
|
||||
// std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << " [2] cb = " << CTransaction(cb).ToString() << std::endl;
|
||||
// std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << " [2] current_work.GetBlock().vtx[0] = " << current_work.GetBlock().vtx[0].ToString() << std::endl;
|
||||
// }
|
||||
|
||||
CBlockHeader blkhdr;
|
||||
// Setup native proof-of-work
|
||||
|
||||
@@ -992,14 +974,6 @@ bool SubmitBlock(StratumClient& client, const uint256& job_id, const StratumWork
|
||||
blkhdr.hashMerkleRoot = current_work.GetBlock().hashMerkleRoot;
|
||||
blkhdr.nNonce = (uint256) nonce;
|
||||
|
||||
// example how to display constructed block
|
||||
// if (instance_of_cstratumparams.fstdErrDebugOutput) {
|
||||
// CBlockIndex index {blkhdr};
|
||||
// index.SetHeight(current_work.nHeight);
|
||||
// std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << " blkhdr.hashPrevBlock = " << blkhdr.hashPrevBlock.GetHex() << std::endl;
|
||||
// std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << " blkhdr = " << blockToJSON(blkhdr, &index).write() << std::endl;
|
||||
// }
|
||||
|
||||
// block is constructed, now it's time to VerifyEH
|
||||
|
||||
if (instance_of_cstratumparams.fCheckEquihashSolution && !CheckEquihashSolution(&blkhdr, Params()))
|
||||
@@ -1018,7 +992,6 @@ bool SubmitBlock(StratumClient& client, const uint256& job_id, const StratumWork
|
||||
uint8_t pubkey33[33]; int32_t height = current_work.nHeight;
|
||||
res = CheckProofOfWork(blkhdr, pubkey33, height, Params().GetConsensus());
|
||||
}
|
||||
// if (instance_of_cstratumparams.fstdErrDebugOutput) std::cerr << DateTimeStrPrecise() << "res[1] = " << res << std::endl;
|
||||
|
||||
uint256 hash = blkhdr.GetHash();
|
||||
|
||||
@@ -1061,27 +1034,8 @@ bool SubmitBlock(StratumClient& client, const uint256& job_id, const StratumWork
|
||||
shares_accepted_since_last = counter_TotalShares - counter_prev;
|
||||
start = finish;
|
||||
counter_prev = counter_TotalShares;
|
||||
// std::cerr << strprintf("%f ms - %" PRIu64 "", elapsed.count(), shares_accepted_since_last) << std::endl;
|
||||
}
|
||||
|
||||
bool fDisplayDiffHUSH = true; // otherwise it will display ccminer diff
|
||||
|
||||
std::cerr << DateTimeStrPrecise() <<
|
||||
strprintf("%saccepted: %" PRIu64 "/%" PRIu64 "%s ", ColorTypeNames[cl_WHT], counter_TotalBlocks, counter_TotalShares, ColorTypeNames[cl_N] );
|
||||
if (fDisplayDiffHUSH) {
|
||||
/* hushd diff display */
|
||||
std::cerr << strprintf("%slocal %g%s ", "\x1B[90m", hush_local_diff, ColorTypeNames[cl_N]) <<
|
||||
strprintf("%s(diff %g, target %g) %s ", ColorTypeNames[cl_WHT], hush_real_diff, hush_target_diff, ColorTypeNames[cl_N]);
|
||||
} else { /* ccminer diff display */
|
||||
std::cerr << strprintf("%slocal %.3f%s ", "\x1B[90m", ccminer_local_diff, ColorTypeNames[cl_N]) <<
|
||||
strprintf("%s(diff %.3f, target %.3f) %s", ColorTypeNames[cl_WHT], ccminer_real_diff, ccminer_target_diff, ColorTypeNames[cl_N]); // ccminer diff
|
||||
}
|
||||
|
||||
std::cerr << "" <<
|
||||
strprintf("%f ms ", elapsed.count()) << // 1 share took elapsed ms
|
||||
strprintf("%s%s%s ", ColorTypeNames[cl_LGR], (res ? "yay!!!": "yes!"), ColorTypeNames[cl_N]) <<
|
||||
std::endl;
|
||||
|
||||
// (diff %g, target %g), %
|
||||
if (res) {
|
||||
|
||||
@@ -1097,7 +1051,6 @@ bool SubmitBlock(StratumClient& client, const uint256& job_id, const StratumWork
|
||||
block.nVersion = version;
|
||||
// block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||
block.hashMerkleRoot = block.BuildMerkleTree();
|
||||
//if (instance_of_cstratumparams.fstdErrDebugOutput) std::cerr << "hashMerkleRoot = " << block.hashMerkleRoot.GetHex() << std::endl;
|
||||
|
||||
block.nTime = nTime;
|
||||
// block.nNonce = nNonce;
|
||||
@@ -1106,22 +1059,12 @@ bool SubmitBlock(StratumClient& client, const uint256& job_id, const StratumWork
|
||||
block.nNonce = (uint256) nonce;
|
||||
block.nSolution = std::vector<unsigned char>(sol.begin() + 3, sol.end());
|
||||
|
||||
// example how to pre-check the equihash solution
|
||||
// if(instance_of_cstratumparams.fstdErrDebugOutput) {
|
||||
// CBlockIndex index {blkhdr};
|
||||
// index.SetHeight(-1);
|
||||
// std::cerr << "block = " << blockToJSON(block, &index, true).write(1) << std::endl;
|
||||
// std::cerr << "CheckEquihashSolution = " << CheckEquihashSolution(&block, Params()) << std::endl;
|
||||
// }
|
||||
|
||||
// std::shared_ptr<const CBlock> pblock = std::make_shared<const CBlock>(block);
|
||||
// res = ProcessNewBlock(Params(), pblock, true, NULL);
|
||||
|
||||
CValidationState state;
|
||||
res = ProcessNewBlock(0,0,state, NULL, &block, true /* forceProcessing */ , NULL);
|
||||
|
||||
//if (instance_of_cstratumparams.fstdErrDebugOutput) std::cerr << DateTimeStrPrecise() << "res[2] = " << res << std::endl;
|
||||
|
||||
// we haven't PreciousBlock, so we can't prioritize the block this way for now
|
||||
/*
|
||||
if (res) {
|
||||
@@ -1207,14 +1150,6 @@ UniValue stratum_mining_subscribe(StratumClient& client, const UniValue& params)
|
||||
* sExtraNonce1 for a given client based on m_secret.
|
||||
*/
|
||||
|
||||
// if (instance_of_cstratumparams.fstdErrDebugOutput && vExtraNonce1.size() > 3) {
|
||||
// std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << " " << strprintf("client.m_supports_extranonce = %d, [%d, %d, %d, %d], %s", client.m_supports_extranonce, vExtraNonce1[0], vExtraNonce1[1], vExtraNonce1[2], vExtraNonce1[3], sExtraNonce1) << std::endl;
|
||||
// // recalc from client.m_secret example
|
||||
// uint256 sha256;
|
||||
// CSHA256().Write(client.m_secret.begin(), 32).Finalize(sha256.begin());
|
||||
// std::cerr << __func__ << ": " << __FILE__ << "," << __LINE__ << " " << HexStr(std::vector<unsigned char>(sha256.begin(), sha256.begin() + 4)) << std::endl;
|
||||
// }
|
||||
|
||||
ret.push_back(NullUniValue);
|
||||
ret.push_back(sExtraNonce1);
|
||||
|
||||
@@ -1340,10 +1275,8 @@ UniValue stratum_mining_submit(StratumClient& client, const UniValue& params)
|
||||
bool fEWBFJobIDFixNeeded = false;
|
||||
uint256 ret;
|
||||
if (params[1].isStr()) {
|
||||
//std::cerr << "\"" << params[1].get_str() << "\"" << std::endl;
|
||||
const std::string job_id_str = params[1].get_str();
|
||||
const std::string hexDigits = "0123456789abcdef";
|
||||
// std::cerr << strprintf("\"%s\" (%d)", job_id_str, job_id_str.length()) << std::endl;
|
||||
if (job_id_str.length() == 63) {
|
||||
fEWBFJobIDFixNeeded = true;
|
||||
for(const auto& hexDigit : hexDigits) {
|
||||
@@ -1816,7 +1749,7 @@ void SendKeepAlivePackets()
|
||||
if ( (client.m_last_tip && client.m_last_tip->GetHeight() == chainActive.Tip()->GetHeight()) || (!client.m_last_tip) )
|
||||
{
|
||||
LOCK(cs_stratum);
|
||||
std::cerr << DateTimeStrPrecise() << "\033[31m" << client.m_from.ToString() << "\033[0m seems stucked (ccminer issue), need to emulate new block incoming to unstuck!" << std::endl;
|
||||
LogPrint("stratum", "%s seems stucked (ccminer issue), need to emulate new block incoming to unstuck!\n", client.m_from.ToString());
|
||||
mempool.AddTransactionsUpdated(1);
|
||||
client.m_last_tip = (client.m_last_tip ? nullptr : chainActive.Tip());
|
||||
client.m_nextid++;
|
||||
@@ -1836,7 +1769,7 @@ bool InitStratumServer()
|
||||
|
||||
int stratumPort = BaseParams().StratumPort();
|
||||
int defaultPort = GetArg("-stratumport", stratumPort);
|
||||
fprintf(stderr,"%s: Starting built-in stratum server on port %d\n",__func__, defaultPort );
|
||||
LogPrintf("%s: Starting built-in stratum server on port %d\n",__func__, defaultPort );
|
||||
|
||||
|
||||
if (!InitStratumAllowList(stratum_allow_subnets)) {
|
||||
@@ -1959,7 +1892,7 @@ UniValue rpc_stratum_updatework(const UniValue& params, bool fHelp, const CPubKe
|
||||
|
||||
// Ignore clients that aren't authorized yet.
|
||||
if (!client.m_authorized && client.m_aux_addr.empty()) {
|
||||
fprintf(stderr,"%s: Ignoring unauthorized client\n", __func__);
|
||||
LogPrint("stratum", "%s: Ignoring unauthorized client\n", __func__);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user