Skip to content

Commit ec4e43c

Browse files
committed
Merge #23235: Reduce unnecessary default logging
b5950dd validation: put coins cache write log into bench debug log (Anthony Towns) 31b2b80 blockstorage: use debug log category (Anthony Towns) da94ebc validation: move header validation error logging to VALIDATION debug category (Anthony Towns) 1d7d835 validation: include block hash when reporting prev block not found errors (Anthony Towns) Pull request description: Moves the following log messages into debug log categories: * "AcceptBlockHeader: ..." to validation * "Prune: deleted blk/rev" to new blockstorage log category * "Leaving block file" moves from validation to blockstorage * "write coins cache to disk" to bench Also adds the hash of the block to the log message when AcceptBlockHeader is rejecting because of problems with the prev block. ACKs for top commit: practicalswift: cr ACK b5950dd Empact: Code review ACK bitcoin/bitcoin@b5950dd laanwj: Code review ACK b5950dd promag: Code review ACK b5950dd. meshcollider: Code review ACK b5950dd Tree-SHA512: a73fdbfe8d36da48a3e89c2d5e0b6a3c5045d280c1a57f61c38d0d21f4f198aece4bd85155be3439e179d5dabdb523bf15fa0395e0e3ceff19c878ba3112c840
2 parents 71a85fb + b5950dd commit ec4e43c

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

src/logging.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ const CLogCategoryDesc LogCategories[] =
161161
{BCLog::IPC, "ipc"},
162162
{BCLog::LOCK, "lock"},
163163
{BCLog::UTIL, "util"},
164+
{BCLog::BLOCKSTORE, "blockstorage"},
164165
{BCLog::ALL, "1"},
165166
{BCLog::ALL, "all"},
166167
};

src/logging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace BCLog {
6161
IPC = (1 << 23),
6262
LOCK = (1 << 24),
6363
UTIL = (1 << 25),
64+
BLOCKSTORE = (1 << 26),
6465
ALL = ~(uint32_t)0,
6566
};
6667

src/node/blockstorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune)
204204
FlatFilePos pos(*it, 0);
205205
fs::remove(BlockFileSeq().FileName(pos));
206206
fs::remove(UndoFileSeq().FileName(pos));
207-
LogPrintf("Prune: %s deleted blk/rev (%05u)\n", __func__, *it);
207+
LogPrint(BCLog::BLOCKSTORE, "Prune: %s deleted blk/rev (%05u)\n", __func__, *it);
208208
}
209209
}
210210

@@ -261,7 +261,7 @@ bool FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight,
261261

262262
if ((int)nFile != nLastBlockFile) {
263263
if (!fKnown) {
264-
LogPrint(BCLog::VALIDATION, "Leaving block file %i: %s\n", nLastBlockFile, vinfoBlockFile[nLastBlockFile].ToString());
264+
LogPrint(BCLog::BLOCKSTORE, "Leaving block file %i: %s\n", nLastBlockFile, vinfoBlockFile[nLastBlockFile].ToString());
265265
}
266266
FlushBlockFile(!fKnown, finalize_undo);
267267
nLastBlockFile = nFile;

src/validation.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,8 +2029,8 @@ bool CChainState::FlushStateToDisk(
20292029
}
20302030
// Flush best chain related state. This can only be done if the blocks / block index write was also done.
20312031
if (fDoFullFlush && !CoinsTip().GetBestBlock().IsNull()) {
2032-
LOG_TIME_SECONDS(strprintf("write coins cache to disk (%d coins, %.2fkB)",
2033-
coins_count, coins_mem_usage / 1000));
2032+
LOG_TIME_MILLIS_WITH_CATEGORY(strprintf("write coins cache to disk (%d coins, %.2fkB)",
2033+
coins_count, coins_mem_usage / 1000), BCLog::BENCH);
20342034

20352035
// Typical Coin structures on disk are around 48 bytes in size.
20362036
// Pushing a new one to the database can cause it to be written
@@ -3205,7 +3205,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
32053205
if (ppindex)
32063206
*ppindex = pindex;
32073207
if (pindex->nStatus & BLOCK_FAILED_MASK) {
3208-
LogPrintf("ERROR: %s: block %s is marked invalid\n", __func__, hash.ToString());
3208+
LogPrint(BCLog::VALIDATION, "%s: block %s is marked invalid\n", __func__, hash.ToString());
32093209
return state.Invalid(BlockValidationResult::BLOCK_CACHED_INVALID, "duplicate");
32103210
}
32113211
return true;
@@ -3220,16 +3220,18 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
32203220
CBlockIndex* pindexPrev = nullptr;
32213221
BlockMap::iterator mi = m_block_index.find(block.hashPrevBlock);
32223222
if (mi == m_block_index.end()) {
3223-
LogPrintf("ERROR: %s: prev block not found\n", __func__);
3223+
LogPrint(BCLog::VALIDATION, "%s: %s prev block not found\n", __func__, hash.ToString());
32243224
return state.Invalid(BlockValidationResult::BLOCK_MISSING_PREV, "prev-blk-not-found");
32253225
}
32263226
pindexPrev = (*mi).second;
32273227
if (pindexPrev->nStatus & BLOCK_FAILED_MASK) {
3228-
LogPrintf("ERROR: %s: prev block invalid\n", __func__);
3228+
LogPrint(BCLog::VALIDATION, "%s: %s prev block invalid\n", __func__, hash.ToString());
32293229
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, "bad-prevblk");
32303230
}
3231-
if (!ContextualCheckBlockHeader(block, state, *this, chainparams, pindexPrev, GetAdjustedTime()))
3232-
return error("%s: Consensus::ContextualCheckBlockHeader: %s, %s", __func__, hash.ToString(), state.ToString());
3231+
if (!ContextualCheckBlockHeader(block, state, *this, chainparams, pindexPrev, GetAdjustedTime())) {
3232+
LogPrint(BCLog::VALIDATION, "%s: Consensus::ContextualCheckBlockHeader: %s, %s\n", __func__, hash.ToString(), state.ToString());
3233+
return false;
3234+
}
32333235

32343236
/* Determine if this block descends from any block which has been found
32353237
* invalid (m_failed_blocks), then mark pindexPrev and any blocks between
@@ -3264,7 +3266,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
32643266
setDirtyBlockIndex.insert(invalid_walk);
32653267
invalid_walk = invalid_walk->pprev;
32663268
}
3267-
LogPrintf("ERROR: %s: prev block invalid\n", __func__);
3269+
LogPrint(BCLog::VALIDATION, "%s: %s prev block invalid\n", __func__, hash.ToString());
32683270
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, "bad-prevblk");
32693271
}
32703272
}

test/functional/rpc_misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def run_test(self):
5757
self.log.info("test logging rpc and help")
5858

5959
# Test logging RPC returns the expected number of logging categories.
60-
assert_equal(len(node.logging()), 26)
60+
assert_equal(len(node.logging()), 27)
6161

6262
# Test toggling a logging category on/off/on with the logging RPC.
6363
assert_equal(node.logging()['qt'], True)

0 commit comments

Comments
 (0)