]> Git Repo - VerusCoin.git/blame - doc/zmq.md
Add 1.0.7 release notes and update authors.md
[VerusCoin.git] / doc / zmq.md
CommitLineData
f200002c
JG
1# Block and Transaction Broadcasting With ZeroMQ
2
3[ZeroMQ](http://zeromq.org/) is a lightweight wrapper around TCP
9540b0c6 4connections, inter-process communication, and shared-memory,
f200002c
JG
5providing various message-oriented semantics such as publish/subcribe,
6request/reply, and push/pull.
7
4fbc46c2
JG
8The Zcash daemon can be configured to act as a trusted "border
9router", implementing the zcash wire protocol and relay, making
f200002c
JG
10consensus decisions, maintaining the local blockchain database,
11broadcasting locally generated transactions into the network, and
12providing a queryable RPC interface to interact on a polled basis for
13requesting blockchain related data. However, there exists only a
14limited service to notify external software of events like the arrival
15of new blocks or transactions.
16
9540b0c6
JC
17The ZeroMQ facility implements a notification interface through a set
18of specific notifiers. Currently there are notifiers that publish
f200002c 19blocks and transactions. This read-only facility requires only the
9540b0c6 20connection of a corresponding ZeroMQ subscriber port in receiving
f200002c
JG
21software; it is not authenticated nor is there any two-way protocol
22involvement. Therefore, subscribers should validate the received data
23since it may be out of date, incomplete or even invalid.
24
9540b0c6
JC
25ZeroMQ sockets are self-connecting and self-healing; that is,
26connections made between two endpoints will be automatically restored
27after an outage, and either end may be freely started or stopped in
28any order.
f200002c
JG
29
30Because ZeroMQ is message oriented, subscribers receive transactions
31and blocks all-at-once and do not need to implement any sort of
32buffering or reassembly.
33
34## Prerequisites
35
4fbc46c2 36The ZeroMQ feature in Zcash requires ZeroMQ API version 4.x or
7c8845ed
JG
37newer, which you will need to install if you are not using the depends
38system. Typically, it is packaged by distributions as something like
edcec148 39*libzmq5-dev*. The C++ wrapper for ZeroMQ is *not* needed.
f200002c 40
9540b0c6
JC
41In order to run the example Python client scripts in contrib/ one must
42also install *python-zmq*, though this is not necessary for daemon
43operation.
f200002c
JG
44
45## Enabling
46
d5f4dc15
JC
47By default, the ZeroMQ feature is automatically compiled in if the
48necessary prerequisites are found. To disable, use --disable-zmq
4fbc46c2 49during the *configure* step of building zcashd:
f200002c 50
d5f4dc15 51 $ ./configure --disable-zmq (other options)
f200002c 52
d5f4dc15
JC
53To actually enable operation, one must set the appropriate options on
54the commandline or in the configuration file.
f200002c
JG
55
56## Usage
57
58Currently, the following notifications are supported:
59
60 -zmqpubhashtx=address
61 -zmqpubhashblock=address
62 -zmqpubrawblock=address
63 -zmqpubrawtx=address
64
9540b0c6
JC
65The socket type is PUB and the address must be a valid ZeroMQ socket
66address. The same address can be used in more than one notification.
f200002c
JG
67
68For instance:
69
4fbc46c2
JG
70 $ zcashd -zmqpubhashtx=tcp://127.0.0.1:28332 \
71 -zmqpubrawtx=ipc:///tmp/zcashd.tx.raw
f200002c
JG
72
73Each PUB notification has a topic and body, where the header
9540b0c6
JC
74corresponds to the notification type. For instance, for the
75notification `-zmqpubhashtx` the topic is `hashtx` (no null
76terminator) and the body is the hexadecimal transaction hash (32
77bytes).
f200002c 78
4fbc46c2 79These options can also be provided in zcash.conf.
f200002c
JG
80
81ZeroMQ endpoint specifiers for TCP (and others) are documented in the
678b614a 82[ZeroMQ API](http://api.zeromq.org/4-0:_start).
f200002c
JG
83
84Client side, then, the ZeroMQ subscriber socket must have the
9540b0c6
JC
85ZMQ_SUBSCRIBE option set to one or either of these prefixes (for
86instance, just `hash`); without doing so will result in no messages
87arriving. Please see `contrib/zmq/zmq_sub.py` for a working example.
f200002c
JG
88
89## Remarks
90
4fbc46c2 91From the perspective of zcashd, the ZeroMQ socket is write-only; PUB
f200002c 92sockets don't even have a read function. Thus, there is no state
4fbc46c2 93introduced into zcashd directly. Furthermore, no information is
f200002c
JG
94broadcast that wasn't already received from the public P2P network.
95
96No authentication or authorization is done on connecting clients; it
97is assumed that the ZeroMQ port is exposed only to trusted entities,
98using other means such as firewalling.
99
9540b0c6
JC
100Note that when the block chain tip changes, a reorganisation may occur
101and just the tip will be notified. It is up to the subscriber to
102retrieve the chain from the last known block to the new tip.
3ba2e19e
JS
103
104There are several possibilities that ZMQ notification can get lost
105during transmission depending on the communication type your are
4fbc46c2 106using. Zcashd appends an up-counting sequence number to each
3ba2e19e 107notification which allows listeners to detect lost notifications.
This page took 0.03339 seconds and 4 git commands to generate.