6
6
#ifndef BITCOIN_VALIDATIONINTERFACE_H
7
7
#define BITCOIN_VALIDATIONINTERFACE_H
8
8
9
- #include < kernel/cs_main.h>
10
9
#include < kernel/chain.h>
10
+ #include < kernel/cs_main.h>
11
11
#include < primitives/transaction.h> // CTransaction(Ref)
12
12
#include < sync.h>
13
13
14
+ #include < cstddef>
15
+ #include < cstdint>
14
16
#include < functional>
15
17
#include < memory>
18
+ #include < vector>
16
19
17
20
class BlockValidationState ;
18
21
class CBlock ;
@@ -24,41 +27,14 @@ enum class MemPoolRemovalReason;
24
27
struct RemovedMempoolTransactionInfo ;
25
28
struct NewMempoolTransactionInfo ;
26
29
27
- /* * Register subscriber */
28
30
void RegisterValidationInterface (CValidationInterface* callbacks);
29
- /* * Unregister subscriber. DEPRECATED. This is not safe to use when the RPC server or main message handler thread is running. */
30
31
void UnregisterValidationInterface (CValidationInterface* callbacks);
31
- /* * Unregister all subscribers */
32
32
void UnregisterAllValidationInterfaces ();
33
33
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 */
39
34
void RegisterSharedValidationInterface (std::shared_ptr<CValidationInterface> callbacks);
40
- /* * Unregister subscriber */
41
35
void UnregisterSharedValidationInterface (std::shared_ptr<CValidationInterface> callbacks);
42
36
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
- */
52
37
void 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
- */
62
38
void SyncWithValidationInterfaceQueue () LOCKS_EXCLUDED(cs_main);
63
39
64
40
/* *
@@ -194,12 +170,10 @@ class CMainSignals {
194
170
private:
195
171
std::unique_ptr<MainSignalsImpl> m_internals;
196
172
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
-
202
173
public:
174
+ CMainSignals ();
175
+ ~CMainSignals ();
176
+
203
177
/* * Register a CScheduler to give callbacks which should run in the background (may only be called once) */
204
178
void RegisterBackgroundSignalScheduler (CScheduler& scheduler);
205
179
/* * Unregister a CScheduler to give callbacks which should run in the background - these callbacks will now be dropped! */
@@ -209,6 +183,43 @@ class CMainSignals {
209
183
210
184
size_t CallbacksPending ();
211
185
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);
212
223
213
224
void UpdatedBlockTip (const CBlockIndex *, const CBlockIndex *, bool fInitialDownload );
214
225
void TransactionAddedToMempool (const NewMempoolTransactionInfo&, uint64_t mempool_sequence);
0 commit comments