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