[bisq-network/proposals] Using ZeroMQ instead or in parallel with bitcoind's blocknotify for DAO full nodes (#73)

KanoczTomas notifications at github.com
Thu Feb 14 08:49:21 UTC 2019

> _This is a Bisq Network proposal. Please familiarize yourself with the [submission and review process](https://docs.bisq.network/proposals.html)._
# Using ZeroMQ instead or in parallel with bitcoind's blocknotify for DAO full nodes

## Current state
Currently the bisq `DAO` full node requires a blocknotify script that sends the hash of the newest block to a port defined in a script.
Current bitcoin.conf entry needed for blocknotify:
blocknotify=./blocknotify %s
Example blocknotify script content (Linux):
echo $1 | nc -w 1 5120
A script needs to exist, have proper execution rights for bitcoind to successfully run it. Besides user needs to have netcat installed which might be cumbersome on other platforms than Linux.

## Why is it a good idea to change current state ?
As the blocknotify script uses netcat (nc) in the current state it is essentially using a tcp connection to localhost. While the script used with blocknotify can be altered to run the bisq node and bitcoind deamon on a separate physical (or virtual) server a better approach using ZeroMQ is available.

## What is ZeroMQ?
`ZeroMQ` is a subscription service that requires very little load on the server and client side. The server connects to a tcp socket where it emits events. The client can subscribe to those events when connected to the tcp socket of the server. The server writes data only once, yet all clients get it.

## bitcoind ZeroMQ support
Bitcoind supports `ZeroMQ` for a long time. There are 4 events (topics) a subscriber can subscribe to:
  1. **hashtx** - emits the hash of the newest transaction
  2. **hashblock** - emits the hash of the newest block
  3. **rawtx** - emits the full newest raw transaction 
  4. **rawblock** - emits the full newest raw block

`ZeroMQ` is considered a notification service by bitcoind and `RPC` has to be further used to retrieve data and have 100% guarantee the data is correct. It means it is not a replacement for `RPC`, but another notification option.
`ZeroMQ` has to be activated in the configuration of `bitcoind`, an example where all events are emmited to the same port (the clients filter based on topic to which they subscribed):
## Example usage in other project
An example of how the `rawtx` is used to retrieve fees and show `mempool transactions` in realtime (**warning, JavaScript code, do not look at it if you hate JS**):

## What needs to change in bisq to use ZeroMQ?
A `java` library can be used to connect to `bitcoind`'s `ZeroMQ` service and listen for **hashblock** events. The code handling the blockhash does not need to change, as the `ZeroMQ` message payload contains the same data as netcat is sending in the current implementation (namely a string = hash of the newest block). 
Perhaps this `java` lib could be used: https://github.com/zeromq/jeromq
Equivalent `ZeroMQ` configuration in `bitcoind` using port 5120:
## What bisq gains by using ZeroMQ?
Besides dropping the need to have netcat installed and a script distributed (per OS of course) to handle notifications I can imagine the bisq full node to create a ZeroMQ server as well and expose `ZeroMQ` events as `bitcoind` has for the `DAO`. That way a lot of possibilities for monitoring tools, block explorers towards bisq could be opened using very little code and effort. 
Suggested **event**(topic) names for the bisq `DAO`:
  1. **bsqhashtx** - emits the hash of the newest BSQ transaction
  2. **bsqhashblock** - emits the hash of the newest block containing BSQ transactions
  3. **bsqrawtx** - emits the full raw BSQ transaction 
  4. **bswrawblock** - emits the full raw block containing BSQ transactions

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20190214/32b972f5/attachment.html>

More information about the bisq-github mailing list