19 #include <unordered_map>
20 #include <boost/signals2/signal.hpp>
48 boost::signals2::signal<void (
const std::shared_ptr<const CBlock> &,
const uint256& blockHash,
int nBlockHeight, int64_t blockTime)>
BlockDisconnected;
60 std::unordered_map<CValidationInterface*, ValidationInterfaceConnections>
m_connMainSignals;
89 return m_internals->m_schedulerClient.CallbacksPending();
122 g_signals.
m_internals->m_connMainSignals.erase(pwalletIn);
140 g_signals.
m_internals->m_schedulerClient.AddToProcessQueue(std::move(func));
149 std::promise<void> promise;
153 promise.get_future().wait();
160 #define ENQUEUE_AND_LOG_EVENT(event, fmt, name, ...) \
162 auto local_name = (name); \
163 LOG_EVENT("Enqueuing " fmt, local_name, __VA_ARGS__); \
164 m_internals->m_schedulerClient.AddToProcessQueue([=] { \
165 LOG_EVENT(fmt, local_name, __VA_ARGS__); \
170 #define LOG_EVENT(fmt, ...) \
171 LogPrint(BCLog::VALIDATION, fmt "\n", __VA_ARGS__)
175 auto event = [pindexNew,
this] {
186 auto event = [pindexNew, pindexFork, fInitialDownload,
this] {
187 m_internals->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
196 auto event = [ptx,
this] {
203 auto event = [ptx, reason,
this] {
204 m_internals->TransactionRemovedFromMempool(ptx, reason);
210 auto event = [pblock, pindex,
this] {
214 pblock->GetHash().ToString(), pindex->
nHeight);
218 auto event = [pblock, blockHash, nBlockHeight, blockTime,
this] {
219 m_internals->BlockDisconnected(pblock, blockHash, nBlockHeight, blockTime);
222 blockHash.
ToString(), nBlockHeight, blockTime);
226 auto event = [locator,
this] {
230 locator.
IsNull() ?
"null" : locator.
vHave.front().ToString());
239 LOG_EVENT(
"%s: block hash=%s (state=%s)", __func__,
244 m_internals->NotifyMasternodeListChanged(undo, oldMNList, diff);
245 LOG_EVENT(
"%s: (undo=%d) old list for=%s, added=%d, updated=%d, removed=%d", __func__,
The block chain is a tree shaped structure starting with the genesis block at the root,...
uint256 GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
std::set< uint64_t > removedMns
std::map< uint64_t, CDeterministicMNStateDiff > updatedMNs
std::vector< CDeterministicMNCPtr > addedMNs
const uint256 & GetBlockHash() const
size_t CallbacksPending()
std::unique_ptr< MainSignalsInstance > m_internals
void SetBestChain(const CBlockLocator &)
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)
void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList &oldMNList, const CDeterministicMNListDiff &diff)
void UnregisterBackgroundSignalScheduler()
Unregister a CScheduler to give callbacks which should run in the background - these callbacks will n...
void AcceptedBlockHeader(const CBlockIndex *pindexNew)
void Broadcast(CConnman *connman)
void BlockChecked(const CBlock &, const CValidationState &)
void RegisterBackgroundSignalScheduler(CScheduler &scheduler)
Register a CScheduler to give callbacks which should run in the background (may only be called once)
void BlockDisconnected(const std::shared_ptr< const CBlock > &block, const uint256 &blockHash, int nBlockHeight, int64_t blockTime)
void TransactionAddedToMempool(const CTransactionRef &ptxn)
void BlockConnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
void FlushBackgroundCallbacks()
Call any remaining callbacks on the calling thread.
void TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason)
Implement this to subscribe to events generated in validation.
virtual void BlockDisconnected(const std::shared_ptr< const CBlock > &block, const uint256 &blockHash, int nBlockHeight, int64_t blockTime)
Notifies listeners of a block being disconnected.
virtual void ResendWalletTransactions(CConnman *connman)
Tells listeners to broadcast their data.
virtual void TransactionAddedToMempool(const CTransactionRef &ptxn)
Notifies listeners of a transaction having been added to mempool.
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
Notifies listeners when the block chain tip advances.
virtual void TransactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason)
Notifies listeners of a transaction leaving mempool.
virtual void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList &oldMNList, const CDeterministicMNListDiff &diff)
Notifies listeners of updated deterministic masternode list.
virtual void SetBestChain(const CBlockLocator &locator)
Notifies listeners of the new active block chain on-disk.
virtual void BlockConnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Notifies listeners of a block being connected.
virtual void AcceptedBlockHeader(const CBlockIndex *pindexNew)
virtual void BlockChecked(const CBlock &, const CValidationState &)
Capture information about block/transaction validation.
Class used by CScheduler clients which may schedule multiple jobs which are required to be run serial...
std::string ToString() const
RecursiveMutex cs_main
Global state.
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
std::vector< uint256 > vHave
boost::signals2::signal< void(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)> UpdatedBlockTip
Notifies listeners of updated block chain tip.
boost::signals2::signal< void(const std::shared_ptr< const CBlock > &, const CBlockIndex *pindex)> BlockConnected
Notifies listeners of a block being connected.
boost::signals2::signal< void(const CBlock &, const CValidationState &)> BlockChecked
Notifies listeners of a block validation result.
SingleThreadedSchedulerClient m_schedulerClient
boost::signals2::signal< void(const CTransactionRef &, MemPoolRemovalReason reason)> TransactionRemovedFromMempool
Notifies listeners of a transaction removal from the mempool.
std::unordered_map< CValidationInterface *, ValidationInterfaceConnections > m_connMainSignals
boost::signals2::signal< void(CConnman *connman)> Broadcast
Tells listeners to broadcast their data.
boost::signals2::signal< void(const std::shared_ptr< const CBlock > &, const uint256 &blockHash, int nBlockHeight, int64_t blockTime)> BlockDisconnected
Notifies listeners of a block being disconnected.
boost::signals2::signal< void(const CBlockLocator &)> SetBestChain
Notifies listeners of a new active block chain.
MainSignalsInstance(CScheduler *pscheduler)
boost::signals2::signal< void(bool undo, const CDeterministicMNList &oldMNList, const CDeterministicMNListDiff &diff)> NotifyMasternodeListChanged
Notifies listeners of updated deterministic masternode list.
boost::signals2::signal< void(const CTransactionRef &)> TransactionAddedToMempool
Notifies listeners of a transaction having been added to mempool.
boost::signals2::signal< void(const CBlockIndex *)> AcceptedBlockHeader
Notifies listeners of accepted block header.
boost::signals2::scoped_connection TransactionAddedToMempool
boost::signals2::scoped_connection UpdatedBlockTip
boost::signals2::scoped_connection SetBestChain
boost::signals2::scoped_connection BlockDisconnected
boost::signals2::scoped_connection AcceptedBlockHeader
boost::signals2::scoped_connection Broadcast
boost::signals2::scoped_connection BlockChecked
boost::signals2::scoped_connection TransactionRemovedFromMempool
boost::signals2::scoped_connection BlockConnected
boost::signals2::scoped_connection NotifyMasternodeListChanged
#define AssertLockNotHeld(cs)
std::shared_ptr< const CTransaction > CTransactionRef
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
std::string FormatStateMessage(const CValidationState &state)
Convert CValidationState to a human-readable message for logging.
CMainSignals & GetMainSignals()
#define LOG_EVENT(fmt,...)
void CallFunctionInValidationInterfaceQueue(std::function< void()> func)
Pushes a function to callback onto the notification queue, guaranteeing any callbacks generated prior...
void UnregisterValidationInterface(CValidationInterface *pwalletIn)
Unregister a wallet from core.
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > pwalletIn)
void UnregisterAllValidationInterfaces()
Unregister all wallets from core.
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > pwalletIn)
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
#define ENQUEUE_AND_LOG_EVENT(event, fmt, name,...)