From a254a7b70cafab645a3eff8f18370d977a4cb43c Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 29 Nov 2024 16:16:36 +0700 Subject: [PATCH] refactor: sping LogAcceptCategory and LogAcceptDebug --- src/llmq/commitment.cpp | 6 +++--- src/llmq/dkgsession.cpp | 4 ++-- src/llmq/instantsend.cpp | 4 ++-- src/llmq/signing_shares.cpp | 2 +- src/llmq/utils.cpp | 12 ++++++------ src/logging.h | 8 +++++++- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 2 +- 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/llmq/commitment.cpp b/src/llmq/commitment.cpp index ea131b113c..607be69f1b 100644 --- a/src/llmq/commitment.cpp +++ b/src/llmq/commitment.cpp @@ -82,7 +82,7 @@ bool CFinalCommitment::Verify(CDeterministicMNManager& dmnman, gsl::not_nullproTxHash.ToString().substr(0, 4) << " | "; @@ -181,7 +181,7 @@ bool CheckLLMQCommitment(CDeterministicMNManager& dmnman, const ChainstateManage return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-commitment-type"); } - if (LogAcceptCategory(BCLog::LLMQ)) { + if (LogAcceptDebug(BCLog::LLMQ)) { std::stringstream ss; for (const auto i: irange::range(llmq_params_opt->size)) { ss << "v[" << i << "]=" << qcTx.commitment.validMembers[i]; diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index fe695354a6..b1b01014d3 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -120,7 +120,7 @@ bool CDKGSession::Init(const uint256& _myProTxHash, int _quorumIndex) CDKGLogger logger(*this, __func__, __LINE__); - if (LogAcceptCategory(BCLog::LLMQ) && IsQuorumRotationEnabled(params, m_quorum_base_block_index)) { + if (LogAcceptDebug(BCLog::LLMQ) && IsQuorumRotationEnabled(params, m_quorum_base_block_index)) { int cycleQuorumBaseHeight = m_quorum_base_block_index->nHeight - quorumIndex; const CBlockIndex* pCycleQuorumBaseBlockIndex = m_quorum_base_block_index->GetAncestor(cycleQuorumBaseHeight); std::stringstream ss; @@ -138,7 +138,7 @@ bool CDKGSession::Init(const uint256& _myProTxHash, int _quorumIndex) if (!myProTxHash.IsNull()) { dkgDebugManager.InitLocalSessionStatus(params, quorumIndex, m_quorum_base_block_index->GetBlockHash(), m_quorum_base_block_index->nHeight); relayMembers = utils::GetQuorumRelayMembers(params, m_dmnman, m_quorum_base_block_index, myProTxHash, true); - if (LogAcceptCategory(BCLog::LLMQ)) { + if (LogAcceptDebug(BCLog::LLMQ)) { std::stringstream ss; for (const auto& r : relayMembers) { ss << r.ToString().substr(0, 4) << " | "; diff --git a/src/llmq/instantsend.cpp b/src/llmq/instantsend.cpp index 935795672d..d027ff94c3 100644 --- a/src/llmq/instantsend.cpp +++ b/src/llmq/instantsend.cpp @@ -639,7 +639,7 @@ void CInstantSendManager::HandleNewInputLockRecoveredSig(const CRecoveredSig& re return; } - if (LogAcceptCategory(BCLog::INSTANTSEND)) { + if (LogAcceptDebug(BCLog::INSTANTSEND)) { for (const auto& in : tx->vin) { auto id = ::SerializeHash(std::make_pair(INPUTLOCK_REQUESTID_PREFIX, in.prevout)); if (id == recoveredSig.getId()) { @@ -1469,7 +1469,7 @@ void CInstantSendManager::ProcessPendingRetryLockTxs() // CheckCanLock is already called by ProcessTx, so we should avoid calling it twice. But we also shouldn't spam // the logs when retrying TXs that are not ready yet. - if (LogAcceptCategory(BCLog::INSTANTSEND)) { + if (LogAcceptDebug(BCLog::INSTANTSEND)) { if (!CheckCanLock(*tx, false, Params().GetConsensus())) { continue; } diff --git a/src/llmq/signing_shares.cpp b/src/llmq/signing_shares.cpp index 08e068ee2c..2b72df3e2e 100644 --- a/src/llmq/signing_shares.cpp +++ b/src/llmq/signing_shares.cpp @@ -1334,7 +1334,7 @@ void CSigSharesManager::Cleanup() const auto& oneSigShare = m->begin()->second; std::string strMissingMembers; - if (LogAcceptCategory(BCLog::LLMQ_SIGS)) { + if (LogAcceptDebug(BCLog::LLMQ_SIGS)) { if (const auto quorumIt = quorums.find(std::make_pair(oneSigShare.getLlmqType(), oneSigShare.getQuorumHash())); quorumIt != quorums.end()) { const auto& quorum = quorumIt->second; for (const auto i : irange::range(quorum->members.size())) { diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index fe1fb2a1d9..4f7d635958 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -216,7 +216,7 @@ std::vector> ComputeQuorumMembersByQuarterRota //TODO Check if it is triggered from outside (P2P, block validation). Throwing an exception is probably a wiser choice //assert (!newQuarterMembers.empty()); - if (LogAcceptCategory(BCLog::LLMQ)) { + if (LogAcceptDebug(BCLog::LLMQ)) { for (const size_t i : irange::range(nQuorums)) { std::stringstream ss; @@ -249,7 +249,7 @@ std::vector> ComputeQuorumMembersByQuarterRota std::move(previousQuarters.quarterHMinusC[i].begin(), previousQuarters.quarterHMinusC[i].end(), std::back_inserter(quorumMembers[i])); std::move(newQuarterMembers[i].begin(), newQuarterMembers[i].end(), std::back_inserter(quorumMembers[i])); - if (LogAcceptCategory(BCLog::LLMQ)) { + if (LogAcceptDebug(BCLog::LLMQ)) { std::stringstream ss; ss << " ["; for (const auto &m: quorumMembers[i]) { @@ -397,7 +397,7 @@ std::vector> BuildNewQuorumQuarterMembers(cons sortedCombinedMnsList.push_back(std::move(m)); } - if (LogAcceptCategory(BCLog::LLMQ)) { + if (LogAcceptDebug(BCLog::LLMQ)) { std::stringstream ss; ss << " ["; for (const auto &m: sortedCombinedMnsList) { @@ -517,7 +517,7 @@ std::vector> GetQuorumQuarterMembersBySnapshot std::move(sortedMnsUsedAtH.begin(), sortedMnsUsedAtH.end(), std::back_inserter(sortedCombinedMns)); } - if (LogAcceptCategory(BCLog::LLMQ)) { + if (LogAcceptDebug(BCLog::LLMQ)) { std::stringstream ss; ss << " ["; for (const auto &m: sortedCombinedMns) { @@ -789,7 +789,7 @@ bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, CConnman& } if (!connections.empty()) { if (!connman.HasMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash()) && - LogAcceptCategory(BCLog::LLMQ)) { + LogAcceptDebug(BCLog::LLMQ)) { std::string debugMsg = strprintf("%s -- adding masternodes quorum connections for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString()); for (const auto& c : connections) { auto dmn = tip_mn_list.GetValidMN(c); @@ -836,7 +836,7 @@ void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman } if (!probeConnections.empty()) { - if (LogAcceptCategory(BCLog::LLMQ)) { + if (LogAcceptDebug(BCLog::LLMQ)) { std::string debugMsg = strprintf("%s -- adding masternodes probes for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString()); for (const auto& c : probeConnections) { auto dmn = tip_mn_list.GetValidMN(c); diff --git a/src/logging.h b/src/logging.h index 8e8574ea29..a7f10f9cbf 100644 --- a/src/logging.h +++ b/src/logging.h @@ -226,11 +226,17 @@ namespace BCLog { BCLog::Logger& LogInstance(); /** Return true if log accepts specified category, at the specified level. */ -static inline bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level = BCLog::Level::Debug) +static inline bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level) { return LogInstance().WillLogCategoryLevel(category, level); } +/** Return true if log accepts specified category, at the debug level. */ +static inline bool LogAcceptDebug(BCLog::LogFlags category) +{ + return LogAcceptCategory(category, BCLog::Level::Debug); +} + /** Return true if str parses as a log category and set the flag */ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 832840db59..35da41971c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3432,7 +3432,7 @@ std::vector CWallet::SelectCoinsGroupedByAddresses(bool fSkipD } // debug - if (LogAcceptCategory(BCLog::SELECTCOINS)) { + if (LogAcceptCategory(BCLog::SELECTCOINS, BCLog::Level::Debug)) { std::string strMessage = "SelectCoinsGroupedByAddresses - vecTallyRet:\n"; for (const auto& item : vecTallyRet) strMessage += strprintf(" %s %f\n", EncodeDestination(item.txdest), float(item.nAmount)/COIN); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 49c8b96a51..e3164577e5 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -152,7 +152,7 @@ extern const std::map WALLET_FLAG_CAVEATS; // evaluating arguments when logging for the category is not enabled. #define WalletCJLogPrint(wallet, ...) \ do { \ - if (LogAcceptCategory(BCLog::COINJOIN)) { \ + if (LogAcceptDebug(BCLog::COINJOIN)) { \ wallet->WalletLogPrintf(__VA_ARGS__); \ } \ } while (0)