Skip to content

Conversation

@notmandatory
Copy link
Member

@notmandatory notmandatory commented Sep 26, 2025

Description

Cherry-pick of commits from #310 and #336.

Refactored Wallet apply updates or blocks to return events and removed v2.x *_events functions.

Notes to the reviewers

I decided to remove the *_events functions added in bdk_wallet-2.2 and 2.3 releases and return events from the original apply_* functions since 3.0 is a breaking milestone and I want to remove the redundant functions.

Changelog notice

BREAKING CHANGES

  • Refactored Wallet apply updates or blocks to return Vec<WalletEvent>
    - Wallet::apply_update
    - Wallet::apply_block
    - Wallet::apply_block_connected_to

  • Removed redundant functions:
    - Wallet::apply_update_events
    - Wallet::apply_block_events
    - Wallet::apply_block_connected_to_events

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • This pull request breaks the existing API

@notmandatory notmandatory self-assigned this Sep 26, 2025
@notmandatory notmandatory added this to the Wallet 3.0.0 milestone Sep 26, 2025
@notmandatory notmandatory moved this to In Progress in BDK Wallet Sep 26, 2025
@notmandatory notmandatory moved this from In Progress to Todo in BDK Wallet Sep 26, 2025
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.

Hey @notmandatory thanks for your work on this! I left some comments related to code quality. As always, nits are non-blocking.

