diff options
Diffstat (limited to 'src/validationinterface.h')
-rw-r--r-- | src/validationinterface.h | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/src/validationinterface.h b/src/validationinterface.h index ed6c560944..f9a359b7ad 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -30,6 +30,14 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn); void UnregisterValidationInterface(CValidationInterface* pwalletIn); /** Unregister all wallets from core */ void UnregisterAllValidationInterfaces(); + +// Alternate registration functions that release a shared_ptr after the last +// notification is sent. These are useful for race-free cleanup, since +// unregistration is nonblocking and can return before the last notification is +// processed. +void RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks); +void UnregisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks); + /** * Pushes a function to callback onto the notification queue, guaranteeing any * callbacks generated prior to now are finished when the function is called. @@ -92,10 +100,32 @@ protected: /** * 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. + * This notification fires for transactions that are removed from the + * mempool for the following reasons: + * + * - EXPIRY (expired from mempool after -mempoolexpiry hours) + * - SIZELIMIT (removed in size limiting if the mempool exceeds -maxmempool megabytes) + * - REORG (removed during a reorg) + * - CONFLICT (removed because it conflicts with in-block transaction) + * - REPLACED (removed due to RBF replacement) + * + * This does not fire for transactions that are removed from the mempool + * because they have been included in a block. Any client that is interested + * in transactions removed from the mempool for inclusion in a block can learn + * about those transactions from the BlockConnected notification. + * + * Transactions that are removed from the mempool because they conflict + * with a transaction in the new block will have + * TransactionRemovedFromMempool events fired *before* the BlockConnected + * event is fired. If multiple blocks are connected in one step, then the + * ordering could be: + * + * - TransactionRemovedFromMempool(tx1 from block A) + * - TransactionRemovedFromMempool(tx2 from block A) + * - TransactionRemovedFromMempool(tx1 from block B) + * - TransactionRemovedFromMempool(tx2 from block B) + * - BlockConnected(A) + * - BlockConnected(B) * * Called on a background thread. */ @@ -106,7 +136,7 @@ protected: * * Called on a background thread. */ - virtual void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, const std::vector<CTransactionRef> &txnConflicted) {} + virtual void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex) {} /** * Notifies listeners of a block being disconnected * @@ -141,7 +171,7 @@ protected: * 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 */ virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& block) {}; - friend void ::RegisterValidationInterface(CValidationInterface*); + friend void ::RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface>); friend void ::UnregisterValidationInterface(CValidationInterface*); friend void ::UnregisterAllValidationInterfaces(); }; @@ -151,7 +181,7 @@ class CMainSignals { private: std::unique_ptr<MainSignalsInstance> m_internals; - friend void ::RegisterValidationInterface(CValidationInterface*); + friend void ::RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface>); friend void ::UnregisterValidationInterface(CValidationInterface*); friend void ::UnregisterAllValidationInterfaces(); friend void ::CallFunctionInValidationInterfaceQueue(std::function<void ()> func); @@ -170,7 +200,7 @@ public: void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload); void TransactionAddedToMempool(const CTransactionRef &); void TransactionRemovedFromMempool(const CTransactionRef &); - void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>> &); + void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex); void BlockDisconnected(const std::shared_ptr<const CBlock> &, const CBlockIndex* pindex); void ChainStateFlushed(const CBlockLocator &); void BlockChecked(const CBlock&, const BlockValidationState&); |