-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add ZeroMQ notifications #6103
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
Add ZeroMQ notifications #6103
Conversation
|
||
static void zmqError(const char *str) | ||
{ | ||
LogPrint("ZMQ error: %s, errno=%s\n", str, zmq_strerror(errno)); |
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.
This entire file needs to be retabbed.
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.
L39: s/LogPrint
/LogPrintf
otherwise you start introducing a debug category with string identifier "ZMQ error: %s, errno=%s\n"
.
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.
Fixed in upcoming commit
Are you planning on supplying an RPC/regression test for this? |
That work was in previous PR. I can't see a use case where this is useful. Maybe @jmcorgan have something to say about that, otherwise I would remove this RPC call. |
@@ -95,6 +97,12 @@ class CClientUIInterface | |||
|
|||
/** New block has been accepted */ | |||
boost::signals2::signal<void (const uint256& hash)> NotifyBlockTip; | |||
|
|||
/** New block has been accepted */ | |||
boost::signals2::signal<void (const CBlock& block)> NotifyAcceptBlock; |
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.
As mentioned in one of the previous PRs, block acceptance is really not interesting or useful. It does not mean the block is part of the best chain, or even that it is valid. Use the NotifyBlockTip signal place, which indicates a new tip of the best chain was accepted.
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.
Fixed in upcoming commit
As far as I know, no RPC tests for ZMQ support have yet been PR'd. I think there might be some confusion here. When I say RPC tests, I mean the Python regression tests that live qa/rpc-tests tree. They're pretty much only called RPC tests because of history and the primary way they interface with bitcoind. They exercise and verify many large bits of functionality and are always useful! Case in point, when REST support was originally added, it had some pretty serious bugs that weren't caught because there was no RPC test. See PR #5379 for an example of how RPC tests for the REST interface were implemented. I suppose RPC tests could be PR'd separately, but I bet this will go in faster and with more enthusiasm if tests are added. |
@promag Nice that you have started recycle/update/rebase this! |
Currently, the ZeroMQ facility only needs to have the ZeroMQ endpoint | ||
specified: | ||
|
||
$ bitcoind -zmqpub=tcp://127.0.0.1/28332 |
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.
this should be: bitcoind -zmqpub=tcp://127.0.0.1:28332
(dash colon instead slash before port)
Edit: dash / colon
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.
fixed in upcoming commit
LOCK(cs_main); | ||
|
||
CBlockIndex* pblockindex = mapBlockIndex[hash]; | ||
if(!ReadBlockFromDisk(blk, pblockindex)) |
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.
I believe this is the right way of getting a block.
I'm planning to add the option -zmqformat=raw|json. This way a subscriber doesn't need to rely on 3rd libs to process the messages. What do you think? |
// Global state | ||
extern bool fZMQPub; | ||
|
||
#if ENABLE_ZMQ |
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.
Is the reason why the #ifdefs
are here instead of wrapping the code-part in init.cpp
to lower the #ifdef in init.cpp
? Maybe also something for @jgarzik to answer.
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.
FYI #4594 (comment)
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.
@promag: Thanks. Yes this makes sense.
Would be nice if you could cherry-pick / pull-in this RPC/ZMQ test case: |
@@ -1022,6 +1029,11 @@ bool AppInit2(boost::thread_group& threadGroup) | |||
BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"]) | |||
AddOneShot(strDest); | |||
|
|||
if (mapArgs.count("-zmqpub")) | |||
{ | |||
ZMQInitialize(mapArgs["zmqpub"]); |
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.
typo: should be ZMQInitialize(mapArgs["-zmqpub"]);
(mind the dash)
@promag: I would not add JSON support and keep ZMQ as clean and low-level as possible. Keeping it bin only can make things faster and with JSON there is always a risks of things get handled different during enc-/decoding of JSON streams depending on the library you use. |
Tested reviewed leak-checked ACK. |
CBlock blk; | ||
{ | ||
LOCK(cs_main); | ||
|
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.
nit: L128 has whitespace.
nit: diff --git a/src/zmqports.cpp b/src/zmqports.cpp
index d083292..bd1229c 100644
--- a/src/zmqports.cpp
+++ b/src/zmqports.cpp
@@ -155,6 +155,9 @@ void ZMQShutdown()
zmq_ctx_destroy(zmqContext);
zmqContext = 0;
+
+ uiInterface.NotifyBlockTip.disconnect(ZMQPublishBlock);
+ uiInterface.NotifyRelayTx.disconnect(ZMQPublishTransaction);
}
fZMQPub = false; |
@jonasschnelli Regarding the output formats, I don't think having JSON is that bad, it is just an option.
|
@promag I agree with 1 (p2p) and 3 (hash). IMO the ZMQ interface is a push/notify interface (for now). If someone like to get JSON output he could do a RPC request with received data. Adding JSON format over ZMQ level would just encourage user "to go the wrong way". |
Specifically for blocks, I'm not sure that pushing full blocks is even useful, unless we make it push all new blocks (including intermediary reorged ones). The interesting information is "there is a new block chain tip, and this is it". |
@sipa consider the following use case: a subscriber wants to know if there are transactions (in the new block chain tip) with outputs targeting a set of addresses. |
I'm not sure if publishing a block of 20MB is problematic. |
929ba9b
to
7565cf2
Compare
@jonasschnelli @jgarzik @jtimon please review the documentation change. |
@@ -0,0 +1,176 @@ | |||
// Copyright (c) 2009-2010 Satoshi Nakamoto | |||
// Copyright (c) 2009-2014 The Bitcoin Core developers |
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.
nit: remove L1
AND s/2009-2014/2015
?
Just git a build error on debian:
The source of the problem is probably an outdated libzmq. I have installed libzmq1(-dev): During configure we might ask for |
Using |
#include "main.h" | ||
#include "streams.h" | ||
#include "util.h" | ||
#include "netbase.h" |
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.
nit: i think this include can be removed. Compiles fine on OSX/Debian without this include.
@theuni can you take a look? |
53cf8e4
to
1e48d06
Compare
In general, this appears merge-ready once
We can iterate further once it's in-tree. |
Agree with @jgarzik. There are serval proposal for improvements (autodetect libzmq3, avoid locking by passing |
Continues Johnathan Corgan's work. Publishing multipart messages Bugfix: Add missing zmq header includes Bugfix: Adjust build system to link ZeroMQ code for Qt binaries
@jonasschnelli rebase@force-push solved. |
Add ZeroMQ notifications Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6103 - bitcoin/bitcoin#6684 - bitcoin/bitcoin#6686 - bitcoin/bitcoin#6736 - bitcoin/bitcoin#6739 - bitcoin/bitcoin#6743 - bitcoin/bitcoin#6768 - bitcoin/bitcoin#6779 - bitcoin/bitcoin#6810 - bitcoin/bitcoin#6927 - bitcoin/bitcoin#6980 (only upgrading zeromq) - bitcoin/bitcoin#6680 - bitcoin/bitcoin#7058 - bitcoin/bitcoin#7621 - bitcoin/bitcoin#7335 (only parts affecting `zmq_test.py`) - bitcoin/bitcoin#7853 (only parts affecting `zmq_test.py`) - bitcoin/bitcoin#7762 - bitcoin/bitcoin#7993 (only upgrading zeromq) - bitcoin/bitcoin#8238 - bitcoin/bitcoin#8701 - bitcoin/bitcoin#6685 Closes #2020.
Add ZeroMQ notifications Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6103 - bitcoin/bitcoin#6684 - bitcoin/bitcoin#6686 - bitcoin/bitcoin#6736 - bitcoin/bitcoin#6739 - bitcoin/bitcoin#6743 - bitcoin/bitcoin#6768 - bitcoin/bitcoin#6779 - bitcoin/bitcoin#6810 - bitcoin/bitcoin#6927 - bitcoin/bitcoin#6980 (only upgrading zeromq) - bitcoin/bitcoin#6680 - bitcoin/bitcoin#7058 - bitcoin/bitcoin#7621 - bitcoin/bitcoin#7335 (only parts affecting `zmq_test.py`) - bitcoin/bitcoin#7853 (only parts affecting `zmq_test.py`) - bitcoin/bitcoin#7762 - bitcoin/bitcoin#7993 (only upgrading zeromq) - bitcoin/bitcoin#8238 - bitcoin/bitcoin#8701 - bitcoin/bitcoin#6685 Closes #2020.
Continues Johnathan Corgan and Jeff Garzik's work. Supercedes #4594 and #5303.
As discussed in #6072 and #5328.