2020-12-31 09:48:25 +01:00
|
|
|
// Copyright (c) 2015-2020 The Bitcoin Core developers
|
2014-11-18 12:06:32 -05:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H
|
|
|
|
#define BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H
|
|
|
|
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <zmq/zmqabstractnotifier.h>
|
2014-11-18 12:06:32 -05:00
|
|
|
|
2015-09-16 16:42:23 +02:00
|
|
|
class CBlockIndex;
|
|
|
|
|
2014-11-18 12:06:32 -05:00
|
|
|
class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier
|
|
|
|
{
|
2016-03-29 14:30:02 +02:00
|
|
|
private:
|
2018-08-24 20:42:03 -04:00
|
|
|
uint32_t nSequence {0U}; //!< upcounting per message sequence number
|
2016-03-29 14:30:02 +02:00
|
|
|
|
2014-11-18 12:06:32 -05:00
|
|
|
public:
|
2016-03-29 14:30:02 +02:00
|
|
|
|
|
|
|
/* send zmq multipart message
|
|
|
|
parts:
|
|
|
|
* command
|
|
|
|
* data
|
|
|
|
* message sequence number
|
|
|
|
*/
|
2018-11-10 20:05:34 +00:00
|
|
|
bool SendZmqMessage(const char *command, const void* data, size_t size);
|
2016-03-29 14:30:02 +02:00
|
|
|
|
2017-06-20 21:58:56 +02:00
|
|
|
bool Initialize(void *pcontext) override;
|
|
|
|
void Shutdown() override;
|
2014-11-18 12:06:32 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class CZMQPublishHashBlockNotifier : public CZMQAbstractPublishNotifier
|
|
|
|
{
|
|
|
|
public:
|
2017-06-20 21:58:56 +02:00
|
|
|
bool NotifyBlock(const CBlockIndex *pindex) override;
|
2014-11-18 12:06:32 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier
|
|
|
|
{
|
|
|
|
public:
|
2017-06-20 21:58:56 +02:00
|
|
|
bool NotifyTransaction(const CTransaction &transaction) override;
|
2014-11-18 12:06:32 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier
|
|
|
|
{
|
|
|
|
public:
|
2017-06-20 21:58:56 +02:00
|
|
|
bool NotifyBlock(const CBlockIndex *pindex) override;
|
2014-11-18 12:06:32 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class CZMQPublishRawTransactionNotifier : public CZMQAbstractPublishNotifier
|
|
|
|
{
|
|
|
|
public:
|
2017-06-20 21:58:56 +02:00
|
|
|
bool NotifyTransaction(const CTransaction &transaction) override;
|
2014-11-18 12:06:32 -05:00
|
|
|
};
|
|
|
|
|
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
|
|
|
class CZMQPublishSequenceNotifier : public CZMQAbstractPublishNotifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool NotifyBlockConnect(const CBlockIndex *pindex) override;
|
|
|
|
bool NotifyBlockDisconnect(const CBlockIndex *pindex) override;
|
|
|
|
bool NotifyTransactionAcceptance(const CTransaction &transaction, uint64_t mempool_sequence) override;
|
|
|
|
bool NotifyTransactionRemoval(const CTransaction &transaction, uint64_t mempool_sequence) override;
|
|
|
|
};
|
|
|
|
|
2014-11-18 12:06:32 -05:00
|
|
|
#endif // BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H
|