Skip to content

Conversation

@notmandatory
Copy link
Member

@notmandatory notmandatory commented Sep 13, 2025

Description

Adds WalletEvent enum of user facing events that are generated when a sync update is applied to a wallet using the
new Wallet::apply_update_events function.

fixes #6

Notes to the reviewers

I also modified wallet test_utils to add a new_wallet_and_funding_update function that returns a new wallet with an update that funds it. I used this new function in the original new_funded_wallet so there's no duplication.

Changelog notice

Checklists

All Submissions:

New Features:

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

@notmandatory notmandatory changed the title Return wallet events when committing new change sets Return wallet events when applying updates Sep 13, 2025
@notmandatory notmandatory self-assigned this Sep 13, 2025
@notmandatory notmandatory added the new feature New feature or request label Sep 13, 2025
@notmandatory notmandatory moved this to In Progress in BDK Wallet Sep 13, 2025
@notmandatory notmandatory added this to the Wallet 2.2.0 milestone Sep 13, 2025
@coveralls
Copy link

coveralls commented Sep 13, 2025

Pull Request Test Coverage Report for Build 17985287671

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.096%

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

💛 - Coveralls

@notmandatory
Copy link
Member Author

notmandatory commented Sep 17, 2025

After I get a 👍 from @tnull on the WalletEvent enum variants I'll finish up the PR and move it out of draft. I went with a more granular number of variants than we discussed so that this feature can be used more cleanly in on-chain wallet apps.

I'd also like to get feedback from any other wallet devs and the FFI team on how this could help with building more responsive wallet apps.

A few TODOs I have left are:

  • add simple examples for using the events
  • create an ADR for this feature

I'm not planning to add an events version of Wallet::apply_block for 2.2 since it's not required by current users and expands the scope of this PR too much.

After this PR is done I'll create a breaking PRs for the 3.0 milestone that deprecates the new function and modifies the function signature of Wallet::apply_update and Wallet::apply_block instead.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Generally looks good! I left some comments. Mostly I still think that some of these variants are too verbose and/or could be combined, potentially by tracking some optional fields. But no strong opinion/no blocker from my side.