Comment on lines +94 to +102
if chain_tip1 != chain_tip2 {
events.push(WalletEvent::ChainTipChanged {
old_tip: chain_tip1,
new_tip: chain_tip2,
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be helpful to know which blocks were connected and/or disconnected.

Copy link
Member Author

@notmandatory notmandatory Oct 1, 2025

Choose a reason for hiding this comment

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

Do you mean a list of connected/disconnected block ids? I didn't add any other info here because @tnull didn't need it for LDK's use case. Do you have some use or user in mind for this extra info?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I mean the block IDs. It's just a more complete way of describing how the chain tip changed.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ValuedMammal are you thinking of something like adding connected and disconnected fields to this variant:

    /// The latest chain tip known to the wallet changed.
    ChainTipChanged {
        /// Previous chain tip.
        old_tip: BlockId,
        /// New chain tip.
        new_tip: BlockId,
        /// Newly connected blocks.
        connected: Vec<BlockId>,
        /// Newly disconnected blocks.
        disconnected: Vec<BlockId>,
    },

I'm still not clear on how this info would be used by a wallet user since it's more of an internal detail.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've seen a similar thing used in LDK, for example Cache and Listen, but don't know if it's also applicable in this context.

@coveralls
Copy link

coveralls commented Oct 5, 2025

Pull Request Test Coverage Report for Build 18893642494

Details

  • 158 of 161 (98.14%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 85.16%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/wallet/event.rs 79 82 96.34%
Totals Coverage Status
Change from base Build 18891447990: 0.2%
Covered Lines: 7110
Relevant Lines: 8349

💛 - Coveralls

@ValuedMammal ValuedMammal moved this from Todo to In Progress in BDK Wallet Oct 7, 2025
@notmandatory notmandatory force-pushed the feat/changeset_events_300 branch 2 times, most recently from 21eaa1f to 488b373 Compare October 29, 2025 00:11
@notmandatory
Copy link
Member Author

notmandatory commented Oct 29, 2025

Addressed initial comments from @ValuedMammal and rebased on master branch.

Next steps:

  • remove Wallet::apply_update_events and change Wallet::apply_update to return events instead
  • investigate returning events from Wallet::apply_block
  • add examples for getting affected UTXOs/addresses from tx related WalletEvents

@notmandatory
Copy link
Member Author

I will cherry-pick and incorporate commits from #336 for apply_block_events and apply_block_connected_to_events when it's merged.

@notmandatory notmandatory force-pushed the feat/changeset_events_300 branch 2 times, most recently from 8d580ed to 6c5c755 Compare November 13, 2025 16:42
@notmandatory
Copy link
Member Author

notmandatory commented Nov 13, 2025

Finished cherry-picking from #336 and rebased on master branch.

@codecov
Copy link

codecov bot commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.78%. Comparing base (d825f8c) to head (45b3cd0).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #319      +/-   ##
==========================================
+ Coverage   85.24%   85.78%   +0.53%     
==========================================
  Files          23       24       +1     
  Lines        8229     8348     +119     
==========================================
+ Hits         7015     7161     +146     
+ Misses       1214     1187      -27     
Flag Coverage Δ
rust 85.78% <100.00%> (+0.53%) ⬆️

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 changed the title Return wallet events when applying updates (3.0 milestone) Return wallet events when applying updates and blocks (3.0 milestone) Nov 13, 2025
notmandatory and others added 8 commits December 5, 2025 14:23
# Conflicts:
#	src/wallet/event.rs
WalletEvent is a enum of user facing events that are
generated when a sync update is applied to a wallet using the
Wallet::apply_update_events function.
per suggestions from ValuedMammal:
1. re-export WalletEvent type
2. add comments to wallet_events function
3. rename ambiguous variable names in wallet_events from cp to pos
4. remove signing from wallet_event tests
5. change wallet_events function assert_eq to debug_asset_eq
6. update ADR 0003 decision outcome and add option 4 re: creating events only from Update
Previously, we added a new `Wallet::apply_update_events` method that
returned `WalletEvent`s. Unfortunately, no corresponding APIs were added
for the `apply_block` counterparts. Here we fix this omission.
Co-authored-by: Steve Myers <github@notmandatory.org>
Also did minor cleanup of apply_update_events tests.
@notmandatory notmandatory force-pushed the feat/changeset_events_300 branch from 6c5c755 to e0bef3b Compare December 5, 2025 20:25
BREAKING CHANGE:

1. changed functions to return WalletEvents:
   - Wallet::apply_update
   - Wallet::apply_block
   - Wallet::apply_block_connected_to

2. removed functions:
   - Wallet::apply_update_events
   - Wallet::apply_block_events
   - Wallet::apply_block_connected_to_events
@notmandatory notmandatory force-pushed the feat/changeset_events_300 branch from a868aa8 to 66cedb4 Compare December 6, 2025 00:48
@notmandatory
Copy link
Member Author

Refactored to return events from original apply_update, apply_block* functions, removed *_events functions, see 66cedb4.

@notmandatory
Copy link
Member Author

Added one more commit with some docs improvements and refactored out helper method based on suggestions from Claude LLM 🤖.

- Enhanced WalletEvent documentation with clearer explanations
- Expanded apply_update() docs with examples and persistence warnings
- Extracted collect_wallet_txs() to reduce code duplication
- Fixed minor typos and improved code clarity

🤖 LLM-assisted changes
@notmandatory notmandatory force-pushed the feat/changeset_events_300 branch from 5f276a6 to 45b3cd0 Compare December 9, 2025 02:59
@notmandatory
Copy link
Member Author

I haven't added an example for getting affected UTXOs/addresses from a Transaction related WalletEvents. This is a bit out of scope for this PR and should get it's own PR, either to add an example or add a helper function to Wallet to do it.

@notmandatory
Copy link
Member Author

I haven't added an example for getting affected UTXOs/addresses from a Transaction related WalletEvents. This is a bit out of scope for this PR and should get it's own PR, either to add an example or add a helper function to Wallet to do it.

My thinking is to provide a new helper method Wallet::send_and_received_txouts to accomplish this. See: bitcoindevkit/bdk#2081

@ValuedMammal
Copy link
Collaborator

In 95e681a: f Duplicate event logic rather than business logic

If this is a fixup commit I guess it can be squashed into the previous one.

@ValuedMammal
Copy link
Collaborator

This is a bit out of scope for this PR and should get it's own PR, either to add an example or add a helper function to Wallet to do it.

On second thought isn't this precisely what the user is asking for in issue #6, suggesting we should have something like WalletEvent::UtxoSent, and WalletEvent::UtxoReceived?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants