Coverage Report

Created: 2026-09-02 14:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/validationinterface.cpp
Line
Count
Source
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present 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/mempool_entry.h>
11
#include <kernel/mempool_removal_reason.h>
12
#include <kernel/types.h>
13
#include <primitives/block.h>
14
#include <primitives/transaction.h>
15
#include <util/check.h>
16
#include <util/log.h>
17
#include <util/task_runner.h>
18
19
#include <future>
20
#include <memory>
21
#include <unordered_map>
22
#include <utility>
23
24
using kernel::ChainstateRole;
25
26
/**
27
 * ValidationSignalsImpl manages a list of shared_ptr<CValidationInterface> callbacks.
28
 *
29
 * A std::unordered_map is used to track what callbacks are currently
30
 * registered, and a std::list is used to store the callbacks that are
31
 * currently registered as well as any callbacks that are just unregistered
32
 * and about to be deleted when they are done executing.
33
 */
34
class ValidationSignalsImpl
35
{
36
private:
37
    Mutex m_mutex;
38
    //! List entries consist of a callback pointer and reference count. The
39
    //! count is equal to the number of current executions of that entry, plus 1
40
    //! if it's registered. It cannot be 0 because that would imply it is
41
    //! unregistered and also not being executed (so shouldn't exist).
42
    struct ListEntry { std::shared_ptr<CValidationInterface> callbacks; int count = 1; };
43
    std::list<ListEntry> m_list GUARDED_BY(m_mutex);
44
    std::unordered_map<CValidationInterface*, std::list<ListEntry>::iterator> m_map GUARDED_BY(m_mutex);
45
46
public:
47
    std::unique_ptr<util::TaskRunnerInterface> m_task_runner;
48
49
    explicit ValidationSignalsImpl(std::unique_ptr<util::TaskRunnerInterface> task_runner)
50
1.35k
        : m_task_runner{std::move(Assert(task_runner))} {}
51
52
    void Register(std::shared_ptr<CValidationInterface> callbacks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
53
260k
    {
54
260k
        LOCK(m_mutex);
55
260k
        auto inserted = m_map.emplace(callbacks.get(), m_list.end());
56
260k
        if (inserted.second) inserted.first->second = m_list.emplace(m_list.end());
57
260k
        inserted.first->second->callbacks = std::move(callbacks);
58
260k
    }
59
60
    void Unregister(CValidationInterface* callbacks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
61
260k
    {
62
260k
        LOCK(m_mutex);
63
260k
        auto it = m_map.find(callbacks);
64
260k
        if (it != m_map.end()) {
65
260k
            if (!--it->second->count) m_list.erase(it->second);
66
260k
            m_map.erase(it);
67
260k
        }
68
260k
    }
69
70
    //! Clear unregisters every previously registered callback, erasing every
71
    //! map entry. After this call, the list may still contain callbacks that
72
    //! are currently executing, but it will be cleared when they are done
73
    //! executing.
74
    void Clear() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
75
1.17k
    {
76
1.17k
        LOCK(m_mutex);
77
1.17k
        for (const auto& entry : m_map) {
78
1
            if (!--entry.second->count) m_list.erase(entry.second);
79
1
        }
80
1.17k
        m_map.clear();
81
1.17k
    }
82
83
    template<typename F> void Iterate(F&& f) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
84
640k
    {
85
640k
        WAIT_LOCK(m_mutex, lock);
86
2.25M
        for (auto it = m_list.begin(); it != m_list.end();) {
87
1.61M
            ++it->count;
88
1.61M
            {
89
1.61M
                REVERSE_LOCK(lock, m_mutex);
90
1.61M
                f(*it->callbacks);
91
1.61M
            }
92
1.61M
            it = --it->count ? std::next(it) : m_list.erase(it);
93
1.61M
        }
94
640k
    }
validationinterface.cpp:void ValidationSignalsImpl::Iterate<ValidationSignals::UpdatedBlockTip(CBlockIndex const*, CBlockIndex const*, bool)::$_0::operator()() const::'lambda'(CValidationInterface&)>(ValidationSignals::UpdatedBlockTip(CBlockIndex const*, CBlockIndex const*, bool)::$_0::operator()() const::'lambda'(CValidationInterface&)&&)
Line
Count
Source
84
94.0k
    {
85
94.0k
        WAIT_LOCK(m_mutex, lock);
86
344k
        for (auto it = m_list.begin(); it != m_list.end();) {
87
250k
            ++it->count;
88
250k
            {
89
250k
                REVERSE_LOCK(lock, m_mutex);
90
250k
                f(*it->callbacks);
91
250k
            }
92
250k
            it = --it->count ? std::next(it) : m_list.erase(it);
93
250k
        }
94
94.0k
    }
validationinterface.cpp:void ValidationSignalsImpl::Iterate<ValidationSignals::ActiveTipChange(CBlockIndex const&, bool)::$_0>(ValidationSignals::ActiveTipChange(CBlockIndex const&, bool)::$_0&&)
Line
Count
Source
84
97.0k
    {
85
97.0k
        WAIT_LOCK(m_mutex, lock);
86
357k
        for (auto it = m_list.begin(); it != m_list.end();) {
87
260k
            ++it->count;
88
260k
            {
89
260k
                REVERSE_LOCK(lock, m_mutex);
90
260k
                f(*it->callbacks);
91
260k
            }
92
260k
            it = --it->count ? std::next(it) : m_list.erase(it);
93
260k
        }
94
97.0k
    }
validationinterface.cpp:void ValidationSignalsImpl::Iterate<ValidationSignals::TransactionAddedToMempool(NewMempoolTransactionInfo const&, unsigned long)::$_0::operator()() const::'lambda'(CValidationInterface&)>(ValidationSignals::TransactionAddedToMempool(NewMempoolTransactionInfo const&, unsigned long)::$_0::operator()() const::'lambda'(CValidationInterface&)&&)
Line
Count
Source
84
26.9k
    {
85
26.9k
        WAIT_LOCK(m_mutex, lock);
86
88.8k
        for (auto it = m_list.begin(); it != m_list.end();) {
87
61.9k
            ++it->count;
88
61.9k
            {
89
61.9k
                REVERSE_LOCK(lock, m_mutex);
90
61.9k
                f(*it->callbacks);
91
61.9k
            }
92
61.9k
            it = --it->count ? std::next(it) : m_list.erase(it);
93
61.9k
        }
94
26.9k
    }
validationinterface.cpp:void ValidationSignalsImpl::Iterate<ValidationSignals::TransactionRemovedFromMempool(std::shared_ptr<CTransaction const> const&, MemPoolRemovalReason, unsigned long)::$_0::operator()() const::'lambda'(CValidationInterface&)>(ValidationSignals::TransactionRemovedFromMempool(std::shared_ptr<CTransaction const> const&, MemPoolRemovalReason, unsigned long)::$_0::operator()() const::'lambda'(CValidationInterface&)&&)
Line
Count
Source
84
2.24k
    {
85
2.24k
        WAIT_LOCK(m_mutex, lock);
86
6.90k
        for (auto it = m_list.begin(); it != m_list.end();) {
87
4.66k
            ++it->count;
88
4.66k
            {
89
4.66k
                REVERSE_LOCK(lock, m_mutex);
90
4.66k
                f(*it->callbacks);
91
4.66k
            }
92
4.66k
            it = --it->count ? std::next(it) : m_list.erase(it);
93
4.66k
        }
94
2.24k
    }
validationinterface.cpp:void ValidationSignalsImpl::Iterate<ValidationSignals::BlockConnected(kernel::ChainstateRole const&, std::shared_ptr<CBlock const>, CBlockIndex const*)::$_0::operator()() const::'lambda'(CValidationInterface&)>(ValidationSignals::BlockConnected(kernel::ChainstateRole const&, std::shared_ptr<CBlock const>, CBlockIndex const*)::$_0::operator()() const::'lambda'(CValidationInterface&)&&)
Line
Count
Source
84
103k
    {
85
103k
        WAIT_LOCK(m_mutex, lock);
86
373k
        for (auto it = m_list.begin(); it != m_list.end();) {
87
270k
            ++it->count;
88
270k
            {
89
270k
                REVERSE_LOCK(lock, m_mutex);
90
270k
                f(*it->callbacks);
91
270k
            }
92
270k
            it = --it->count ? std::next(it) : m_list.erase(it);
93
270k
        }
94
103k
    }
validationinterface.cpp:void ValidationSignalsImpl::Iterate<ValidationSignals::MempoolTransactionsRemovedForBlock(std::shared_ptr<CBlock const>, std::vector<RemovedMempoolTransactionInfo, std::allocator<RemovedMempoolTransactionInfo>>, unsigned int)::$_0::operator()() const::'lambda'(CValidationInterface&)>(ValidationSignals::MempoolTransactionsRemovedForBlock(std::shared_ptr<CBlock const>, std::vector<RemovedMempoolTransactionInfo, std::allocator<RemovedMempoolTransactionInfo>>, unsigned int)::$_0::operator()() const::'lambda'(CValidationInterface&)&&)
Line
Count
Source
84
86.7k
    {
85
86.7k
        WAIT_LOCK(m_mutex, lock);
86
318k
        for (auto it = m_list.begin(); it != m_list.end();) {
87
231k
            ++it->count;
88
231k
            {
89
231k
                REVERSE_LOCK(lock, m_mutex);
90
231k
                f(*it->callbacks);
91
231k
            }
92
231k
            it = --it->count ? std::next(it) : m_list.erase(it);
93
231k
        }
94
86.7k
    }
validationinterface.cpp:void ValidationSignalsImpl::Iterate<ValidationSignals::BlockDisconnected(std::shared_ptr<CBlock const>, CBlockIndex const*)::$_0::operator()() const::'lambda'(CValidationInterface&)>(ValidationSignals::BlockDisconnected(std::shared_ptr<CBlock const>, CBlockIndex const*)::$_0::operator()() const::'lambda'(CValidationInterface&)&&)
Line
Count
Source
84
10.1k
    {
85
10.1k
        WAIT_LOCK(m_mutex, lock);
86
30.9k
        for (auto it = m_list.begin(); it != m_list.end();) {
87
20.7k
            ++it->count;
88
20.7k
            {
89
20.7k
                REVERSE_LOCK(lock, m_mutex);
90
20.7k
                f(*it->callbacks);
91
20.7k
            }
92
20.7k
            it = --it->count ? std::next(it) : m_list.erase(it);
93
20.7k
        }
94
10.1k
    }
validationinterface.cpp:void ValidationSignalsImpl::Iterate<ValidationSignals::ChainStateFlushed(kernel::ChainstateRole const&, CBlockLocator const&)::$_0::operator()() const::'lambda'(CValidationInterface&)>(ValidationSignals::ChainStateFlushed(kernel::ChainstateRole const&, CBlockLocator const&)::$_0::operator()() const::'lambda'(CValidationInterface&)&&)
Line
Count
Source
84
2.47k
    {
85
2.47k
        WAIT_LOCK(m_mutex, lock);
86
5.46k
        for (auto it = m_list.begin(); it != m_list.end();) {
87
2.99k
            ++it->count;
88
2.99k
            {
89
2.99k
                REVERSE_LOCK(lock, m_mutex);
90
2.99k
                f(*it->callbacks);
91
2.99k
            }
92
2.99k
            it = --it->count ? std::next(it) : m_list.erase(it);
93
2.99k
        }
94
2.47k
    }
validationinterface.cpp:void ValidationSignalsImpl::Iterate<ValidationSignals::BlockChecked(std::shared_ptr<CBlock const> const&, BlockValidationState const&)::$_0>(ValidationSignals::BlockChecked(std::shared_ptr<CBlock const> const&, BlockValidationState const&)::$_0&&)
Line
Count
Source
84
138k
    {
85
138k
        WAIT_LOCK(m_mutex, lock);
86
435k
        for (auto it = m_list.begin(); it != m_list.end();) {
87
297k
            ++it->count;
88
297k
            {
89
297k
                REVERSE_LOCK(lock, m_mutex);
90
297k
                f(*it->callbacks);
91
297k
            }
92
297k
            it = --it->count ? std::next(it) : m_list.erase(it);
93
297k
        }
94
138k
    }
validationinterface.cpp:void ValidationSignalsImpl::Iterate<ValidationSignals::NewPoWValidBlock(CBlockIndex const*, std::shared_ptr<CBlock const> const&)::$_0>(ValidationSignals::NewPoWValidBlock(CBlockIndex const*, std::shared_ptr<CBlock const> const&)::$_0&&)
Line
Count
Source
84
79.4k
    {
85
79.4k
        WAIT_LOCK(m_mutex, lock);
86
298k
        for (auto it = m_list.begin(); it != m_list.end();) {
87
218k
            ++it->count;
88
218k
            {
89
218k
                REVERSE_LOCK(lock, m_mutex);
90
218k
                f(*it->callbacks);
91
218k
            }
92
218k
            it = --it->count ? std::next(it) : m_list.erase(it);
93
218k
        }
94
79.4k
    }
95
};
96
97
ValidationSignals::ValidationSignals(std::unique_ptr<util::TaskRunnerInterface> task_runner)
98
1.35k
    : m_internals{std::make_unique<ValidationSignalsImpl>(std::move(task_runner))} {}
99
100
1.35k
ValidationSignals::~ValidationSignals() = default;
101
102
void ValidationSignals::FlushBackgroundCallbacks()
103
1.35k
{
104
1.35k
    m_internals->m_task_runner->flush();
105
1.35k
}
106
107
size_t ValidationSignals::CallbacksPending()
108
125k
{
109
125k
    return m_internals->m_task_runner->size();
110
125k
}
111
112
void ValidationSignals::RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks)
113
260k
{
114
    // Each connection captures the shared_ptr to ensure that each callback is
115
    // executed before the subscriber is destroyed. For more details see #18338.
116
260k
    m_internals->Register(std::move(callbacks));
117
260k
}
118
119
void ValidationSignals::RegisterValidationInterface(CValidationInterface* callbacks)
120
2.32k
{
121
    // Create a shared_ptr with a no-op deleter - CValidationInterface lifecycle
122
    // is managed by the caller.
123
2.32k
    RegisterSharedValidationInterface({callbacks, [](CValidationInterface*){}});
124
2.32k
}
125
126
void ValidationSignals::UnregisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks)
127
258k
{
128
258k
    UnregisterValidationInterface(callbacks.get());
129
258k
}
130
131
void ValidationSignals::UnregisterValidationInterface(CValidationInterface* callbacks)
132
260k
{
133
260k
    m_internals->Unregister(callbacks);
134
260k
}
135
136
void ValidationSignals::UnregisterAllValidationInterfaces()
137
1.17k
{
138
1.17k
    m_internals->Clear();
139
1.17k
}
140
141
void ValidationSignals::CallFunctionInValidationInterfaceQueue(std::function<void()> func)
142
27.3k
{
143
27.3k
    m_internals->m_task_runner->insert(std::move(func));
144
27.3k
}
145
146
void ValidationSignals::SyncWithValidationInterfaceQueue()
147
27.3k
{
148
27.3k
    AssertLockNotHeld(cs_main);
149
    // Block until the validation queue drains
150
27.3k
    std::promise<void> promise;
151
27.3k
    CallFunctionInValidationInterfaceQueue([&promise] {
152
27.3k
        promise.set_value();
153
27.3k
    });
154
27.3k
    promise.get_future().wait();
155
27.3k
}
156
157
// Use a macro instead of a function for conditional logging to prevent
158
// evaluating arguments when logging is not enabled.
159
#define ENQUEUE_AND_LOG_EVENT(event, log_msg)                                                                    \
160
326k
    do {                                                                                                         \
161
326k
        static_assert(std::is_rvalue_reference_v<decltype((event))>,                                             \
162
326k
                      "event must be passed as an rvalue");                                                      \
163
326k
        static_assert(std::is_rvalue_reference_v<decltype((log_msg))>,                                           \
164
326k
                      "log_msg must be passed as an rvalue");                                                    \
165
326k
        auto enqueue_log_msg = (log_msg);                                                                        \
166
326k
        LOG_EVENT("Enqueuing %s", enqueue_log_msg);                                                              \
167
326k
        m_internals->m_task_runner->insert([local_log_msg = std::move(enqueue_log_msg), local_event = (event)] { \
168
325k
            LOG_EVENT("%s", local_log_msg);                                                                      \
169
325k
            local_event();                                                                                       \
170
325k
        });                                                                                                      \
validationinterface.cpp:ValidationSignals::UpdatedBlockTip(CBlockIndex const*, CBlockIndex const*, bool)::$_1::operator()() const
Line
Count
Source
167
94.0k
        m_internals->m_task_runner->insert([local_log_msg = std::move(enqueue_log_msg), local_event = (event)] { \
168
94.0k
            LOG_EVENT("%s", local_log_msg);                                                                      \
169
94.0k
            local_event();                                                                                       \
170
94.0k
        });                                                                                                      \
validationinterface.cpp:ValidationSignals::TransactionAddedToMempool(NewMempoolTransactionInfo const&, unsigned long)::$_1::operator()() const
Line
Count
Source
167
26.9k
        m_internals->m_task_runner->insert([local_log_msg = std::move(enqueue_log_msg), local_event = (event)] { \
168
26.9k
            LOG_EVENT("%s", local_log_msg);                                                                      \
169
26.9k
            local_event();                                                                                       \
170
26.9k
        });                                                                                                      \
validationinterface.cpp:ValidationSignals::TransactionRemovedFromMempool(std::shared_ptr<CTransaction const> const&, MemPoolRemovalReason, unsigned long)::$_1::operator()() const
Line
Count
Source
167
2.24k
        m_internals->m_task_runner->insert([local_log_msg = std::move(enqueue_log_msg), local_event = (event)] { \
168
2.24k
            LOG_EVENT("%s", local_log_msg);                                                                      \
169
2.24k
            local_event();                                                                                       \
170
2.24k
        });                                                                                                      \
validationinterface.cpp:ValidationSignals::BlockConnected(kernel::ChainstateRole const&, std::shared_ptr<CBlock const>, CBlockIndex const*)::$_1::operator()() const
Line
Count
Source
167
103k
        m_internals->m_task_runner->insert([local_log_msg = std::move(enqueue_log_msg), local_event = (event)] { \
168
103k
            LOG_EVENT("%s", local_log_msg);                                                                      \
169
103k
            local_event();                                                                                       \
170
103k
        });                                                                                                      \
validationinterface.cpp:ValidationSignals::MempoolTransactionsRemovedForBlock(std::shared_ptr<CBlock const>, std::vector<RemovedMempoolTransactionInfo, std::allocator<RemovedMempoolTransactionInfo>>, unsigned int)::$_1::operator()() const
Line
Count
Source
167
86.7k
        m_internals->m_task_runner->insert([local_log_msg = std::move(enqueue_log_msg), local_event = (event)] { \
168
86.7k
            LOG_EVENT("%s", local_log_msg);                                                                      \
169
86.7k
            local_event();                                                                                       \
170
86.7k
        });                                                                                                      \
validationinterface.cpp:ValidationSignals::BlockDisconnected(std::shared_ptr<CBlock const>, CBlockIndex const*)::$_1::operator()() const
Line
Count
Source
167
10.1k
        m_internals->m_task_runner->insert([local_log_msg = std::move(enqueue_log_msg), local_event = (event)] { \
168
10.1k
            LOG_EVENT("%s", local_log_msg);                                                                      \
169
10.1k
            local_event();                                                                                       \
170
10.1k
        });                                                                                                      \
validationinterface.cpp:ValidationSignals::ChainStateFlushed(kernel::ChainstateRole const&, CBlockLocator const&)::$_1::operator()() const
Line
Count
Source
167
2.47k
        m_internals->m_task_runner->insert([local_log_msg = std::move(enqueue_log_msg), local_event = (event)] { \
168
2.47k
            LOG_EVENT("%s", local_log_msg);                                                                      \
169
2.47k
            local_event();                                                                                       \
170
2.47k
        });                                                                                                      \
171
326k
    } while (0)
