Skip to content

Add apply_unconfirmed_txs_events and apply_evicted_txs_events#388

Merged
ValuedMammal merged 3 commits intobitcoindevkit:masterfrom
notmandatory:feat/mempool_events
Mar 6, 2026
Merged

Add apply_unconfirmed_txs_events and apply_evicted_txs_events#388
ValuedMammal merged 3 commits intobitcoindevkit:masterfrom
notmandatory:feat/mempool_events

Conversation

@notmandatory
Copy link
Member

@notmandatory notmandatory commented Feb 26, 2026

Description

fixes #374

Notes to the reviewers

To reduce duplicate code I also refactored all the _events functions to use new wallet_txs_to_map helper.

Changelog notice

  • Add Wallet::apply_unconfirmed_txs_events
  • Add Wallet::apply_evicted_txs_events
  • Add Wallet::events_helper function for advanced users

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@notmandatory notmandatory self-assigned this Feb 26, 2026
@notmandatory notmandatory added the new feature New feature or request label Feb 26, 2026
@notmandatory notmandatory added this to the Wallet 3.0.0 milestone Feb 26, 2026
@notmandatory
Copy link
Member Author

Per discussion in #374 I'm happy to deprecate these _events functions and replace them with some sort of CanonicalView::diff once that feature is available in bdk_chain. But for now I expect we'll be shipping 3.0 with the current bdk_chain 0.23.

If we agree to go this direction for 3.0 then I'll finish adding tests and cherry-pick these commits back to the release/2.x branch.

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 78.57143% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.77%. Comparing base (c422104) to head (45f4e22).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
src/wallet/mod.rs 78.57% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #388      +/-   ##
==========================================
+ Coverage   79.17%   79.77%   +0.60%     
==========================================
  Files          24       24              
  Lines        5311     5266      -45     
  Branches      242      241       -1     
==========================================
- Hits         4205     4201       -4     
+ Misses       1029      988      -41     
  Partials       77       77              
Flag Coverage Δ
rust 79.77% <78.57%> (+0.60%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@notmandatory notmandatory force-pushed the feat/mempool_events branch 2 times, most recently from 4883f54 to c845417 Compare February 26, 2026 18:20
@notmandatory
Copy link
Member Author

Added a couple simple tests. Ready for review.

@notmandatory notmandatory marked this pull request as ready for review February 26, 2026 18:33
@notmandatory notmandatory moved this to Needs Review in BDK Wallet Feb 26, 2026
@notmandatory
Copy link
Member Author

notmandatory commented Feb 27, 2026

Updated with a couple changes suggested by @ValuedMammal (and also by Claude, will get it to review patches before pushing next time 🤖 ).

  • moved new helper function to impl Wallet since it's only used there
  • removed unneeded Result return from new mempool _events functions

@reez
Copy link

reez commented Mar 3, 2026

LGTM

From bdk-ffi perspective,apply_unconfirmed_txs_events & apply_evicted_txs_events would be nice additions, so i made a note on our 3.0 tracking issue about this PR. I also will keep tabs on wallet_events & CanonicalView::diff timeline to see how we should go about exposing wallet_events if it looks like it will be deprecated quickly if CanonicalView::diff becomes available soon after.

@ValuedMammal
Copy link
Collaborator

ValuedMammal commented Mar 4, 2026

In c4084ab

Looks like you're missing a newline in the commit message

Edit: Fixed in ab82463

…events

- refactor _events functions to use new map_transactions helper
@ValuedMammal ValuedMammal force-pushed the feat/mempool_events branch from 08ffbae to ab82463 Compare March 4, 2026 17:22
This can be used to generate `WalletEvent`s after executing a
function defined by the caller.

Refactored the `*_events` functions to use the events helper
internally.

test: Test that no events are returned by applying an empty
Update and applying the same Update twice.
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.

utACK 12c453f

It looks way better with the events_helper fn 🚀. I left a single nit (non-blocker), and a fix (blocker) suggestion.

@notmandatory notmandatory force-pushed the feat/mempool_events branch from a61a41d to 45f4e22 Compare March 5, 2026 02:51
@notmandatory
Copy link
Member Author

Thanks @ValuedMammal for the cool helper function and extra tests. I've fixed the doc issues @oleonardolima found.

Copy link
Member Author

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

ACK 45f4e22

Copy link
Contributor

@nymius nymius left a comment

Choose a reason for hiding this comment

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

ACK 45f4e22

I've executed tests successfully.
Coverage output is confusing, but I think it's pointing to pre-existent uncovered code.

I summarized the context of these changes here, mainly as a helper for me, but hope it can help others too. Let me know if you spot any errors:

bdk_wallet 3.0.0 (Depends on bdk_chain 0.23)
├───Issue #6: Missing user facing events from wallet updates
|	└──── PR #319
|			├─ PR #310
|			|   ├─ WalletEvents { ChainTipChanged, TxConfirmed, TxUnconfirmed, TxReplaced, TxDropped}
|			|   ├─ wallet_events ("wallet diff")
|			|   └─ Wallet::apply_update_events: get events after applying updates
|			|
|			├─ PR #336 (release 2.2.0): block event variants
|			|   ├─ Wallet::apply_block_events
|			|   └─ Wallet::apply_block_connected_to_events
|			|   
|			└─ ADR 3: Return user-facing events when applying updates after syncing
|			
└───Issue #374: Missing user facing events from mempool changes
	└─ PR #388
	  ├─ Wallet::apply_unconfirmed_txs_events
	  ├─ Wallet::apply_evicted_txs_events
	  └─ Wallet::events_helper

I agree with the conclusions derived from #319 (comment). I think it is a more elegant solution.
It's going to deprecate 0003_events.md and merit a new ADR amending it and referencing a canonical view ADR.

This is a high level summary of what I extracted from the ongoing discussions about next steps:

bdk_wallet x.x.x (Depends on bdk_chain 0.24)
├─── Remove WalletEvents { ... }
├─── Add TransactionEvents { ChainTipChanged, TxConfirmed, TxUnconfirmed, TxReplaced, TxDropped}
├─── Add fn diff(self: &CanonicalView, other: &CanonicalView) -> TransactionEvents
├─── Add fn canonical_view(self: &Wallet) -> CanonicalView to produce wallet snapshots and compute events from CanonicalView::diff
├─── Deprecate ADR 003?
├─── Add ADR 004? Referencing changes due to new CanonicalView. Maybe add a bdk_chain ADR too?
└─── Add notice for *_events method deprecation in bdk_wallet x+1.x.x?

@110CodingP
Copy link
Contributor

110CodingP commented Mar 5, 2026

ACK 45f4e22

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.

ACK 45f4e22

Copy link
Collaborator

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

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

ACK 45f4e22; ran the tests locally

@ValuedMammal ValuedMammal merged commit e2b4ad9 into bitcoindevkit:master Mar 6, 2026
16 of 17 checks passed
@github-project-automation github-project-automation bot moved this from Needs Review to Done in BDK Wallet Mar 6, 2026
@ValuedMammal ValuedMammal mentioned this pull request Mar 6, 2026
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New feature or request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add APIs to return WalletEvents when applying mempool transactions (or make wallet_events helper pub)

7 participants