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