|
5 | 5 |
|
6 | 6 | #include <validationinterface.h>
|
7 | 7 |
|
| 8 | +#include <chain.h> |
| 9 | +#include <consensus/validation.h> |
| 10 | +#include <logging.h> |
8 | 11 | #include <primitives/block.h>
|
| 12 | +#include <primitives/transaction.h> |
9 | 13 | #include <scheduler.h>
|
| 14 | +#include <util/validation.h> |
10 | 15 |
|
11 | 16 | #include <future>
|
12 | 17 | #include <unordered_map>
|
@@ -110,52 +115,89 @@ void SyncWithValidationInterfaceQueue() {
|
110 | 115 | promise.get_future().wait();
|
111 | 116 | }
|
112 | 117 |
|
| 118 | +// Use a macro instead of a function for conditional logging to prevent |
| 119 | +// evaluating arguments when logging is not enabled. |
| 120 | +// |
| 121 | +// NOTE: The lambda captures all local variables by value. |
| 122 | +#define ENQUEUE_AND_LOG_EVENT(event, fmt, name, ...) \ |
| 123 | + do { \ |
| 124 | + auto local_name = (name); \ |
| 125 | + LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \ |
| 126 | + m_internals->m_schedulerClient.AddToProcessQueue([=] { \ |
| 127 | + LOG_EVENT(fmt, local_name, __VA_ARGS__); \ |
| 128 | + event(); \ |
| 129 | + }); \ |
| 130 | + } while (0) |
| 131 | + |
| 132 | +#define LOG_EVENT(fmt, ...) \ |
| 133 | + LogPrint(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) |
113 | 134 |
|
114 | 135 | void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
|
115 | 136 | // Dependencies exist that require UpdatedBlockTip events to be delivered in the order in which
|
116 | 137 | // the chain actually updates. One way to ensure this is for the caller to invoke this signal
|
117 | 138 | // in the same critical section where the chain is updated
|
118 | 139 |
|
119 |
| - m_internals->m_schedulerClient.AddToProcessQueue([pindexNew, pindexFork, fInitialDownload, this] { |
| 140 | + auto event = [pindexNew, pindexFork, fInitialDownload, this] { |
120 | 141 | m_internals->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
|
121 |
| - }); |
| 142 | + }; |
| 143 | + ENQUEUE_AND_LOG_EVENT(event, "%s: new block hash=%s fork block hash=%s (in IBD=%s)", __func__, |
| 144 | + pindexNew->GetBlockHash().ToString(), |
| 145 | + pindexFork ? pindexFork->GetBlockHash().ToString() : "null", |
| 146 | + fInitialDownload); |
122 | 147 | }
|
123 | 148 |
|
124 | 149 | void CMainSignals::TransactionAddedToMempool(const CTransactionRef &ptx) {
|
125 |
| - m_internals->m_schedulerClient.AddToProcessQueue([ptx, this] { |
| 150 | + auto event = [ptx, this] { |
126 | 151 | m_internals->TransactionAddedToMempool(ptx);
|
127 |
| - }); |
| 152 | + }; |
| 153 | + ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__, |
| 154 | + ptx->GetHash().ToString(), |
| 155 | + ptx->GetWitnessHash().ToString()); |
128 | 156 | }
|
129 | 157 |
|
130 | 158 | void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef &ptx) {
|
131 |
| - m_internals->m_schedulerClient.AddToProcessQueue([ptx, this] { |
| 159 | + auto event = [ptx, this] { |
132 | 160 | m_internals->TransactionRemovedFromMempool(ptx);
|
133 |
| - }); |
| 161 | + }; |
| 162 | + ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__, |
| 163 | + ptx->GetHash().ToString(), |
| 164 | + ptx->GetWitnessHash().ToString()); |
134 | 165 | }
|
135 | 166 |
|
136 | 167 | void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>>& pvtxConflicted) {
|
137 |
| - m_internals->m_schedulerClient.AddToProcessQueue([pblock, pindex, pvtxConflicted, this] { |
| 168 | + auto event = [pblock, pindex, pvtxConflicted, this] { |
138 | 169 | m_internals->BlockConnected(pblock, pindex, *pvtxConflicted);
|
139 |
| - }); |
| 170 | + }; |
| 171 | + ENQUEUE_AND_LOG_EVENT(event, "%s: block hash=%s block height=%d", __func__, |
| 172 | + pblock->GetHash().ToString(), |
| 173 | + pindex->nHeight); |
140 | 174 | }
|
141 | 175 |
|
142 | 176 | void CMainSignals::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
|
143 | 177 | {
|
144 |
| - m_internals->m_schedulerClient.AddToProcessQueue([pblock, pindex, this] { |
| 178 | + auto event = [pblock, pindex, this] { |
145 | 179 | m_internals->BlockDisconnected(pblock, pindex);
|
146 |
| - }); |
| 180 | + }; |
| 181 | + ENQUEUE_AND_LOG_EVENT(event, "%s: block hash=%s block height=%d", __func__, |
| 182 | + pblock->GetHash().ToString(), |
| 183 | + pindex->nHeight); |
147 | 184 | }
|
148 | 185 |
|
149 | 186 | void CMainSignals::ChainStateFlushed(const CBlockLocator &locator) {
|
150 |
| - m_internals->m_schedulerClient.AddToProcessQueue([locator, this] { |
| 187 | + auto event = [locator, this] { |
151 | 188 | m_internals->ChainStateFlushed(locator);
|
152 |
| - }); |
| 189 | + }; |
| 190 | + ENQUEUE_AND_LOG_EVENT(event, "%s: block hash=%s", __func__, |
| 191 | + locator.IsNull() ? "null" : locator.vHave.front().ToString()); |
153 | 192 | }
|
154 | 193 |
|
155 | 194 | void CMainSignals::BlockChecked(const CBlock& block, const BlockValidationState& state) {
|
| 195 | + LOG_EVENT("%s: block hash=%s state=%s", __func__, |
| 196 | + block.GetHash().ToString(), FormatStateMessage(state)); |
156 | 197 | m_internals->BlockChecked(block, state);
|
157 | 198 | }
|
158 | 199 |
|
159 | 200 | void CMainSignals::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock> &block) {
|
| 201 | + LOG_EVENT("%s: block hash=%s", __func__, block->GetHash().ToString()); |
160 | 202 | m_internals->NewPoWValidBlock(pindex, block);
|
161 | 203 | }
|
0 commit comments