/Users/eugenesiegel/btc/bitcoin/src/validationinterface.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | | // Copyright (c) 2009-2022 The Bitcoin Core developers |
3 | | // Distributed under the MIT software license, see the accompanying |
4 | | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | | |
6 | | #include <validationinterface.h> |
7 | | |
8 | | #include <chain.h> |
9 | | #include <consensus/validation.h> |
10 | | #include <kernel/chain.h> |
11 | | #include <kernel/mempool_entry.h> |
12 | | #include <kernel/mempool_removal_reason.h> |
13 | | #include <logging.h> |
14 | | #include <primitives/block.h> |
15 | | #include <primitives/transaction.h> |
16 | | #include <util/check.h> |
17 | | #include <util/task_runner.h> |
18 | | |
19 | | #include <future> |
20 | | #include <memory> |
21 | | #include <unordered_map> |
22 | | #include <utility> |
23 | | |
24 | | /** |
25 | | * ValidationSignalsImpl manages a list of shared_ptr<CValidationInterface> callbacks. |
26 | | * |
27 | | * A std::unordered_map is used to track what callbacks are currently |
28 | | * registered, and a std::list is used to store the callbacks that are |
29 | | * currently registered as well as any callbacks that are just unregistered |
30 | | * and about to be deleted when they are done executing. |
31 | | */ |
32 | | class ValidationSignalsImpl |
33 | | { |
34 | | private: |
35 | | Mutex m_mutex; |
36 | | //! List entries consist of a callback pointer and reference count. The |
37 | | //! count is equal to the number of current executions of that entry, plus 1 |
38 | | //! if it's registered. It cannot be 0 because that would imply it is |
39 | | //! unregistered and also not being executed (so shouldn't exist). |
40 | | struct ListEntry { std::shared_ptr<CValidationInterface> callbacks; int count = 1; }; |
41 | | std::list<ListEntry> m_list GUARDED_BY(m_mutex); |
42 | | std::unordered_map<CValidationInterface*, std::list<ListEntry>::iterator> m_map GUARDED_BY(m_mutex); |
43 | | |
44 | | public: |
45 | | std::unique_ptr<util::TaskRunnerInterface> m_task_runner; |
46 | | |
47 | | explicit ValidationSignalsImpl(std::unique_ptr<util::TaskRunnerInterface> task_runner) |
48 | 38.8k | : m_task_runner{std::move(Assert(task_runner))} {} Line | Count | Source | 106 | 38.8k | #define Assert(val) inline_assertion_check<true>(val, __FILE__, __LINE__, __func__, #val) |
|
49 | | |
50 | | void Register(std::shared_ptr<CValidationInterface> callbacks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
51 | 38.8k | { |
52 | 38.8k | LOCK(m_mutex); Line | Count | Source | 259 | 38.8k | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 38.8k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 38.8k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 38.8k | #define PASTE(x, y) x ## y |
|
|
|
|
53 | 38.8k | auto inserted = m_map.emplace(callbacks.get(), m_list.end()); |
54 | 38.8k | if (inserted.second) inserted.first->second = m_list.emplace(m_list.end()); |
55 | 38.8k | inserted.first->second->callbacks = std::move(callbacks); |
56 | 38.8k | } |
57 | | |
58 | | void Unregister(CValidationInterface* callbacks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
59 | 0 | { |
60 | 0 | LOCK(m_mutex); Line | Count | Source | 259 | 0 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 0 | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 0 | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 0 | #define PASTE(x, y) x ## y |
|
|
|
|
61 | 0 | auto it = m_map.find(callbacks); |
62 | 0 | if (it != m_map.end()) { |
63 | 0 | if (!--it->second->count) m_list.erase(it->second); |
64 | 0 | m_map.erase(it); |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | | //! Clear unregisters every previously registered callback, erasing every |
69 | | //! map entry. After this call, the list may still contain callbacks that |
70 | | //! are currently executing, but it will be cleared when they are done |
71 | | //! executing. |
72 | | void Clear() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
73 | 0 | { |
74 | 0 | LOCK(m_mutex); Line | Count | Source | 259 | 0 | #define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 0 | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 0 | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 0 | #define PASTE(x, y) x ## y |
|
|
|
|
75 | 0 | for (const auto& entry : m_map) { |
76 | 0 | if (!--entry.second->count) m_list.erase(entry.second); |
77 | 0 | } |
78 | 0 | m_map.clear(); |
79 | 0 | } |
80 | | |
81 | | template<typename F> void Iterate(F&& f) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) |
82 | 1.14M | { |
83 | 1.14M | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 26.6k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 26.6k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 188k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 188k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 261k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 261k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 205k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 205k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 31.4k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 31.4k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 31.4k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 31.4k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 4.80k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 4.80k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 14.2k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 14.2k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 193k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 193k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 184k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 184k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
|
84 | 2.28M | for (auto it = m_list.begin(); it != m_list.end();) { |
85 | 1.14M | ++it->count; |
86 | 1.14M | { |
87 | 1.14M | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 26.6k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 26.6k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 26.6k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 26.6k | #define PASTE(x, y) x ## y |
|
|
|
| REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 188k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 188k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 188k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 188k | #define PASTE(x, y) x ## y |
|
|
|
| REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 261k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 261k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 261k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 261k | #define PASTE(x, y) x ## y |
|
|
|
| REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 205k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 205k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 205k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 205k | #define PASTE(x, y) x ## y |
|
|
|
| REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 31.4k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 31.4k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 31.4k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 31.4k | #define PASTE(x, y) x ## y |
|
|
|
| REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 31.4k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 31.4k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 31.4k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 31.4k | #define PASTE(x, y) x ## y |
|
|
|
| REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 4.80k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 4.80k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 4.80k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 4.80k | #define PASTE(x, y) x ## y |
|
|
|
| REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 14.2k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 14.2k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 14.2k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 14.2k | #define PASTE(x, y) x ## y |
|
|
|
| REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 193k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 193k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 193k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 193k | #define PASTE(x, y) x ## y |
|
|
|
| REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 184k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 184k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 184k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 184k | #define PASTE(x, y) x ## y |
|
|
|
|
88 | 1.14M | f(*it->callbacks); |
89 | 1.14M | } |
90 | 1.14M | it = --it->count ? std::next(it) : m_list.erase(it)0 ; |
91 | 1.14M | } |
92 | 1.14M | } validationinterface.cpp:_ZN21ValidationSignalsImpl7IterateIZZN17ValidationSignals15UpdatedBlockTipEPK11CBlockIndexS4_bENK3$_0clEvEUlR20CValidationInterfaceE_EEvOT_ Line | Count | Source | 82 | 26.6k | { | 83 | 26.6k | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 26.6k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 26.6k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| 84 | 53.2k | for (auto it = m_list.begin(); it != m_list.end();) { | 85 | 26.6k | ++it->count; | 86 | 26.6k | { | 87 | 26.6k | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 26.6k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 26.6k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 26.6k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 26.6k | #define PASTE(x, y) x ## y |
|
|
|
| 88 | 26.6k | f(*it->callbacks); | 89 | 26.6k | } | 90 | 26.6k | it = --it->count ? std::next(it) : m_list.erase(it)0 ; | 91 | 26.6k | } | 92 | 26.6k | } |
validationinterface.cpp:_ZN21ValidationSignalsImpl7IterateIZN17ValidationSignals15ActiveTipChangeERK11CBlockIndexbE3$_0EEvOT_ Line | Count | Source | 82 | 188k | { | 83 | 188k | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 188k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 188k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| 84 | 377k | for (auto it = m_list.begin(); it != m_list.end();) { | 85 | 188k | ++it->count; | 86 | 188k | { | 87 | 188k | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 188k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 188k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 188k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 188k | #define PASTE(x, y) x ## y |
|
|
|
| 88 | 188k | f(*it->callbacks); | 89 | 188k | } | 90 | 188k | it = --it->count ? std::next(it) : m_list.erase(it)0 ; | 91 | 188k | } | 92 | 188k | } |
validationinterface.cpp:_ZN21ValidationSignalsImpl7IterateIZZN17ValidationSignals25TransactionAddedToMempoolERK25NewMempoolTransactionInfoyENK3$_0clEvEUlR20CValidationInterfaceE_EEvOT_ Line | Count | Source | 82 | 261k | { | 83 | 261k | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 261k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 261k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| 84 | 523k | for (auto it = m_list.begin(); it != m_list.end();) { | 85 | 261k | ++it->count; | 86 | 261k | { | 87 | 261k | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 261k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 261k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 261k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 261k | #define PASTE(x, y) x ## y |
|
|
|
| 88 | 261k | f(*it->callbacks); | 89 | 261k | } | 90 | 261k | it = --it->count ? std::next(it) : m_list.erase(it)0 ; | 91 | 261k | } | 92 | 261k | } |
validationinterface.cpp:_ZN21ValidationSignalsImpl7IterateIZZN17ValidationSignals29TransactionRemovedFromMempoolERKNSt3__110shared_ptrIK12CTransactionEE20MemPoolRemovalReasonyENK3$_0clEvEUlR20CValidationInterfaceE_EEvOT_ Line | Count | Source | 82 | 205k | { | 83 | 205k | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 205k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 205k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| 84 | 411k | for (auto it = m_list.begin(); it != m_list.end();) { | 85 | 205k | ++it->count; | 86 | 205k | { | 87 | 205k | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 205k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 205k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 205k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 205k | #define PASTE(x, y) x ## y |
|
|
|
| 88 | 205k | f(*it->callbacks); | 89 | 205k | } | 90 | 205k | it = --it->count ? std::next(it) : m_list.erase(it)0 ; | 91 | 205k | } | 92 | 205k | } |
validationinterface.cpp:_ZN21ValidationSignalsImpl7IterateIZZN17ValidationSignals14BlockConnectedE14ChainstateRoleRKNSt3__110shared_ptrIK6CBlockEEPK11CBlockIndexENK3$_0clEvEUlR20CValidationInterfaceE_EEvOT_ Line | Count | Source | 82 | 31.4k | { | 83 | 31.4k | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 31.4k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 31.4k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| 84 | 62.8k | for (auto it = m_list.begin(); it != m_list.end();) { | 85 | 31.4k | ++it->count; | 86 | 31.4k | { | 87 | 31.4k | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 31.4k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 31.4k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 31.4k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 31.4k | #define PASTE(x, y) x ## y |
|
|
|
| 88 | 31.4k | f(*it->callbacks); | 89 | 31.4k | } | 90 | 31.4k | it = --it->count ? std::next(it) : m_list.erase(it)0 ; | 91 | 31.4k | } | 92 | 31.4k | } |
validationinterface.cpp:_ZN21ValidationSignalsImpl7IterateIZZN17ValidationSignals34MempoolTransactionsRemovedForBlockERKNSt3__16vectorI29RemovedMempoolTransactionInfoNS2_9allocatorIS4_EEEEjENK3$_0clEvEUlR20CValidationInterfaceE_EEvOT_ Line | Count | Source | 82 | 31.4k | { | 83 | 31.4k | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 31.4k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 31.4k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| 84 | 62.8k | for (auto it = m_list.begin(); it != m_list.end();) { | 85 | 31.4k | ++it->count; | 86 | 31.4k | { | 87 | 31.4k | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 31.4k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 31.4k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 31.4k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 31.4k | #define PASTE(x, y) x ## y |
|
|
|
| 88 | 31.4k | f(*it->callbacks); | 89 | 31.4k | } | 90 | 31.4k | it = --it->count ? std::next(it) : m_list.erase(it)0 ; | 91 | 31.4k | } | 92 | 31.4k | } |
validationinterface.cpp:_ZN21ValidationSignalsImpl7IterateIZZN17ValidationSignals17BlockDisconnectedERKNSt3__110shared_ptrIK6CBlockEEPK11CBlockIndexENK3$_0clEvEUlR20CValidationInterfaceE_EEvOT_ Line | Count | Source | 82 | 4.80k | { | 83 | 4.80k | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 4.80k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 4.80k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| 84 | 9.60k | for (auto it = m_list.begin(); it != m_list.end();) { | 85 | 4.80k | ++it->count; | 86 | 4.80k | { | 87 | 4.80k | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 4.80k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 4.80k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 4.80k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 4.80k | #define PASTE(x, y) x ## y |
|
|
|
| 88 | 4.80k | f(*it->callbacks); | 89 | 4.80k | } | 90 | 4.80k | it = --it->count ? std::next(it) : m_list.erase(it)0 ; | 91 | 4.80k | } | 92 | 4.80k | } |
validationinterface.cpp:_ZN21ValidationSignalsImpl7IterateIZZN17ValidationSignals17ChainStateFlushedE14ChainstateRoleRK13CBlockLocatorENK3$_0clEvEUlR20CValidationInterfaceE_EEvOT_ Line | Count | Source | 82 | 14.2k | { | 83 | 14.2k | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 14.2k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 14.2k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| 84 | 28.4k | for (auto it = m_list.begin(); it != m_list.end();) { | 85 | 14.2k | ++it->count; | 86 | 14.2k | { | 87 | 14.2k | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 14.2k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 14.2k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 14.2k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 14.2k | #define PASTE(x, y) x ## y |
|
|
|
| 88 | 14.2k | f(*it->callbacks); | 89 | 14.2k | } | 90 | 14.2k | it = --it->count ? std::next(it) : m_list.erase(it)0 ; | 91 | 14.2k | } | 92 | 14.2k | } |
validationinterface.cpp:_ZN21ValidationSignalsImpl7IterateIZN17ValidationSignals12BlockCheckedERKNSt3__110shared_ptrIK6CBlockEERK20BlockValidationStateE3$_0EEvOT_ Line | Count | Source | 82 | 193k | { | 83 | 193k | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 193k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 193k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| 84 | 387k | for (auto it = m_list.begin(); it != m_list.end();) { | 85 | 193k | ++it->count; | 86 | 193k | { | 87 | 193k | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 193k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 193k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 193k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 193k | #define PASTE(x, y) x ## y |
|
|
|
| 88 | 193k | f(*it->callbacks); | 89 | 193k | } | 90 | 193k | it = --it->count ? std::next(it) : m_list.erase(it)0 ; | 91 | 193k | } | 92 | 193k | } |
validationinterface.cpp:_ZN21ValidationSignalsImpl7IterateIZN17ValidationSignals16NewPoWValidBlockEPK11CBlockIndexRKNSt3__110shared_ptrIK6CBlockEEE3$_0EEvOT_ Line | Count | Source | 82 | 184k | { | 83 | 184k | WAIT_LOCK(m_mutex, lock); Line | Count | Source | 265 | 184k | #define WAIT_LOCK(cs, name) UniqueLock name(LOCK_ARGS(cs)) Line | Count | Source | 263 | 184k | #define LOCK_ARGS(cs) MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__ |
|
| 84 | 368k | for (auto it = m_list.begin(); it != m_list.end();) { | 85 | 184k | ++it->count; | 86 | 184k | { | 87 | 184k | REVERSE_LOCK(lock, m_mutex); Line | Count | Source | 245 | 184k | #define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__) Line | Count | Source | 11 | 184k | #define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) Line | Count | Source | 9 | 184k | #define PASTE2(x, y) PASTE(x, y) Line | Count | Source | 8 | 184k | #define PASTE(x, y) x ## y |
|
|
|
| 88 | 184k | f(*it->callbacks); | 89 | 184k | } | 90 | 184k | it = --it->count ? std::next(it) : m_list.erase(it)0 ; | 91 | 184k | } | 92 | 184k | } |
|
93 | | }; |
94 | | |
95 | | ValidationSignals::ValidationSignals(std::unique_ptr<util::TaskRunnerInterface> task_runner) |
96 | 38.8k | : m_internals{std::make_unique<ValidationSignalsImpl>(std::move(task_runner))} {} |
97 | | |
98 | 38.8k | ValidationSignals::~ValidationSignals() = default; |
99 | | |
100 | | void ValidationSignals::FlushBackgroundCallbacks() |
101 | 38.8k | { |
102 | 38.8k | m_internals->m_task_runner->flush(); |
103 | 38.8k | } |
104 | | |
105 | | size_t ValidationSignals::CallbacksPending() |
106 | 398k | { |
107 | 398k | return m_internals->m_task_runner->size(); |
108 | 398k | } |
109 | | |
110 | | void ValidationSignals::RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks) |
111 | 38.8k | { |
112 | | // Each connection captures the shared_ptr to ensure that each callback is |
113 | | // executed before the subscriber is destroyed. For more details see #18338. |
114 | 38.8k | m_internals->Register(std::move(callbacks)); |
115 | 38.8k | } |
116 | | |
117 | | void ValidationSignals::RegisterValidationInterface(CValidationInterface* callbacks) |
118 | 38.8k | { |
119 | | // Create a shared_ptr with a no-op deleter - CValidationInterface lifecycle |
120 | | // is managed by the caller. |
121 | 38.8k | RegisterSharedValidationInterface({callbacks, [](CValidationInterface*){}}); |
122 | 38.8k | } |
123 | | |
124 | | void ValidationSignals::UnregisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks) |
125 | 0 | { |
126 | 0 | UnregisterValidationInterface(callbacks.get()); |
127 | 0 | } |
128 | | |
129 | | void ValidationSignals::UnregisterValidationInterface(CValidationInterface* callbacks) |
130 | 0 | { |
131 | 0 | m_internals->Unregister(callbacks); |
132 | 0 | } |
133 | | |
134 | | void ValidationSignals::UnregisterAllValidationInterfaces() |
135 | 0 | { |
136 | 0 | m_internals->Clear(); |
137 | 0 | } |
138 | | |
139 | | void ValidationSignals::CallFunctionInValidationInterfaceQueue(std::function<void()> func) |
140 | 77.7k | { |
141 | 77.7k | m_internals->m_task_runner->insert(std::move(func)); |
142 | 77.7k | } |
143 | | |
144 | | void ValidationSignals::SyncWithValidationInterfaceQueue() |
145 | 77.7k | { |
146 | 77.7k | AssertLockNotHeld(cs_main); Line | Count | Source | 142 | 77.7k | #define AssertLockNotHeld(cs) AssertLockNotHeldInline(#cs, __FILE__, __LINE__, &cs) |
|
147 | | // Block until the validation queue drains |
148 | 77.7k | std::promise<void> promise; |
149 | 77.7k | CallFunctionInValidationInterfaceQueue([&promise] { |
150 | 77.7k | promise.set_value(); |
151 | 77.7k | }); |
152 | 77.7k | promise.get_future().wait(); |
153 | 77.7k | } |
154 | | |
155 | | // Use a macro instead of a function for conditional logging to prevent |
156 | | // evaluating arguments when logging is not enabled. |
157 | | // |
158 | | // NOTE: The lambda captures all local variables by value. |
159 | | #define ENQUEUE_AND_LOG_EVENT(event, fmt, name, ...) \ |
160 | 575k | do { \ |
161 | 575k | auto local_name = (name); \ |
162 | 575k | LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \ |
163 | 575k | m_internals->m_task_runner->insert([=] { \ |
164 | 575k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 26.6k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 26.6k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 26.6k | do { \ | 374 | 26.6k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 26.6k | } while (0) |
|
|
| LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 261k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 261k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 261k | do { \ | 374 | 261k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 261k | } while (0) |
|
|
| LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 205k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 205k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 205k | do { \ | 374 | 205k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 205k | } while (0) |
|
|
| LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 31.4k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 31.4k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 31.4k | do { \ | 374 | 31.4k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 31.4k | } while (0) |
|
|
| LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 31.4k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 31.4k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 31.4k | do { \ | 374 | 31.4k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 31.4k | } while (0) |
|
|
| LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 4.80k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 4.80k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 4.80k | do { \ | 374 | 4.80k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 4.80k | } while (0) |
|
|
| LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 14.2k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 14.2k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 14.2k | do { \ | 374 | 14.2k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 14.2k | } while (0) |
|
|
|
165 | 575k | event(); \ |
166 | 575k | }); \ validationinterface.cpp:_ZZN17ValidationSignals15UpdatedBlockTipEPK11CBlockIndexS2_bENK3$_1clEv Line | Count | Source | 163 | 26.6k | m_internals->m_task_runner->insert([=] { \ | 164 | 26.6k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 26.6k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 26.6k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 26.6k | do { \ | 374 | 26.6k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 26.6k | } while (0) |
|
|
| 165 | 26.6k | event(); \ | 166 | 26.6k | }); \ |
validationinterface.cpp:_ZZN17ValidationSignals25TransactionAddedToMempoolERK25NewMempoolTransactionInfoyENK3$_1clEv Line | Count | Source | 163 | 261k | m_internals->m_task_runner->insert([=] { \ | 164 | 261k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 261k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 261k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 261k | do { \ | 374 | 261k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 261k | } while (0) |
|
|
| 165 | 261k | event(); \ | 166 | 261k | }); \ |
validationinterface.cpp:_ZZN17ValidationSignals29TransactionRemovedFromMempoolERKNSt3__110shared_ptrIK12CTransactionEE20MemPoolRemovalReasonyENK3$_1clEv Line | Count | Source | 163 | 205k | m_internals->m_task_runner->insert([=] { \ | 164 | 205k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 205k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 205k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 205k | do { \ | 374 | 205k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 205k | } while (0) |
|
|
| 165 | 205k | event(); \ | 166 | 205k | }); \ |
validationinterface.cpp:_ZZN17ValidationSignals14BlockConnectedE14ChainstateRoleRKNSt3__110shared_ptrIK6CBlockEEPK11CBlockIndexENK3$_1clEv Line | Count | Source | 163 | 31.4k | m_internals->m_task_runner->insert([=] { \ | 164 | 31.4k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 31.4k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 31.4k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 31.4k | do { \ | 374 | 31.4k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 31.4k | } while (0) |
|
|
| 165 | 31.4k | event(); \ | 166 | 31.4k | }); \ |
validationinterface.cpp:_ZZN17ValidationSignals34MempoolTransactionsRemovedForBlockERKNSt3__16vectorI29RemovedMempoolTransactionInfoNS0_9allocatorIS2_EEEEjENK3$_1clEv Line | Count | Source | 163 | 31.4k | m_internals->m_task_runner->insert([=] { \ | 164 | 31.4k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 31.4k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 31.4k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 31.4k | do { \ | 374 | 31.4k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 31.4k | } while (0) |
|
|
| 165 | 31.4k | event(); \ | 166 | 31.4k | }); \ |
validationinterface.cpp:_ZZN17ValidationSignals17BlockDisconnectedERKNSt3__110shared_ptrIK6CBlockEEPK11CBlockIndexENK3$_1clEv Line | Count | Source | 163 | 4.80k | m_internals->m_task_runner->insert([=] { \ | 164 | 4.80k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 4.80k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 4.80k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 4.80k | do { \ | 374 | 4.80k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 4.80k | } while (0) |
|
|
| 165 | 4.80k | event(); \ | 166 | 4.80k | }); \ |
validationinterface.cpp:_ZZN17ValidationSignals17ChainStateFlushedE14ChainstateRoleRK13CBlockLocatorENK3$_1clEv Line | Count | Source | 163 | 14.2k | m_internals->m_task_runner->insert([=] { \ | 164 | 14.2k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 14.2k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 14.2k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 14.2k | do { \ | 374 | 14.2k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 14.2k | } while (0) |
|
|
| 165 | 14.2k | event(); \ | 166 | 14.2k | }); \ |
|
167 | 575k | } while (0) |
168 | | |
169 | | #define LOG_EVENT(fmt, ...) \ |
170 | 1.71M | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) |
171 | | |
172 | 26.6k | void ValidationSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) { |
173 | | // Dependencies exist that require UpdatedBlockTip events to be delivered in the order in which |
174 | | // the chain actually updates. One way to ensure this is for the caller to invoke this signal |
175 | | // in the same critical section where the chain is updated |
176 | | |
177 | 26.6k | auto event = [pindexNew, pindexFork, fInitialDownload, this] { |
178 | 26.6k | m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload); }); |
179 | 26.6k | }; |
180 | 26.6k | ENQUEUE_AND_LOG_EVENT(event, "%s: new block hash=%s fork block hash=%s (in IBD=%s)", __func__, Line | Count | Source | 160 | 26.6k | do { \ | 161 | 26.6k | auto local_name = (name); \ | 162 | 26.6k | LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 26.6k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 26.6k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 26.6k | do { \ | 374 | 26.6k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 26.6k | } while (0) |
|
|
| 163 | 26.6k | m_internals->m_task_runner->insert([=] { \ | 164 | 26.6k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ | 165 | 26.6k | event(); \ | 166 | 26.6k | }); \ | 167 | 26.6k | } while (0) |
|
181 | 26.6k | pindexNew->GetBlockHash().ToString(), |
182 | 26.6k | pindexFork ? pindexFork->GetBlockHash().ToString() : "null", |
183 | 26.6k | fInitialDownload); |
184 | 26.6k | } |
185 | | |
186 | | void ValidationSignals::ActiveTipChange(const CBlockIndex& new_tip, bool is_ibd) |
187 | 188k | { |
188 | 188k | LOG_EVENT("%s: new block hash=%s block height=%d", __func__, new_tip.GetBlockHash().ToString(), new_tip.nHeight); Line | Count | Source | 170 | 188k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 188k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 188k | do { \ | 374 | 188k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 188k | } while (0) |
|
|
|
189 | 188k | m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ActiveTipChange(new_tip, is_ibd); }); |
190 | 188k | } |
191 | | |
192 | | void ValidationSignals::TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) |
193 | 261k | { |
194 | 261k | auto event = [tx, mempool_sequence, this] { |
195 | 261k | m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(tx, mempool_sequence); }); |
196 | 261k | }; |
197 | 261k | ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__, Line | Count | Source | 160 | 261k | do { \ | 161 | 261k | auto local_name = (name); \ | 162 | 261k | LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 261k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 261k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 261k | do { \ | 374 | 261k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 261k | } while (0) |
|
|
| 163 | 261k | m_internals->m_task_runner->insert([=] { \ | 164 | 261k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ | 165 | 261k | event(); \ | 166 | 261k | }); \ | 167 | 261k | } while (0) |
|
198 | 261k | tx.info.m_tx->GetHash().ToString(), |
199 | 261k | tx.info.m_tx->GetWitnessHash().ToString()); |
200 | 261k | } |
201 | | |
202 | 205k | void ValidationSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) { |
203 | 205k | auto event = [tx, reason, mempool_sequence, this] { |
204 | 205k | m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionRemovedFromMempool(tx, reason, mempool_sequence); }); |
205 | 205k | }; |
206 | 205k | ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s reason=%s", __func__, Line | Count | Source | 160 | 205k | do { \ | 161 | 205k | auto local_name = (name); \ | 162 | 205k | LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 205k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 205k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 205k | do { \ | 374 | 205k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 205k | } while (0) |
|
|
| 163 | 205k | m_internals->m_task_runner->insert([=] { \ | 164 | 205k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ | 165 | 205k | event(); \ | 166 | 205k | }); \ | 167 | 205k | } while (0) |
|
207 | 205k | tx->GetHash().ToString(), |
208 | 205k | tx->GetWitnessHash().ToString(), |
209 | 205k | RemovalReasonToString(reason)); |
210 | 205k | } |
211 | | |
212 | 31.4k | void ValidationSignals::BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex) { |
213 | 31.4k | auto event = [role, pblock, pindex, this] { |
214 | 31.4k | m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockConnected(role, pblock, pindex); }); |
215 | 31.4k | }; |
216 | 31.4k | ENQUEUE_AND_LOG_EVENT(event, "%s: block hash=%s block height=%d", __func__, Line | Count | Source | 160 | 31.4k | do { \ | 161 | 31.4k | auto local_name = (name); \ | 162 | 31.4k | LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 31.4k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 31.4k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 31.4k | do { \ | 374 | 31.4k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 31.4k | } while (0) |
|
|
| 163 | 31.4k | m_internals->m_task_runner->insert([=] { \ | 164 | 31.4k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ | 165 | 31.4k | event(); \ | 166 | 31.4k | }); \ | 167 | 31.4k | } while (0) |
|
217 | 31.4k | pblock->GetHash().ToString(), |
218 | 31.4k | pindex->nHeight); |
219 | 31.4k | } |
220 | | |
221 | | void ValidationSignals::MempoolTransactionsRemovedForBlock(const std::vector<RemovedMempoolTransactionInfo>& txs_removed_for_block, unsigned int nBlockHeight) |
222 | 31.4k | { |
223 | 31.4k | auto event = [txs_removed_for_block, nBlockHeight, this] { |
224 | 31.4k | m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.MempoolTransactionsRemovedForBlock(txs_removed_for_block, nBlockHeight); }); |
225 | 31.4k | }; |
226 | 31.4k | ENQUEUE_AND_LOG_EVENT(event, "%s: block height=%s txs removed=%s", __func__, Line | Count | Source | 160 | 31.4k | do { \ | 161 | 31.4k | auto local_name = (name); \ | 162 | 31.4k | LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 31.4k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 31.4k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 31.4k | do { \ | 374 | 31.4k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 31.4k | } while (0) |
|
|
| 163 | 31.4k | m_internals->m_task_runner->insert([=] { \ | 164 | 31.4k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ | 165 | 31.4k | event(); \ | 166 | 31.4k | }); \ | 167 | 31.4k | } while (0) |
|
227 | 31.4k | nBlockHeight, |
228 | 31.4k | txs_removed_for_block.size()); |
229 | 31.4k | } |
230 | | |
231 | | void ValidationSignals::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex) |
232 | 4.80k | { |
233 | 4.80k | auto event = [pblock, pindex, this] { |
234 | 4.80k | m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockDisconnected(pblock, pindex); }); |
235 | 4.80k | }; |
236 | 4.80k | ENQUEUE_AND_LOG_EVENT(event, "%s: block hash=%s block height=%d", __func__, Line | Count | Source | 160 | 4.80k | do { \ | 161 | 4.80k | auto local_name = (name); \ | 162 | 4.80k | LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 4.80k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 4.80k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 4.80k | do { \ | 374 | 4.80k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 4.80k | } while (0) |
|
|
| 163 | 4.80k | m_internals->m_task_runner->insert([=] { \ | 164 | 4.80k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ | 165 | 4.80k | event(); \ | 166 | 4.80k | }); \ | 167 | 4.80k | } while (0) |
|
237 | 4.80k | pblock->GetHash().ToString(), |
238 | 4.80k | pindex->nHeight); |
239 | 4.80k | } |
240 | | |
241 | 14.2k | void ValidationSignals::ChainStateFlushed(ChainstateRole role, const CBlockLocator &locator) { |
242 | 14.2k | auto event = [role, locator, this] { |
243 | 14.2k | m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ChainStateFlushed(role, locator); }); |
244 | 14.2k | }; |
245 | 14.2k | ENQUEUE_AND_LOG_EVENT(event, "%s: block hash=%s", __func__, Line | Count | Source | 160 | 14.2k | do { \ | 161 | 14.2k | auto local_name = (name); \ | 162 | 14.2k | LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \ Line | Count | Source | 170 | 14.2k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 14.2k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 14.2k | do { \ | 374 | 14.2k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 14.2k | } while (0) |
|
|
| 163 | 14.2k | m_internals->m_task_runner->insert([=] { \ | 164 | 14.2k | LOG_EVENT(fmt, local_name, __VA_ARGS__); \ | 165 | 14.2k | event(); \ | 166 | 14.2k | }); \ | 167 | 14.2k | } while (0) |
|
246 | 14.2k | locator.IsNull() ? "null" : locator.vHave.front().ToString()); |
247 | 14.2k | } |
248 | | |
249 | | void ValidationSignals::BlockChecked(const std::shared_ptr<const CBlock>& block, const BlockValidationState& state) |
250 | 193k | { |
251 | 193k | LOG_EVENT("%s: block hash=%s state=%s", __func__, Line | Count | Source | 170 | 193k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 193k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 193k | do { \ | 374 | 193k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 193k | } while (0) |
|
|
|
252 | 193k | block->GetHash().ToString(), state.ToString()); |
253 | 193k | m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockChecked(block, state); }); |
254 | 193k | } |
255 | | |
256 | 184k | void ValidationSignals::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock> &block) { |
257 | 184k | LOG_EVENT("%s: block hash=%s", __func__, block->GetHash().ToString()); Line | Count | Source | 170 | 184k | LogDebug(BCLog::VALIDATION, fmt "\n", __VA_ARGS__) Line | Count | Source | 381 | 184k | #define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__) Line | Count | Source | 373 | 184k | do { \ | 374 | 184k | if (LogAcceptCategory((category), (level))) { \ | 375 | 0 | bool rate_limit{level >= BCLog::Level::Info}; \ | 376 | 0 | LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \ Line | Count | Source | 350 | 0 | #define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__) |
| 377 | 0 | } \ | 378 | 184k | } while (0) |
|
|
|
258 | 184k | m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.NewPoWValidBlock(pindex, block); }); |
259 | 184k | } |