Is it important that we log the entire message when enqueueing? Because if not, and we log e.g. just the function name, I think we don’t really need any of these macros?
0diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp
1index cc1abcd6cd..038e9d220b 100644
2--- a/src/validationinterface.cpp
3+++ b/src/validationinterface.cpp
4@@ -154,123 +154,100 @@ void ValidationSignals::SyncWithValidationInterfaceQueue()
5 promise.get_future().wait();
6 }
7
8-// Use a macro instead of a function for conditional logging to prevent
9-// evaluating arguments when logging is not enabled.
10-//
11-// NOTE: The lambda captures the event by move
12-#define ENQUEUE_AND_LOG_EVENT(event, log_msg) \
13- do { \
14- static_assert(std::is_rvalue_reference_v<decltype((event))>, \
15- "event must be passed as an rvalue"); \
16- static_assert(!std::is_const_v<std::remove_reference_t<decltype((log_msg))>>, \
17- "log_msg must be mutable reference"); \
18- LOG_EVENT("Enqueuing %s", log_msg); \
19- m_internals->m_task_runner->insert([local_log_msg = std::move(log_msg), local_event = (event)] { \
20- LOG_EVENT("%s", local_log_msg); \
21- local_event(); \
22- }); \
23- } while (0)
24-
25-#define LOG_MSG(fmt, ...) \
26- (ShouldLog(BCLog::VALIDATION, BCLog::Level::Debug) ? tfm::format((fmt), __VA_ARGS__) : std::string{})
27-
28-#define LOG_EVENT(fmt, ...) \
29- LogDebug(BCLog::VALIDATION, fmt, __VA_ARGS__)
30-
31 void ValidationSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
32 // Dependencies exist that require UpdatedBlockTip events to be delivered in the order in which
33 // the chain actually updates. One way to ensure this is for the caller to invoke this signal
34 // in the same critical section where the chain is updated
35
36- auto log_msg = LOG_MSG("%s: new block hash=%s fork block hash=%s (in IBD=%s)", __func__,
37- pindexNew->GetBlockHash().ToString(),
38- pindexFork ? pindexFork->GetBlockHash().ToString() : "null",
39- fInitialDownload);
40- auto event = [pindexNew, pindexFork, fInitialDownload, this] {
41+ LogDebug(BCLog::VALIDATION, "Enqueuing %s event", __func__);
42+ m_internals->m_task_runner->insert([pindexNew, pindexFork, fInitialDownload, this] {
43+ LogDebug(BCLog::VALIDATION, "%s: new block hash=%s fork block hash=%s (in IBD=%s)", __func__,
44+ pindexNew->GetBlockHash().ToString(),
45+ pindexFork ? pindexFork->GetBlockHash().ToString() : "null",
46+ fInitialDownload);
47 m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload); });
48- };
49- ENQUEUE_AND_LOG_EVENT(std::move(event), log_msg);
50+ });
51 }
52
53 void ValidationSignals::ActiveTipChange(const CBlockIndex& new_tip, bool is_ibd)
54 {
55- LOG_EVENT("%s: new block hash=%s block height=%d", __func__, new_tip.GetBlockHash().ToString(), new_tip.nHeight);
56+ LogDebug(BCLog::VALIDATION, "%s: new block hash=%s block height=%d", __func__, new_tip.GetBlockHash().ToString(), new_tip.nHeight);
57 m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ActiveTipChange(new_tip, is_ibd); });
58 }
59
60 void ValidationSignals::TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence)
61 {
62- auto log_msg = LOG_MSG("%s: txid=%s wtxid=%s", __func__,
63- tx.info.m_tx->GetHash().ToString(),
64- tx.info.m_tx->GetWitnessHash().ToString());
65- auto event = [tx, mempool_sequence, this] {
66+ LogDebug(BCLog::VALIDATION, "Enqueuing %s event", __func__);
67+ m_internals->m_task_runner->insert([tx, mempool_sequence, this] {
68+ LogDebug(BCLog::VALIDATION, "%s: txid=%s wtxid=%s", __func__,
69+ tx.info.m_tx->GetHash().ToString(),
70+ tx.info.m_tx->GetWitnessHash().ToString());
71 m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(tx, mempool_sequence); });
72- };
73- ENQUEUE_AND_LOG_EVENT(std::move(event), log_msg);
74+ });
75 }
76
77 void ValidationSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) {
78- auto log_msg = LOG_MSG("%s: txid=%s wtxid=%s reason=%s", __func__,
79- tx->GetHash().ToString(),
80- tx->GetWitnessHash().ToString(),
81- RemovalReasonToString(reason));
82- auto event = [tx, reason, mempool_sequence, this] {
83+ LogDebug(BCLog::VALIDATION, "Enqueuing %s event", __func__);
84+ m_internals->m_task_runner->insert([tx, reason, mempool_sequence, this] {
85+ LogDebug(BCLog::VALIDATION, "%s: txid=%s wtxid=%s reason=%s", __func__,
86+ tx->GetHash().ToString(),
87+ tx->GetWitnessHash().ToString(),
88+ RemovalReasonToString(reason));
89 m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionRemovedFromMempool(tx, reason, mempool_sequence); });
90- };
91- ENQUEUE_AND_LOG_EVENT(std::move(event), log_msg);
92+ });
93 }
94
95 void ValidationSignals::BlockConnected(const ChainstateRole& role, std::shared_ptr<const CBlock> pblock, const CBlockIndex* pindex)
96 {
97- auto log_msg = LOG_MSG("%s: block hash=%s block height=%d", __func__,
98- pblock->GetHash().ToString(),
99- pindex->nHeight);
100- auto event = [role, pblock = std::move(pblock), pindex, this] {
101+ LogDebug(BCLog::VALIDATION, "Enqueuing %s event", __func__);
102+ m_internals->m_task_runner->insert([role, pblock = std::move(pblock), pindex, this] {
103+ LogDebug(BCLog::VALIDATION, "%s: block hash=%s block height=%d", __func__,
104+ pblock->GetHash().ToString(),
105+ pindex->nHeight);
106 m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockConnected(role, pblock, pindex); });
107- };
108- ENQUEUE_AND_LOG_EVENT(std::move(event), log_msg);
109+ });
110 }
111
112 void ValidationSignals::MempoolTransactionsRemovedForBlock(const std::vector<RemovedMempoolTransactionInfo>& txs_removed_for_block, unsigned int nBlockHeight)
113 {
114- auto log_msg = LOG_MSG("%s: block height=%s txs removed=%s", __func__,
115- nBlockHeight,
116- txs_removed_for_block.size());
117- auto event = [txs_removed_for_block, nBlockHeight, this] {
118+ LogDebug(BCLog::VALIDATION, "Enqueuing %s event", __func__);
119+ m_internals->m_task_runner->insert([txs_removed_for_block, nBlockHeight, this] {
120+ LogDebug(BCLog::VALIDATION, "%s: block height=%d txs removed=%d", __func__,
121+ nBlockHeight,
122+ txs_removed_for_block.size());
123 m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.MempoolTransactionsRemovedForBlock(txs_removed_for_block, nBlockHeight); });
124- };
125- ENQUEUE_AND_LOG_EVENT(std::move(event), log_msg);
126+ });
127 }
128
129 void ValidationSignals::BlockDisconnected(std::shared_ptr<const CBlock> pblock, const CBlockIndex* pindex)
130 {
131- auto log_msg = LOG_MSG("%s: block hash=%s block height=%d", __func__,
132- pblock->GetHash().ToString(),
133- pindex->nHeight);
134- auto event = [pblock = std::move(pblock), pindex, this] {
135+ LogDebug(BCLog::VALIDATION, "Enqueuing %s event", __func__);
136+ m_internals->m_task_runner->insert([pblock = std::move(pblock), pindex, this] {
137+ LogDebug(BCLog::VALIDATION, "%s: block hash=%s block height=%d", __func__,
138+ pblock->GetHash().ToString(),
139+ pindex->nHeight);
140 m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockDisconnected(pblock, pindex); });
141- };
142- ENQUEUE_AND_LOG_EVENT(std::move(event), log_msg);
143+ });
144 }
145
146 void ValidationSignals::ChainStateFlushed(const ChainstateRole& role, const CBlockLocator& locator)
147 {
148- auto log_msg = LOG_MSG("%s: block hash=%s", __func__,
149- locator.IsNull() ? "null" : locator.vHave.front().ToString());
150- auto event = [role, locator, this] {
151+ LogDebug(BCLog::VALIDATION, "Enqueuing %s event", __func__);
152+ m_internals->m_task_runner->insert([role, locator, this] {
153+ LogDebug(BCLog::VALIDATION, "%s: block hash=%s", __func__,
154+ locator.IsNull() ? "null" : locator.vHave.front().ToString());
155 m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ChainStateFlushed(role, locator); });
156- };
157- ENQUEUE_AND_LOG_EVENT(std::move(event), log_msg);
158+ });
159 }
160
161 void ValidationSignals::BlockChecked(const std::shared_ptr<const CBlock>& block, const BlockValidationState& state)
162 {
163- LOG_EVENT("%s: block hash=%s state=%s", __func__,
164- block->GetHash().ToString(), state.ToString());
165+ LogDebug(BCLog::VALIDATION, "%s: block hash=%s state=%s", __func__,
166+ block->GetHash().ToString(), state.ToString());
167 m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockChecked(block, state); });
168 }
169
170 void ValidationSignals::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock> &block) {
171- LOG_EVENT("%s: block hash=%s", __func__, block->GetHash().ToString());
172+ LogDebug(BCLog::VALIDATION, "%s: block hash=%s", __func__, block->GetHash().ToString());
173 m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.NewPoWValidBlock(pindex, block); });
174 }