mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
zmq: read raw block with ReadRawBlockFromDisk
This commit is contained in:
parent
da338aada7
commit
38265cc14e
5 changed files with 10 additions and 12 deletions
|
@ -1452,9 +1452,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
|
|
||||||
#if ENABLE_ZMQ
|
#if ENABLE_ZMQ
|
||||||
g_zmq_notification_interface = CZMQNotificationInterface::Create(
|
g_zmq_notification_interface = CZMQNotificationInterface::Create(
|
||||||
[&chainman = node.chainman](CBlock& block, const CBlockIndex& index) {
|
[&chainman = node.chainman](std::vector<uint8_t>& block, const CBlockIndex& index) {
|
||||||
assert(chainman);
|
assert(chainman);
|
||||||
return chainman->m_blockman.ReadBlockFromDisk(block, index);
|
return chainman->m_blockman.ReadRawBlockFromDisk(block, WITH_LOCK(cs_main, return index.GetBlockPos()));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (g_zmq_notification_interface) {
|
if (g_zmq_notification_interface) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ std::list<const CZMQAbstractNotifier*> CZMQNotificationInterface::GetActiveNotif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CZMQNotificationInterface> CZMQNotificationInterface::Create(std::function<bool(CBlock&, const CBlockIndex&)> get_block_by_index)
|
std::unique_ptr<CZMQNotificationInterface> CZMQNotificationInterface::Create(std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> get_block_by_index)
|
||||||
{
|
{
|
||||||
std::map<std::string, CZMQNotifierFactory> factories;
|
std::map<std::string, CZMQNotifierFactory> factories;
|
||||||
factories["pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
|
factories["pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class CBlock;
|
class CBlock;
|
||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
|
@ -25,7 +26,7 @@ public:
|
||||||
|
|
||||||
std::list<const CZMQAbstractNotifier*> GetActiveNotifiers() const;
|
std::list<const CZMQAbstractNotifier*> GetActiveNotifiers() const;
|
||||||
|
|
||||||
static std::unique_ptr<CZMQNotificationInterface> Create(std::function<bool(CBlock&, const CBlockIndex&)> get_block_by_index);
|
static std::unique_ptr<CZMQNotificationInterface> Create(std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> get_block_by_index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
|
|
|
@ -243,16 +243,13 @@ bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
|
||||||
{
|
{
|
||||||
LogPrint(BCLog::ZMQ, "Publish rawblock %s to %s\n", pindex->GetBlockHash().GetHex(), this->address);
|
LogPrint(BCLog::ZMQ, "Publish rawblock %s to %s\n", pindex->GetBlockHash().GetHex(), this->address);
|
||||||
|
|
||||||
DataStream ss;
|
std::vector<uint8_t> block{};
|
||||||
CBlock block;
|
|
||||||
if (!m_get_block_by_index(block, *pindex)) {
|
if (!m_get_block_by_index(block, *pindex)) {
|
||||||
zmqError("Can't read block from disk");
|
zmqError("Can't read block from disk");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ss << TX_WITH_WITNESS(block);
|
return SendZmqMessage(MSG_RAWBLOCK, block.data(), block.size());
|
||||||
|
|
||||||
return SendZmqMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
|
bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class CBlock;
|
|
||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
class CTransaction;
|
class CTransaction;
|
||||||
|
|
||||||
|
@ -49,10 +49,10 @@ public:
|
||||||
class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier
|
class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const std::function<bool(CBlock&, const CBlockIndex&)> m_get_block_by_index;
|
const std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> m_get_block_by_index;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CZMQPublishRawBlockNotifier(std::function<bool(CBlock&, const CBlockIndex&)> get_block_by_index)
|
CZMQPublishRawBlockNotifier(std::function<bool(std::vector<uint8_t>&, const CBlockIndex&)> get_block_by_index)
|
||||||
: m_get_block_by_index{std::move(get_block_by_index)} {}
|
: m_get_block_by_index{std::move(get_block_by_index)} {}
|
||||||
bool NotifyBlock(const CBlockIndex *pindex) override;
|
bool NotifyBlock(const CBlockIndex *pindex) override;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue