Skip to content

Detect new mempool txs #1988

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

Merged
merged 5 commits into from
Jul 26, 2025

Conversation

evanlinjin
Copy link
Member

@evanlinjin evanlinjin commented Jul 4, 2025

Description

There is a bug in bdk_bitcoind_rpc where some new mempool transactions will not be emitted at all.

This problem exists because the avoid-re-emission logic depends on rounded-to-nearest-second timestamps.

The fix is to just emit all mempool transactions but wrap them in Arcs so that emission becomes cheap.

Background: I tried using bdk_bitcoind_rpc as the chain-source to write an example to showcase the IntentTracker. However, bdk_bitcoind_rpc failed to emit some mempool transactions.

Notes to the reviewers

The test added in c22c68f fails without these fixes.

Some tests are removed as they are no longer relevant.

Changelog notice

Fixed:
- Some mempool transactions not being emitted at all. The fix is to replace the avoid-re-emission-logic with one which emits all mempool transactions.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo +nightly fmt and cargo clippy before committing

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
    * [ ] I'm linking the issue being fixed by this PR

@evanlinjin evanlinjin force-pushed the fix/bitcoind_rpc_mempool branch from c494aef to 7b010af Compare July 4, 2025 10:32
@evanlinjin evanlinjin moved this to In Progress in BDK Chain Jul 4, 2025
Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

cACK
I think the new simplified approach looks better.

I'm still in the process of a deeper review. However, when I'm trying to run the detect_new_mempool_txs, on both commits, it takes more than 60 seconds and becomes stale, still unsure if it's a local issue.

@evanlinjin
Copy link
Member Author

@oleonardolima are you on Linux or OSX?

@LagginTimes
Copy link
Contributor

cACK I think the new simplified approach looks better.

I'm still in the process of a deeper review. However, when I'm trying to run the detect_new_mempool_txs, on both commits, it takes more than 60 seconds and becomes stale, still unsure if it's a local issue.

FWIW, the detect_new_mempool_txs test runs successfully on my machine (Linux).

Copy link
Contributor

@LagginTimes LagginTimes left a comment

Choose a reason for hiding this comment

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

Re-ACK 51ee99a

@oleonardolima

This comment was marked as resolved.

Instead of having an avoid-reemission logic based on timestamps returned
by bitcoind RPC, we wrap all transactions in `Arc` and always emit the
entire mempool. This makes emission cheap while avoiding the flawed
avoid-reemission logic.
This is the more performant method. The downside is that mempool txids
are not returned to the seen-in-mempool timestamps so the caller either
needs to provide this, or we need to rely on std to get the current
timestamp.

* `Emitter::mempool` method now requires the `std` feature. A non-std
  version of this is added: `Emitter::mempool_at` which takes in a
  `sync_time` parameter.

Additional changes:

* `NO_EXPECTED_MEMPOOL_TXIDS` is renamed to `NO_EXPECTED_MEMPOOL_TXS`.
* Updated documentation.
* Fix imports so that `bdk_bitcoind_rpc` compiles without `std`.
@evanlinjin evanlinjin force-pushed the fix/bitcoind_rpc_mempool branch from 16199c2 to 7de3b71 Compare July 10, 2025 04:59
@evanlinjin evanlinjin marked this pull request as ready for review July 10, 2025 05:00
@evanlinjin evanlinjin moved this from In Progress to Needs Review in BDK Chain Jul 10, 2025
@evanlinjin evanlinjin force-pushed the fix/bitcoind_rpc_mempool branch from b09a2d9 to 73ab1eb Compare July 11, 2025 08:47
@evanlinjin evanlinjin added this to the Wallet 2.1.0 milestone Jul 18, 2025
Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

tACK 73ab1eb

It looks good. I've tested in regtest with the bitcoind_rpc example, and it worked just fine.

@nymius
Copy link
Contributor

nymius commented Jul 21, 2025

cACK 51ee99a

@evanlinjin evanlinjin merged commit a48c97a into bitcoindevkit:master Jul 26, 2025
19 checks passed
@github-project-automation github-project-automation bot moved this from Needs Review to Done in BDK Chain Jul 26, 2025
@oleonardolima oleonardolima mentioned this pull request Jul 31, 2025
16 tasks
kwsantiago pushed a commit to kwsantiago/bdk that referenced this pull request Aug 5, 2025
51ee99a docs(bitcoind_rpc): fixed typo in docs (Wei Chen)
73ab1eb chore(bitcoind_rpc): Make clippy happy (志宇)
7e894f4 feat(bitcoind_rpc)!: Use `getrawmempool` without verbose (志宇)
05464ec fix(bitcoind_rpc)!: Simplify emitter (志宇)
67dfb0b test(bitcoind_rpc): Detect new mempool txs (志宇)

Pull request description:

  ### Description

  There is a bug in `bdk_bitcoind_rpc` where some new mempool transactions will not be emitted at all.

  This problem exists because the avoid-re-emission logic depends on rounded-to-nearest-second timestamps.

  The fix is to just emit all mempool transactions but wrap them in `Arc`s so that emission becomes cheap.

  **Background:** I tried using `bdk_bitcoind_rpc` as the chain-source to write an example to showcase the [`IntentTracker`](bitcoindevkit/bdk_wallet#257). However, `bdk_bitcoind_rpc` failed to emit some mempool transactions.

  ### Notes to the reviewers

  The test added in c22c68f fails without these fixes.

  Some tests are removed as they are no longer relevant.

  ### Changelog notice

  ```md
  Fixed:
  - Some mempool transactions not being emitted at all. The fix is to replace the avoid-re-emission-logic with one which emits all mempool transactions.
  ```

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo +nightly fmt` and `cargo clippy` before committing

  #### Bugfixes:

  * [x] This pull request breaks the existing API
  * [x] I've added tests to reproduce the issue which are now passing
  ~* [ ] I'm linking the issue being fixed by this PR~

ACKs for top commit:
  nymius:
    cACK 51ee99a
  LagginTimes:
    Re-ACK 51ee99a

Tree-SHA512: 04e180e1d28c3f4c581a61ccac95e8e7e6927123d272ed07eae0ae51bf70799df44298b47ba0e49a309fd76366875e8d18d73478252931713137844857b8ed5a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants