zmq: Pass lambda to zmq's ZMQPublishRawBlockNotifier

The lambda captures a reference to the chainman unique_ptr to retrieve
block data. An assert is added on the chainman to ensure that the lambda
is not used while the chainman is uninitialized.

This is done in preparation for the following commits where blockstorage
functions are made BlockManager methods.
This commit is contained in:
TheCharlatan
2023-05-03 22:24:21 +02:00
parent 8ed4ff8e05
commit cfbb212493
6 changed files with 21 additions and 9 deletions

View File

@@ -1424,7 +1424,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
}
#if ENABLE_ZMQ
g_zmq_notification_interface = CZMQNotificationInterface::Create();
g_zmq_notification_interface = CZMQNotificationInterface::Create(
[&chainman = node.chainman](CBlock& block, const CBlockIndex& index) {
assert(chainman);
return node::ReadBlockFromDisk(block, &index, chainman->GetConsensus());
});
if (g_zmq_notification_interface) {
RegisterValidationInterface(g_zmq_notification_interface.get());