From 40519a92409c9b239a112e16a60cf9110851ae34 Mon Sep 17 00:00:00 2001 From: jamescowens Date: Sun, 31 May 2020 20:39:41 -0400 Subject: [PATCH 1/7] Remove debug2 and replace with BCLog::LogFlags::MINER --- src/init.cpp | 8 ------ src/logging.h | 1 + src/miner.cpp | 58 ++++++++++++++++++++----------------------- src/rpcblockchain.cpp | 19 -------------- src/rpcserver.cpp | 1 - src/util.cpp | 1 - src/util.h | 1 - src/wallet.cpp | 4 +-- 8 files changed, 30 insertions(+), 63 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 8790cdd524..071cef5e77 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -608,14 +608,6 @@ bool AppInit2(ThreadHandlerPtr threads) LogPrintf("Entering debug mode."); } - fDebug2 = false; - - if (GetArg("-debug2", "false") == "true") - { - fDebug2 = true; - LogPrintf("Entering GRC debug mode 2."); - } - fDebug10 = false; if (GetArg("-debug10", "false") == "true") diff --git a/src/logging.h b/src/logging.h index 0493b05fcf..019ee3c982 100644 --- a/src/logging.h +++ b/src/logging.h @@ -83,6 +83,7 @@ namespace BCLog { TALLY = (1 << 25), ACCRUAL = (1 << 26), CONTRACT = (1 << 27), + MINER = (1 << 28), ALL = ~(uint32_t)0, }; diff --git a/src/miner.cpp b/src/miner.cpp index 4e8594b2c8..0ca1ff7f51 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -129,13 +129,11 @@ bool SignClaim( return error("%s: Signature failed. Check beacon key", __func__); } - if (fDebug2) { - LogPrintf( - "%s: Signed for CPID %s and block hash %s with signature %s", - cpid->ToString(), - last_block_hash.ToString(), - HexStr(claim.m_signature)); - } + LogPrint(BCLog::LogFlags::MINER, + "%s: Signed for CPID %s and block hash %s with signature %s", + cpid->ToString(), + last_block_hash.ToString(), + HexStr(claim.m_signature)); return true; } @@ -536,7 +534,7 @@ bool CreateCoinStake( CBlock &blocknew, CKey &key, return false; } - if(fDebug2) LogPrintf("CreateCoinStake: Staking nTime/16= %d Bits= %u", + LogPrint(BCLog::LogFlags::MINER, "CreateCoinStake: Staking nTime/16= %d Bits= %u", txnew.nTime/16,blocknew.nBits); for(const auto& pcoin : CoinsToStake) @@ -576,19 +574,17 @@ bool CreateCoinStake( CBlock &blocknew, CKey &key, StakeDiffSum += StakeKernelDiff; StakeDiffMax = std::max(StakeDiffMax,StakeKernelDiff); - if (fDebug2) { - LogPrintf( -"CreateCoinStake: V%d Time %.f, Por_Nonce %.f, Bits %jd, Weight %jd\n" -" Stk %72s\n" -" Trg %72s\n" -" Diff %0.7f of %0.7f", - blocknew.nVersion, - (double)txnew.nTime, mdPORNonce, - (intmax_t)blocknew.nBits,(intmax_t)CoinWeight, - StakeKernelHash.GetHex().c_str(), StakeTarget.GetHex().c_str(), - StakeKernelDiff, GetBlockDifficulty(blocknew.nBits) - ); - } + LogPrint(BCLog::LogFlags::MINER, + "CreateCoinStake: V%d Time %.f, Por_Nonce %.f, Bits %jd, Weight %jd\n" + " Stk %72s\n" + " Trg %72s\n" + " Diff %0.7f of %0.7f", + blocknew.nVersion, + (double)txnew.nTime, mdPORNonce, + (intmax_t)blocknew.nBits,(intmax_t)CoinWeight, + StakeKernelHash.GetHex().c_str(), StakeTarget.GetHex().c_str(), + StakeKernelDiff, GetBlockDifficulty(blocknew.nBits) + ); if( StakeKernelHash <= StakeTarget ) { @@ -821,14 +817,14 @@ void SplitCoinStakeOutput(CBlock &blocknew, int64_t &nReward, bool &fEnableStake if (fEnableStakeSplit) { unsigned int nSplitStakeOutputs = min((nMaxOutputs - nOutputsUsed), GetNumberOfStakeOutputs(nRemainingStakeOutputValue, nMinStakeSplitValue, dEfficiency)); - if (fDebug2) LogPrintf("SplitCoinStakeOutput: nStakeOutputs = %u", nSplitStakeOutputs); + LogPrint(BCLog::LogFlags::MINER, "SplitCoinStakeOutput: nStakeOutputs = %u", nSplitStakeOutputs); // Set Actual Stake output value for split stakes to remaining output value divided by the number of split // stake outputs. int64_t nActualStakeOutputValue = nRemainingStakeOutputValue / nSplitStakeOutputs; - if (fDebug2) LogPrintf("SplitCoinStakeOutput: nSplitStakeOutputs = %f", nSplitStakeOutputs); - if (fDebug2) LogPrintf("SplitCoinStakeOutput: nActualStakeOutputValue = %f", CoinToDouble(nActualStakeOutputValue)); + LogPrint(BCLog::LogFlags::MINER, "SplitCoinStakeOutput: nSplitStakeOutputs = %f", nSplitStakeOutputs); + LogPrint(BCLog::LogFlags::MINER, "SplitCoinStakeOutput: nActualStakeOutputValue = %f", CoinToDouble(nActualStakeOutputValue)); int64_t nSumStakeOutputValue = 0; for (unsigned int i = 1; i < nSplitStakeOutputs; i++) @@ -884,12 +880,12 @@ unsigned int GetNumberOfStakeOutputs(int64_t &nValue, int64_t &nMinStakeSplitVal nDesiredStakeOutputValue = G * GetAverageDifficulty(160) * (3.0 / 2.0) * (1 / dEfficiency - 1) * COIN; nDesiredStakeOutputValue = max(nMinStakeSplitValue, nDesiredStakeOutputValue); - if (fDebug2) LogPrintf("GetNumberOfStakeOutputs: nDesiredStakeOutputValue = %f", CoinToDouble(nDesiredStakeOutputValue)); + LogPrint(BCLog::LogFlags::MINER, "GetNumberOfStakeOutputs: nDesiredStakeOutputValue = %f", CoinToDouble(nDesiredStakeOutputValue)); // Divide nValue by nDesiredStakeUTXOValue. We purposely want this to be integer division to round down. nStakeOutputs = max((int64_t) 1, nValue / nDesiredStakeOutputValue); - if (fDebug2) LogPrintf("GetNumberOfStakeOutputs: nStakeOutputs = %u", nStakeOutputs); + LogPrint(BCLog::LogFlags::MINER, "GetNumberOfStakeOutputs: nStakeOutputs = %u", nStakeOutputs); } return(nStakeOutputs); @@ -1135,7 +1131,7 @@ bool GetSideStakingStatusAndAlloc(SideStakeAlloc& vSideStakeAlloc) double dSumAllocation = 0.0; bool fEnableSideStaking = GetBoolArg("-enablesidestaking"); - if (fDebug2) LogPrintf("StakeMiner: fEnableSideStaking = %u", fEnableSideStaking); + LogPrint(BCLog::LogFlags::MINER, "StakeMiner: fEnableSideStaking = %u", fEnableSideStaking); // If side staking is enabled, parse destinations and allocations. We don't need to worry about any that are rejected // other than a warning message, because any unallocated rewards will go back into the coinstake output(s). @@ -1194,7 +1190,7 @@ bool GetSideStakingStatusAndAlloc(SideStakeAlloc& vSideStakeAlloc) } vSideStakeAlloc.push_back(std::pair(sAddress, dAllocation)); - if (fDebug2) LogPrintf("StakeMiner: SideStakeAlloc Address %s, Allocation %f", sAddress.c_str(), dAllocation); + LogPrint(BCLog::LogFlags::MINER, "StakeMiner: SideStakeAlloc Address %s, Allocation %f", sAddress.c_str(), dAllocation); vSubParam.clear(); } @@ -1214,7 +1210,7 @@ bool GetStakeSplitStatusAndParams(int64_t& nMinStakeSplitValue, double& dEfficie { // Parse StakeSplit and SideStaking flags. bool fEnableStakeSplit = GetBoolArg("-enablestakesplit"); - if (fDebug2) LogPrintf("StakeMiner: fEnableStakeSplit = %u", fEnableStakeSplit); + LogPrint(BCLog::LogFlags::MINER, "StakeMiner: fEnableStakeSplit = %u", fEnableStakeSplit); // If stake output splitting is enabled, determine efficiency and minimum stake split value. if (fEnableStakeSplit) @@ -1226,13 +1222,13 @@ bool GetStakeSplitStatusAndParams(int64_t& nMinStakeSplitValue, double& dEfficie else if (dEfficiency < 0.75) dEfficiency = 0.75; - if (fDebug2) LogPrintf("StakeMiner: dEfficiency = %f", dEfficiency); + LogPrint(BCLog::LogFlags::MINER, "StakeMiner: dEfficiency = %f", dEfficiency); // Pull Minimum Post Stake UTXO Split Value from config or command line parameter. // Default to 800 and do not allow it to be specified below 800 GRC. nMinStakeSplitValue = max(GetArg("-minstakesplitvalue", MIN_STAKE_SPLIT_VALUE_GRC), MIN_STAKE_SPLIT_VALUE_GRC) * COIN; - if (fDebug2) LogPrintf("StakeMiner: nMinStakeSplitValue = %f", CoinToDouble(nMinStakeSplitValue)); + LogPrint(BCLog::LogFlags::MINER, "StakeMiner: nMinStakeSplitValue = %f", CoinToDouble(nMinStakeSplitValue)); // For the definition of the constant G, please see // https://docs.google.com/document/d/1OyuTwdJx1Ax2YZ42WYkGn_UieN0uY13BTlA5G5IAN00/edit?usp=sharing diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index fca0da5c8d..6347e2c36a 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1248,25 +1248,6 @@ UniValue debug10(const UniValue& params, bool fHelp) return res; } -UniValue debug2(const UniValue& params, bool fHelp) -{ - if (fHelp || params.size() != 1) - throw runtime_error( - "debug2 \n" - "\n" - " -> Specify true or false\n" - "\n" - "Enable or disable debug mode on the fly\n"); - - UniValue res(UniValue::VOBJ); - - fDebug2 = params[0].get_bool(); - - res.pushKV("Debug2", fDebug2 ? "Entering debug mode." : "Exiting debug mode."); - - return res; -} - UniValue getlistof(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index cde2b331cf..7bf19da442 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -362,7 +362,6 @@ static const CRPCCommand vRPCCommands[] = { "currentcontractaverage", ¤tcontractaverage, cat_developer }, { "debug", &debug, cat_developer }, { "debug10", &debug10, cat_developer }, - { "debug2", &debug2, cat_developer }, { "exportstats1", &rpc_exportstats, cat_developer }, { "getblockstats", &rpc_getblockstats, cat_developer }, { "getlistof", &getlistof, cat_developer }, diff --git a/src/util.cpp b/src/util.cpp index 34faa2e76f..e15c86159c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -67,7 +67,6 @@ ArgsMap mapArgs; ArgsMultiMap mapMultiArgs; bool fDebug = false; -bool fDebug2 = false; bool fDebug10 = false; bool fPrintToConsole = false; diff --git a/src/util.h b/src/util.h index 400de2a6fa..41fdbf1b50 100644 --- a/src/util.h +++ b/src/util.h @@ -119,7 +119,6 @@ extern ArgsMap mapArgs; extern ArgsMultiMap mapMultiArgs; extern bool fDebug; -extern bool fDebug2; extern bool fDebug10; extern bool fPrintToConsole; diff --git a/src/wallet.cpp b/src/wallet.cpp index 93361d8280..9802a09cf8 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1564,7 +1564,7 @@ bool CWallet::SelectCoinsForStaking(unsigned int nSpendTime, std::vector vCoins; @@ -1590,7 +1590,7 @@ bool CWallet::SelectCoinsForStaking(unsigned int nSpendTime, std::vector= n) { - if (fDebug2 && fMiner) + if (LogInstance().WillLogCategory(BCLog::LogFlags::MINER) && fMiner) LogPrintf("SelectCoinsForStaking: UTXO=%s (BalanceToConsider=%.8f >= Value=%.8f)", pcoin->vout[i].GetHash().ToString(), BalanceToConsider / (double)COIN, n / (double)COIN); vCoinsRet.push_back(make_pair(pcoin, i)); From 0825d26961006fd704222c9825a5a7b473593eca Mon Sep 17 00:00:00 2001 From: jamescowens Date: Sun, 31 May 2020 22:03:49 -0400 Subject: [PATCH 2/7] Remove debug10 and replace with BCLog::LogFlags::NOISY --- src/contract/polls.cpp | 2 +- src/init.cpp | 11 +++-- src/kernel.cpp | 7 ++- src/logging.h | 2 + src/main.cpp | 95 ++++++++++++++++++++--------------------- src/miner.cpp | 16 +++---- src/net.cpp | 79 +++++++++++++++++----------------- src/net.h | 8 +--- src/netbase.cpp | 4 +- src/rpcblockchain.cpp | 18 +++++--- src/rpcserver.cpp | 2 +- src/scraper/scraper.cpp | 43 +++++++++++++------ src/util.cpp | 11 +++-- src/util.h | 1 - src/wallet.cpp | 4 +- 15 files changed, 161 insertions(+), 142 deletions(-) diff --git a/src/contract/polls.cpp b/src/contract/polls.cpp index 07a1821d34..0b09027764 100644 --- a/src/contract/polls.cpp +++ b/src/contract/polls.cpp @@ -467,7 +467,7 @@ double ReturnVerifiedVotingBalance(std::string sXML, bool bCreatedAfterSecurityU double dTotalVotedBalance = RoundFromString(ExtractXML(sPayload,"",""),2); double dLegacyBalance = RoundFromString(ExtractXML(sXML,"",""),0); - if (fDebug10) LogPrintf("Total Voted Balance %f, Legacy Balance %f", dTotalVotedBalance, dLegacyBalance); + LogPrint(BCLog::LogFlags::NOISY, "Total Voted Balance %f, Legacy Balance %f", dTotalVotedBalance, dLegacyBalance); if (!bCreatedAfterSecurityUpgrade) return dLegacyBalance; double dCounted = 0; diff --git a/src/init.cpp b/src/init.cpp index 071cef5e77..ffd29aa13b 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -605,15 +605,14 @@ bool AppInit2(ThreadHandlerPtr threads) if (GetArg("-debug", "false") == "true") { fDebug = true; - LogPrintf("Entering debug mode."); + LogPrintf("Enabling debug category VERBOSE from legacy debug."); + LogInstance().EnableCategory(BCLog::LogFlags::VERBOSE); } - fDebug10 = false; - if (GetArg("-debug10", "false") == "true") { - fDebug10 = true; - LogPrintf("Entering GRC debug mode 10."); + LogPrintf("Entering debug category NOISY from legacy debug mode 10."); + LogInstance().EnableCategory(BCLog::LogFlags::NOISY); } @@ -1098,7 +1097,7 @@ bool AppInit2(ThreadHandlerPtr threads) g_banman = MakeUnique(GetDataDir() / "banlist.dat", &uiInterface, GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME)); uiInterface.InitMessage(_("Loading addresses...")); - if (fDebug10) LogPrintf("Loading addresses..."); + LogPrint(BCLog::LogFlags::NOISY, "Loading addresses..."); nStart = GetTimeMillis(); { diff --git a/src/kernel.cpp b/src/kernel.cpp index df972bbcd7..e3dc809920 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -280,10 +280,9 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod int64_t nModifierTime = 0; if (!GetLastStakeModifier(pindexPrev, nStakeModifier, nModifierTime)) return error("ComputeNextStakeModifier: unable to get last modifier"); - if (fDebug10) - { - LogPrintf("ComputeNextStakeModifier: prev modifier=0x%016" PRIx64 " time=%s", nStakeModifier, DateTimeStrFormat(nModifierTime)); - } + + LogPrint(BCLog::LogFlags::VERBOSE, "ComputeNextStakeModifier: prev modifier=0x%016" PRIx64 " time=%s", nStakeModifier, DateTimeStrFormat(nModifierTime)); + if (nModifierTime / nModifierInterval >= pindexPrev->GetBlockTime() / nModifierInterval) return true; diff --git a/src/logging.h b/src/logging.h index 019ee3c982..d61ff84596 100644 --- a/src/logging.h +++ b/src/logging.h @@ -84,6 +84,8 @@ namespace BCLog { ACCRUAL = (1 << 26), CONTRACT = (1 << 27), MINER = (1 << 28), + VERBOSE = (1 << 29), // This corresponds to the old horizontal category "debug". + NOISY = (1 << 30), // This corresponds to the old horizontal category "debug10". ALL = ~(uint32_t)0, }; diff --git a/src/main.cpp b/src/main.cpp index 1331faaa50..f192a747bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -192,8 +192,8 @@ double GetEstimatedNetworkWeight(unsigned int nPoSInterval) // The constant below comes from (MaxHash / StandardDifficultyTarget) * 16 sec / 90 sec. If you divide it by 80 to convert to GRC you // get the familiar 9544517.40667 result = 763561392.533 * GetAverageDifficulty(nPoSInterval); - if (fDebug10) LogPrintf("GetEstimatedNetworkWeight debug: Network Weight = %f", result); - if (fDebug10) LogPrintf("GetEstimatedNetworkWeight debug: Network Weight in GRC = %f", result / 80.0); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedNetworkWeight debug: Network Weight = %f", result); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedNetworkWeight debug: Network Weight in GRC = %f", result / 80.0); return result; } @@ -285,8 +285,8 @@ double GetAverageDifficulty(unsigned int nPoSInterval) { dDiffSum += dDiff; nStakesHandled++; - if (fDebug10) LogPrintf("GetAverageDifficulty debug: dDiff = %f", dDiff); - if (fDebug10) LogPrintf("GetAverageDifficulty debug: nStakesHandled = %u", nStakesHandled); + LogPrint(BCLog::LogFlags::NOISY, "GetAverageDifficulty debug: dDiff = %f", dDiff); + LogPrint(BCLog::LogFlags::NOISY, "GetAverageDifficulty debug: nStakesHandled = %u", nStakesHandled); } } @@ -294,7 +294,7 @@ double GetAverageDifficulty(unsigned int nPoSInterval) } result = nStakesHandled ? dDiffSum / nStakesHandled : 0; - if (fDebug10) LogPrintf("GetAverageDifficulty debug: Average dDiff = %f", result); + LogPrint(BCLog::LogFlags::NOISY, "GetAverageDifficulty debug: Average dDiff = %f", result); return result; } @@ -331,7 +331,7 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double // if dConfidence = 0, then the result must be 0. if (!dConfidence) { - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: Confidence of 0 specified: ETTS = %f", result); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: Confidence of 0 specified: ETTS = %f", result); return result; } @@ -349,13 +349,13 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double // Get out early if not staking, ignore_staking_status is false, and not able_to_stake and set return value of 0. if (!ignore_staking_status && !staking && !able_to_stake) { - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: Not staking: ETTS = %f", result); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: Not staking: ETTS = %f", result); return result; } int64_t nValue = 0; int64_t nCurrentTime = GetAdjustedTime(); - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: nCurrentTime = %i", nCurrentTime); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: nCurrentTime = %i", nCurrentTime); CTxDB txdb("r"); @@ -363,7 +363,7 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double // 16 hours * 3600 / 256 = 225 time bins for evaluation. Otherwise for a large number of UTXO's, this algorithm could become // really expensive. const int ETTS_TIMESTAMP_MASK = (16 * (STAKE_TIMESTAMP_MASK + 1)) - 1; - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: ETTS_TIMESTAMP_MASK = %x", ETTS_TIMESTAMP_MASK); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: ETTS_TIMESTAMP_MASK = %x", ETTS_TIMESTAMP_MASK); int64_t BalanceAvailForStaking = 0; vector vCoins; @@ -373,13 +373,13 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double BalanceAvailForStaking = pwalletMain->GetBalance() - nReserveBalance; - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: BalanceAvailForStaking = %u", BalanceAvailForStaking); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: BalanceAvailForStaking = %u", BalanceAvailForStaking); // Get out early if no balance available and set return value of 0. This should already have happened above, because with no // balance left after reserve, staking should be disabled; however, just to be safe... if (BalanceAvailForStaking <= 0) { - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: No balance available: ETTS = %f", result); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: No balance available: ETTS = %f", result); return result; } @@ -398,16 +398,16 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double UniqueUTXOTimes.insert(nCurrentTime); // Debug output cooldown... - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: nStakeMinAge = %i", nStakeMinAge); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: nStakeMinAge = %i", nStakeMinAge); // If dDiff = 0 from supplied argument (which is also the default), then derive a smoothed difficulty over the default PoSInterval of 40 blocks by calling // GetAverageDifficulty(40), otherwise let supplied argument dDiff stand. if (!dDiff) dDiff = GetAverageDifficulty(40); - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: dDiff = %f", dDiff); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: dDiff = %f", dDiff); // The stake probability per "throw" of 1 weight unit = target value at diff of 1.0 / (maxhash * diff). This happens effectively every STAKE_TIMESTAMP_MASK+1 sec. double dUnitStakeProbability = 1 / (4295032833.0 * dDiff); - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: dUnitStakeProbability = %e", dUnitStakeProbability); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: dUnitStakeProbability = %e", dUnitStakeProbability); int64_t nTime = 0; @@ -431,7 +431,7 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double if (BalanceAvailForStaking >= nValue && nValue >= 1250000) { vUTXO.push_back(std::pair( nTime, nValue)); - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: pair (relative to current time: <%i, %i>", nTime - nCurrentTime, nValue); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: pair (relative to current time: <%i, %i>", nTime - nCurrentTime, nValue); // Only record a time below if it is after nCurrentTime, because UTXO's that have matured already are already stakeable and can be grouped (will be found) // by the nCurrentTime record that was already injected above. @@ -460,7 +460,7 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double for (auto& iterUTXO : vUTXO) { - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: Unique UTXO Time: %u, vector pair <%u, %u>", nTime, iterUTXO.first, iterUTXO.second); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: Unique UTXO Time: %u, vector pair <%u, %u>", nTime, iterUTXO.first, iterUTXO.second); // If the "negative Gantt chart bar" is ending or has ended for a UTXO, it now accumulates probability. (I.e. the event time being checked // is greater than or equal to the cooldown expiration of the UTXO.) @@ -471,15 +471,15 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double nCoinWeight = iterUTXO.second / 1250000; dProbAccumulator = 1 - ((1 - dProbAccumulator) * (1 - (dUnitStakeProbability * nCoinWeight))); - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: dProbAccumulator = %e", dProbAccumulator); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: dProbAccumulator = %e", dProbAccumulator); } } nDeltaTime = nTime - nTimePrev; nThrows = nDeltaTime / (STAKE_TIMESTAMP_MASK + 1); - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: nThrows = %i", nThrows); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: nThrows = %i", nThrows); dCumulativeProbability = 1 - ((1 - dCumulativeProbability) * pow((1 - dProbAccumulator), nThrows)); - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: dCumulativeProbability = %e", dCumulativeProbability); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: dCumulativeProbability = %e", dCumulativeProbability); if (dCumulativeProbability >= dConfidence) break; @@ -493,26 +493,26 @@ double GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, double // be greater than zero. We must compute the amount of time beyond nTime that is required to bridge the gap between // dCumulativeProbability and dConfidence. If (dConfidence - dCumulativeProbability) <= 0 then we overshot during the Gantt chart area, // and we will back off by nThrows amount, which will now be negative. - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: dProbAccumulator = %e", dProbAccumulator); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: dProbAccumulator = %e", dProbAccumulator); // Shouldn't happen because if we are down here, we are staking, and there have to be eligible UTXO's, but just in case... if (dProbAccumulator == 0.0) { - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: ERROR in dProbAccumulator calculations"); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: ERROR in dProbAccumulator calculations"); return result; } - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: dConfidence = %f", dConfidence); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: dConfidence = %f", dConfidence); // If nThrows is negative, this just means we overshot in the Gantt chart loop and have to backtrack by nThrows. nThrows = (int64_t)((log(1 - dConfidence) - log(1 - dCumulativeProbability)) / log(1 - dProbAccumulator)); - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: nThrows = %i", nThrows); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: nThrows = %i", nThrows); nDeltaTime = nThrows * (STAKE_TIMESTAMP_MASK + 1); - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: nDeltaTime = %i", nDeltaTime); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: nDeltaTime = %i", nDeltaTime); // Because we are looking at the delta time required past nTime, which is where we exited the Gantt chart loop. result = nDeltaTime + nTime - nCurrentTime; - if (fDebug10) LogPrintf("GetEstimatedTimetoStake debug: ETTS at %d confidence = %i", dConfidence, result); + LogPrint(BCLog::LogFlags::NOISY, "GetEstimatedTimetoStake debug: ETTS at %d confidence = %i", dConfidence, result); return result; } @@ -2821,14 +2821,14 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) nStakeReward = nTxValueOut - nTxValueIn; if (tx.vout.size() > 3 && pindex->nHeight > nGrandfather) bIsDPOR = true; // ResearchAge: Verify vouts cannot contain any other payments except coinstake: PASS (GetValueOut returns the sum of all spent coins in the coinstake) - if (fDebug10) + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) { int64_t nTotalCoinstake = 0; for (unsigned int i = 0; i < tx.vout.size(); i++) { nTotalCoinstake += tx.vout[i].nValue; } - if (fDebug10) LogPrintf(" nHeight %d; nTCS %f; nTxValueOut %f", + LogPrint(BCLog::LogFlags::NOISY, " nHeight %d; nTCS %f; nTxValueOut %f", pindex->nHeight,CoinToDouble(nTotalCoinstake),CoinToDouble(nTxValueOut)); } @@ -3443,7 +3443,7 @@ bool CBlock::CheckBlock(std::string sCaller, int height1, int64_t Mint, bool fCh { double blockVersion = BlockVersion(claim.m_client_version); double cvn = ClientVersionNew(); - if (fDebug10) LogPrintf("BV %f, CV %f ",blockVersion,cvn); + LogPrint(BCLog::LogFlags::NOISY, "BV %f, CV %f ",blockVersion,cvn); // Enforce Beacon Age if (blockVersion < 3588 && height1 > 860500 && !fTestNet) return error("CheckBlock[]: Old client spamming new blocks after mandatory upgrade "); @@ -4516,8 +4516,9 @@ bool SecurityTest(CNode* pfrom, bool acid_test) bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived) { RandAddSeedPerfmon(); - if (fDebug10) - LogPrintf("received: %s from %s (%" PRIszu " bytes)", strCommand, pfrom->addrName, vRecv.size()); + + LogPrint(BCLog::LogFlags::NOISY, "received: %s from %s (%" PRIszu " bytes)", strCommand, pfrom->addrName, vRecv.size()); + if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE"); @@ -4562,14 +4563,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, >> nTime >> addrMe; - if (fDebug10) - LogPrintf("received aries version %i ...", pfrom->nVersion); + LogPrint(BCLog::LogFlags::NOISY, "received aries version %i ...", pfrom->nVersion); int64_t timedrift = std::abs(GetAdjustedTime() - nTime); if (timedrift > (8*60)) { - if (fDebug10) LogPrintf("Disconnecting unauthorized peer with Network Time so far off by %" PRId64 " seconds!", timedrift); + LogPrint(BCLog::LogFlags::NOISY, "Disconnecting unauthorized peer with Network Time so far off by %" PRId64 " seconds!", timedrift); pfrom->Misbehaving(100); pfrom->fDisconnect = true; return false; @@ -4580,7 +4580,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (pfrom->nVersion < 180321 && fTestNet) { // disconnect from peers older than this proto version - if (fDebug10) LogPrintf("Testnet partner %s using obsolete version %i; disconnecting", pfrom->addr.ToString(), pfrom->nVersion); + LogPrint(BCLog::LogFlags::NOISY, "Testnet partner %s using obsolete version %i; disconnecting", pfrom->addr.ToString(), pfrom->nVersion); pfrom->fDisconnect = true; return false; } @@ -4588,7 +4588,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (pfrom->nVersion < MIN_PEER_PROTO_VERSION) { // disconnect from peers older than this proto version - if (fDebug10) LogPrintf("partner %s using obsolete version %i; disconnecting", pfrom->addr.ToString(), pfrom->nVersion); + LogPrint(BCLog::LogFlags::NOISY, "partner %s using obsolete version %i; disconnecting", pfrom->addr.ToString(), pfrom->nVersion); pfrom->fDisconnect = true; return false; } @@ -4596,7 +4596,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (pfrom->nVersion < 180323 && !fTestNet && pindexBest->nHeight > 860500) { // disconnect from peers older than this proto version - Enforce Beacon Age - 3-26-2017 - if (fDebug10) LogPrintf("partner %s using obsolete version %i (before enforcing beacon age); disconnecting", pfrom->addr.ToString(), pfrom->nVersion); + LogPrint(BCLog::LogFlags::NOISY, "partner %s using obsolete version %i (before enforcing beacon age); disconnecting", pfrom->addr.ToString(), pfrom->nVersion); pfrom->fDisconnect = true; return false; } @@ -4604,7 +4604,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (!fTestNet && pfrom->nVersion < 180314) { // disconnect from peers older than this proto version - if (fDebug10) LogPrintf("ResearchAge: partner %s using obsolete version %i; disconnecting", pfrom->addr.ToString(), pfrom->nVersion); + LogPrint(BCLog::LogFlags::NOISY, "ResearchAge: partner %s using obsolete version %i; disconnecting", pfrom->addr.ToString(), pfrom->nVersion); pfrom->fDisconnect = true; return false; } @@ -4735,7 +4735,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->fSuccessfullyConnected = true; - if (fDebug10) LogPrintf("receive version message: version %d, blocks=%d, us=%s, them=%s, peer=%s", pfrom->nVersion, + LogPrint(BCLog::LogFlags::NOISY, "receive version message: version %d, blocks=%d, us=%s, them=%s, peer=%s", pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), addrFrom.ToString(), pfrom->addr.ToString()); cPeerBlockCounts.input(pfrom->nStartingHeight); @@ -4865,8 +4865,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, fAlreadyHave = fAlreadyHave && CScraperManifest::AlreadyHave(pfrom, inv); } - if (fDebug10) - LogPrintf(" got inventory: %s %s", inv.ToString(), fAlreadyHave ? "have" : "new"); + LogPrint(BCLog::LogFlags::NOISY, " got inventory: %s %s", inv.ToString(), fAlreadyHave ? "have" : "new"); if (!fAlreadyHave) pfrom->AskFor(inv); @@ -4877,8 +4876,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // the last block in an inv bundle sent in response to getblocks. Try to detect // this situation and push another getblocks to continue. pfrom->PushGetBlocks(mapBlockIndex[inv.hash], uint256(), true); - if (fDebug10) - LogPrintf("force getblock request: %s", inv.ToString()); + LogPrint(BCLog::LogFlags::NOISY, "force getblock request: %s", inv.ToString()); } // Track requests for our stuff @@ -5151,7 +5149,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, uint256 hashBlock = block.GetHash(true); LogPrintf(" Received block %s; ", hashBlock.ToString()); - if (fDebug10) block.print(); + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) block.print(); CInv inv(MSG_BLOCK, hashBlock); pfrom->AddInventoryKnown(inv); @@ -5384,10 +5382,9 @@ bool ProcessMessages(CNode* pfrom) // get next message CNetMessage& msg = *it; - //if (fDebug10) - // LogPrintf("ProcessMessages(message %u msgsz, %zu bytes, complete:%s)", - // msg.hdr.nMessageSize, msg.vRecv.size(), - // msg.complete() ? "Y" : "N"); + LogPrint(BCLog::LogFlags::NOISY, "ProcessMessages(message %u msgsz, %zu bytes, complete:%s)", + msg.hdr.nMessageSize, msg.vRecv.size(), + msg.complete() ? "Y" : "N"); // end, if an incomplete message is found if (!msg.complete()) @@ -5398,7 +5395,7 @@ bool ProcessMessages(CNode* pfrom) // Scan for message start if (memcmp(msg.hdr.pchMessageStart, pchMessageStart, sizeof(pchMessageStart)) != 0) { - if (fDebug10) LogPrintf("PROCESSMESSAGE: INVALID MESSAGESTART"); + LogPrint(BCLog::LogFlags::NOISY, "PROCESSMESSAGE: INVALID MESSAGESTART"); fOk = false; break; } @@ -5463,7 +5460,7 @@ bool ProcessMessages(CNode* pfrom) if (!fRet) { - if (fDebug10) LogPrintf("ProcessMessage(%s, %u bytes) FAILED", strCommand, nMessageSize); + LogPrint(BCLog::LogFlags::NOISY, "ProcessMessage(%s, %u bytes) FAILED", strCommand, nMessageSize); } } diff --git a/src/miner.cpp b/src/miner.cpp index 0ca1ff7f51..76fe2b3a26 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -284,7 +284,7 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev) CTransaction txPrev; CTxIndex txindex; - if (fDebug10) LogPrintf("Enumerating tx %s ",tx.GetHash().GetHex()); + LogPrint(BCLog::LogFlags::NOISY, "Enumerating tx %s ",tx.GetHash().GetHex()); if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex)) { @@ -307,7 +307,7 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev) // Use list for automatic deletion vOrphan.push_back(COrphan(&tx)); porphan = &vOrphan.back(); - if (fDebug10) LogPrintf("Orphan tx %s ",tx.GetHash().GetHex()); + LogPrint(BCLog::LogFlags::NOISY, "Orphan tx %s ",tx.GetHash().GetHex()); msMiningErrorsExcluded += tx.GetHash().GetHex() + ":ORPHAN;"; } mapDependers[txin.prevout.hash].push_back(porphan); @@ -416,7 +416,7 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev) bool fInvalid; if (!tx.FetchInputs(txdb, mapTestPoolTmp, false, true, mapInputs, fInvalid)) { - if (fDebug10) LogPrintf("Unable to fetch inputs for tx %s ", tx.GetHash().GetHex()); + LogPrint(BCLog::LogFlags::NOISY, "Unable to fetch inputs for tx %s ", tx.GetHash().GetHex()); msMiningErrorsExcluded += tx.GetHash().GetHex() + ":UnableToFetchInputs;"; continue; } @@ -424,7 +424,7 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev) int64_t nTxFees = tx.GetValueIn(mapInputs)-tx.GetValueOut(); if (nTxFees < nMinFee) { - if (fDebug10) LogPrintf("Not including tx %s due to TxFees of %" PRId64 ", bare min fee is %" PRId64, tx.GetHash().GetHex(), nTxFees, nMinFee); + LogPrint(BCLog::LogFlags::NOISY, "Not including tx %s due to TxFees of %" PRId64 ", bare min fee is %" PRId64, tx.GetHash().GetHex(), nTxFees, nMinFee); msMiningErrorsExcluded += tx.GetHash().GetHex() + ":FeeTooSmall(" + RoundToString(CoinToDouble(nFees),8) + "," +RoundToString(CoinToDouble(nMinFee),8) + ");"; continue; @@ -433,7 +433,7 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev) nTxSigOps += tx.GetP2SHSigOpCount(mapInputs); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) { - if (fDebug10) LogPrintf("Not including tx %s due to exceeding max sigops of %d, sigops is %d", + LogPrint(BCLog::LogFlags::NOISY, "Not including tx %s due to exceeding max sigops of %d, sigops is %d", tx.GetHash().GetHex(), (nBlockSigOps+nTxSigOps), MAX_BLOCK_SIGOPS); msMiningErrorsExcluded += tx.GetHash().GetHex() + ":ExceededSigOps(" + ToString(nBlockSigOps) + "," + ToString(nTxSigOps) + ")(" @@ -444,7 +444,7 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev) if (!tx.ConnectInputs(txdb, mapInputs, mapTestPoolTmp, CDiskTxPos(1,1,1), pindexPrev, false, true)) { - if (fDebug10) LogPrintf("Unable to connect inputs for tx %s ",tx.GetHash().GetHex()); + LogPrint(BCLog::LogFlags::NOISY, "Unable to connect inputs for tx %s ",tx.GetHash().GetHex()); msMiningErrorsExcluded += tx.GetHash().GetHex() + ":UnableToConnectInputs();"; continue; } @@ -459,7 +459,7 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev) nBlockSigOps += nTxSigOps; nFees += nTxFees; - if (fDebug10 || GetBoolArg("-printpriority")) + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY) || GetBoolArg("-printpriority")) { LogPrintf("priority %.1f feeperkb %.1f txid %s", dPriority, dFeePerKb, tx.GetHash().ToString()); @@ -484,7 +484,7 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev) } } - if (fDebug10 || GetBoolArg("-printpriority")) + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY) || GetBoolArg("-printpriority")) LogPrintf("CreateNewBlock(): total size %" PRIu64, nBlockSize); } diff --git a/src/net.cpp b/src/net.cpp index f3ef44e8f8..f5958ff32e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -290,14 +290,14 @@ bool RecvLine(SOCKET hSocket, string& strLine) if (nBytes == 0) { // socket closed - if (fDebug10) LogPrintf("socket closed"); + LogPrint(BCLog::LogFlags::NOISY, "socket closed"); return false; } else { // socket error int nErr = WSAGetLastError(); - if (fDebug10) LogPrintf("recv err: %d", nErr); + LogPrint(BCLog::LogFlags::NOISY, "recv err: %d", nErr); return false; } } @@ -345,7 +345,7 @@ bool AddLocal(const CService& addr, int nScore) try { - if (fDebug10) LogPrintf("AddLocal(%s,%i)", addr.ToString(), nScore); + LogPrint(BCLog::LogFlags::NOISY, "AddLocal(%s,%i)", addr.ToString(), nScore); { LOCK(cs_mapLocalHost); @@ -428,7 +428,7 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha SOCKET hSocket; if (!ConnectSocket(addrConnect, hSocket)) { - if (fDebug10) LogPrintf("GetMyExternalIP() : unable to connect to %s ", addrConnect.ToString()); + LogPrint(BCLog::LogFlags::NOISY, "GetMyExternalIP() : unable to connect to %s ", addrConnect.ToString()); return false; } @@ -461,7 +461,7 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha while (strLine.size() > 0 && isspace(strLine[strLine.size()-1])) strLine.resize(strLine.size()-1); CService addr(strLine,0,true); - if (fDebug10) LogPrintf("GetMyExternalIP() received [%s] %s", strLine, addr.ToString()); + LogPrint(BCLog::LogFlags::NOISY, "GetMyExternalIP() received [%s] %s", strLine, addr.ToString()); if (!addr.IsValid() || !addr.IsRoutable()) return false; ipRet.SetIP(addr); @@ -622,7 +622,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest) { addrman.Attempt(addrConnect); /// debug print - if (fDebug10) LogPrintf("connected %s", pszDest ? pszDest : addrConnect.ToString()); + LogPrint(BCLog::LogFlags::NOISY, "connected %s", pszDest ? pszDest : addrConnect.ToString()); // Set to non-blocking #ifdef WIN32 u_long nOne = 1; @@ -661,7 +661,7 @@ void CNode::CloseSocketDisconnect() fDisconnect = true; if (hSocket != INVALID_SOCKET) { - if (fDebug10) LogPrintf("disconnecting node %s", addrName); + LogPrint(BCLog::LogFlags::NOISY, "disconnecting node %s", addrName); closesocket(hSocket); hSocket = INVALID_SOCKET; @@ -719,7 +719,7 @@ void CNode::PushVersion() CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService("0.0.0.0",0))); CAddress addrMe = GetLocalAddress(&addr); RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); - if (fDebug10) LogPrintf("send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s", + LogPrint(BCLog::LogFlags::NOISY, "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), addrYou.ToString(), addr.ToString()); std::string sboinchashargs; @@ -966,7 +966,7 @@ void SocketSendData(CNode *pnode) int nErr = WSAGetLastError(); if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS) { - if (fDebug10) LogPrintf("socket send error %d", nErr); + LogPrint(BCLog::LogFlags::NOISY, "socket send error %d", nErr); pnode->CloseSocketDisconnect(); } } @@ -1009,7 +1009,7 @@ void ThreadSocketHandler(void* parg) void ThreadSocketHandler2(void* parg) { - if (fDebug10) LogPrintf("ThreadSocketHandler started"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadSocketHandler started"); list vNodesDisconnected; unsigned int nPrevNodeCount = 0; @@ -1142,7 +1142,7 @@ void ThreadSocketHandler2(void* parg) if (have_fds) { int nErr = WSAGetLastError(); - if (fDebug10) LogPrintf("socket select error %d", nErr); + LogPrint(BCLog::LogFlags::NOISY, "socket select error %d", nErr); for (unsigned int i = 0; i <= hSocketMax; i++) FD_SET(i, &fdsetRecv); } @@ -1183,18 +1183,21 @@ void ThreadSocketHandler2(void* parg) } else if (nInbound >= GetArg("-maxconnections", 250) - MAX_OUTBOUND_CONNECTIONS) { - if (fDebug10) - LogPrintf("Surpassed max inbound connections maxconnections:%" PRId64 " minus max_outbound:%i", GetArg("-maxconnections",250), MAX_OUTBOUND_CONNECTIONS); + LogPrint(BCLog::LogFlags::NOISY, + "Surpassed max inbound connections maxconnections:%" PRId64 " minus max_outbound:%i", + GetArg("-maxconnections",250), + MAX_OUTBOUND_CONNECTIONS); + closesocket(hSocket); } else if (g_banman->IsBanned(addr)) { - if (fDebug10) LogPrintf("connection from %s dropped (banned)", addr.ToString()); + LogPrint(BCLog::LogFlags::NOISY, "connection from %s dropped (banned)", addr.ToString()); closesocket(hSocket); } else { - if (fDebug10) LogPrintf("accepted connection %s", addr.ToString()); + LogPrint(BCLog::LogFlags::NOISY, "accepted connection %s", addr.ToString()); CNode* pnode = new CNode(hSocket, addr, "", true); pnode->AddRef(); { @@ -1251,7 +1254,7 @@ void ThreadSocketHandler2(void* parg) // socket closed gracefully if (!pnode->fDisconnect) { - if (fDebug10) LogPrintf("socket closed"); + LogPrint(BCLog::LogFlags::NOISY, "socket closed"); } pnode->CloseSocketDisconnect(); } @@ -1263,7 +1266,7 @@ void ThreadSocketHandler2(void* parg) { if (!pnode->fDisconnect) { - if (fDebug10) LogPrintf("socket recv error %d", nErr); + LogPrint(BCLog::LogFlags::NOISY, "socket recv error %d", nErr); } pnode->CloseSocketDisconnect(); } @@ -1290,8 +1293,8 @@ void ThreadSocketHandler2(void* parg) // Consider this for future removal as this really is not beneficial nor harmful. if ((GetAdjustedTime() - pnode->nTimeConnected) > (60*60*2) && (vNodes.size() > (MAX_OUTBOUND_CONNECTIONS*.75))) { - if (fDebug10) - LogPrintf("Node %s connected longer than 2 hours with connection count of %zd, disconnecting. ", NodeAddress(pnode), vNodes.size()); + LogPrint(BCLog::LogFlags::NOISY, "Node %s connected longer than 2 hours with connection count of %zd, disconnecting. ", + NodeAddress(pnode), vNodes.size()); pnode->fDisconnect = true; @@ -1304,8 +1307,8 @@ void ThreadSocketHandler2(void* parg) { if (pnode->nLastRecv == 0 || pnode->nLastSend == 0) { - if (fDebug10) - LogPrintf("socket no message in first %d seconds, %d %d", PEER_TIMEOUT, pnode->nLastRecv != 0, pnode->nLastSend != 0); + LogPrint(BCLog::LogFlags::NOISY, "socket no message in first %d seconds, %d %d", + PEER_TIMEOUT, pnode->nLastRecv != 0, pnode->nLastSend != 0); pnode->fDisconnect = true; @@ -1377,7 +1380,7 @@ void ThreadMapPort(void* parg) void ThreadMapPort2(void* parg) { - if (fDebug10) LogPrintf("ThreadMapPort started"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadMapPort started"); std::string port = strprintf("%u", GetListenPort()); const char * multicastif = 0; @@ -1471,7 +1474,7 @@ void ThreadMapPort2(void* parg) i++; } } else { - if (fDebug10) LogPrintf("No valid UPnP IGDs found"); + LogPrint(BCLog::LogFlags::NOISY, "No valid UPnP IGDs found"); freeUPNPDevlist(devlist); devlist = 0; if (r != 0) FreeUPNPUrls(&urls); @@ -1528,24 +1531,24 @@ void ThreadDNSAddressSeed(void* parg) } catch(boost::thread_interrupted&) { - if (fDebug10) LogPrintf("ThreadDNSAddressSeed exited (interrupt)"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadDNSAddressSeed exited (interrupt)"); return; } catch (...) { throw; // support pthread_cancel() } - if (fDebug10) LogPrintf("ThreadDNSAddressSeed exited"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadDNSAddressSeed exited"); } void ThreadDNSAddressSeed2(void* parg) { - if (fDebug10) LogPrintf("ThreadDNSAddressSeed started"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadDNSAddressSeed started"); int found = 0; if (!fTestNet) { - if (fDebug10) LogPrintf("Loading addresses from DNS seeds (could take a while)"); + LogPrint(BCLog::LogFlags::NOISY, "Loading addresses from DNS seeds (could take a while)"); for (unsigned int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) { if (HaveNameProxy()) { @@ -1569,7 +1572,7 @@ void ThreadDNSAddressSeed2(void* parg) } } - if (fDebug10) LogPrintf("%d addresses found from DNS seeds", found); + LogPrint(BCLog::LogFlags::NOISY, "%d addresses found from DNS seeds", found); } @@ -1597,7 +1600,7 @@ void DumpAddresses() CAddrDB adb; adb.Write(addrman); - if (fDebug10) LogPrintf("Flushed %d addresses to peers.dat %" PRId64 "ms", addrman.size(), GetTimeMillis() - nStart); + LogPrint(BCLog::LogFlags::NOISY, "Flushed %d addresses to peers.dat %" PRId64 "ms", addrman.size(), GetTimeMillis() - nStart); } @@ -1681,7 +1684,7 @@ void static ProcessOneShot() void static ThreadStakeMiner(void* parg) { - if (fDebug10) LogPrintf("ThreadStakeMiner started"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadStakeMiner started"); CWallet* pwallet = (CWallet*)parg; try { @@ -1705,7 +1708,7 @@ void static ThreadStakeMiner(void* parg) void static ThreadScraper(void* parg) { - if (fDebug10) LogPrintf("ThreadSraper starting"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadSraper starting"); try { fScraperActive = true; @@ -1733,7 +1736,7 @@ void static ThreadScraper(void* parg) void static ThreadNeuralNetwork(void* parg) { - if (fDebug10) LogPrintf("ThreadNeuralNetwork starting"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadNeuralNetwork starting"); try { NeuralNetwork(); @@ -1776,7 +1779,7 @@ uint64_t CNode::GetTotalBytesSent() void ThreadOpenConnections2(void* parg) { - if (fDebug10) LogPrintf("ThreadOpenConnections started"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadOpenConnections started"); // Connect to specific addresses if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) @@ -1918,7 +1921,7 @@ void ThreadOpenAddedConnections(void* parg) void ThreadOpenAddedConnections2(void* parg) { - if (fDebug10) LogPrintf("ThreadOpenAddedConnections started"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadOpenAddedConnections started"); if (mapArgs.count("-addnode") == 0) return; @@ -2040,7 +2043,7 @@ void ThreadMessageHandler(void* parg) void ThreadMessageHandler2(void* parg) { - if (fDebug10) LogPrintf("ThreadMessageHandler started"); + LogPrint(BCLog::LogFlags::NOISY, "ThreadMessageHandler started"); while (!fShutdown) { vector vNodesCopy; @@ -2160,12 +2163,12 @@ bool BindListenPort(const CService &addrBind, string& strError) // Allow binding if the port is still in TIME_WAIT state after // the program was closed and restarted. Not an issue on windows. if (setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int)) < 0) - if (fDebug10) LogPrintf("setsockopt(SO_REUSEADDR) failed"); + LogPrint(BCLog::LogFlags::NOISY, "setsockopt(SO_REUSEADDR) failed"); #ifdef SO_REUSEPORT // Not all systems have SO_REUSEPORT. Required by OSX, available in some // Linux flavors. if (setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEPORT, (void*)&nOne, sizeof(int)) < 0) - if (fDebug10) LogPrintf("setsockopt(SO_SO_REUSEPORT) failed"); + LogPrint(BCLog::LogFlags::NOISY, "setsockopt(SO_SO_REUSEPORT) failed"); #endif #endif @@ -2210,7 +2213,7 @@ bool BindListenPort(const CService &addrBind, string& strError) LogPrintf("%s", strError); return false; } - if (fDebug10) LogPrintf("Bound to %s", addrBind.ToString()); + LogPrint(BCLog::LogFlags::NOISY, "Bound to %s", addrBind.ToString()); // Listen for incoming connections if (listen(hListenSocket, SOMAXCONN) == SOCKET_ERROR) diff --git a/src/net.h b/src/net.h index 5c0f08cec1..221c7bb11d 100644 --- a/src/net.h +++ b/src/net.h @@ -463,8 +463,7 @@ class CNode LEAVE_CRITICAL_SECTION(cs_vSend); - if (fDebug10) - LogPrintf("(aborted)"); + LogPrint(BCLog::LogFlags::NOISY, "(aborted)"); } void EndMessage() @@ -490,10 +489,7 @@ class CNode assert(ssSend.size () >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum)); memcpy((char*)&ssSend[CMessageHeader::CHECKSUM_OFFSET], &nChecksum, sizeof(nChecksum)); - if (fDebug10) - { - LogPrintf("(%d bytes)", nSize); - } + LogPrint(BCLog::LogFlags::NOISY, "(%d bytes)", nSize); std::deque::iterator it = vSendMsg.insert(vSendMsg.end(), CSerializeData()); ssSend.GetAndClear(*it); diff --git a/src/netbase.cpp b/src/netbase.cpp index 3c358623df..db10e855a9 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -393,7 +393,9 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe } if (nRet != 0) { - if (fDebug10) LogPrintf("socket connect() failed after select(): %s, Destination Addr %s ",strerror(nRet),addrConnect.ToString()); + LogPrint(BCLog::LogFlags::NOISY, "socket connect() failed after select(): %s, Destination Addr %s ", + strerror(nRet), addrConnect.ToString()); + closesocket(hSocket); return false; } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 6347e2c36a..5fdabdc7aa 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -317,8 +317,8 @@ UniValue getblockhash(const UniValue& params, bool fHelp) int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) throw runtime_error("Block number out of range."); - if (fDebug10) - LogPrintf("Getblockhash %d", nHeight); + + LogPrint(BCLog::LogFlags::NOISY, "Getblockhash %d", nHeight); LOCK(cs_main); @@ -1237,13 +1237,21 @@ UniValue debug10(const UniValue& params, bool fHelp) "debug10 \n" "\n" " -> Specify true or false\n" - "Enable or disable debug mode on the fly\n"); + "Enable or disable NOISY logging category (aka old debug10) on the fly\n" + "This is deprecated by the \"logging noisy\" command.\n"); UniValue res(UniValue::VOBJ); - fDebug10 = params[0].get_bool(); + if(params[0].get_bool()) + { + LogInstance().EnableCategory(BCLog::LogFlags::NOISY); + } + else + { + LogInstance().DisableCategory(BCLog::LogFlags::NOISY); + } - res.pushKV("Debug10", fDebug10 ? "Entering debug mode." : "Exiting debug mode."); + res.pushKV("Logging category NOISY (aka old debug10) ", LogInstance().WillLogCategory(BCLog::LogFlags::NOISY) ? "Enabled." : "Disabled."); return res; } diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 7bf19da442..5553301f5e 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -722,7 +722,7 @@ void JSONRequest::parse(const UniValue& valRequest) throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string"); strMethod = valMethod.get_str(); if (strMethod != "getwork" && strMethod != "getblocktemplate") - if (fDebug10) LogPrintf("ThreadRPCServer method=%s", strMethod); + LogPrint(BCLog::LogFlags::NOISY, "ThreadRPCServer method=%s", strMethod); // Parse params UniValue valParams = find_value(request, "params"); diff --git a/src/scraper/scraper.cpp b/src/scraper/scraper.cpp index 4a43a67724..c4937d3450 100755 --- a/src/scraper/scraper.cpp +++ b/src/scraper/scraper.cpp @@ -1330,7 +1330,10 @@ bool ScraperDirectoryAndConfigSanity() { entry = StructScraperFileManifest.mScraperFileManifest.find(dir.path().filename().string()); - if (fDebug10) _log(logattribute::INFO, "ScraperDirectoryAndConfigSanity", "Iterating through directory - checking file " + filename); + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) + { + _log(logattribute::INFO, "ScraperDirectoryAndConfigSanity", "Iterating through directory - checking file " + filename); + } if (entry == StructScraperFileManifest.mScraperFileManifest.end()) { @@ -1360,7 +1363,10 @@ bool ScraperDirectoryAndConfigSanity() int64_t nFileRetentionTime = fExplorer ? EXPLORER_EXTENDED_FILE_RETENTION_TIME : SCRAPER_FILE_RETENTION_TIME; - if (fDebug10) _log(logattribute::INFO, "ScraperDirectoryAndConfigSanity", "Iterating through map - checking map entry " + entry_copy->first); + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) + { + _log(logattribute::INFO, "ScraperDirectoryAndConfigSanity", "Iterating through map - checking map entry " + entry_copy->first); + } if (!fs::exists(pathScraper / entry_copy->first) || ((GetAdjustedTime() - entry_copy->second.timestamp) > nFileRetentionTime) @@ -1390,7 +1396,7 @@ bool ScraperDirectoryAndConfigSanity() else { _log(logattribute::INFO, "ScraperDirectoryAndConfigSanity", "Loaded team IDs file into map."); - if (fDebug10) + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) { _log(logattribute::INFO, "ScraperDirectoryAndConfigSanity", "TeamIDMap contents:"); for (const auto& iter : TeamIDMap) @@ -5243,13 +5249,19 @@ scraperSBvalidationtype ValidateSuperblock(const NN::Superblock& NewFormatSuperb // content hash - manifest hash std::map mMatchingManifestContentHashes; - if (fDebug10) _log(logattribute::INFO, "ValidateSuperblock", "nUnderlyingManifestReducedContentHash = " + std::to_string(nUnderlyingManifestReducedContentHash)); + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) + { + _log(logattribute::INFO, "ValidateSuperblock", "nUnderlyingManifestReducedContentHash = " + std::to_string(nUnderlyingManifestReducedContentHash)); + } for (const auto& iter : mManifestsBinnedbyContent) { uint32_t nReducedManifestContentHash = iter.first.GetUint64() >> (32 + nAdditionalBitShift); - if (fDebug10) _log(logattribute::INFO, "ValidateSuperblock", "nReducedManifestContentHash = " + std::to_string(nReducedManifestContentHash)); + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) + { + _log(logattribute::INFO, "ValidateSuperblock", "nReducedManifestContentHash = " + std::to_string(nReducedManifestContentHash)); + } // This has the effect of only storing the first one of the series of matching manifests that match the hint, // because of the insert. Below we will count the others matching to check for a supermajority. @@ -5426,15 +5438,18 @@ scraperSBvalidationtype ValidateSuperblock(const NN::Superblock& NewFormatSuperb // Only process if there is a valid entry in the superblock. if (const auto SBProjectIter = NewFormatSuperblock.m_projects.Try(iWhitelistProject.m_name)) { - if (fDebug10) _log(logattribute::INFO, - "ValidateSuperblock", - "by project uncached:\n" - "nReducedProjectObjectContentHash_prebitshift = " + std::to_string(nReducedProjectObjectContentHash_prebitshift) + "\n" - + " SBProjectIter->m_convergence_hint = " + std::to_string(SBProjectIter->m_convergence_hint) + "\n" - + " nReducedProjectObjectContentHash = " + std::to_string(nReducedProjectObjectContentHash) + "\n" - + " SBProjectIter->m_convergence_hint >> " + std::to_string(nAdditionalBitShift) - + " = " + std::to_string(SBProjectIter->m_convergence_hint >> nAdditionalBitShift) + "\n" - ); + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) + { + _log(logattribute::INFO, + "ValidateSuperblock", + "by project uncached:\n" + "nReducedProjectObjectContentHash_prebitshift = " + std::to_string(nReducedProjectObjectContentHash_prebitshift) + "\n" + + " SBProjectIter->m_convergence_hint = " + std::to_string(SBProjectIter->m_convergence_hint) + "\n" + + " nReducedProjectObjectContentHash = " + std::to_string(nReducedProjectObjectContentHash) + "\n" + + " SBProjectIter->m_convergence_hint >> " + std::to_string(nAdditionalBitShift) + + " = " + std::to_string(SBProjectIter->m_convergence_hint >> nAdditionalBitShift) + "\n" + ); + } // Only process if the (reduced content hash) for the project object matches the hint. if (nReducedProjectObjectContentHash == SBProjectIter->m_convergence_hint >> nAdditionalBitShift) diff --git a/src/util.cpp b/src/util.cpp index e15c86159c..de3e341d8c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -67,7 +67,6 @@ ArgsMap mapArgs; ArgsMultiMap mapMultiArgs; bool fDebug = false; -bool fDebug10 = false; bool fPrintToConsole = false; bool fPrintToDebugger = false; @@ -199,7 +198,7 @@ void RandAddSeedPerfmon() { RAND_add(pdata, nSize, nSize/100.0); memset(pdata, 0, nSize); - if (fDebug10) LogPrint("rand", "RandAddSeed() %lu bytes", nSize); + LogPrint(BCLog::LogFlags::NOISY, "rand", "RandAddSeed() %lu bytes", nSize); } #endif } @@ -848,7 +847,7 @@ std::string GetFileContents(const fs::path filepath) return "-1"; } - if (fDebug10) LogPrintf("loading file to string %s", filepath); + LogPrint(BCLog::LogFlags::NOISY, "loading file to string %s", filepath); std::ostringstream out; @@ -885,7 +884,7 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample) // Add data vTimeOffsets.input(nOffsetSample); - if (fDebug10) LogPrintf("Added time data, samples %d, offset %+" PRId64 " (%+" PRId64 " minutes)", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); + LogPrint(BCLog::LogFlags::NOISY, "Added time data, samples %d, offset %+" PRId64 " (%+" PRId64 " minutes)", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) { // We believe the median of the other nodes 95% and our own node's time ("0" initial offset) 5%. This will also act to gently converge the network to consensus UTC, in case @@ -916,12 +915,12 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample) } } } - if (fDebug10) { + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) { for (auto const& n : vSorted) LogPrintf("%+" PRId64 " ", n); LogPrintf("| "); } - if (fDebug10) LogPrintf("nTimeOffset = %+" PRId64 " (%+" PRId64 " minutes)", nTimeOffset, nTimeOffset/60); + LogPrint(BCLog::LogFlags::NOISY, "nTimeOffset = %+" PRId64 " (%+" PRId64 " minutes)", nTimeOffset, nTimeOffset/60); } } diff --git a/src/util.h b/src/util.h index 41fdbf1b50..4c06e1e7ec 100644 --- a/src/util.h +++ b/src/util.h @@ -119,7 +119,6 @@ extern ArgsMap mapArgs; extern ArgsMultiMap mapMultiArgs; extern bool fDebug; -extern bool fDebug10; extern bool fPrintToConsole; extern bool fPrintToDebugger; diff --git a/src/wallet.cpp b/src/wallet.cpp index 9802a09cf8..6ae39ea83f 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1122,7 +1122,7 @@ void CWalletTx::RelayWalletTransaction(CTxDB& txdb) uint256 hash = GetHash(); if (!txdb.ContainsTx(hash)) { - if (fDebug10) LogPrintf("Relaying wtx %s", hash.ToString().substr(0,10)); + LogPrint(BCLog::LogFlags::NOISY, "Relaying wtx %s", hash.ToString().substr(0,10)); RelayTransaction((CTransaction)*this, hash); } } @@ -2187,7 +2187,7 @@ bool CWallet::TopUpKeyPool(unsigned int nSize) if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey()))) throw runtime_error("TopUpKeyPool() : writing generated key failed"); setKeyPool.insert(nEnd); - if (fDebug10) LogPrintf("keypool added key %" PRId64 ", size=%" PRIszu, nEnd, setKeyPool.size()); + LogPrint(BCLog::LogFlags::NOISY, "keypool added key %" PRId64 ", size=%" PRIszu, nEnd, setKeyPool.size()); } } return true; From 1dc615ca0a24aa9c355bdc9b260b5c82f699bb87 Mon Sep 17 00:00:00 2001 From: jamescowens Date: Sun, 31 May 2020 22:42:15 -0400 Subject: [PATCH 3/7] Remove debug and replace with BCLog::LogFlags::VERBOSE --- src/init.cpp | 7 ++--- src/kernel.cpp | 24 ++++++++-------- src/main.cpp | 33 ++++++++++++--------- src/main.h | 2 +- src/miner.cpp | 6 ++-- src/net.cpp | 4 +-- src/neuralnet/quorum.cpp | 49 +++++++++++++------------------- src/qt/qtipcserver.cpp | 2 +- src/qt/transactiondesc.cpp | 2 +- src/qt/transactiontablemodel.cpp | 10 +++---- src/qt/walletmodel.cpp | 2 +- src/rpcblockchain.cpp | 32 +++++++++++++-------- src/rpcrawtransaction.cpp | 12 ++++---- src/scraper/http.cpp | 3 +- src/scraper/scraper.cpp | 3 +- src/test/DoS_tests.cpp | 4 +-- src/util.cpp | 2 -- src/util.h | 2 -- src/wallet.cpp | 16 +++++------ 19 files changed, 102 insertions(+), 113 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index ffd29aa13b..2850d61657 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -600,11 +600,8 @@ bool AppInit2(ThreadHandlerPtr threads) // ********************************************************* Step 3: parameter-to-internal-flags - fDebug = false; - if (GetArg("-debug", "false") == "true") { - fDebug = true; LogPrintf("Enabling debug category VERBOSE from legacy debug."); LogInstance().EnableCategory(BCLog::LogFlags::VERBOSE); } @@ -732,7 +729,7 @@ bool AppInit2(ThreadHandlerPtr threads) fDevbuildCripple = true; LogPrintf("WARNING: Running development version outside of testnet!\n" "Staking and sending transactions will be disabled."); - if( (GetArg("-devbuild", "") == "override") && fDebug ) + if( (GetArg("-devbuild", "") == "override") && LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) fDevbuildCripple = false; } @@ -1126,7 +1123,7 @@ bool AppInit2(ThreadHandlerPtr threads) RandAddSeedPerfmon(); //// debug print - if (fDebug) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) { LogPrintf("mapBlockIndex.size() = %" PRIszu, mapBlockIndex.size()); LogPrintf("nBestHeight = %d", nBestHeight); diff --git a/src/kernel.cpp b/src/kernel.cpp index e3dc809920..3b75b187fe 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -247,7 +247,7 @@ static bool SelectBlockFromCandidates( } } - if (fDebug && GetBoolArg("-printstakemodifier")) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printstakemodifier")) LogPrintf("SelectBlockFromCandidates: selection hash=%s", hashBest.ToString()); return fSelected; @@ -333,12 +333,12 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod nStakeModifierNew |= (((uint64_t)pindex->GetStakeEntropyBit()) << nRound); // add the selected block from candidates to selected list mapSelectedBlocks.insert(make_pair(pindex->GetBlockHash(), pindex)); - if (fDebug && GetBoolArg("-printstakemodifier")) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printstakemodifier")) LogPrintf("ComputeNextStakeModifier: selected round %d stop=%s height=%d bit=%d", nRound, DateTimeStrFormat(nSelectionIntervalStop), pindex->nHeight, pindex->GetStakeEntropyBit()); } // Print selection map for visualization of the selected blocks - if (fDebug && GetBoolArg("-printstakemodifier")) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printstakemodifier")) { string strSelectionMap = ""; // '-' indicates proof-of-work blocks not selected @@ -360,7 +360,7 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod LogPrintf("ComputeNextStakeModifier: selection height [%d, %d] map %s", nHeightFirstCandidate, pindexPrev->nHeight, strSelectionMap); } - if (fDebug) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) { LogPrintf("ComputeNextStakeModifier: new modifier=0x%016" PRIx64 " time=%s", nStakeModifierNew, DateTimeStrFormat(pindexPrev->GetBlockTime())); } @@ -599,14 +599,14 @@ bool CheckProofOfStakeV8( bnTarget *= Weight; - if(fDebug) LogPrintf( -"CheckProofOfStakeV8:%s Time1 %.f, Time2 %.f, Time3 %.f, Bits %u, Weight %.f\n" -" Stk %72s\n" -" Trg %72s", generated_by_me?" Local,":"", - (double)header.nTime, (double)txPrev.nTime, (double)tx.nTime, - Block.nBits, (double)Weight, - CBigNum(hashProofOfStake).GetHex(), bnTarget.GetHex() - ); + LogPrint(BCLog::LogFlags::VERBOSE, + "CheckProofOfStakeV8:%s Time1 %.f, Time2 %.f, Time3 %.f, Bits %u, Weight %.f\n" + " Stk %72s\n" + " Trg %72s", generated_by_me?" Local,":"", + (double)header.nTime, (double)txPrev.nTime, (double)tx.nTime, + Block.nBits, (double)Weight, + CBigNum(hashProofOfStake).GetHex(), bnTarget.GetHex() + ); // Now check if proof-of-stake hash meets target protocol return bnHashProof <= bnTarget; diff --git a/src/main.cpp b/src/main.cpp index f192a747bd..279e03b71c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1435,8 +1435,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput // At default rate it would take over a month to fill 1GB if (dFreeCount > GetArg("-limitfreerelay", 15)*10*1000 && !IsFromMe(tx)) return error("AcceptToMemoryPool : free transaction rejected by rate limiter"); - if (fDebug) - LogPrint("mempool", "Rate limit dFreeCount: %g => %g", dFreeCount, dFreeCount+nSize); + if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) + { + LogPrint(BCLog::LogFlags::MEMPOOL, "Rate limit dFreeCount: %g => %g", dFreeCount, dFreeCount+nSize); + } dFreeCount += nSize; } } @@ -1450,7 +1452,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput // This is done last to help prevent CPU exhaustion denial-of-service attacks. if (!tx.ConnectInputs(txdb, mapInputs, mapUnused, CDiskTxPos(1,1,1), pindexBest, false, false)) { - if (fDebug || true) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) || true) { return error("AcceptToMemoryPool : Unable to Connect Inputs %s", hash.ToString().c_str()); } @@ -1476,7 +1478,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput // If updated, erase old tx from wallet if (ptxOld) EraseFromWallets(ptxOld->GetHash()); - if (fDebug) LogPrint("mempool", "AcceptToMemoryPool : accepted %s (poolsz %" PRIszu ")", hash.ToString(), pool.mapTx.size()); + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) + { + LogPrint("mempool", "AcceptToMemoryPool : accepted %s (poolsz %" PRIszu ")", hash.ToString(), pool.mapTx.size()); + } return true; } @@ -1979,7 +1984,7 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map& mapTes // Get prev tx from single transactions in memory if (!mempool.lookup(prevout.hash, txPrev)) { - if (fDebug) LogPrintf("FetchInputs() : %s mempool Tx prev not found %s", GetHash().ToString().substr(0,10), prevout.hash.ToString().substr(0,10)); + LogPrint(BCLog::LogFlags::VERBOSE, "FetchInputs() : %s mempool Tx prev not found %s", GetHash().ToString().substr(0,10), prevout.hash.ToString().substr(0,10)); return false; } if (!fFound) @@ -2155,7 +2160,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, map& vResurrect, unsigned if(!pindexBest->pprev) return error("DisconnectBlocksBatch: attempt to reorganize beyond genesis"); /*fatal*/ - if (fDebug) LogPrintf("DisconnectBlocksBatch: %s",pindexBest->GetBlockHash().GetHex()); + LogPrint(BCLog::LogFlags::VERBOSE, "DisconnectBlocksBatch: %s",pindexBest->GetBlockHash().GetHex()); CBlock block; if (!block.ReadFromDisk(pindexBest)) @@ -3103,7 +3108,7 @@ bool ReorganizeChain(CTxDB& txdb, unsigned &cnt_dis, unsigned &cnt_con, CBlock & pwalletMain->FixSpentCoins(nMismatchSpent, nBalanceInQuestion); } - if (fDebug && cnt_dis>0) LogPrintf("ReorganizeChain: disconnected %d blocks",cnt_dis); + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && cnt_dis > 0) LogPrintf("ReorganizeChain: disconnected %d blocks",cnt_dis); for(CBlockIndex *p = pindexNew; p != pcommon; p=p->pprev) vConnect.push_front(p); @@ -3130,7 +3135,7 @@ bool ReorganizeChain(CTxDB& txdb, unsigned &cnt_dis, unsigned &cnt_con, CBlock & uint256 hash = block.GetHash(true); arith_uint256 nBestBlockTrust; - if (fDebug) LogPrintf("ReorganizeChain: connect %s",hash.ToString()); + LogPrint(BCLog::LogFlags::VERBOSE, "ReorganizeChain: connect %s",hash.ToString()); if (!txdb.TxnBegin()) return error("ReorganizeChain: TxnBegin failed"); @@ -3202,7 +3207,7 @@ bool ReorganizeChain(CTxDB& txdb, unsigned &cnt_dis, unsigned &cnt_con, CBlock & } } - if (fDebug && (cnt_dis>0 || cnt_con>1)) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && (cnt_dis > 0 || cnt_con > 1)) LogPrintf("ReorganizeChain: Disconnected %d and Connected %d blocks.",cnt_dis,cnt_con); return true; @@ -3239,7 +3244,7 @@ bool SetBestChain(CTxDB& txdb, CBlock &blockNew, CBlockIndex* pindexNew) ::SetBestChain(locator); } - if (fDebug) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) { LogPrintf("{SBC} {%s %d} trust=%s date=%s", hashBestChain.ToString(), nBestHeight, @@ -3298,12 +3303,12 @@ bool CTransaction::GetCoinAge(CTxDB& txdb, uint64_t& nCoinAge) const int64_t nValueIn = txPrev.vout[txin.prevout.n].nValue; bnCentSecond += CBigNum(nValueIn) * (nTime-txPrev.nTime) / CENT; - if (fDebug && GetBoolArg("-printcoinage")) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printcoinage")) LogPrintf("coin age nValueIn=%" PRId64 " nTimeDiff=%d bnCentSecond=%s", nValueIn, nTime - txPrev.nTime, bnCentSecond.ToString()); } CBigNum bnCoinDay = bnCentSecond * CENT / COIN / (24 * 60 * 60); - if (fDebug && GetBoolArg("-printcoinage")) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printcoinage")) LogPrintf("coin age bnCoinDay=%s", bnCoinDay.ToString()); nCoinAge = bnCoinDay.getuint64(); return true; @@ -4530,7 +4535,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { if ((!IsLockTimeWithinMinutes(nLastAskedForBlocks, 5, GetAdjustedTime()) && WalletOutOfSync()) || (WalletOutOfSync() && fTestNet)) { - if(fDebug) LogPrintf("Bootup"); + LogPrint(BCLog::LogFlags::VERBOSE, "Bootup"); AskForOutstandingBlocks(uint256()); } } diff --git a/src/main.h b/src/main.h index cdccb19220..bfc56c1259 100644 --- a/src/main.h +++ b/src/main.h @@ -1300,7 +1300,7 @@ class CBlock : public CBlockHeader { // Take last bit of block hash as entropy bit unsigned int nEntropyBit = ((GetHash(true).GetUint64()) & 1llu); - if (fDebug && GetBoolArg("-printstakemodifier")) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printstakemodifier")) LogPrintf("GetStakeEntropyBit: hashBlock=%s nEntropyBit=%u", GetHash(true).ToString(), nEntropyBit); return nEntropyBit; } diff --git a/src/miner.cpp b/src/miner.cpp index 76fe2b3a26..2087598e54 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -72,9 +72,7 @@ bool ReturnMinerError(CMinerStatus& status, CMinerStatus::ReasonNotStakingCatego status.SetReasonNotStaking(not_staking_error); - if (fDebug) { - LogPrintf("CreateCoinStake: %s", MinerStatus.ReasonNotStaking); - } + LogPrint(BCLog::LogFlags::VERBOSE, "CreateCoinStake: %s", MinerStatus.ReasonNotStaking); return false; } @@ -294,7 +292,7 @@ bool CreateRestOfTheBlock(CBlock &block, CBlockIndex* pindexPrev) if (!mempool.mapTx.count(txin.prevout.hash)) { LogPrintf("ERROR: mempool transaction missing input"); - if (fDebug) assert("mempool transaction missing input" == 0); + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) assert("mempool transaction missing input" == 0); fMissingInputs = true; if (porphan) vOrphan.pop_back(); diff --git a/src/net.cpp b/src/net.cpp index f5958ff32e..4fca0f65f2 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -756,13 +756,13 @@ bool CNode::Misbehaving(int howmuch) if (nMisbehavior >= GetArg("-banscore", 100)) { - if (fDebug) LogPrintf("Misbehaving: %s (%d -> %d) DISCONNECTING", addr.ToString(), nMisbehavior-howmuch, nMisbehavior); + LogPrint(BCLog::LogFlags::VERBOSE, "Misbehaving: %s (%d -> %d) DISCONNECTING", addr.ToString(), nMisbehavior-howmuch, nMisbehavior); g_banman->Ban(addr, BanReasonNodeMisbehaving); CloseSocketDisconnect(); return true; } else - if (fDebug) LogPrintf("Misbehaving: %s (%d -> %d)", addr.ToString(), nMisbehavior-howmuch, nMisbehavior); + LogPrint(BCLog::LogFlags::VERBOSE, "Misbehaving: %s (%d -> %d)", addr.ToString(), nMisbehavior-howmuch, nMisbehavior); return false; } } diff --git a/src/neuralnet/quorum.cpp b/src/neuralnet/quorum.cpp index 04ebbed244..28cf471387 100644 --- a/src/neuralnet/quorum.cpp +++ b/src/neuralnet/quorum.cpp @@ -94,7 +94,7 @@ class SuperblockIndex }; if (m_pending.empty()) { - if (fDebug) { + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) { log(height, "none pending."); } @@ -104,7 +104,7 @@ class SuperblockIndex auto pending_iter = m_pending.upper_bound(height); if (pending_iter == m_pending.begin()) { - if (fDebug) { + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) { log(height, "not pending."); } @@ -358,21 +358,18 @@ class LegacyConsensus CBitcoinAddress address(grc_address); if (!address.IsValid()) { - if (fDebug) { - LogPrintf("Quorum::RecordVote: invalid address: %s HASH: %s", - grc_address, - quorum_hash.ToString()); - } + LogPrint(BCLog::LogFlags::VERBOSE, + "Quorum::RecordVote: invalid address: %s HASH: %s", + grc_address, + quorum_hash.ToString()); return; } if (!Participating(grc_address, pindex->nTime)) { - if (fDebug) { - LogPrintf("Quorum::RecordVote: not participating: %s HASH: %s", - grc_address, - quorum_hash.ToString()); - } + LogPrint(BCLog::LogFlags::VERBOSE, "Quorum::RecordVote: not participating: %s HASH: %s", + grc_address, + quorum_hash.ToString()); return; } @@ -910,15 +907,13 @@ class SuperblockValidator const ResolvedProject& project = project_pair.second; const size_t part_index = remainder / project.m_combiner_mask; - if (fDebug) { - LogPrintf( + LogPrint(BCLog::LogFlags::VERBOSE, "ValidateSuperblock(): uncached by project: " "%" PRIszu "/%" PRIszu " = part_index = %" PRIszu " index max = %" PRIszu, remainder, project.m_combiner_mask, part_index, project.m_resolved_parts.size() - 1); - } const auto& resolved_part = project.m_resolved_parts[part_index]; @@ -1249,21 +1244,17 @@ class SuperblockValidator content_hash_tally[content_hash]++; } - if (fDebug) { - LogPrintf( - "ValidateSuperblock(): manifest content hash %s " - "matched convergence hint. Matches %" PRIszu, - content_hash.ToString(), - content_hash_tally[content_hash]); - } + LogPrint(BCLog::LogFlags::VERBOSE, + "ValidateSuperblock(): manifest content hash %s " + "matched convergence hint. Matches %" PRIszu, + content_hash.ToString(), + content_hash_tally[content_hash]); if (content_hash_tally[content_hash] >= supermajority) { - if (fDebug) { - LogPrintf( + LogPrint(BCLog::LogFlags::VERBOSE, "ValidateSuperblock(): supermajority found for " "manifest content hash: %s. Trying validation.", content_hash.ToString()); - } if (TryManifest(manifest_hash)) { return true; @@ -1353,11 +1344,9 @@ class SuperblockValidator ProjectResolver resolver(std::move(candidates), ScraperCullAndBinCScraperManifests()); ProjectCombiner combiner = resolver.ResolveProjectParts(); - if (fDebug) { - LogPrintf( - "ValidateSuperblock(): by-project possible combinations: %" PRIszu, - combiner.TotalCombinations()); - } + LogPrint(BCLog::LogFlags::VERBOSE, + "ValidateSuperblock(): by-project possible combinations: %" PRIszu, + combiner.TotalCombinations()); while (const auto combination_option = combiner.GetNextConvergence()) { if (combination_option->ComputeQuorumHash() == m_quorum_hash) { diff --git a/src/qt/qtipcserver.cpp b/src/qt/qtipcserver.cpp index 83749d9c07..68324414a7 100644 --- a/src/qt/qtipcserver.cpp +++ b/src/qt/qtipcserver.cpp @@ -91,7 +91,7 @@ static void ipcThread(void* pArg) static void ipcThread2(void* pArg) { - if (fDebug) LogPrintf("ipcThread started"); + LogPrint(BCLog::LogFlags::VERBOSE, "ipcThread started"); message_queue* mq = (message_queue*)pArg; char buffer[MAX_URI_LENGTH + 1] = ""; diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index cc38190181..416c2250e7 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -333,7 +333,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, unsigned int vo } } - if (fDebug || true) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) || true) { strHTML += "

" + tr("Transaction Debits/Credits") + "

"; diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 0140a3865a..780ab1c0e5 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -66,7 +66,7 @@ class TransactionTablePriv */ void refreshWallet() { - if (fDebug) LogPrintf("refreshWallet"); + LogPrint(BCLog::LogFlags::VERBOSE, "refreshWallet"); cachedWallet.clear(); { LOCK2(cs_main, wallet->cs_wallet); @@ -85,7 +85,7 @@ class TransactionTablePriv */ void updateWallet(const uint256 &hash, int status) { - if (fDebug) LogPrintf("updateWallet %s %i", hash.ToString(), status); + LogPrint(BCLog::LogFlags::VERBOSE, "updateWallet %s %i", hash.ToString(), status); { LOCK2(cs_main, wallet->cs_wallet); @@ -115,7 +115,7 @@ class TransactionTablePriv status = CT_DELETED; /* In model, but want to hide, treat as deleted */ } - if (fDebug) LogPrintf(" inWallet=%i inModel=%i Index=%i-%i showTransaction=%i derivedStatus=%i", inWallet, inModel, lowerIndex, upperIndex, showTransaction, status); + LogPrint(BCLog::LogFlags::VERBOSE, " inWallet=%i inModel=%i Index=%i-%i showTransaction=%i derivedStatus=%i", inWallet, inModel, lowerIndex, upperIndex, showTransaction, status); switch(status) @@ -123,12 +123,12 @@ class TransactionTablePriv case CT_NEW: if(inModel) { - if (fDebug) LogPrintf("Warning: updateWallet: Got CT_NEW, but transaction is already in model"); + LogPrint(BCLog::LogFlags::VERBOSE, "Warning: updateWallet: Got CT_NEW, but transaction is already in model"); break; } if(!inWallet) { - if (fDebug) LogPrintf("Warning: updateWallet: Got CT_NEW, but transaction is not in wallet"); + LogPrint(BCLog::LogFlags::VERBOSE, "Warning: updateWallet: Got CT_NEW, but transaction is not in wallet"); break; } if(showTransaction) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 4b635f147f..869dd723df 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -360,7 +360,7 @@ static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet, static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, const uint256 &hash, ChangeType status) { - if (fDebug) LogPrintf("NotifyTransactionChanged %s status=%i", hash.GetHex(), status); + LogPrint(BCLog::LogFlags::VERBOSE, "NotifyTransactionChanged %s status=%i", hash.GetHex(), status); QMetaObject::invokeMethod(walletmodel, "updateTransaction", Qt::QueuedConnection, Q_ARG(QString, QString::fromStdString(hash.GetHex())), Q_ARG(int, status)); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5fdabdc7aa..6ccb463a20 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -438,7 +438,7 @@ UniValue rainbymagnitude(const UniValue& params, bool fHelp) std::string sProject = params[0].get_str(); - if (fDebug) LogPrintf("rainbymagnitude: sProject = %s", sProject.c_str()); + LogPrint(BCLog::LogFlags::VERBOSE, "rainbymagnitude: sProject = %s", sProject.c_str()); double dAmount = params[1].get_real(); @@ -466,7 +466,7 @@ UniValue rainbymagnitude(const UniValue& params, bool fHelp) mScraperConvergedStats = ConvergedScraperStatsCache.mScraperConvergedStats; } - if (fDebug) LogPrintf("rainbymagnitude: mScraperConvergedStats size = %u", mScraperConvergedStats.size()); + LogPrint(BCLog::LogFlags::VERBOSE, "rainbymagnitude: mScraperConvergedStats size = %u", mScraperConvergedStats.size()); double dTotalAmount = 0; int64_t nTotalAmount = 0; @@ -517,7 +517,7 @@ UniValue rainbymagnitude(const UniValue& params, bool fHelp) continue; } - if (fDebug) LogPrintf("INFO: rainbymagnitude: address = %s.", address.ToString()); + LogPrint(BCLog::LogFlags::VERBOSE, "INFO: rainbymagnitude: address = %s.", address.ToString()); mCPIDRain[CPIDKey] = std::make_pair(address, dCPIDMag); @@ -525,7 +525,7 @@ UniValue rainbymagnitude(const UniValue& params, bool fHelp) // into the RAIN map, and will be used to normalize the payments. dTotalMagnitude += dCPIDMag; - if (fDebug) LogPrintf("rainmagnitude: CPID = %s, address = %s, dCPIDMag = %f", + LogPrint(BCLog::LogFlags::VERBOSE, "rainmagnitude: CPID = %s, address = %s, dCPIDMag = %f", CPIDKey.ToString(), address.ToString(), dCPIDMag); } } @@ -554,7 +554,7 @@ UniValue rainbymagnitude(const UniValue& params, bool fHelp) vecSend.push_back(std::make_pair(scriptPubKey, nAmount)); - if (fDebug) LogPrintf("rainmagnitude: address = %s, amount = %f", iter.second.first.ToString(), CoinToDouble(nAmount)); + LogPrint(BCLog::LogFlags::VERBOSE, "rainmagnitude: address = %s, amount = %f", iter.second.first.ToString(), CoinToDouble(nAmount)); } LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1025,19 +1025,19 @@ UniValue superblocks(const UniValue& params, bool fHelp) if (params.size() > 0) { lookback = params[0].get_int(); - if (fDebug) LogPrintf("INFO: superblocks: lookback %i", lookback); + LogPrint(BCLog::LogFlags::VERBOSE, "INFO: superblocks: lookback %i", lookback); } if (params.size() > 1) { displaycontract = params[1].get_bool(); - if (fDebug) LogPrintf("INFO: superblocks: display contract %i", displaycontract); + LogPrint(BCLog::LogFlags::VERBOSE, "INFO: superblocks: display contract %i", displaycontract); } if (params.size() > 2) { cpid = params[2].get_str(); - if (fDebug) LogPrintf("INFO: superblocks: CPID %s", cpid); + LogPrint(BCLog::LogFlags::VERBOSE, "INFO: superblocks: CPID %s", cpid); } LOCK(cs_main); @@ -1219,13 +1219,21 @@ UniValue debug(const UniValue& params, bool fHelp) "\n" " -> Specify true or false\n" "\n" - "Enable or disable debug mode on the fly\n"); + "Enable or disable VERBOSE logging category (aka old debug) on the fly\n" + "This is deprecated by the \"logging verbose\" command.\n"); UniValue res(UniValue::VOBJ); - fDebug = params[0].get_bool(); + if(params[0].get_bool()) + { + LogInstance().EnableCategory(BCLog::LogFlags::VERBOSE); + } + else + { + LogInstance().DisableCategory(BCLog::LogFlags::VERBOSE); + } - res.pushKV("Debug", fDebug ? "Entering debug mode." : "Exiting debug mode."); + res.pushKV("Logging category NOISY (aka old debug10) ", LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) ? "Enabled." : "Disabled."); return res; } @@ -1794,7 +1802,7 @@ UniValue MagnitudeReport(const NN::Cpid cpid) json.pushKV("Accrual Days", calc->AccrualDays()); json.pushKV("Owed", ValueFromAmount(calc->Accrual())); - if (fDebug) { + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) { json.pushKV("Owed (raw)", ValueFromAmount(calc->RawAccrual())); json.pushKV("Owed (last superblock)", ValueFromAmount(account.m_accrual)); } diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 72b91250ab..336ea37242 100755 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -74,7 +74,7 @@ std::vector> GetTxStakeBoincHashInfo(const C res.push_back(std::make_pair(_("Fees Collected"), FormatMoney(GetFeesCollected(block)))); res.push_back(std::make_pair(_("Is Superblock"), (claim.ContainsSuperblock() ? "Yes" : "No"))); - if(fDebug) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) { if (claim.ContainsSuperblock()) res.push_back(std::make_pair(_("Neural Contract Binary Size"), ToString(GetSerializeSize(claim.m_superblock, 1, 1)))); @@ -99,7 +99,7 @@ std::vector> GetTxNormalBoincHashInfo(const res.push_back(std::make_pair(_("Network Date"), TimestampToHRDate((double)mtx.nTime))); - if (fDebug) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) res.push_back(std::make_pair(_("Message Length"), ToString(msg.length()))); std::string sMessageType = ExtractXML(msg, "", ""); @@ -128,7 +128,7 @@ std::vector> GetTxNormalBoincHashInfo(const // of delete in addkey to remove a beacon the 1 in 1 res.push_back(std::make_pair(_("ERROR"), _("Invalid beacon contract. Size: ") + ToString(sBeaconEncodedContract.length()))); - if (fDebug) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) res.push_back(std::make_pair(_("Message Data"), sBeaconEncodedContract)); return res; @@ -196,7 +196,7 @@ std::vector> GetTxNormalBoincHashInfo(const res.push_back(std::make_pair(_("Share Type"), _("Unable to extract Share Type. Vote likely > 6 months old"))); res.push_back(std::make_pair(_("Answer"), sVoteAnswer)); - if (fDebug) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) res.push_back(std::make_pair(_("Share Type Debug"), sVoteShareType)); return res; @@ -316,7 +316,7 @@ std::vector> GetTxNormalBoincHashInfo(const { res.push_back(std::make_pair(_("Message Type"), _("Unknown"))); - if (fDebug) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) res.push_back(std::make_pair(_("Data"), msg)); return res; @@ -757,7 +757,7 @@ UniValue consolidateunspent(const UniValue& params, bool fHelp) nValue += nUTXOValue; - if (fDebug) LogPrintf("INFO: consolidateunspent: input value = %f, confirmations = %" PRId64, ((double) out.first) / (double) COIN, out.second.nDepth); + LogPrint(BCLog::LogFlags::VERBOSE, "INFO: consolidateunspent: input value = %f, confirmations = %" PRId64, ((double) out.first) / (double) COIN, out.second.nDepth); setCoins.insert(make_pair(out.second.tx, out.second.i)); diff --git a/src/scraper/http.cpp b/src/scraper/http.cpp index 874cb9c65e..e19802f9ef 100644 --- a/src/scraper/http.cpp +++ b/src/scraper/http.cpp @@ -392,8 +392,7 @@ std::string Http::GetSnapshotSHA256() else { - if (fDebug) - LogPrintf("Snapshot Downloader: Receives SHA256SUM of %s", buffer.substr(0, loc)); + LogPrint(BCLog::LogFlags::VERBOSE, "Snapshot Downloader: Receives SHA256SUM of %s", buffer.substr(0, loc)); return buffer.substr(0, loc); } diff --git a/src/scraper/scraper.cpp b/src/scraper/scraper.cpp index c4937d3450..97954c4115 100755 --- a/src/scraper/scraper.cpp +++ b/src/scraper/scraper.cpp @@ -33,7 +33,6 @@ fs::path pathDataDir = {}; fs::path pathScraper = {}; extern bool fShutdown; -extern bool fDebug; extern CWallet* pwalletMain; bool fScraperActive = false; std::vector> vuserpass; @@ -381,7 +380,7 @@ class ScraperLogger ssPrevArchiveCheckDate << PrevArchiveCheckDate; // Goes in main log only and not subject to category. - if (fDebug) LogPrintf("INFO: ScraperLogger: ArchiveCheckDate %s, PrevArchiveCheckDate %s", ssArchiveCheckDate.str(), ssPrevArchiveCheckDate.str()); + LogPrint(BCLog::LogFlags::VERBOSE, "INFO: ScraperLogger: ArchiveCheckDate %s, PrevArchiveCheckDate %s", ssArchiveCheckDate.str(), ssPrevArchiveCheckDate.str()); fs::path LogArchiveDir = pathDataDir / "logarchive"; diff --git a/src/test/DoS_tests.cpp b/src/test/DoS_tests.cpp index 172091234d..ee1a0d1cf2 100755 --- a/src/test/DoS_tests.cpp +++ b/src/test/DoS_tests.cpp @@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(DoS_checkSig) boost::posix_time::ptime mst2 = boost::posix_time::microsec_clock::local_time(); boost::posix_time::time_duration msdiff = mst2 - mst1; long nOneValidate = msdiff.total_milliseconds(); - if (fDebug) LogPrintf("DoS_Checksig sign: %ld", nOneValidate); + LogPrint(BCLog::LogFlags::VERBOSE, "DoS_Checksig sign: %ld", nOneValidate); // ... now validating repeatedly should be quick: // 2.8GHz machine, -g build: Sign takes ~760ms, @@ -254,7 +254,7 @@ BOOST_AUTO_TEST_CASE(DoS_checkSig) mst2 = boost::posix_time::microsec_clock::local_time(); msdiff = mst2 - mst1; long nManyValidate = msdiff.total_milliseconds(); - if (fDebug) LogPrintf("DoS_Checksig five: %ld", nManyValidate); + LogPrint(BCLog::LogFlags::VERBOSE, "DoS_Checksig five: %ld", nManyValidate); BOOST_CHECK_MESSAGE(nManyValidate < nOneValidate, "Signature cache timing failed"); diff --git a/src/util.cpp b/src/util.cpp index de3e341d8c..8dd5e823c7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -66,8 +66,6 @@ using namespace std; ArgsMap mapArgs; ArgsMultiMap mapMultiArgs; -bool fDebug = false; - bool fPrintToConsole = false; bool fPrintToDebugger = false; bool fRequestShutdown = false; diff --git a/src/util.h b/src/util.h index 4c06e1e7ec..33cfb6e72d 100644 --- a/src/util.h +++ b/src/util.h @@ -118,8 +118,6 @@ typedef std::map, mapArgscomp> ArgsMultiMa extern ArgsMap mapArgs; extern ArgsMultiMap mapMultiArgs; -extern bool fDebug; - extern bool fPrintToConsole; extern bool fPrintToDebugger; extern bool fRequestShutdown; diff --git a/src/wallet.cpp b/src/wallet.cpp index 6ae39ea83f..022e9839b8 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -435,7 +435,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock, CWalletDB* LogPrintf("WalletUpdateSpent: bad wtx %s", wtx.GetHash().ToString()); else if (!wtx.IsSpent(txin.prevout.n) && IsMine(wtx.vout[txin.prevout.n])) { - if (fDebug) LogPrintf("WalletUpdateSpent found spent coin %s gC %s", FormatMoney(wtx.GetCredit()), wtx.GetHash().ToString()); + LogPrint(BCLog::LogFlags::VERBOSE, "WalletUpdateSpent found spent coin %s gC %s", FormatMoney(wtx.GetCredit()), wtx.GetHash().ToString()); wtx.MarkSpent(txin.prevout.n); wtx.WriteToDisk(pwalletdb); NotifyTransactionChanged(this, txin.prevout.hash, CT_UPDATED); @@ -530,7 +530,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb) } else { - if (fDebug) LogPrintf("AddToWallet() : found %s in block %s not in index", + LogPrint(BCLog::LogFlags::VERBOSE, "AddToWallet() : found %s in block %s not in index", wtxIn.GetHash().ToString().substr(0,10), wtxIn.hashBlock.ToString()); } @@ -1495,7 +1495,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, nValueRet += vValue[i].first; } - if (fDebug && GetBoolArg("-printpriority")) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printpriority")) { //// debug print LogPrintf("SelectCoins() best subset: "); @@ -1877,7 +1877,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) } { LOCK2(cs_main, cs_wallet); - if (fDebug) LogPrintf("CommitTransaction:\n%s", wtxNew.ToString()); + LogPrint(BCLog::LogFlags::VERBOSE, "CommitTransaction:\n%s", wtxNew.ToString()); { // This is only to keep the database open to defeat the auto-flush for the // duration of this scope. This is the only place where this optimization @@ -2216,7 +2216,7 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool) if (!HaveKey(keypool.vchPubKey.GetID())) throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); assert(keypool.vchPubKey.IsValid()); - if (fDebug && GetBoolArg("-printkeypool")) + if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) && GetBoolArg("-printkeypool")) LogPrintf("keypool reserve %" PRId64, nIndex); } } @@ -2244,8 +2244,7 @@ void CWallet::KeepKey(int64_t nIndex) CWalletDB walletdb(strWalletFile); walletdb.ErasePool(nIndex); } - if(fDebug) - LogPrintf("keypool keep %" PRId64, nIndex); + LogPrint(BCLog::LogFlags::VERBOSE, "keypool keep %" PRId64, nIndex); } void CWallet::ReturnKey(int64_t nIndex) @@ -2255,8 +2254,7 @@ void CWallet::ReturnKey(int64_t nIndex) LOCK(cs_wallet); setKeyPool.insert(nIndex); } - if(fDebug) - LogPrintf("keypool return %" PRId64, nIndex); + LogPrint(BCLog::LogFlags::VERBOSE, "keypool return %" PRId64, nIndex); } bool CWallet::GetKeyFromPool(CPubKey& result, bool fAllowReuse) From 7a7ca991a2547c3f90b4cb1bbb0a8faac085e8b8 Mon Sep 17 00:00:00 2001 From: jamescowens Date: Sun, 31 May 2020 23:00:22 -0400 Subject: [PATCH 4/7] Remove legacy category strings and replace with enum --- src/addrman.cpp | 2 +- src/addrman.h | 6 +++--- src/alert.cpp | 8 ++++---- src/banman.cpp | 6 +++--- src/db.cpp | 14 +++++++------- src/logging.h | 2 +- src/main.cpp | 8 ++++---- src/scraper_net.cpp | 18 +++++++++--------- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index cde4f2494e..2f50117fec 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -302,7 +302,7 @@ void CAddrMan::Good_(const CService &addr, int64_t nTime) // TODO: maybe re-add the node, but for now, just bail out if (nUBucket == -1) return; - LogPrint("addrman", "Moving %s to tried", addr.ToString()); + LogPrint(BCLog::LogFlags::ADDRMAN, "Moving %s to tried", addr.ToString()); // move nId to the tried tables MakeTried(info, nId, nUBucket); diff --git a/src/addrman.h b/src/addrman.h index 36cf832781..a481cb37c4 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -403,7 +403,7 @@ class CAddrMan LOCK(cs); int err; if ((err=Check_())) - LogPrint("addrman", "ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i", err); + LogPrint(BCLog::LogFlags::ADDRMAN, "ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i", err); } #endif } @@ -419,7 +419,7 @@ class CAddrMan Check(); } if (fRet) - LogPrint("addrman","Added %s from %s: %i tried, %i new", addr.ToStringIPPort(), source.ToString(), nTried, nNew); + LogPrint(BCLog::LogFlags::ADDRMAN,"Added %s from %s: %i tried, %i new", addr.ToStringIPPort(), source.ToString(), nTried, nNew); return fRet; } @@ -435,7 +435,7 @@ class CAddrMan Check(); } if (nAdd) - LogPrint("addrman","Added %i addresses from %s: %i tried, %i new", nAdd, source.ToString(), nTried, nNew); + LogPrint(BCLog::LogFlags::ADDRMAN,"Added %i addresses from %s: %i tried, %i new", nAdd, source.ToString(), nTried, nNew); return nAdd > 0; } diff --git a/src/alert.cpp b/src/alert.cpp index 3790e22680..dd3eff8d7c 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -213,13 +213,13 @@ bool CAlert::ProcessAlert(bool fThread) const CAlert& alert = (*mi).second; if (Cancels(alert)) { - LogPrint("alert", "cancelling alert %d", alert.nID); + LogPrint(BCLog::LogFlags::ALERT, "cancelling alert %d", alert.nID); uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED); mapAlerts.erase(mi++); } else if (!alert.IsInEffect()) { - LogPrint("alert", "expiring alert %d", alert.nID); + LogPrint(BCLog::LogFlags::ALERT, "expiring alert %d", alert.nID); uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED); mapAlerts.erase(mi++); } @@ -233,7 +233,7 @@ bool CAlert::ProcessAlert(bool fThread) const CAlert& alert = item.second; if (alert.Cancels(*this)) { - LogPrint("alert", "alert already cancelled by %d", alert.nID); + LogPrint(BCLog::LogFlags::ALERT, "alert already cancelled by %d", alert.nID); return false; } } @@ -271,6 +271,6 @@ bool CAlert::ProcessAlert(bool fThread) } } - LogPrint("alert", "accepted alert %d, AppliesToMe()=%d", nID, AppliesToMe()); + LogPrint(BCLog::LogFlags::ALERT, "accepted alert %d, AppliesToMe()=%d", nID, AppliesToMe()); return true; } diff --git a/src/banman.cpp b/src/banman.cpp index 9cbc5bccdc..e3ba279893 100644 --- a/src/banman.cpp +++ b/src/banman.cpp @@ -23,7 +23,7 @@ BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t SetBannedSetDirty(false); // no need to write down, just read data SweepBanned(); // sweep out unused entries - LogPrint("network", "Loaded %d banned node ips/subnets from banlist.dat %dms\n", + LogPrint(BCLog::LogFlags::NET, "Loaded %d banned node ips/subnets from banlist.dat %dms\n", banmap.size(), GetTimeMillis() - n_start); } else { LogPrintf("Invalid or missing banlist.dat; recreating\n"); @@ -51,7 +51,7 @@ void BanMan::DumpBanlist() SetBannedSetDirty(false); } - LogPrint("network", "Flushed %d banned node ips/subnets to banlist.dat %dms\n", + LogPrint(BCLog::LogFlags::NET, "Flushed %d banned node ips/subnets to banlist.dat %dms\n", banmap.size(), GetTimeMillis() - n_start); } @@ -208,7 +208,7 @@ void BanMan::SweepBanned() m_is_dirty = true; notify_ui = true; - LogPrint("net", "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, sub_net.ToString()); + LogPrint(BCLog::LogFlags::NET, "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, sub_net.ToString()); } else ++it; } diff --git a/src/db.cpp b/src/db.cpp index 6e428f08b0..3d9ae949dc 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -118,7 +118,7 @@ void CDBEnv::MakeMock() if (fShutdown) throw runtime_error("CDBEnv::MakeMock(): during shutdown"); - LogPrint("db", "CDBEnv::MakeMock()"); + LogPrint(BCLog::LogFlags::WALLETDB, "CDBEnv::MakeMock()"); dbenv.set_cachesize(1, 0, 1); dbenv.set_lg_bsize(10485760*4); @@ -452,7 +452,7 @@ void CDBEnv::Flush(bool fShutdown) int64_t nStart = GetTimeMillis(); // Flush log data to the actual data file // on all files that are not in use - LogPrint("db", "Flush(%s)%s", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started"); + LogPrint(BCLog::LogFlags::WALLETDB, "Flush(%s)%s", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started"); if (!fDbEnvInit) return; { @@ -462,23 +462,23 @@ void CDBEnv::Flush(bool fShutdown) { string strFile = (*mi).first; int nRefCount = (*mi).second; - LogPrint("db", "%s refcount=%d", strFile, nRefCount); + LogPrint(BCLog::LogFlags::WALLETDB, "%s refcount=%d", strFile, nRefCount); if (nRefCount == 0) { // Move log data to the dat file CloseDb(strFile); - LogPrint("db", "%s checkpoint", strFile); + LogPrint(BCLog::LogFlags::WALLETDB, "%s checkpoint", strFile); dbenv.txn_checkpoint(0, 0, 0); - LogPrint("db", "%s detach", strFile); + LogPrint(BCLog::LogFlags::WALLETDB, "%s detach", strFile); if (!fMockDb) dbenv.lsn_reset(strFile.c_str(), 0); - LogPrint("db", "%s closed", strFile); + LogPrint(BCLog::LogFlags::WALLETDB, "%s closed", strFile); mapFileUseCount.erase(mi++); } else mi++; } - LogPrint("db", "DBFlush(%s)%s ended %15" PRId64 "ms", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); + LogPrint(BCLog::LogFlags::WALLETDB, "DBFlush(%s)%s ended %15" PRId64 "ms", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); if (fShutdown) { char** listp; diff --git a/src/logging.h b/src/logging.h index d61ff84596..1d2d4a6419 100644 --- a/src/logging.h +++ b/src/logging.h @@ -85,7 +85,7 @@ namespace BCLog { CONTRACT = (1 << 27), MINER = (1 << 28), VERBOSE = (1 << 29), // This corresponds to the old horizontal category "debug". - NOISY = (1 << 30), // This corresponds to the old horizontal category "debug10". + NOISY = (1 << 30), // This corresponds to the old horizontal category "debug10". ALL = ~(uint32_t)0, }; diff --git a/src/main.cpp b/src/main.cpp index 279e03b71c..7eb5082db9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -776,7 +776,7 @@ bool AddOrphanTx(const CTransaction& tx) if (nSize > 5000) { - LogPrint("mempool", "ignoring large orphan tx (size: %" PRIszu ", hash: %s)", nSize, hash.ToString().substr(0,10)); + LogPrint(BCLog::LogFlags::MEMPOOL, "ignoring large orphan tx (size: %" PRIszu ", hash: %s)", nSize, hash.ToString().substr(0,10)); return false; } @@ -784,7 +784,7 @@ bool AddOrphanTx(const CTransaction& tx) for (auto const& txin : tx.vin) mapOrphanTransactionsByPrev[txin.prevout.hash].insert(hash); - LogPrint("mempool", "stored orphan tx %s (mapsz %" PRIszu ")", hash.ToString().substr(0,10), mapOrphanTransactions.size()); + LogPrint(BCLog::LogFlags::MEMPOOL, "stored orphan tx %s (mapsz %" PRIszu ")", hash.ToString().substr(0,10), mapOrphanTransactions.size()); return true; } @@ -1468,7 +1468,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput LOCK(pool.cs); if (ptxOld) { - LogPrint("mempool", "AcceptToMemoryPool : replacing tx %s with new version", ptxOld->GetHash().ToString()); + LogPrint(BCLog::LogFlags::MEMPOOL, "AcceptToMemoryPool : replacing tx %s with new version", ptxOld->GetHash().ToString()); pool.remove(*ptxOld); } pool.addUnchecked(hash, tx); @@ -1480,7 +1480,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput EraseFromWallets(ptxOld->GetHash()); if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) { - LogPrint("mempool", "AcceptToMemoryPool : accepted %s (poolsz %" PRIszu ")", hash.ToString(), pool.mapTx.size()); + LogPrint(BCLog::LogFlags::MEMPOOL, "AcceptToMemoryPool : accepted %s (poolsz %" PRIszu ")", hash.ToString(), pool.mapTx.size()); } return true; } diff --git a/src/scraper_net.cpp b/src/scraper_net.cpp index 6f044f2977..ee4585a75d 100644 --- a/src/scraper_net.cpp +++ b/src/scraper_net.cpp @@ -57,7 +57,7 @@ bool CSplitBlob::RecvPart(CNode* pfrom, CDataStream& vRecv) if (!part.present()) { - LogPrint("manifest", "received part %s %u refs", hash.GetHex(), (unsigned) part.refs.size()); + LogPrint(BCLog::LogFlags::MANIFEST, "received part %s %u refs", hash.GetHex(), (unsigned) part.refs.size()); part.data = CSerializeData(vRecv.begin(),vRecv.end()); //TODO: replace with move constructor for (const auto& ref : part.refs) @@ -74,7 +74,7 @@ bool CSplitBlob::RecvPart(CNode* pfrom, CDataStream& vRecv) } else { - LogPrint("manifest", "received duplicate part %s", hash.GetHex()); + LogPrint(BCLog::LogFlags::MANIFEST, "received duplicate part %s", hash.GetHex()); return false; } } @@ -213,7 +213,7 @@ bool CScraperManifest::AlreadyHave(CNode* pfrom, const CInv& inv) } else { - if (pfrom) LogPrint("manifest", "new manifest %s from %s", inv.hash.GetHex(), pfrom->addrName); + if (pfrom) LogPrint(BCLog::LogFlags::MANIFEST, "new manifest %s from %s", inv.hash.GetHex(), pfrom->addrName); return false; } } @@ -514,7 +514,7 @@ void CScraperManifest::UnserializeCheck(CDataStream& ss, unsigned int& banscore_ uint256 hash = Hash(pbegin, ss.begin()); ss >> signature; - LogPrint("manifest", "CScraperManifest::UnserializeCheck: hash of signature = %s", Hash(signature.begin(), signature.end()).GetHex()); + LogPrint(BCLog::LogFlags::MANIFEST, "CScraperManifest::UnserializeCheck: hash of signature = %s", Hash(signature.begin(), signature.end()).GetHex()); CKey mkey; if (!mkey.SetPubKey(pubkey)) throw error("CScraperManifest: Invalid manifest key"); @@ -640,7 +640,7 @@ bool CScraperManifest::RecvManifest(CNode* pfrom, CDataStream& vRecv) } catch (bool& e) { mapManifest.erase(hash); - LogPrint("manifest", "invalid manifest %s received", hash.GetHex()); + LogPrint(BCLog::LogFlags::MANIFEST, "invalid manifest %s received", hash.GetHex()); if (pfrom) { @@ -652,7 +652,7 @@ bool CScraperManifest::RecvManifest(CNode* pfrom, CDataStream& vRecv) } catch(std::ios_base::failure& e) { mapManifest.erase(hash); - LogPrint("manifest", "invalid manifest %s received", hash.GetHex()); + LogPrint(BCLog::LogFlags::MANIFEST, "invalid manifest %s received", hash.GetHex()); if (pfrom) { @@ -673,7 +673,7 @@ bool CScraperManifest::RecvManifest(CNode* pfrom, CDataStream& vRecv) LOCK(cs_mapParts); - LogPrint("manifest", "received manifest %s with %u / %u parts", hash.GetHex(),(unsigned)manifest.cntPartsRcvd,(unsigned)manifest.vParts.size()); + LogPrint(BCLog::LogFlags::MANIFEST, "received manifest %s with %u / %u parts", hash.GetHex(),(unsigned)manifest.cntPartsRcvd,(unsigned)manifest.vParts.size()); if (manifest.isComplete()) { /* If we already got all the parts in memory, signal completion */ @@ -711,7 +711,7 @@ bool CScraperManifest::addManifest(std::unique_ptr&& m, CKey& LogPrint(BCLog::LogFlags::SCRAPER, "INFO: CScraperManifest::addManifest: hash of signature = %s", Hash(m->signature.begin(), m->signature.end()).GetHex()); - LogPrint("manifest", "adding new local manifest"); + LogPrint(BCLog::LogFlags::MANIFEST, "adding new local manifest"); /* try inserting into map */ const auto it = mapManifest.emplace(hash, std::move(m)); @@ -748,7 +748,7 @@ bool CScraperManifest::addManifest(std::unique_ptr&& m, CKey& void CScraperManifest::Complete() { /* Notify peers that we have a new manifest */ - LogPrint("manifest", "manifest %s complete with %u parts", phash->GetHex(),(unsigned)vParts.size()); + LogPrint(BCLog::LogFlags::MANIFEST, "manifest %s complete with %u parts", phash->GetHex(),(unsigned)vParts.size()); { LOCK(cs_vNodes); for (auto const& pnode : vNodes) From 49022f238a23f049a1d956a390daab1f928d503e Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Mon, 1 Jun 2020 01:20:45 -0400 Subject: [PATCH 5/7] Fix wrong text on debug RPC Co-authored-by: Cy Rossignol --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 6ccb463a20..361d3ab692 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1233,7 +1233,7 @@ UniValue debug(const UniValue& params, bool fHelp) LogInstance().DisableCategory(BCLog::LogFlags::VERBOSE); } - res.pushKV("Logging category NOISY (aka old debug10) ", LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) ? "Enabled." : "Disabled."); + res.pushKV("Logging category VERBOSE (aka old debug) ", LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE) ? "Enabled." : "Disabled."); return res; } From c0220a6e1acc939401bca064084355f3cf289e3d Mon Sep 17 00:00:00 2001 From: jamescowens Date: Mon, 1 Jun 2020 15:14:34 -0400 Subject: [PATCH 6/7] Add missed entries to logging description array --- src/logging.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/logging.cpp b/src/logging.cpp index 880d4d6bf6..9b8cd92148 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -182,6 +182,9 @@ const CLogCategoryDesc LogCategories[] = {BCLog::TALLY, "tally"}, {BCLog::ACCRUAL, "accrual"}, {BCLog::CONTRACT, "contract"}, + {BCLog::MINER, "miner"}, + {BCLog::VERBOSE, "verbose"}, + {BCLog::NOISY, "noisy"}, {BCLog::ALL, "1"}, {BCLog::ALL, "all"}, }; From 1bba908fa7f389ef74c6bc745ee639bce6d7055a Mon Sep 17 00:00:00 2001 From: jamescowens Date: Mon, 1 Jun 2020 17:15:03 -0400 Subject: [PATCH 7/7] Remove NOISY wrapper from MEMPOOL log category entries --- src/main.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7eb5082db9..f0f10a9316 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1435,10 +1435,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput // At default rate it would take over a month to fill 1GB if (dFreeCount > GetArg("-limitfreerelay", 15)*10*1000 && !IsFromMe(tx)) return error("AcceptToMemoryPool : free transaction rejected by rate limiter"); - if (LogInstance().WillLogCategory(BCLog::LogFlags::NOISY)) - { - LogPrint(BCLog::LogFlags::MEMPOOL, "Rate limit dFreeCount: %g => %g", dFreeCount, dFreeCount+nSize); - } + + LogPrint(BCLog::LogFlags::MEMPOOL, "Rate limit dFreeCount: %g => %g", dFreeCount, dFreeCount+nSize); dFreeCount += nSize; } } @@ -1478,10 +1476,9 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool* pfMissingInput // If updated, erase old tx from wallet if (ptxOld) EraseFromWallets(ptxOld->GetHash()); - if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE)) - { - LogPrint(BCLog::LogFlags::MEMPOOL, "AcceptToMemoryPool : accepted %s (poolsz %" PRIszu ")", hash.ToString(), pool.mapTx.size()); - } + + LogPrint(BCLog::LogFlags::MEMPOOL, "AcceptToMemoryPool : accepted %s (poolsz %" PRIszu ")", hash.ToString(), pool.mapTx.size()); + return true; }