/// A confirmed transaction is now confirmed in a new block.
///
/// This can happen after a chain reorg.
TxConfirmedNewBlock {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe TxConfirmationStatusChanged or similar?

Copy link
Member Author

@notmandatory notmandatory Sep 17, 2025

Choose a reason for hiding this comment

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

I combined with TxConfirmed and added old_block_time to indicate the Tx changed blocks instead of using a new event.

rustaceanrob added a commit to rustaceanrob/kyoto that referenced this pull request Sep 17, 2025
I looked/experimented with BDK, particularly the `bdk_chain`, and I
think [this
method](https://docs.rs/bdk_chain/latest/bdk_chain/struct.CheckPoint.html#method.insert)
is sufficient to remove the store entirely instead of deprecating it.
Since every block header is now emitted, the `bdk_kyoto` integration can
make use of this to avoid starting on an orphan block. Reorganizations
don't need to be explicitly emitted. Rather, the node can just emit
whatever chain it is on and `CheckPoint::insert` will reconsile the
changes.

It looks like there will also be nice [user facing
events](bitcoindevkit/bdk_wallet#310), so
explicitly informing about a re-org might even be returned in the wallet
update.

This Kyoto now acts as a decision-maker for the the chain of most work,
but there is now a single source-of-truth for the history of headers.
rustaceanrob added a commit to rustaceanrob/kyoto that referenced this pull request Sep 17, 2025
I looked/experimented with BDK, particularly the `bdk_chain`, and I
think [this
method](https://docs.rs/bdk_chain/latest/bdk_chain/struct.CheckPoint.html#method.insert)
is sufficient to remove the store entirely instead of deprecating it.
Since every block header is now emitted, the `bdk_kyoto` integration can
make use of this to avoid starting on an orphan block. Reorganizations
don't need to be explicitly emitted. Rather, the node can just emit
whatever chain it is on and `CheckPoint::insert` will reconsile the
changes.

It looks like there will also be nice [user facing
events](bitcoindevkit/bdk_wallet#310), so
explicitly informing about a re-org might even be returned in the wallet
update.

This Kyoto now acts as a decision-maker for the the chain of most work,
but there is now a single source-of-truth for the history of headers.
@notmandatory
Copy link
Member Author

@tnull thanks for the suggestions, I've updated the events to combine NewConfirmed and TxConfirmedNewBlock into TxConfirmed. And NewUnconfirmed into TxUnconfirmed. In both cases using a old_block_time: Option<ConfirmationBlockTime> field to indicate if the Tx was previously confirmed or not. Does this make sense?

@notmandatory
Copy link
Member Author

Thanks for the feedback @oleonardolima, fixed.

@notmandatory notmandatory force-pushed the feat/changeset_events branch 2 times, most recently from 72e13bc to 8112805 Compare September 22, 2025 00:32
@notmandatory notmandatory marked this pull request as ready for review September 22, 2025 00:41
@notmandatory
Copy link
Member Author

I added an example for the Wallet::apply_update_events and added an ADR. Ready to review.

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 0c5f4a4

Copy link
Member

@thunderbiscuit thunderbiscuit left a comment

Choose a reason for hiding this comment

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

Tested ACK 0c5f4a4.

I think I'll need to use it and see it in production before I get the feel for whether this is all I want/need and in the format I want it, so it's great that you can release this in the 2.2! We should be able to provide polish to the feature if ever it's needed for the 3.0 release.

Thanks for writing the ADR. Very helpful, now and in the future.

/// Transaction id.
txid: Txid,
/// Transaction.
tx: Arc<Transaction>,
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we need the whole transaction here. Feels like the txid is enough information for the "messaging" purpose of this WalletEvent type, but maybe you had something in mind for it?

Copy link
Member Author

@notmandatory notmandatory Sep 24, 2025

Choose a reason for hiding this comment

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

This is just a pointer to a Transaction that already exists in the Wallet's local chain so doesn't cost much to include it and could be useful for a caller who wants to look through it. But I agree it's not strictly needed since the user has the Txid and could call Wallet::get_tx() to get the full WalletTx which includes the Arc<Transaction> .

I suspect even for the bdk-ffi bindings this field would still be an Arc<Transaction> so shouldn't cost much there to included it either. But I haven't tried to implement the bindings for this yet.

@tnull do you think your project will use this Arc to the full Transaction ?

/// Transaction id.
txid: Txid,
/// Transaction.
tx: Arc<Transaction>,
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. Wondering about the reason for the full tx to be returned here.

@notmandatory notmandatory force-pushed the feat/changeset_events branch 2 times, most recently from 5dfb09e to 0a176ce Compare September 24, 2025 02:23
@notmandatory notmandatory moved this from In Progress to Needs Review in BDK Wallet Sep 24, 2025
@notmandatory
Copy link
Member Author

notmandatory commented Sep 24, 2025

I just realized I built this on the master branch so I'll need a followup PR to back port it to the release/2.2 branch. Will do that after this one is merged. EDIT: scratch that, I'm going to rebase this one on release/2.2 and make a new one for master so we can talk about changes on that one for 3.0. All commits are the same but cherry-picked onto the release/2.2 branch.

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.
@notmandatory notmandatory changed the base branch from master to release/2.2 September 24, 2025 17:52
Copy link
Member

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

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 c6fb9b3

@notmandatory notmandatory merged commit d77fd95 into bitcoindevkit:release/2.2 Sep 26, 2025
20 checks passed
@github-project-automation github-project-automation bot moved this from Needs Review to Done in BDK Wallet Sep 26, 2025
open-archer702 added a commit to open-archer702/kyoto that referenced this pull request Sep 29, 2025
I looked/experimented with BDK, particularly the `bdk_chain`, and I
think [this
method](https://docs.rs/bdk_chain/latest/bdk_chain/struct.CheckPoint.html#method.insert)
is sufficient to remove the store entirely instead of deprecating it.
Since every block header is now emitted, the `bdk_kyoto` integration can
make use of this to avoid starting on an orphan block. Reorganizations
don't need to be explicitly emitted. Rather, the node can just emit
whatever chain it is on and `CheckPoint::insert` will reconsile the
changes.

It looks like there will also be nice [user facing
events](bitcoindevkit/bdk_wallet#310), so
explicitly informing about a re-org might even be returned in the wallet
update.

This Kyoto now acts as a decision-maker for the the chain of most work,
but there is now a single source-of-truth for the history of headers.
@ovitrif ovitrif mentioned this pull request Sep 30, 2025
14 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 user-facing events for applying updates after syncing

5 participants