172
173
#define LOG_MSG(fmt, ...) \
174
326k
    (util::log::ShouldDebugLog(BCLog::VALIDATION) ? tfm::format((fmt), __VA_ARGS__) : std::string{})
175
176
#define LOG_EVENT(fmt, ...) \
177
967k
    LogDebug(BCLog::VALIDATION, fmt, __VA_ARGS__)
178
179
94.0k
void ValidationSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
180
    // Dependencies exist that require UpdatedBlockTip events to be delivered in the order in which
181
    // the chain actually updates. One way to ensure this is for the caller to invoke this signal
182
    // in the same critical section where the chain is updated
183
184
94.0k
    auto log_msg = LOG_MSG("%s: new block hash=%s fork block hash=%s (in IBD=%s)", __func__,
185
94.0k
                          pindexNew->GetBlockHash().ToString(),
186
94.0k
                          pindexFork ? pindexFork->GetBlockHash().ToString() : "null",
187
94.0k
                          fInitialDownload);
188
94.0k
    auto event = [pindexNew, pindexFork, fInitialDownload, this] {
189
250k
        m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload); });
190
94.0k
    };
191
94.0k
    ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
192
94.0k
}
193
194
void ValidationSignals::ActiveTipChange(const CBlockIndex& new_tip, bool is_ibd)
195
97.0k
{
196
97.0k
    LOG_EVENT("%s: new block hash=%s block height=%d", __func__, new_tip.GetBlockHash().ToString(), new_tip.nHeight);
197
260k
    m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ActiveTipChange(new_tip, is_ibd); });
