Skip to content

Conversation

jmcorgan
Copy link
Contributor

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.

laanwj added 5 commits August 18, 2016 18:22
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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@jmcorgan
Copy link
Contributor Author

Hmm, looks like zmq_test.py needs some attention.

@dcousens
Copy link
Contributor

dcousens commented Aug 24, 2016

a transaction was added to the mempool

OOI, is the case if a re-org occurs and the transaction only existed in the pre re-org chain?

@jonasschnelli
Copy link
Contributor

Needs rebased. Thanks.

@jonasschnelli
Copy link
Contributor

Conceptual issue:
Shouldn't there be a special ZMQ message when bitcoind starts up?
Because of the nature of the "self-healing" ZMQ connections, listeners should probabyl be informed if bitcoind restarts (which currently result in sweeping the mempool).
Maybe it could be a specific "clearmempool" message during startup.

@bitkevin
Copy link
Contributor

bitkevin commented Oct 26, 2016

Nice work!

My suggestion:

  1. when start or restart bitcoind there should be a special event to tell consumers which listen to the ZMQ. (same as @jonasschnelli)
  2. Add rawhex in the message. The consumers need to decode hex rawtx after get the ZMQ message, otherwise they need to do another RPC call 'getrawtransaction'.
  3. When remove txs, they should be in order: remove children first and then the parents. ZMQ messages should also in the particular order. (Maybe the PR has already guarantee of it, I am not sure)

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.

@laanwj laanwj mentioned this pull request Dec 19, 2016
@dcousens
Copy link
Contributor

concept ACK

@jtimon
Copy link
Contributor

jtimon commented Dec 20, 2016

Needs rebase

@fanquake
Copy link
Member

@jmcorgan Are you planning on continuing this work? Needs a rebase, and nits addressed.

@dcousens
Copy link
Contributor

Close now?

@laanwj
Copy link
Member

laanwj commented Jan 24, 2017

Closing (for now). Might pick this up later.

@laanwj laanwj closed this Jan 24, 2017
@karelbilek
Copy link
Contributor

karelbilek commented Mar 17, 2017

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%

#9371

@jmcorgan
Copy link
Contributor Author

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.

@laanwj
Copy link
Member

laanwj commented Mar 17, 2017

@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.

@Sjors
Copy link
Member

Sjors commented Nov 29, 2017

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).

@maflcko
Copy link
Member

maflcko commented Nov 29, 2021

picked up (sort of) in #23624

@bitcoin bitcoin locked and limited conversation to collaborators Nov 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.