Bitcoin Core  0.19.99
P2P Digital Currency
validationinterface.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2020 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 #ifndef BITCOIN_VALIDATIONINTERFACE_H
7 #define BITCOIN_VALIDATIONINTERFACE_H
8 
9 #include <primitives/transaction.h> // CTransaction(Ref)
10 #include <sync.h>
11 
12 #include <functional>
13 #include <memory>
14 
15 extern RecursiveMutex cs_main;
17 class CBlock;
18 class CBlockIndex;
19 struct CBlockLocator;
20 class CConnman;
22 class uint256;
23 class CScheduler;
24 
25 // These functions dispatch to one or all registered wallets
26 
42 void CallFunctionInValidationInterfaceQueue(std::function<void ()> func);
53 
70 protected:
75  ~CValidationInterface() = default;
85  virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {}
91  virtual void TransactionAddedToMempool(const CTransactionRef &ptxn) {}
102  virtual void TransactionRemovedFromMempool(const CTransactionRef &ptx) {}
109  virtual void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, const std::vector<CTransactionRef> &txnConflicted) {}
115  virtual void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex) {}
132  virtual void ChainStateFlushed(const CBlockLocator &locator) {}
139  virtual void BlockChecked(const CBlock&, const BlockValidationState&) {}
143  virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& block) {};
144  friend void ::RegisterValidationInterface(CValidationInterface*);
145  friend void ::UnregisterValidationInterface(CValidationInterface*);
147 };
148 
149 struct MainSignalsInstance;
151 private:
152  std::unique_ptr<MainSignalsInstance> m_internals;
153 
157  friend void ::CallFunctionInValidationInterfaceQueue(std::function<void ()> func);
158 
159 public:
166 
167  size_t CallbacksPending();
168 
169 
170  void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
173  void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>> &);
174  void BlockDisconnected(const std::shared_ptr<const CBlock> &, const CBlockIndex* pindex);
175  void ChainStateFlushed(const CBlockLocator &);
176  void BlockChecked(const CBlock&, const BlockValidationState&);
177  void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr<const CBlock>&);
178 };
179 
181 
182 #endif // BITCOIN_VALIDATIONINTERFACE_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:408
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)
std::unique_ptr< MainSignalsInstance > m_internals
virtual void ChainStateFlushed(const CBlockLocator &locator)
Notifies listeners of the new active block chain on-disk.
Describes a place in the block chain to another node such that if the other node doesn&#39;t have the sam...
Definition: block.h:126
virtual void BlockDisconnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Notifies listeners of a block being disconnected.
void BlockDisconnected(const std::shared_ptr< const CBlock > &, const CBlockIndex *pindex)
Definition: block.h:72
virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr< const CBlock > &block)
Notifies listeners that a block which builds directly on our current tip has been received and connec...
void UnregisterBackgroundSignalScheduler()
Unregister a CScheduler to give callbacks which should run in the background - these callbacks will n...
void TransactionRemovedFromMempool(const CTransactionRef &)
virtual void BlockChecked(const CBlock &, const BlockValidationState &)
Notifies listeners of a block validation result.
Implement this to subscribe to events generated in validation.
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.
void SyncWithValidationInterfaceQueue() LOCKS_EXCLUDED(cs_main)
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
Notifies listeners when the block chain tip advances.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: validation.cpp:106
void CallFunctionInValidationInterfaceQueue(std::function< void()> func)
Pushes a function to callback onto the notification queue, guaranteeing any callbacks generated prior...
Definition: net.h:121
void ChainStateFlushed(const CBlockLocator &)
CMainSignals & GetMainSignals()
void RegisterBackgroundSignalScheduler(CScheduler &scheduler)
Register a CScheduler to give callbacks which should run in the background (may only be called once) ...
256-bit opaque blob.
Definition: uint256.h:120
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:50
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:137
void FlushBackgroundCallbacks()
Call any remaining callbacks on the calling thread.
void UnregisterAllValidationInterfaces()
Unregister all wallets from core.
virtual void TransactionRemovedFromMempool(const CTransactionRef &ptx)
Notifies listeners of a transaction leaving mempool.
virtual void TransactionAddedToMempool(const CTransactionRef &ptxn)
Notifies listeners of a transaction having been added to mempool.
virtual void BlockConnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex, const std::vector< CTransactionRef > &txnConflicted)
Notifies listeners of a block being connected.
void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr< const CBlock > &)
void BlockChecked(const CBlock &, const BlockValidationState &)
void UnregisterValidationInterface(CValidationInterface *pwalletIn)
Unregister a wallet from core.
void BlockConnected(const std::shared_ptr< const CBlock > &, const CBlockIndex *pindex, const std::shared_ptr< const std::vector< CTransactionRef >> &)
void TransactionAddedToMempool(const CTransactionRef &)