198
97.0k
}
199
200
void ValidationSignals::TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence)
201
26.9k
{
202
26.9k
    auto log_msg = LOG_MSG("%s: txid=%s wtxid=%s", __func__,
203
26.9k
                          tx.info.m_tx->GetHash().ToString(),
204
26.9k
                          tx.info.m_tx->GetWitnessHash().ToString());
205
26.9k
    auto event = [tx, mempool_sequence, this] {
206
61.9k
        m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(tx, mempool_sequence); });
207
26.9k
    };
208
26.9k
    ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
209
26.9k
}
210
211
2.24k
void ValidationSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) {
212
2.24k
    auto log_msg = LOG_MSG("%s: txid=%s wtxid=%s reason=%s", __func__,
213
2.24k
                          tx->GetHash().ToString(),
214
2.24k
                          tx->GetWitnessHash().ToString(),
215
2.24k
                          RemovalReasonToString(reason));
216
2.24k
    auto event = [tx, reason, mempool_sequence, this] {
217
4.66k
        m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionRemovedFromMempool(tx, reason, mempool_sequence); });
218
2.24k
    };
219
2.24k
    ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
220
2.24k
}
221
222
void ValidationSignals::BlockConnected(const ChainstateRole& role, std::shared_ptr<const CBlock> pblock, const CBlockIndex* pindex)
223
103k
{
224
103k
    auto log_msg = LOG_MSG("%s: block hash=%s block height=%d", __func__,
225
103k
                          pblock->GetHash().ToString(),
226
103k
                          pindex->nHeight);
227
103k
    auto event = [role, pblock = std::move(pblock), pindex, this] {
228
270k
        m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockConnected(role, pblock, pindex); });
