2019-12-30 06:39:22 -03:00
|
|
|
// Copyright (c) 2015-2019 The Bitcoin Core developers
|
2014-11-18 14:06:32 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H
|
|
|
|
#define BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H
|
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <validationinterface.h>
|
2017-01-20 20:27:13 -03:00
|
|
|
#include <list>
|
2020-09-01 03:40:13 -04:00
|
|
|
#include <memory>
|
2014-11-18 14:06:32 -03:00
|
|
|
|
2015-09-16 11:42:23 -03:00
|
|
|
class CBlockIndex;
|
2014-11-18 14:06:32 -03:00
|
|
|
class CZMQAbstractNotifier;
|
|
|
|
|
2017-07-12 16:48:36 -04:00
|
|
|
class CZMQNotificationInterface final : public CValidationInterface
|
2014-11-18 14:06:32 -03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~CZMQNotificationInterface();
|
|
|
|
|
2018-06-29 10:10:01 -04:00
|
|
|
std::list<const CZMQAbstractNotifier*> GetActiveNotifiers() const;
|
|
|
|
|
2016-11-29 23:43:29 -03:00
|
|
|
static CZMQNotificationInterface* Create();
|
2014-11-18 14:06:32 -03:00
|
|
|
|
2015-11-01 15:09:17 -03:00
|
|
|
protected:
|
2014-11-18 14:06:32 -03:00
|
|
|
bool Initialize();
|
|
|
|
void Shutdown();
|
|
|
|
|
2015-11-01 15:09:17 -03:00
|
|
|
// CValidationInterface
|
Add 'sequence' zmq publisher to track all block (dis)connects, mempool deltas
Using the zmq notifications to avoid excessive mempool polling can be difficult
given the current notifications available. It announces all transactions
being added to mempool or included in blocks, but announces no evictions
and gives no indication if the transaction is in the mempool or a block.
Block notifications for zmq are also substandard, in that it only announces
block tips, while all block transactions are still announced.
This commit adds a unified stream which can be used to closely track mempool:
1) getrawmempool to fill out mempool knowledge
2) if txhash is announced, add or remove from set
based on add/remove flag
3) if blockhash is announced, get block txn list,
remove from those transactions local view of mempool
4) if we drop a sequence number, go to (1)
The mempool sequence number starts at the value 1, and
increments each time a transaction enters the mempool,
or is evicted from the mempool for any reason, including
block inclusion. The mempool sequence number is published
via ZMQ for any transaction-related notification.
These features allow for ZMQ/RPC consumer to track mempool
state in a more exacting way, without unnecesarily polling
getrawmempool. See interface_zmq.py::test_mempool_sync for
example usage.
2020-09-04 11:55:58 -04:00
|
|
|
void TransactionAddedToMempool(const CTransactionRef& tx, uint64_t mempool_sequence) override;
|
|
|
|
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override;
|
2019-11-11 12:43:34 -03:00
|
|
|
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override;
|
2019-07-24 15:41:41 -04:00
|
|
|
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) override;
|
2017-02-08 16:00:14 -03:00
|
|
|
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
|
2014-11-18 14:06:32 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
CZMQNotificationInterface();
|
|
|
|
|
|
|
|
void *pcontext;
|
2020-09-01 03:40:13 -04:00
|
|
|
std::list<std::unique_ptr<CZMQAbstractNotifier>> notifiers;
|
2014-11-18 14:06:32 -03:00
|
|
|
};
|
|
|
|
|
2018-06-29 09:16:31 -04:00
|
|
|
extern CZMQNotificationInterface* g_zmq_notification_interface;
|
|
|
|
|
2014-11-18 14:06:32 -03:00
|
|
|
#endif // BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H
|