Skip to content

Conversation

instagibbs
Copy link
Member

@instagibbs instagibbs commented Jul 23, 2020

This PR creates a new ZMQ notifier that gives a "total hash history" of block (dis)connection, mempool addition/substraction, all in one pipeline. It also exposes a "mempool sequence number" to both this notifier and getrawmempool results, which allows the consumer to use the results together without confusion about ordering of results and without excessive getrawmempool polling.

See the functional test interfaces_zmq.py::test_mempool_sync which shows the proposed user flow for the client-side tracking of mempool contents and confirmations.

Inspired by #19462 (comment)
Alternative to #19462 due to noted deficiencies in current zmq notification streams.

Also fixes a legacy zmq test that didn't actually trigger a reorg because of identical blocks being generated on each side of the split(oops)

@instagibbs
Copy link
Member Author

instagibbs commented Jul 23, 2020

fixed bug(was pushing to verbose list of transactions)

looking at another racey looking failure:

    assert_equal((payment_txid_2, "A", seq_num), seq.receive_sequence())
  File "/home/travis/build/bitcoin/bitcoin/ci/scratch/build/bitcoin-arm-linux-gnueabihf/test/functional/test_framework/util.py", line 49, in assert_equal
    raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
AssertionError: not(('1ac086d8f16212a6bab2bceee95742ff09e9477928c2e09e931a57c382d7b09b', 'A', 4) == ('1ac086d8f16212a6bab2bceee95742ff09e9477928c2e09e931a57c382d7b09b', 'A', 5))

edit: Pushed fix(I hope) for that.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 23, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think #19476 makes life easier for the client in regards to fault tolerance and simplicity. With this PR, the client still has to bake its state from RPC and ZMQ.

I think you could extract CValidationInterface changes to a different PR.

# Generate 2 blocks in nodes[1]
self.nodes[1].generatetoaddress(2, ADDRESS_BCRT1_UNSPENDABLE)
# Generate 2 blocks in nodes[1] to a different address to ensure split
self.nodes[1].generatetoaddress(2, ADDRESS_BCRT1_P2WSH_OP_TRUE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

951507c

oops 😅 good catch.

@instagibbs
Copy link
Member Author

instagibbs commented Jul 23, 2020 via email

@promag
Copy link
Contributor

promag commented Jul 26, 2020

That's said they're not necessarily in competition.

I wasn't suggesting otherwise 👍

@jonasschnelli
Copy link
Contributor

Concept ACK

@instagibbs
Copy link
Member Author

I'm running some extensive testing of this PR against testnet and mainnet nodes, tracking expected mempool for a couple weeks using a modified test harness. Once I'm satisfied I'll be updating the test for this PR with the updated logic(if any) and maybe the consumer tool itself.

@instagibbs
Copy link
Member Author

added test showing conflicted tx from block announcement("R" shows up before "C")

@instagibbs
Copy link
Member Author

instagibbs commented Jul 27, 2020

Was able to replicate a seeming gap in mempool_sequence values being reported. Pushed a possibly controversial fix(touching mempool logic) showing that it fixes the test case written.

While that is a very minimal change I can understand it might rub people the wrong way.

The alternatives are:
0) Ignore the gaps(print a warning when you see a gap maybe), it doesn't seem to meaningfully interact with using the features as-is. Consumer will be tracking zmq sequence value, and any getrawmempool results will report an "expected" value.

  1. "Just" account for these gaps. When hitting an "R" mempool_sequence gap, sum up those gaps, then make sure that value + the number of found mempool transactions being removed normally equals the mempool_sequence reported in the next mempool report.
  2. Add another removal reporting hook which just announces all txhashes being removed.

(2) seems like way overkill. (0) is fine for mempool view tracking, (1) just allows the consumer to do more asserting I guess, you can take it or leave it.

Thoughts on last commit?

edit: I've decided to just keep behavior as-is to avoid touching mempool code, and update the sample usage test to reflect that check.

src/init.cpp Outdated
@@ -483,10 +483,12 @@ void SetupServerArgs(NodeContext& node)
gArgs.AddArg("-zmqpubhashtx=<address>", "Enable publish hash transaction in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
gArgs.AddArg("-zmqpubrawblock=<address>", "Enable publish raw block in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
gArgs.AddArg("-zmqpubrawtx=<address>", "Enable publish raw transaction in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
gArgs.AddArg("-zmqpubsequence=<address>", "Enable publish hash block and tx sequence in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"sequence" doesn't really express what this does. Maybe "zmqpubmempool"?

@n-thumann
Copy link
Contributor

re-ACK 877f511

…l deltas

Using the zmq notifications to avoid excessive mempool polling can be difficult
given the current notifications available. It announces all transactions
being added to mempool or included in blocks, but announces no evictions
and gives no indication if the transaction is in the mempool or a block.

Block notifications for zmq are also substandard, in that it only announces
block tips, while all block transactions are still announced.

This commit adds a unified stream which can be used to closely track mempool:

1) getrawmempool to fill out mempool knowledge
2) if txhash is announced, add or remove from set
based on add/remove flag
3) if blockhash is announced, get block txn list,
remove from those transactions local view of mempool
4) if we drop a sequence number, go to (1)

The mempool sequence number starts at the value 1, and
increments each time a transaction enters the mempool,
or is evicted from the mempool for any reason, including
block inclusion. The mempool sequence number is published
via ZMQ for any transaction-related notification.

These features allow for ZMQ/RPC consumer to track mempool
state in a more exacting way, without unnecesarily polling
getrawmempool. See interface_zmq.py::test_mempool_sync for
example usage.
@instagibbs
Copy link
Member Author

rebased again

@laanwj
Copy link
Member

laanwj commented Sep 23, 2020

Code review ACK 759d94e

I see a potential confusion between sequence numbers of the individual packets and the "mempool sequence" but this is a matter of documentation, I don't have a suggestion for better naming.

@laanwj laanwj merged commit 9e217f5 into bitcoin:master Sep 23, 2020
@instagibbs
Copy link
Member Author

I see a potential confusion between sequence numbers of the individual packets and the "mempool sequence" but this is a matter of documentation, I don't have a suggestion for better naming.

Willing to entertain any renaming if people think of something better!

@jonatack
Copy link
Member

re-ACK 759d94e

@shuckc
Copy link

shuckc commented Sep 23, 2020

Lovely! Very much look forward to using this.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 23, 2020
…-side mempool tracking

759d94e Update zmq notification documentation and sample consumer (Gregory Sanders)
68c3c7e Add functional tests for zmq sequence topic and mempool sequence logic (Gregory Sanders)
e76fc2b Add 'sequence' zmq publisher to track all block (dis)connects, mempool deltas (Gregory Sanders)
1b615e6 zmq test: Actually make reorg occur (Gregory Sanders)

Pull request description:

  This PR creates a new ZMQ notifier that gives a "total hash history" of block (dis)connection, mempool addition/substraction, all in one pipeline. It also exposes a "mempool sequence number" to both this notifier and `getrawmempool` results, which allows the consumer to use the results together without confusion about ordering of results and without excessive `getrawmempool` polling.

  See the functional test `interfaces_zmq.py::test_mempool_sync` which shows the proposed user flow for the client-side tracking of mempool contents and confirmations.

  Inspired by bitcoin#19462 (comment)
  Alternative to bitcoin#19462 due to noted deficiencies in current zmq notification streams.

  Also fixes a legacy zmq test that didn't actually trigger a reorg because of identical blocks being generated on each side of the split(oops)

ACKs for top commit:
  laanwj:
    Code review ACK 759d94e

