2015-02-05 01:11:44 +01:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2016-12-31 19:01:21 +01:00
|
|
|
// Copyright (c) 2009-2016 The Bitcoin Core developers
|
2015-02-05 01:11:44 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_VALIDATIONINTERFACE_H
|
|
|
|
#define BITCOIN_VALIDATIONINTERFACE_H
|
|
|
|
|
2017-03-30 03:12:42 +02:00
|
|
|
#include "primitives/transaction.h" // CTransaction(Ref)
|
|
|
|
|
2017-06-08 17:13:46 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
|
2015-02-05 01:11:44 +01:00
|
|
|
class CBlock;
|
2015-07-27 15:33:03 +02:00
|
|
|
class CBlockIndex;
|
2015-03-29 13:45:05 +02:00
|
|
|
struct CBlockLocator;
|
2015-09-16 16:42:23 +02:00
|
|
|
class CBlockIndex;
|
2016-05-25 02:56:17 +02:00
|
|
|
class CConnman;
|
2015-07-01 08:32:30 +02:00
|
|
|
class CReserveScript;
|
2015-02-05 01:11:44 +01:00
|
|
|
class CValidationInterface;
|
|
|
|
class CValidationState;
|
|
|
|
class uint256;
|
2017-01-19 22:49:22 +01:00
|
|
|
class CScheduler;
|
2017-01-20 21:08:14 +01:00
|
|
|
class CTxMemPool;
|
|
|
|
enum class MemPoolRemovalReason;
|
2015-02-05 01:11:44 +01:00
|
|
|
|
|
|
|
// These functions dispatch to one or all registered wallets
|
|
|
|
|
|
|
|
/** Register a wallet to receive updates from core */
|
|
|
|
void RegisterValidationInterface(CValidationInterface* pwalletIn);
|
|
|
|
/** Unregister a wallet from core */
|
|
|
|
void UnregisterValidationInterface(CValidationInterface* pwalletIn);
|
|
|
|
/** Unregister all wallets from core */
|
|
|
|
void UnregisterAllValidationInterfaces();
|
2017-06-08 17:13:46 +02:00
|
|
|
/**
|
|
|
|
* Pushes a function to callback onto the notification queue, guaranteeing any
|
|
|
|
* callbacks generated prior to now are finished when the function is called.
|
|
|
|
*
|
|
|
|
* Be very careful blocking on func to be called if any locks are held -
|
|
|
|
* validation interface clients may not be able to make progress as they often
|
|
|
|
* wait for things like cs_main, so blocking until func is called with cs_main
|
|
|
|
* will result in a deadlock (that DEBUG_LOCKORDER will miss).
|
|
|
|
*/
|
|
|
|
void CallFunctionInValidationInterfaceQueue(std::function<void ()> func);
|
2015-02-05 01:11:44 +01:00
|
|
|
|
|
|
|
class CValidationInterface {
|
|
|
|
protected:
|
2015-05-07 16:49:00 +02:00
|
|
|
/** Notifies listeners of updated block chain tip */
|
2017-01-19 22:17:14 +01:00
|
|
|
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {}
|
Also call other wallet notify callbacks in scheduler thread
This runs Block{Connected,Disconnected}, SetBestChain, Inventory,
and TransactionAddedToMempool on the background scheduler thread.
Of those, only BlockConnected is used outside of Wallet/ZMQ, and
is used only for orphan transaction removal in net_processing,
something which does not need to be synchronous with anything
else.
This partially reverts #9583, re-enabling some of the gains from
#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
2017-06-08 17:08:53 +02:00
|
|
|
/**
|
|
|
|
* Notifies listeners of a transaction having been added to mempool.
|
|
|
|
*
|
|
|
|
* Called on a background thread.
|
|
|
|
*/
|
2017-01-19 22:17:14 +01:00
|
|
|
virtual void TransactionAddedToMempool(const CTransactionRef &ptxn) {}
|
2017-01-20 21:08:14 +01:00
|
|
|
/**
|
|
|
|
* Notifies listeners of a transaction leaving mempool.
|
|
|
|
*
|
|
|
|
* This only fires for transactions which leave mempool because of expiry,
|
|
|
|
* size limiting, reorg (changes in lock times/coinbase maturity), or
|
|
|
|
* replacement. This does not include any transactions which are included
|
|
|
|
* in BlockConnectedDisconnected either in block->vtx or in txnConflicted.
|
2017-06-08 17:05:18 +02:00
|
|
|
*
|
|
|
|
* Called on a background thread.
|
2017-01-20 21:08:14 +01:00
|
|
|
*/
|
|
|
|
virtual void TransactionRemovedFromMempool(const CTransactionRef &ptx) {}
|
2017-03-30 03:12:42 +02:00
|
|
|
/**
|
|
|
|
* Notifies listeners of a block being connected.
|
|
|
|
* Provides a vector of transactions evicted from the mempool as a result.
|
Also call other wallet notify callbacks in scheduler thread
This runs Block{Connected,Disconnected}, SetBestChain, Inventory,
and TransactionAddedToMempool on the background scheduler thread.
Of those, only BlockConnected is used outside of Wallet/ZMQ, and
is used only for orphan transaction removal in net_processing,
something which does not need to be synchronous with anything
else.
This partially reverts #9583, re-enabling some of the gains from
#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
2017-06-08 17:08:53 +02:00
|
|
|
*
|
|
|
|
* Called on a background thread.
|
2017-03-30 03:12:42 +02:00
|
|
|
*/
|
2017-01-19 22:17:14 +01:00
|
|
|
virtual void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, const std::vector<CTransactionRef> &txnConflicted) {}
|
Also call other wallet notify callbacks in scheduler thread
This runs Block{Connected,Disconnected}, SetBestChain, Inventory,
and TransactionAddedToMempool on the background scheduler thread.
Of those, only BlockConnected is used outside of Wallet/ZMQ, and
is used only for orphan transaction removal in net_processing,
something which does not need to be synchronous with anything
else.
This partially reverts #9583, re-enabling some of the gains from
#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
2017-06-08 17:08:53 +02:00
|
|
|
/**
|
|
|
|
* Notifies listeners of a block being disconnected
|
|
|
|
*
|
|
|
|
* Called on a background thread.
|
|
|
|
*/
|
2017-01-19 22:17:14 +01:00
|
|
|
virtual void BlockDisconnected(const std::shared_ptr<const CBlock> &block) {}
|
Also call other wallet notify callbacks in scheduler thread
This runs Block{Connected,Disconnected}, SetBestChain, Inventory,
and TransactionAddedToMempool on the background scheduler thread.
Of those, only BlockConnected is used outside of Wallet/ZMQ, and
is used only for orphan transaction removal in net_processing,
something which does not need to be synchronous with anything
else.
This partially reverts #9583, re-enabling some of the gains from
#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
2017-06-08 17:08:53 +02:00
|
|
|
/**
|
|
|
|
* Notifies listeners of the new active block chain on-disk.
|
|
|
|
*
|
|
|
|
* Called on a background thread.
|
|
|
|
*/
|
2017-01-19 22:17:14 +01:00
|
|
|
virtual void SetBestChain(const CBlockLocator &locator) {}
|
Also call other wallet notify callbacks in scheduler thread
This runs Block{Connected,Disconnected}, SetBestChain, Inventory,
and TransactionAddedToMempool on the background scheduler thread.
Of those, only BlockConnected is used outside of Wallet/ZMQ, and
is used only for orphan transaction removal in net_processing,
something which does not need to be synchronous with anything
else.
This partially reverts #9583, re-enabling some of the gains from
#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
2017-06-08 17:08:53 +02:00
|
|
|
/**
|
|
|
|
* Notifies listeners about an inventory item being seen on the network.
|
|
|
|
*
|
|
|
|
* Called on a background thread.
|
|
|
|
*/
|
2017-01-19 22:17:14 +01:00
|
|
|
virtual void Inventory(const uint256 &hash) {}
|
2015-02-05 01:11:44 +01:00
|
|
|
/** Tells listeners to broadcast their data. */
|
2017-01-19 22:17:14 +01:00
|
|
|
virtual void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) {}
|
2017-01-14 22:40:46 +01:00
|
|
|
/**
|
|
|
|
* Notifies listeners of a block validation result.
|
|
|
|
* If the provided CValidationState IsValid, the provided block
|
|
|
|
* is guaranteed to be the current best block at the time the
|
|
|
|
* callback was generated (not necessarily now)
|
|
|
|
*/
|
2017-01-19 22:17:14 +01:00
|
|
|
virtual void BlockChecked(const CBlock&, const CValidationState&) {}
|
2016-12-19 08:26:20 +01:00
|
|
|
/**
|
|
|
|
* Notifies listeners that a block which builds directly on our current tip
|
|
|
|
* has been received and connected to the headers tree, though not validated yet */
|
2017-01-19 22:17:14 +01:00
|
|
|
virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& block) {};
|
|
|
|
friend void ::RegisterValidationInterface(CValidationInterface*);
|
|
|
|
friend void ::UnregisterValidationInterface(CValidationInterface*);
|
|
|
|
friend void ::UnregisterAllValidationInterfaces();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MainSignalsInstance;
|
|
|
|
class CMainSignals {
|
|
|
|
private:
|
|
|
|
std::unique_ptr<MainSignalsInstance> m_internals;
|
|
|
|
|
|
|
|
friend void ::RegisterValidationInterface(CValidationInterface*);
|
|
|
|
friend void ::UnregisterValidationInterface(CValidationInterface*);
|
|
|
|
friend void ::UnregisterAllValidationInterfaces();
|
2017-06-08 17:13:46 +02:00
|
|
|
friend void ::CallFunctionInValidationInterfaceQueue(std::function<void ()> func);
|
2017-01-19 22:49:22 +01:00
|
|
|
|
2017-01-20 21:08:14 +01:00
|
|
|
void MempoolEntryRemoved(CTransactionRef tx, MemPoolRemovalReason reason);
|
|
|
|
|
2017-01-19 22:17:14 +01:00
|
|
|
public:
|
2017-01-19 22:49:22 +01:00
|
|
|
/** Register a CScheduler to give callbacks which should run in the background (may only be called once) */
|
|
|
|
void RegisterBackgroundSignalScheduler(CScheduler& scheduler);
|
|
|
|
/** Unregister a CScheduler to give callbacks which should run in the background - these callbacks will now be dropped! */
|
|
|
|
void UnregisterBackgroundSignalScheduler();
|
2017-06-28 01:07:52 +02:00
|
|
|
/** Call any remaining callbacks on the calling thread */
|
|
|
|
void FlushBackgroundCallbacks();
|
2017-01-19 22:49:22 +01:00
|
|
|
|
2017-01-20 21:08:14 +01:00
|
|
|
/** Register with mempool to call TransactionRemovedFromMempool callbacks */
|
|
|
|
void RegisterWithMempoolSignals(CTxMemPool& pool);
|
|
|
|
/** Unregister with mempool */
|
|
|
|
void UnregisterWithMempoolSignals(CTxMemPool& pool);
|
|
|
|
|
2017-01-19 22:17:14 +01:00
|
|
|
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
|
|
|
|
void TransactionAddedToMempool(const CTransactionRef &);
|
Also call other wallet notify callbacks in scheduler thread
This runs Block{Connected,Disconnected}, SetBestChain, Inventory,
and TransactionAddedToMempool on the background scheduler thread.
Of those, only BlockConnected is used outside of Wallet/ZMQ, and
is used only for orphan transaction removal in net_processing,
something which does not need to be synchronous with anything
else.
This partially reverts #9583, re-enabling some of the gains from
#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
2017-06-08 17:08:53 +02:00
|
|
|
void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>> &);
|
2017-01-19 22:17:14 +01:00
|
|
|
void BlockDisconnected(const std::shared_ptr<const CBlock> &);
|
|
|
|
void SetBestChain(const CBlockLocator &);
|
|
|
|
void Inventory(const uint256 &);
|
|
|
|
void Broadcast(int64_t nBestBlockTime, CConnman* connman);
|
|
|
|
void BlockChecked(const CBlock&, const CValidationState&);
|
|
|
|
void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr<const CBlock>&);
|
2015-02-05 01:11:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
CMainSignals& GetMainSignals();
|
|
|
|
|
|
|
|
#endif // BITCOIN_VALIDATIONINTERFACE_H
|