-
Notifications
You must be signed in to change notification settings - Fork 37.8k
zmq: mempool notifications #8549
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
Conversation
Add notification signals to make it possible to subscribe to mempool changes: - NotifyEntryAdded(const CTxMemPoolEntry &)> - NotifyEntryRemoved(const CTxMemPoolEntry &, MemPoolRemovalReason)> Also add a mempool removal reason enumeration, which is passed to the removed notification based on why the transaction was removed from the mempool.
Replace factories list with calls to a function. This simplifies the code (every notifier is only created once anyway), and makes it possible to pass arguments to notifier contructors.
Add notifications when transactions enter or leave the mempool. These can be enabled with `pubmempool`: - `mempooladded`: a transaction was added to the mempool - `mempoolremoved`: a transaction was removed from the mempool This allows third-party software to keep track of what is in the mempool in real time.
Make the registration process less circuitous by making the notifiers listen to their appropriate events themselves
@@ -2752,7 +2752,7 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara | |||
list<CTransaction> removed; | |||
CValidationState stateDummy; | |||
if (tx.IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL, true)) { | |||
mempool.removeRecursive(tx, removed); | |||
mempool.removeRecursive(tx, removed, MemPoolRemovalReason::REORG); |
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.
trivial nit: indentation symmetry between mempool.removeRecursive
line and vHashUpdate.push_back
line.
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.
Emacs C++ mode FTW. Will cleanup.
Hmm, looks like zmq_test.py needs some attention. |
OOI, is the case if a re-org occurs and the transaction only existed in the pre re-org chain? |
Needs rebased. Thanks. |
Conceptual issue: |
Nice work! My suggestion:
I patched bitcoind to the same thing: https://github.com/btccom/explorer-kv/blob/master/deploy/docker/bitcoind/v0.12.1/bitcoind-explorer-v0.12.1.patch When bitcoind start, also need to push the latest block in ZMQ, so consumers could know if they need to sync to the latest block(with rpc call to get blocks), after that could consume txs logs from ZMQ. |
concept ACK |
Needs rebase |
@jmcorgan Are you planning on continuing this work? Needs a rebase, and nits addressed. |
Close now? |
Closing (for now). Might pick this up later. |
This would actually be very useful, now with all the full blocks and transactions falling out of mempools more often. Any plans for continuing with this? :) thx edit: oh, there is also this PR, already merged. Not sure what it does 100% |
My own branch was only an attempt at keeping this current with progress on master; the real work was done by @laanwj. I'll defer to him whether or not he's willing to continue from here. |
@jmcorgan @Runn1ng It's on my long list. Sorry for occasionally starting projects then seemingly abandoning them. It's just that it's not always clear how much interest there is in things, and keeping things rebased while it's unclear how much attention something will get sometimes feels like a waste of time. But it's clear that there is user interest in this and some of the changes here have been part of #9371, just not the zmq part. I'll get to that... But if someone else feels like picking this up to accelerate things (hopefully) go ahead. |
Knowing when a transaction is added to the mempool might be useful in the test framework as well, e.g. so sync_mempools can be implemented asynchronously instead of through polling (cc @jnewbery). |
picked up (sort of) in #23624 |
This is a current rebased version of #7753 by @laanwj. Please see that PR for original discussion and existing ACKs.
Add notifications when transactions enter or leave the mempool.
These can be enabled with zmqpubmempool:
mempooladded: a transaction was added to the mempool
mempoolremoved: a transaction was removed from the mempool
[...]
It also makes it possible to keep statistics on why transactions disappear from the mempool.