This adds an Events IPC interface that streams block and mempool events in one ordered stream, addressing gaps in ZMQ notifications and providing a more modular interface. It supports the following subscriptions:
blockConnected: fires for every block connected to the active chain, including during IBD (blocks connected by a background assumeutxo chainstate are skipped). Carries hash, height and optionally the serialized block. ZMQhashblock/rawblockare driven by UpdatedBlockTip, so they skip intermediate blocks when several connect at once and don't fire during IBD.blockDisconnected: fires for every block disconnected during a reorg, with hash, height and optionally the serialized block.txAddedToMempool: fires only for mempool acceptance. Carries txid, wtxid, mempool sequence, fee, vsize and optionally the serialized tx. ZMQhashtx/rawtxalso fire for every tx in connected and disconnected blocks, so a subscriber can't tell whether a tx entered the mempool (pain point of #19462 (comment), #23624#issue-1065790580 and #7753).txRemovedFromMempool: fires for every removal, including txs removed because they were mined (reasonblock), except during IBD, with txid, wtxid, mempool sequence, removal reason and optionally the serialized tx.
ZMQ sequence covers all four of these, but only carries hashes (plus the mempool sequence for "A"/"R"), and "R" doesn't include block-inclusion removals or a reason.
Why not just do it with ZMQ?
- One ordered stream that includes the data.
rawblock/rawtxhave their own sequence numbers and can't be ordered againstsequence. Here every event can include its serialized block or tx in the same ordered stream. Events come in the same order as ZMQsequence, plus block-inclusion removals. - Typed, versioned interface. Cap'n Proto generates the client code and lets the schema evolve without breaking older clients. With ZMQ, clients parse raw bytes by hand which can't evolve existing topics without breaking changes.
- Fixing these in ZMQ would need new topics reporting on the same events as existing ones, which is confusing for users, and changing the existing topics would break current consumers.
- Bounded buffering. Events are buffered per subscription up to a byte limit (
-ipceventsbuffer), and the client pulls them in batches with waitNext. ZMQ limits are message counts per topic (-zmqpub*hwm), which don't bound memory when messages are full blocks.
Why additional data, including derivable ones?
- fee, vsize: neither can be derived from the tx alone, so including them saves RPC calls per tx. RPC calls can also fail if the tx was removed in the time in between.
- mempool sequence: lets a client line events up with
getrawmempool(mempool_sequence=true) to bootstrap and keep a mempool mirror in sync. - height: not in the serialized block, and needed to handle reorgs without an extra RPC call.
- hash, txid, wtxid: identifiers are always included, so clients don't need to branch on
include_data.
Example of simple clients using this interface, including a mempool mirror: https://github.com/ViniciusCestarii/bitcoin-ipc-events-client
Note: to make this interface usable in this PR, the Cap'n Proto union that this uses is mapped by hand in events-types.h. Ideally this support would be added to libmultiprocess first.