Tree-SHA512: 9daf0d7d996190f3a68ff40340a687519323d7a6c51dcb26be457fbc013217ea7b62fbd0700b74b654433d2e370704feb61e5584399290692464fcfcb72ce3b7
domob1812 added a commit to xaya/xaya that referenced this pull request Sep 28, 2020
Merged the Xaya-specific ZMQ notifications with the upstream extension
for sequence (bitcoin/bitcoin#19572).
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 27, 2021
…sub.py file permissions

062e669 script: fix zmq_sub.py file permissions (Jon Atack)
36f8e0c doc: update PyZMQ installation instructions, ZeroMQ link (Jon Atack)

Pull request description:

  Seen while reviewing bitcoin#19572.

ACKs for top commit:
  theStack:
    ACK 062e669 🧷
  fanquake:
    ACK 062e669

Tree-SHA512: 2210d92385377d066984d0a83882c3ece9f0f41c901b7eb375af9cdb57296f50f227c68193ccf35926073c2b788d58976442791a9fce2fc0f76452804d5cee6a
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 28, 2021
…sub.py file permissions

062e669 script: fix zmq_sub.py file permissions (Jon Atack)
36f8e0c doc: update PyZMQ installation instructions, ZeroMQ link (Jon Atack)

Pull request description:

  Seen while reviewing bitcoin#19572.

ACKs for top commit:
  theStack:
    ACK 062e669 🧷
  fanquake:
    ACK 062e669

Tree-SHA512: 2210d92385377d066984d0a83882c3ece9f0f41c901b7eb375af9cdb57296f50f227c68193ccf35926073c2b788d58976442791a9fce2fc0f76452804d5cee6a
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 29, 2021
…sub.py file permissions

062e669 script: fix zmq_sub.py file permissions (Jon Atack)
36f8e0c doc: update PyZMQ installation instructions, ZeroMQ link (Jon Atack)

Pull request description:

  Seen while reviewing bitcoin#19572.

ACKs for top commit:
  theStack:
    ACK 062e669 🧷
  fanquake:
    ACK 062e669

Tree-SHA512: 2210d92385377d066984d0a83882c3ece9f0f41c901b7eb375af9cdb57296f50f227c68193ccf35926073c2b788d58976442791a9fce2fc0f76452804d5cee6a
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
…sub.py file permissions

062e669 script: fix zmq_sub.py file permissions (Jon Atack)
36f8e0c doc: update PyZMQ installation instructions, ZeroMQ link (Jon Atack)

Pull request description:

  Seen while reviewing bitcoin#19572.

ACKs for top commit:
  theStack:
    ACK 062e669 🧷
  fanquake:
    ACK 062e669

Tree-SHA512: 2210d92385377d066984d0a83882c3ece9f0f41c901b7eb375af9cdb57296f50f227c68193ccf35926073c2b788d58976442791a9fce2fc0f76452804d5cee6a
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
…sub.py file permissions

062e669 script: fix zmq_sub.py file permissions (Jon Atack)
36f8e0c doc: update PyZMQ installation instructions, ZeroMQ link (Jon Atack)

Pull request description:

  Seen while reviewing bitcoin#19572.

ACKs for top commit:
  theStack:
    ACK 062e669 🧷
  fanquake:
    ACK 062e669

Tree-SHA512: 2210d92385377d066984d0a83882c3ece9f0f41c901b7eb375af9cdb57296f50f227c68193ccf35926073c2b788d58976442791a9fce2fc0f76452804d5cee6a
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 15, 2021
…sub.py file permissions

062e669 script: fix zmq_sub.py file permissions (Jon Atack)
36f8e0c doc: update PyZMQ installation instructions, ZeroMQ link (Jon Atack)

Pull request description:

  Seen while reviewing bitcoin#19572.

ACKs for top commit:
  theStack:
    ACK 062e669 🧷
  fanquake:
    ACK 062e669

Tree-SHA512: 2210d92385377d066984d0a83882c3ece9f0f41c901b7eb375af9cdb57296f50f227c68193ccf35926073c2b788d58976442791a9fce2fc0f76452804d5cee6a
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 16, 2021
…sub.py file permissions

062e669 script: fix zmq_sub.py file permissions (Jon Atack)
36f8e0c doc: update PyZMQ installation instructions, ZeroMQ link (Jon Atack)

Pull request description:

  Seen while reviewing bitcoin#19572.

ACKs for top commit:
  theStack:
    ACK 062e669 🧷
  fanquake:
    ACK 062e669

Tree-SHA512: 2210d92385377d066984d0a83882c3ece9f0f41c901b7eb375af9cdb57296f50f227c68193ccf35926073c2b788d58976442791a9fce2fc0f76452804d5cee6a
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 14, 2021
Summary:
> This PR creates a new ZMQ notifier that gives a "total hash history" of block (dis)connection, mempool addition/substraction, all in one pipeline. It also exposes a "mempool sequence number" to both this notifier and getrawmempool results, which allows the consumer to use the results together without confusion about ordering of results and without excessive getrawmempool polling.
>
> See the functional test interfaces_zmq.py::test_mempool_sync which shows the proposed user flow for the client-side tracking of mempool contents and confirmations.
>
> Also fixes a legacy zmq test that didn't actually trigger a reorg because of identical blocks being generated on each side of the split(oops)

This is a backport of [[bitcoin/bitcoin#19572 | core#19572]] [1/4]
bitcoin/bitcoin@1b615e6

Note: I wasn't able to reproduce the issue that this commit is supposed to fix. I tried adding an extra line after generating the 2 new blocks on node 1, without being able to get an identical block: `assert disconnect_block not in connect_blocks`

Test Plan: `test/functional/test_runner.py  interface_zmq`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10303
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 14, 2021
Summary:
This is a backport of [[bitcoin/bitcoin#19572 | core#19572]] [3/4]
bitcoin/bitcoin@68c3c7e

The main change from the original PR is the removal of the RBF tests.

Depends on D10304

Test Plan: `test/functional/test_runner.py  interface_zmq`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10306
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 14, 2021
Summary:
This is a backport of [[bitcoin/bitcoin#19572 | core#19572]] [4/4]
bitcoin/bitcoin@759d94e

Depends on D10306

I had to revert the IP address change from D1120 to make the zmq_sub.py script work.

Test Plan:
```
$ src/bitcoind  -daemon -zmqpubrawtx=tcp://127.0.0.1:28332 -zmqpubrawblock=tcp://127.0.0.1:28332 -zmqpubhashtx=tcp://127.0.0.1:28332  -zmqpubhashblock=tcp://127.0.0.1:28332  -zmqpubsequence=tcp://127.0.0.1:28332
$ python ../contrib/zmq/zmq_sub.py
```

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10307
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 14, 2021
Summary:
Add a test to generate a "R" notification by:
 - sending a tx on node0 while the nodes are disconnected
 - verifying that this transaction is added to node0's mempool
 - generating a conflicting tx on node1
 - mining the conflicting tx into a block on node1
 - reconnecting the nodes
 - checking that the first tx is rejected on node0

Also add `noban` permission to all nodes to avoid the tx relay delays, because there are a lot of calls to `sync_all` and this diff adds more of them. This reduces the test run time from 45s to 14s.

This replaces the RBF tests that were in [[bitcoin/bitcoin#19572 | [[bitcoin/bitcoin#19572 | core#19572]]]] backported in D10306.

Test Plan: `test/functional/test_runner.py interface_zmq`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10311
@ghost ghost mentioned this pull request Nov 29, 2021
3 tasks
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 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.