scripted-diff: logging: Drop LogAcceptCategory
What changed, and why it matters
This is a routine internal code cleanup in Bitcoin Core. It replaces an older logging helper function called LogAcceptCategory with newer, more specific helper functions (ShouldDebugLog and ShouldTraceLog). The behavior of the program is intended to remain exactly the same; only the names of the functions used to decide what to log have changed. There is no indication this fixes or introduces a security vulnerability.
No security action required. Treat as normal refactoring. If reviewing, verify that util::log::ShouldDebugLog and util::log::ShouldTraceLog are exact behavioral replacements for the prior LogAcceptCategory calls and that no call sites were missed by the scripted diff.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit is a scripted diff that mechanically replaces calls to LogAcceptCategory(category, level) with util::log::ShouldDebugLog(category) or util::log::ShouldTraceLog(category), depending on the level, and removes the now-unused LogAcceptCategory inline wrapper from src/logging.h. The replacement helpers are presumably existing wrappers around Logger::WillLogCategoryLevel. All changed call sites are in non-consensus logging guard paths: block compact-block logging, LevelDB wrapper, IPC capnp protocol, net processing, wallet coin selection, and SQLite wallet tracing. No logic changes are visible in the diff.
Changed components
src/blockencodings.cppsrc/dbwrapper.cppsrc/ipc/capnp/protocol.cppsrc/logging.hsrc/net_processing.cppsrc/wallet/coinselection.cppsrc/wallet/sqlite.cppInspect captured patch +8 / −14
diff --git a/src/blockencodings.cpp b/src/blockencodings.cpp
index 18799cd8..064e0853 100644
--- a/src/blockencodings.cpp
+++ b/src/blockencodings.cpp
@@ -219,7 +219,7 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
return READ_STATUS_FAILED; // Possible Short ID collision
}
- if (LogAcceptCategory(BCLog::CMPCTBLOCK, BCLog::Level::Debug)) {
+ if (util::log::ShouldDebugLog(BCLog::CMPCTBLOCK)) {
const uint256 hash{block.GetHash()};
uint32_t tx_missing_size{0};
for (const auto& tx : vtx_missing) tx_missing_size += tx->ComputeTotalSize();
diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp
index 3212f6d3..fde8e8e4 100644
--- a/src/dbwrapper.cpp
+++ b/src/dbwrapper.cpp
@@ -59,7 +59,7 @@ public:
// This code is adapted from posix_logger.h, which is why it is using vsprintf.
// Please do not do this in normal code
void Logv(const char * format, va_list ap) override {
- if (!LogAcceptCategory(BCLog::LEVELDB, util::log::Level::Debug)) {
+ if (!util::log::ShouldDebugLog(BCLog::LEVELDB)) {
return;
}
char buffer[500];
@@ -278,7 +278,7 @@ CDBWrapper::~CDBWrapper()
void CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
{
- const bool log_memory = LogAcceptCategory(BCLog::LEVELDB, util::log::Level::Debug);
+ const bool log_memory = util::log::ShouldDebugLog(BCLog::LEVELDB);
double mem_before = 0;
if (log_memory) {
mem_before = DynamicMemoryUsage() / double(1_MiB);
diff --git a/src/ipc/capnp/protocol.cpp b/src/ipc/capnp/protocol.cpp
index 2645e46f..e68ce872 100644
--- a/src/ipc/capnp/protocol.cpp
+++ b/src/ipc/capnp/protocol.cpp
@@ -33,8 +33,8 @@ namespace {
mp::Log GetRequestedIPCLogLevel()
{
- if (LogAcceptCategory(BCLog::IPC, BCLog::Level::Trace)) return mp::Log::Trace;
- if (LogAcceptCategory(BCLog::IPC, BCLog::Level::Debug)) return mp::Log::Debug;
+ if (util::log::ShouldTraceLog(BCLog::IPC)) return mp::Log::Trace;
+ if (util::log::ShouldDebugLog(BCLog::IPC)) return mp::Log::Debug;
// Info, Warning, and Error are logged unconditionally
return mp::Log::Info;
diff --git a/src/logging.h b/src/logging.h
index a727dc24..4bdcd0f2 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -283,10 +283,4 @@ 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)
-{
- return LogInstance().WillLogCategoryLevel(category, level);
-}
-
#endif // BITCOIN_LOGGING_H
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 6d35db93..94861130 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -2607,7 +2607,7 @@ void PeerManagerImpl::SendBlockTransactions(CNode& pfrom, Peer& peer, const CBlo
resp.txn[i] = block.vtx[req.indexes[i]];
}
- if (LogAcceptCategory(BCLog::CMPCTBLOCK, BCLog::Level::Debug)) {
+ if (util::log::ShouldDebugLog(BCLog::CMPCTBLOCK)) {
uint32_t tx_requested_size{0};
for (const auto& tx : resp.txn) tx_requested_size += tx->ComputeTotalSize();
LogDebug(BCLog::CMPCTBLOCK, "Peer %d sent us a GETBLOCKTXN for block %s, sending a BLOCKTXN with %u txns. (%u bytes)\n", pfrom.GetId(), block.GetHash().ToString(), resp.txn.size(), tx_requested_size);
diff --git a/src/wallet/coinselection.cpp b/src/wallet/coinselection.cpp
index d6ea6851..1d9db426 100644
--- a/src/wallet/coinselection.cpp
+++ b/src/wallet/coinselection.cpp
@@ -732,7 +732,7 @@ util::Result<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups, c
result.AddInput(*lowest_larger);
}
- if (LogAcceptCategory(BCLog::SELECTCOINS, BCLog::Level::Debug)) {
+ if (util::log::ShouldDebugLog(BCLog::SELECTCOINS)) {
std::string log_message{"Coin selection best subset: "};
for (unsigned int i = 0; i < applicable_groups.size(); i++) {
if (vfBest[i]) {
diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp
index 3d6583bb..03adc7ec 100644
--- a/src/wallet/sqlite.cpp
+++ b/src/wallet/sqlite.cpp
@@ -267,7 +267,7 @@ void SQLiteDatabase::Open(int additional_flags)
throw std::runtime_error(strprintf("SQLiteDatabase: Failed to enable extended result codes: %s\n", sqlite3_errstr(ret)));
}
// Trace SQL statements if tracing is enabled with -debug=walletdb -loglevel=walletdb:trace
- if (LogAcceptCategory(BCLog::WALLETDB, BCLog::Level::Trace)) {
+ if (util::log::ShouldTraceLog(BCLog::WALLETDB)) {
ret = sqlite3_trace_v2(m_db, SQLITE_TRACE_STMT, TraceSqlCallback, this);
if (ret != SQLITE_OK) {
LogWarning("Failed to enable SQL tracing for %s", Filename());
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.