mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Merge #16688: log: Add validation interface logging
f9abf4ab6dAdd logging for CValidationInterface events (Jeffrey Czyz)6edebacb21Refactor FormatStateMessage for clarity (Jeffrey Czyz)72f3227c83Format CValidationState properly in all cases (Jeffrey Czyz)428ac70095Add VALIDATION to BCLog::LogFlags (Jeffrey Czyz) Pull request description: Add logging of `CValidationInterface` callbacks using a new `VALIDATIONINTERFACE` log flag (see #12994). A separate flag is desirable as the logging can be noisy and thus may need to be disabled without affecting other logging. This could help debug issues where there may be race conditions at play, such as #12978. ACKs for top commit: jnewbery: ACKf9abf4ab6dhebasto: ACKf9abf4ab6dariard: ACKf9abf4a, only changes since0cadb12are replacing log indication `VALIDATIONINTERFACE` by `VALIDATION` and avoiding a forward declaration with a new include ryanofsky: Code review ACKf9abf4ab6d. Just suggested changes since last review (thanks!) Tree-SHA512: 3e0f6e2c8951cf46fbad3ff440971d95d526df2a52a2e4d6452a82785c63d53accfdabae66b0b30e2fe0b00737f8d5cb717edbad1460b63acb11a72c8f5d4236
This commit is contained in:
@@ -5,8 +5,13 @@
|
||||
|
||||
#include <validationinterface.h>
|
||||
|
||||
#include <chain.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <logging.h>
|
||||
#include <primitives/block.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <scheduler.h>
|
||||
#include <util/validation.h>
|
||||
|
||||
#include <future>
|
||||
#include <unordered_map>
|
||||
@@ -110,52 +115,89 @@ void SyncWithValidationInterfaceQueue() {
|
||||
promise.get_future().wait();
|
||||
}
|
||||
|
||||
// Use a macro instead of a function for conditional logging to prevent
|
||||
// evaluating arguments when logging is not enabled.
|
||||
//
|
||||
// NOTE: The lambda captures all local variables by value.
|
||||
#define ENQUEUE_AND_LOG_EVENT(event, fmt, name, ...) \
|
||||
do { \
|
||||
auto local_name = (name); \
|
||||
LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \
|
||||
m_internals->m_schedulerClient.AddToProcessQueue([=] { \
|
||||
LOG_EVENT(fmt, local_name, __VA_ARGS__); \
|
||||
event(); \
|
||||
}); \
|
||||
} while (0)
|
||||
|
||||
#define LOG_EVENT(fmt, ...) \
|
||||
LogPrint(BCLog::VALIDATION, fmt "\n", __VA_ARGS__)
|
||||
|
||||
void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
|
||||
// Dependencies exist that require UpdatedBlockTip events to be delivered in the order in which
|
||||
// the chain actually updates. One way to ensure this is for the caller to invoke this signal
|
||||
// in the same critical section where the chain is updated
|
||||
|
||||
m_internals->m_schedulerClient.AddToProcessQueue([pindexNew, pindexFork, fInitialDownload, this] {
|
||||
auto event = [pindexNew, pindexFork, fInitialDownload, this] {
|
||||
m_internals->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
|
||||
});
|
||||
};
|
||||
ENQUEUE_AND_LOG_EVENT(event, "%s: new block hash=%s fork block hash=%s (in IBD=%s)", __func__,
|
||||
pindexNew->GetBlockHash().ToString(),
|
||||
pindexFork ? pindexFork->GetBlockHash().ToString() : "null",
|
||||
fInitialDownload);
|
||||
}
|
||||
|
||||
void CMainSignals::TransactionAddedToMempool(const CTransactionRef &ptx) {
|
||||
m_internals->m_schedulerClient.AddToProcessQueue([ptx, this] {
|
||||
auto event = [ptx, this] {
|
||||
m_internals->TransactionAddedToMempool(ptx);
|
||||
});
|
||||
};
|
||||
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__,
|
||||
ptx->GetHash().ToString(),
|
||||
ptx->GetWitnessHash().ToString());
|
||||
}
|
||||
|
||||
void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef &ptx) {
|
||||
m_internals->m_schedulerClient.AddToProcessQueue([ptx, this] {
|
||||
auto event = [ptx, this] {
|
||||
m_internals->TransactionRemovedFromMempool(ptx);
|
||||
});
|
||||
};
|
||||
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__,
|
||||
ptx->GetHash().ToString(),
|
||||
ptx->GetWitnessHash().ToString());
|
||||
}
|
||||
|
||||
void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>>& pvtxConflicted) {
|
||||
m_internals->m_schedulerClient.AddToProcessQueue([pblock, pindex, pvtxConflicted, this] {
|
||||
auto event = [pblock, pindex, pvtxConflicted, this] {
|
||||
m_internals->BlockConnected(pblock, pindex, *pvtxConflicted);
|
||||
});
|
||||
};
|
||||
ENQUEUE_AND_LOG_EVENT(event, "%s: block hash=%s block height=%d", __func__,
|
||||
pblock->GetHash().ToString(),
|
||||
pindex->nHeight);
|
||||
}
|
||||
|
||||
void CMainSignals::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
|
||||
{
|
||||
m_internals->m_schedulerClient.AddToProcessQueue([pblock, pindex, this] {
|
||||
auto event = [pblock, pindex, this] {
|
||||
m_internals->BlockDisconnected(pblock, pindex);
|
||||
});
|
||||
};
|
||||
ENQUEUE_AND_LOG_EVENT(event, "%s: block hash=%s block height=%d", __func__,
|
||||
pblock->GetHash().ToString(),
|
||||
pindex->nHeight);
|
||||
}
|
||||
|
||||
void CMainSignals::ChainStateFlushed(const CBlockLocator &locator) {
|
||||
m_internals->m_schedulerClient.AddToProcessQueue([locator, this] {
|
||||
auto event = [locator, this] {
|
||||
m_internals->ChainStateFlushed(locator);
|
||||
});
|
||||
};
|
||||
ENQUEUE_AND_LOG_EVENT(event, "%s: block hash=%s", __func__,
|
||||
locator.IsNull() ? "null" : locator.vHave.front().ToString());
|
||||
}
|
||||
|
||||
void CMainSignals::BlockChecked(const CBlock& block, const BlockValidationState& state) {
|
||||
LOG_EVENT("%s: block hash=%s state=%s", __func__,
|
||||
block.GetHash().ToString(), FormatStateMessage(state));
|
||||
m_internals->BlockChecked(block, state);
|
||||
}
|
||||
|
||||
void CMainSignals::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock> &block) {
|
||||
LOG_EVENT("%s: block hash=%s", __func__, block->GetHash().ToString());
|
||||
m_internals->NewPoWValidBlock(pindex, block);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user