Skip to content

Commit a254a7b

Browse files
knstUdjinM6
authored andcommitted
refactor: sping LogAcceptCategory and LogAcceptDebug
1 parent 82238e6 commit a254a7b

File tree

8 files changed

+23
-17
lines changed

8 files changed

+23
-17
lines changed

src/llmq/commitment.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ bool CFinalCommitment::Verify(CDeterministicMNManager& dmnman, gsl::not_null<con
8282
return false;
8383
}
8484
auto members = utils::GetAllQuorumMembers(llmqType, dmnman, pQuorumBaseBlockIndex);
85-
if (LogAcceptCategory(BCLog::LLMQ)) {
85+
if (LogAcceptDebug(BCLog::LLMQ)) {
8686
std::stringstream ss;
8787
std::stringstream ss2;
8888
for (const auto i: irange::range(llmq_params.size)) {
@@ -106,7 +106,7 @@ bool CFinalCommitment::Verify(CDeterministicMNManager& dmnman, gsl::not_null<con
106106
// sigs are only checked when the block is processed
107107
if (checkSigs) {
108108
uint256 commitmentHash = BuildCommitmentHash(llmq_params.type, quorumHash, validMembers, quorumPublicKey, quorumVvecHash);
109-
if (LogAcceptCategory(BCLog::LLMQ)) {
109+
if (LogAcceptDebug(BCLog::LLMQ)) {
110110
std::stringstream ss3;
111111
for (const auto &mn: members) {
112112
ss3 << mn->proTxHash.ToString().substr(0, 4) << " | ";
@@ -181,7 +181,7 @@ bool CheckLLMQCommitment(CDeterministicMNManager& dmnman, const ChainstateManage
181181
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-qc-commitment-type");
182182
}
183183

184-
if (LogAcceptCategory(BCLog::LLMQ)) {
184+
if (LogAcceptDebug(BCLog::LLMQ)) {
185185
std::stringstream ss;
186186
for (const auto i: irange::range(llmq_params_opt->size)) {
187187
ss << "v[" << i << "]=" << qcTx.commitment.validMembers[i];

src/llmq/dkgsession.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ bool CDKGSession::Init(const uint256& _myProTxHash, int _quorumIndex)
120120

121121
CDKGLogger logger(*this, __func__, __LINE__);
122122

123-
if (LogAcceptCategory(BCLog::LLMQ) && IsQuorumRotationEnabled(params, m_quorum_base_block_index)) {
123+
if (LogAcceptDebug(BCLog::LLMQ) && IsQuorumRotationEnabled(params, m_quorum_base_block_index)) {
124124
int cycleQuorumBaseHeight = m_quorum_base_block_index->nHeight - quorumIndex;
125125
const CBlockIndex* pCycleQuorumBaseBlockIndex = m_quorum_base_block_index->GetAncestor(cycleQuorumBaseHeight);
126126
std::stringstream ss;
@@ -138,7 +138,7 @@ bool CDKGSession::Init(const uint256& _myProTxHash, int _quorumIndex)
138138
if (!myProTxHash.IsNull()) {
139139
dkgDebugManager.InitLocalSessionStatus(params, quorumIndex, m_quorum_base_block_index->GetBlockHash(), m_quorum_base_block_index->nHeight);
140140
relayMembers = utils::GetQuorumRelayMembers(params, m_dmnman, m_quorum_base_block_index, myProTxHash, true);
141-
if (LogAcceptCategory(BCLog::LLMQ)) {
141+
if (LogAcceptDebug(BCLog::LLMQ)) {
142142
std::stringstream ss;
143143
for (const auto& r : relayMembers) {
144144
ss << r.ToString().substr(0, 4) << " | ";

src/llmq/instantsend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ void CInstantSendManager::HandleNewInputLockRecoveredSig(const CRecoveredSig& re
639639
return;
640640
}
641641

642-
if (LogAcceptCategory(BCLog::INSTANTSEND)) {
642+
if (LogAcceptDebug(BCLog::INSTANTSEND)) {
643643
for (const auto& in : tx->vin) {
644644
auto id = ::SerializeHash(std::make_pair(INPUTLOCK_REQUESTID_PREFIX, in.prevout));
645645
if (id == recoveredSig.getId()) {
@@ -1469,7 +1469,7 @@ void CInstantSendManager::ProcessPendingRetryLockTxs()
14691469

14701470
// CheckCanLock is already called by ProcessTx, so we should avoid calling it twice. But we also shouldn't spam
14711471
// the logs when retrying TXs that are not ready yet.
1472-
if (LogAcceptCategory(BCLog::INSTANTSEND)) {
1472+
if (LogAcceptDebug(BCLog::INSTANTSEND)) {
14731473
if (!CheckCanLock(*tx, false, Params().GetConsensus())) {
14741474
continue;
14751475
}

src/llmq/signing_shares.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ void CSigSharesManager::Cleanup()
13341334
const auto& oneSigShare = m->begin()->second;
13351335

13361336
std::string strMissingMembers;
1337-
if (LogAcceptCategory(BCLog::LLMQ_SIGS)) {
1337+
if (LogAcceptDebug(BCLog::LLMQ_SIGS)) {
13381338
if (const auto quorumIt = quorums.find(std::make_pair(oneSigShare.getLlmqType(), oneSigShare.getQuorumHash())); quorumIt != quorums.end()) {
13391339
const auto& quorum = quorumIt->second;
13401340
for (const auto i : irange::range(quorum->members.size())) {

src/llmq/utils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ std::vector<std::vector<CDeterministicMNCPtr>> ComputeQuorumMembersByQuarterRota
216216
//TODO Check if it is triggered from outside (P2P, block validation). Throwing an exception is probably a wiser choice
217217
//assert (!newQuarterMembers.empty());
218218

219-
if (LogAcceptCategory(BCLog::LLMQ)) {
219+
if (LogAcceptDebug(BCLog::LLMQ)) {
220220
for (const size_t i : irange::range(nQuorums)) {
221221
std::stringstream ss;
222222

@@ -249,7 +249,7 @@ std::vector<std::vector<CDeterministicMNCPtr>> ComputeQuorumMembersByQuarterRota
249249
std::move(previousQuarters.quarterHMinusC[i].begin(), previousQuarters.quarterHMinusC[i].end(), std::back_inserter(quorumMembers[i]));
250250
std::move(newQuarterMembers[i].begin(), newQuarterMembers[i].end(), std::back_inserter(quorumMembers[i]));
251251

252-
if (LogAcceptCategory(BCLog::LLMQ)) {
252+
if (LogAcceptDebug(BCLog::LLMQ)) {
253253
std::stringstream ss;
254254
ss << " [";
255255
for (const auto &m: quorumMembers[i]) {
@@ -397,7 +397,7 @@ std::vector<std::vector<CDeterministicMNCPtr>> BuildNewQuorumQuarterMembers(cons
397397
sortedCombinedMnsList.push_back(std::move(m));
398398
}
399399

400-
if (LogAcceptCategory(BCLog::LLMQ)) {
400+
if (LogAcceptDebug(BCLog::LLMQ)) {
401401
std::stringstream ss;
402402
ss << " [";
403403
for (const auto &m: sortedCombinedMnsList) {
@@ -517,7 +517,7 @@ std::vector<std::vector<CDeterministicMNCPtr>> GetQuorumQuarterMembersBySnapshot
517517
std::move(sortedMnsUsedAtH.begin(), sortedMnsUsedAtH.end(), std::back_inserter(sortedCombinedMns));
518518
}
519519

520-
if (LogAcceptCategory(BCLog::LLMQ)) {
520+
if (LogAcceptDebug(BCLog::LLMQ)) {
521521
std::stringstream ss;
522522
ss << " [";
523523
for (const auto &m: sortedCombinedMns) {
@@ -789,7 +789,7 @@ bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, CConnman&
789789
}
790790
if (!connections.empty()) {
791791
if (!connman.HasMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash()) &&
792-
LogAcceptCategory(BCLog::LLMQ)) {
792+
LogAcceptDebug(BCLog::LLMQ)) {
793793
std::string debugMsg = strprintf("%s -- adding masternodes quorum connections for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString());
794794
for (const auto& c : connections) {
795795
auto dmn = tip_mn_list.GetValidMN(c);
@@ -836,7 +836,7 @@ void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman
836836
}
837837

838838
if (!probeConnections.empty()) {
839-
if (LogAcceptCategory(BCLog::LLMQ)) {
839+
if (LogAcceptDebug(BCLog::LLMQ)) {
840840
std::string debugMsg = strprintf("%s -- adding masternodes probes for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString());
841841
for (const auto& c : probeConnections) {
842842
auto dmn = tip_mn_list.GetValidMN(c);

src/logging.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,17 @@ namespace BCLog {
226226
BCLog::Logger& LogInstance();
227227

228228
/** Return true if log accepts specified category, at the specified level. */
229-
static inline bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level = BCLog::Level::Debug)
229+
static inline bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level)
230230
{
231231
return LogInstance().WillLogCategoryLevel(category, level);
232232
}
233233

234+
/** Return true if log accepts specified category, at the debug level. */
235+
static inline bool LogAcceptDebug(BCLog::LogFlags category)
236+
{
237+
return LogAcceptCategory(category, BCLog::Level::Debug);
238+
}
239+
234240
/** Return true if str parses as a log category and set the flag */
235241
bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str);
236242

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3432,7 +3432,7 @@ std::vector<CompactTallyItem> CWallet::SelectCoinsGroupedByAddresses(bool fSkipD
34323432
}
34333433

34343434
// debug
3435-
if (LogAcceptCategory(BCLog::SELECTCOINS)) {
3435+
if (LogAcceptCategory(BCLog::SELECTCOINS, BCLog::Level::Debug)) {
34363436
std::string strMessage = "SelectCoinsGroupedByAddresses - vecTallyRet:\n";
34373437
for (const auto& item : vecTallyRet)
34383438
strMessage += strprintf(" %s %f\n", EncodeDestination(item.txdest), float(item.nAmount)/COIN);

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ extern const std::map<uint64_t,std::string> WALLET_FLAG_CAVEATS;
152152
// evaluating arguments when logging for the category is not enabled.
153153
#define WalletCJLogPrint(wallet, ...) \
154154
do { \
155-
if (LogAcceptCategory(BCLog::COINJOIN)) { \
155+
if (LogAcceptDebug(BCLog::COINJOIN)) { \
156156
wallet->WalletLogPrintf(__VA_ARGS__); \
157157
} \
158158
} while (0)

0 commit comments

Comments
 (0)