New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
listen for new block hashes via ZMQ + fetch block templates via RPC #54
Conversation
dd9448c
to
b5c4bb3
Compare
b5c4bb3
to
2feaf6a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. Left some nitty comments and some error handling fix requests.
We should move the mutinynet and docker setup files in a separate PR. Since these are dev tools, I am not sure yet if we should have these in the repo.
This reverts commit 2feaf6a.
From my experience working on this PR, mutinynet is really useful because it has a block time of ~30s, and waiting ~10min for new blocks on a development workflow is not viable. This will likely be the case for future development as well. But I agree it's perhaps not ideal to impose this into the codebase as a whole, so mutinynet deployment files were moved over to https://github.com/bernardoaraujor/braidpool-mutinynet If needed I can send another PR in the future bringing those over here or somewhere else. |
Thanks for this, good work! But polling bad. Bitcoin provides a ZMQ interface:
This will push block notifications to us. We're going to be very sensitive to latency, with braid bead times that might be as low as 150ms. How do you feel about rewriting this to use ZMQ? |
There's a few different potential dependencies for this ZeroMQ implementation. Here's a summary of the tradeoffs for each option, ranked according to my perceived fitness the problem at hand:
While searching for If I were to choose the best dependency for the long term, option 1 seems the most appealing to me. Option 2 is also a viable path. Please let me know your thoughts @mcelrath @pool2win I pushed an implementation for option 1 on this PR. Alternatively, I also wrote an implementation for option 2, currently available on |
another question that comes to mind is: will braidpool nodes also need to listen for other ZMQ topics aside from asking because of this basically, the current implementation simply gets a ZMQ notification and uses that as a trigger for the if the braidpool node also needs to subscribe to other ZMQ notification topics, the code will need to deserialize the notification message and make sure that different topics are triggering the correct actions |
8b45b92
to
5b68620
Compare
4cda461
to
1af423c
Compare
1af423c
to
1f027b5
Compare
after going back and forth with @antonilol, the so I'm switching to |
tested So the standard way to authenticate to bitcoind is to use cookie authentication, which is the file https://github.com/rust-bitcoin/rust-bitcoincore-rpc/blob/master/client/src/client.rs#L198 Before I merge this, can you get cookie auth working by default (and optional rpcuser/rpcpass)? |
Could you add some debugging around the zmq connection? I didn't have zmq enabled in bitcoind and got no complaints from the braipdool node. e.g. fail if we can't connect to zmq. Secondly can you add some docs around configuring the bitcoin node to publish zmq? I think it's just
Do you understand the "high water mark" config options bitcoin has for zmq? |
this is a problem i have had with the EDIT: maybe it is intentional: https://stackoverflow.com/a/14691718/13800918 EDIT2: it is intentional |
|
i did not get it working with the socket options ( |
This comment was marked as outdated.
This comment was marked as outdated.
update on this comment: it is possible and libzmq exposes functionality for it, and the rust bindings do too. i made a working proof of concept pr: antonilol/rust-bitcoincore-zmq#7, note that the stream will be reusable eventually, that is just not implemented yet |
I realized that it's not safe to assume all zmq notifications would be coming from the same port. So I adapted the code so that the listener function (now called Also, the CLI arg is now called Once we start implementing features based on different topics, we can add new functions and CLI args following a similar pattern.
@mcelrath with regards to zmq debugging, it's probably better to wait until work on antonilol/rust-bitcoincore-zmq#7 is finished I suggest we leave that for a follow-up PR, flagged for future reference here: #59 |
This PR makes the braidpool node able to listen for new block hashes via ZMQ, and fetch new block templates via RPC.
The node now takes some new CLI args, namely:
bitcoin
: IP address for bitcoin noderpcport
: RPC port on bitcoin noderpcuser
: username for RPCs on bitcoin noderpcpass
: password for RPCs on bitcoin nodezmqport
: ZMQ port on bitcoin nodeWe spawn a
tokio
thread calledzmq::listener
that listens to the ZMQ subscriptions. When a newhashblock
notification comes in,block_template::fetcher
calls thegetblocktemplate
RPC and sends the new block template into ampsc
channel.A dummy placeholder
tokio
thread calledblock_template::consumer
consumes thempsc
channel by simply printing the new block templates into the console.