66#ifndef BITCOIN_VALIDATIONINTERFACE_H
77#define BITCOIN_VALIDATIONINTERFACE_H
88
9- #include < kernel/cs_main.h>
109#include < kernel/chain.h>
10+ #include < kernel/cs_main.h>
1111#include < primitives/transaction.h> // CTransaction(Ref)
1212#include < sync.h>
1313
14+ #include < cstddef>
15+ #include < cstdint>
1416#include < functional>
1517#include < memory>
18+ #include < vector>
1619
1720class BlockValidationState ;
1821class CBlock ;
@@ -24,41 +27,14 @@ enum class MemPoolRemovalReason;
2427struct RemovedMempoolTransactionInfo ;
2528struct NewMempoolTransactionInfo ;
2629
27- /* * Register subscriber */
2830void RegisterValidationInterface (CValidationInterface* callbacks);
29- /* * Unregister subscriber. DEPRECATED. This is not safe to use when the RPC server or main message handler thread is running. */
3031void UnregisterValidationInterface (CValidationInterface* callbacks);
31- /* * Unregister all subscribers */
3232void UnregisterAllValidationInterfaces ();
3333
34- // Alternate registration functions that release a shared_ptr after the last
35- // notification is sent. These are useful for race-free cleanup, since
36- // unregistration is nonblocking and can return before the last notification is
37- // processed.
38- /* * Register subscriber */
3934void RegisterSharedValidationInterface (std::shared_ptr<CValidationInterface> callbacks);
40- /* * Unregister subscriber */
4135void UnregisterSharedValidationInterface (std::shared_ptr<CValidationInterface> callbacks);
4236
43- /* *
44- * Pushes a function to callback onto the notification queue, guaranteeing any
45- * callbacks generated prior to now are finished when the function is called.
46- *
47- * Be very careful blocking on func to be called if any locks are held -
48- * validation interface clients may not be able to make progress as they often
49- * wait for things like cs_main, so blocking until func is called with cs_main
50- * will result in a deadlock (that DEBUG_LOCKORDER will miss).
51- */
5237void CallFunctionInValidationInterfaceQueue (std::function<void ()> func);
53- /* *
54- * This is a synonym for the following, which asserts certain locks are not
55- * held:
56- * std::promise<void> promise;
57- * CallFunctionInValidationInterfaceQueue([&promise] {
58- * promise.set_value();
59- * });
60- * promise.get_future().wait();
61- */
6238void SyncWithValidationInterfaceQueue () LOCKS_EXCLUDED(cs_main);
6339
6440/* *
@@ -194,12 +170,10 @@ class CMainSignals {
194170private:
195171 std::unique_ptr<MainSignalsImpl> m_internals;
196172
197- friend void ::RegisterSharedValidationInterface (std::shared_ptr<CValidationInterface>);
198- friend void ::UnregisterValidationInterface (CValidationInterface*);
199- friend void ::UnregisterAllValidationInterfaces ();
200- friend void ::CallFunctionInValidationInterfaceQueue (std::function<void ()> func);
201-
202173public:
174+ CMainSignals ();
175+ ~CMainSignals ();
176+
203177 /* * Register a CScheduler to give callbacks which should run in the background (may only be called once) */
204178 void RegisterBackgroundSignalScheduler (CScheduler& scheduler);
205179 /* * Unregister a CScheduler to give callbacks which should run in the background - these callbacks will now be dropped! */
@@ -209,6 +183,43 @@ class CMainSignals {
209183
210184 size_t CallbacksPending ();
211185
186+ /* * Register subscriber */
187+ void RegisterValidationInterface (CValidationInterface* callbacks);
188+ /* * Unregister subscriber. DEPRECATED. This is not safe to use when the RPC server or main message handler thread is running. */
189+ void UnregisterValidationInterface (CValidationInterface* callbacks);
190+ /* * Unregister all subscribers */
191+ void UnregisterAllValidationInterfaces ();
192+
193+ // Alternate registration functions that release a shared_ptr after the last
194+ // notification is sent. These are useful for race-free cleanup, since
195+ // unregistration is nonblocking and can return before the last notification is
196+ // processed.
197+ /* * Register subscriber */
198+ void RegisterSharedValidationInterface (std::shared_ptr<CValidationInterface> callbacks);
199+ /* * Unregister subscriber */
200+ void UnregisterSharedValidationInterface (std::shared_ptr<CValidationInterface> callbacks);
201+
202+ /* *
203+ * Pushes a function to callback onto the notification queue, guaranteeing any
204+ * callbacks generated prior to now are finished when the function is called.
205+ *
206+ * Be very careful blocking on func to be called if any locks are held -
207+ * validation interface clients may not be able to make progress as they often
208+ * wait for things like cs_main, so blocking until func is called with cs_main
209+ * will result in a deadlock (that DEBUG_LOCKORDER will miss).
210+ */
211+ void CallFunctionInValidationInterfaceQueue (std::function<void ()> func);
212+
213+ /* *
214+ * This is a synonym for the following, which asserts certain locks are not
215+ * held:
216+ * std::promise<void> promise;
217+ * CallFunctionInValidationInterfaceQueue([&promise] {
218+ * promise.set_value();
219+ * });
220+ * promise.get_future().wait();
221+ */
222+ void SyncWithValidationInterfaceQueue () LOCKS_EXCLUDED(cs_main);
212223
213224 void UpdatedBlockTip (const CBlockIndex *, const CBlockIndex *, bool fInitialDownload );
214225 void TransactionAddedToMempool (const NewMempoolTransactionInfo&, uint64_t mempool_sequence);
0 commit comments