Browse Source

add checked block zmq nofitication type to publish verified blocks

pull/28/head
Jane Mercer 5 years ago
parent
commit
222c0b226a
  1. 5
      src/zmq/zmqabstractnotifier.cpp
  2. 1
      src/zmq/zmqabstractnotifier.h
  3. 22
      src/zmq/zmqnotificationinterface.cpp
  4. 2
      src/zmq/zmqnotificationinterface.h
  5. 14
      src/zmq/zmqpublishnotifier.cpp
  6. 6
      src/zmq/zmqpublishnotifier.h

5
src/zmq/zmqabstractnotifier.cpp

@ -16,6 +16,11 @@ bool CZMQAbstractNotifier::NotifyBlock(const CBlockIndex * /*CBlockIndex*/)
return true;
}
bool CZMQAbstractNotifier::NotifyBlock(const CBlock &)
{
return true;
}
bool CZMQAbstractNotifier::NotifyTransaction(const CTransaction &/*transaction*/)
{
return true;

1
src/zmq/zmqabstractnotifier.h

@ -33,6 +33,7 @@ public:
virtual void Shutdown() = 0;
virtual bool NotifyBlock(const CBlockIndex *pindex);
virtual bool NotifyBlock(const CBlock& pblock);
virtual bool NotifyTransaction(const CTransaction &transaction);
protected:

22
src/zmq/zmqnotificationinterface.cpp

@ -39,6 +39,7 @@ CZMQNotificationInterface* CZMQNotificationInterface::CreateWithArguments(const
factories["pubhashtx"] = CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>;
factories["pubrawblock"] = CZMQAbstractNotifier::Create<CZMQPublishRawBlockNotifier>;
factories["pubrawtx"] = CZMQAbstractNotifier::Create<CZMQPublishRawTransactionNotifier>;
factories["pubcheckedblock"] = CZMQAbstractNotifier::Create<CZMQPublishCheckedBlockNotifier>;
for (std::map<std::string, CZMQNotifierFactory>::const_iterator i=factories.begin(); i!=factories.end(); ++i)
{
@ -141,6 +142,27 @@ void CZMQNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindex)
}
}
void CZMQNotificationInterface::BlockChecked(const CBlock& block, const CValidationState& state)
{
if (state.IsInvalid()) {
return;
}
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
{
CZMQAbstractNotifier *notifier = *i;
if (notifier->NotifyBlock(block))
{
i++;
}
else
{
notifier->Shutdown();
i = notifiers.erase(i);
}
}
}
void CZMQNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock)
{
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )

2
src/zmq/zmqnotificationinterface.h

@ -6,6 +6,7 @@
#define BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H
#include "validationinterface.h"
#include "consensus/validation.h"
#include <string>
#include <map>
@ -26,6 +27,7 @@ protected:
// CValidationInterface
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
void UpdatedBlockTip(const CBlockIndex *pindex);
void BlockChecked(const CBlock& block, const CValidationState& state);
private:
CZMQNotificationInterface();

14
src/zmq/zmqpublishnotifier.cpp

@ -12,6 +12,7 @@ static const char *MSG_HASHBLOCK = "hashblock";
static const char *MSG_HASHTX = "hashtx";
static const char *MSG_RAWBLOCK = "rawblock";
static const char *MSG_RAWTX = "rawtx";
static const char *MSG_CHECKEDBLOCK = "checkedblock";
// Internal function to send multipart message
static int zmq_send_multipart(void *sock, const void* data, size_t size, ...)
@ -179,6 +180,19 @@ bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
return SendMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size());
}
bool CZMQPublishCheckedBlockNotifier::NotifyBlock(const CBlock& block)
{
LogPrint("zmq", "zmq: Publish checkedblock %s\n", block.GetHash().GetHex());
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
{
LOCK(cs_main);
ss << block;
}
return SendMessage(MSG_CHECKEDBLOCK, &(*ss.begin()), ss.size());
}
bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
{
uint256 hash = transaction.GetHash();

6
src/zmq/zmqpublishnotifier.h

@ -52,4 +52,10 @@ public:
bool NotifyTransaction(const CTransaction &transaction);
};
class CZMQPublishCheckedBlockNotifier : public CZMQAbstractPublishNotifier
{
public:
bool NotifyBlock(const CBlock &block);
};
#endif // BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H

Loading…
Cancel
Save