From 38265cc14e7d646bf27882329d374d42167eb49f Mon Sep 17 00:00:00 2001 From: Andrew Toth Date: Tue, 12 Mar 2024 12:46:46 -0400 Subject: zmq: read raw block with ReadRawBlockFromDisk --- src/zmq/zmqnotificationinterface.cpp | 2 +- src/zmq/zmqnotificationinterface.h | 3 ++- src/zmq/zmqpublishnotifier.cpp | 7 ++----- src/zmq/zmqpublishnotifier.h | 6 +++--- 4 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src/zmq') diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index 63c2737706..d10db046f5 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -41,7 +41,7 @@ std::list CZMQNotificationInterface::GetActiveNotif return result; } -std::unique_ptr CZMQNotificationInterface::Create(std::function get_block_by_index) +std::unique_ptr CZMQNotificationInterface::Create(std::function&, const CBlockIndex&)> get_block_by_index) { std::map factories; factories["pubhashblock"] = CZMQAbstractNotifier::Create; diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h index 45d0982bd3..c879fdd0dd 100644 --- a/src/zmq/zmqnotificationinterface.h +++ b/src/zmq/zmqnotificationinterface.h @@ -12,6 +12,7 @@ #include #include #include +#include class CBlock; class CBlockIndex; @@ -25,7 +26,7 @@ public: std::list GetActiveNotifiers() const; - static std::unique_ptr Create(std::function get_block_by_index); + static std::unique_ptr Create(std::function&, const CBlockIndex&)> get_block_by_index); protected: bool Initialize(); diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp index 0f20706364..608870c489 100644 --- a/src/zmq/zmqpublishnotifier.cpp +++ b/src/zmq/zmqpublishnotifier.cpp @@ -243,16 +243,13 @@ bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex) { LogPrint(BCLog::ZMQ, "Publish rawblock %s to %s\n", pindex->GetBlockHash().GetHex(), this->address); - DataStream ss; - CBlock block; + std::vector block{}; if (!m_get_block_by_index(block, *pindex)) { zmqError("Can't read block from disk"); return false; } - ss << TX_WITH_WITNESS(block); - - return SendZmqMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size()); + return SendZmqMessage(MSG_RAWBLOCK, block.data(), block.size()); } bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &transaction) diff --git a/src/zmq/zmqpublishnotifier.h b/src/zmq/zmqpublishnotifier.h index a5cd433761..cc941a899c 100644 --- a/src/zmq/zmqpublishnotifier.h +++ b/src/zmq/zmqpublishnotifier.h @@ -10,8 +10,8 @@ #include #include #include +#include -class CBlock; class CBlockIndex; class CTransaction; @@ -49,10 +49,10 @@ public: class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier { private: - const std::function m_get_block_by_index; + const std::function&, const CBlockIndex&)> m_get_block_by_index; public: - CZMQPublishRawBlockNotifier(std::function get_block_by_index) + CZMQPublishRawBlockNotifier(std::function&, const CBlockIndex&)> get_block_by_index) : m_get_block_by_index{std::move(get_block_by_index)} {} bool NotifyBlock(const CBlockIndex *pindex) override; }; -- cgit v1.2.3