Skip to content

Commit 38265cc

Browse files
committed
zmq: read raw block with ReadRawBlockFromDisk
1 parent da338aa commit 38265cc

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,9 +1452,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14521452

14531453
#if ENABLE_ZMQ
14541454
g_zmq_notification_interface = CZMQNotificationInterface::Create(
1455-
[&chainman = node.chainman](CBlock& block, const CBlockIndex& index) {
1455+
[&chainman = node.chainman](std::vector<uint8_t>& block, const CBlockIndex& index) {
14561456
assert(chainman);
1457-
return chainman->m_blockman.ReadBlockFromDisk(block, index);
1457+
return chainman->m_blockman.ReadRawBlockFromDisk(block, WITH_LOCK(cs_main, return index.GetBlockPos()));
14581458
});
14591459

14601460
if (g_zmq_notification_interface) {

src/zmq/zmqnotificationinterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ std::list<const CZMQAbstractNotifier*> CZMQNotificationInterface::GetActiveNotif
4141
return result;
4242
}
4343

44-
std::unique_ptr<CZMQNotificationInterface> CZMQNotificationInterface::Create(std::function<bool(CBlock&, const CBlockIndex&)> get_block_by_index)
44+
std::unique_ptr<CZMQNotificationInterface> CZMQNotificationInterface::Create(std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> get_block_by_index)
4545
{
4646
std::map<std::string, CZMQNotifierFactory> factories;
4747
factories["pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;

src/zmq/zmqnotificationinterface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <functional>
1313
#include <list>
1414
#include <memory>
15+
#include <vector>
1516

1617
class CBlock;
1718
class CBlockIndex;
@@ -25,7 +26,7 @@ class CZMQNotificationInterface final : public CValidationInterface
2526

2627
std::list<const CZMQAbstractNotifier*> GetActiveNotifiers() const;
2728

28-
static std::unique_ptr<CZMQNotificationInterface> Create(std::function<bool(CBlock&, const CBlockIndex&)> get_block_by_index);
29+
static std::unique_ptr<CZMQNotificationInterface> Create(std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> get_block_by_index);
2930

3031
protected:
3132
bool Initialize();

src/zmq/zmqpublishnotifier.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,13 @@ bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
243243
{
244244
LogPrint(BCLog::ZMQ, "Publish rawblock %s to %s\n", pindex->GetBlockHash().GetHex(), this->address);
245245

246-
DataStream ss;
247-
CBlock block;
246+
std::vector<uint8_t> block{};
248247
if (!m_get_block_by_index(block, *pindex)) {
249248
zmqError("Can't read block from disk");
250249
return false;
251250
}
252251

253-
ss << TX_WITH_WITNESS(block);
254-
255-
return SendZmqMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size());
252+
return SendZmqMessage(MSG_RAWBLOCK, block.data(), block.size());
256253
}
257254

258255
bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &transaction)

src/zmq/zmqpublishnotifier.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include <cstddef>
1111
#include <cstdint>
1212
#include <functional>
13+
#include <vector>
1314

14-
class CBlock;
1515
class CBlockIndex;
1616
class CTransaction;
1717

@@ -49,10 +49,10 @@ class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier
4949
class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier
5050
{
5151
private:
52-
const std::function<bool(CBlock&, const CBlockIndex&)> m_get_block_by_index;
52+
const std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> m_get_block_by_index;
5353

5454
public:
55-
CZMQPublishRawBlockNotifier(std::function<bool(CBlock&, const CBlockIndex&)> get_block_by_index)
55+
CZMQPublishRawBlockNotifier(std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> get_block_by_index)
5656
: m_get_block_by_index{std::move(get_block_by_index)} {}
5757
bool NotifyBlock(const CBlockIndex *pindex) override;
5858
};

0 commit comments

Comments
 (0)