229
103k
    };
230
103k
    ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
231
103k
}
232
233
void ValidationSignals::MempoolTransactionsRemovedForBlock(std::shared_ptr<const CBlock> block, std::vector<RemovedMempoolTransactionInfo> txs_removed_for_block, unsigned int block_height)
234
86.7k
{
235
86.7k
    Assume(block);
236
86.7k
    auto log_msg = LOG_MSG("%s: block hash=%s block height=%s txs removed=%s block txs=%s", __func__,
237
86.7k
                           block->GetHash().ToString(),
238
86.7k
                           block_height,
239
86.7k
                           txs_removed_for_block.size(),
240
86.7k
                           block->vtx.size());
241
86.7k
    auto event = [block = std::move(block), txs_removed_for_block = std::move(txs_removed_for_block), block_height, this] {
242
231k
        m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.MempoolTransactionsRemovedForBlock(block, txs_removed_for_block, block_height); });
243
86.7k
    };
244
86.7k
    ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
245
86.7k
}
246
247
void ValidationSignals::BlockDisconnected(std::shared_ptr<const CBlock> pblock, const CBlockIndex* pindex)
248
10.1k
{
249
10.1k
    auto log_msg = LOG_MSG("%s: block hash=%s block height=%d", __func__,
250
10.1k
                          pblock->GetHash().ToString(),
251
10.1k
                          pindex->nHeight);
252
10.1k
    auto event = [pblock = std::move(pblock), pindex, this] {
253
20.7k
        m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockDisconnected(pblock, pindex); });
254
10.1k
    };
255
10.1k
    ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
256
10.1k
}
257
258
void ValidationSignals::ChainStateFlushed(const ChainstateRole& role, const CBlockLocator& locator)
259
3.56k
{
260
3.56k
    auto log_msg = LOG_MSG("%s: block hash=%s", __func__,
261
3.56k
                          locator.IsNull() ? "null" : locator.vHave.front().ToString());
262
3.56k
    auto event = [role, locator, this] {
263
2.99k
        m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ChainStateFlushed(role, locator); });
264
2.47k
    };
265
3.56k
    ENQUEUE_AND_LOG_EVENT(std::move(event), std::move(log_msg));
266
3.56k
}
267
268
void ValidationSignals::BlockChecked(const std::shared_ptr<const CBlock>& block, const BlockValidationState& state)
269
138k
{
270
138k
    LOG_EVENT("%s: block hash=%s state=%s", __func__,
271
138k
              block->GetHash().ToString(), state.ToString());
272
297k
    m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.BlockChecked(block, state); });
273
138k
}
274
275
79.4k
void ValidationSignals::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock> &block) {
276
79.4k
    LOG_EVENT("%s: block hash=%s", __func__, block->GetHash().ToString());
277
218k
    m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.NewPoWValidBlock(pindex, block); });
278
79.4k
}