Skip to content

Multiple wallet syncing#152

Merged
rustaceanrob merged 5 commits intobitcoindevkit:masterfrom
rustaceanrob:26-3-6-multiple-wallets
Mar 13, 2026
Merged

Multiple wallet syncing#152
rustaceanrob merged 5 commits intobitcoindevkit:masterfrom
rustaceanrob:26-3-6-multiple-wallets

Conversation

@rustaceanrob
Copy link
Copy Markdown
Collaborator

@rustaceanrob rustaceanrob commented Mar 6, 2026

Closes #150 and #147

When there was a first attempt at syncing two wallets, the chain information reported from the node was insufficient; however, in the latest releases each wallet should have sufficient information to reconcile changes to the local chain. This PR uses the same typestate trick to have two APIs with shared syncing logic. Either the user will use the light client with a single wallet, in which case they can all UpdateSubscriber::update to receive the Update for that wallet, or they need to sync multiple wallets. In the multiple wallet case, each update is indexed by the DescriptorId for the public, external descriptor of the wallet. The UpdateSubscriber implements an updates method that returns an iterator over each wallet update. Each commit has a detailed comment.

The idea of #147 and similar discussion is to allow more granular access to the syncing logic, but I would like to move opposite of this direction. This API is as high-level as possible, but I believe it reflects the end use case we are going for, which is one user with potentially 3-5 descriptors that they want to sync simultaneously.

cc @thunderbiscuit

@rustaceanrob rustaceanrob changed the title Multuple wallet syncing Multiple wallet syncing Mar 6, 2026
@rustaceanrob rustaceanrob force-pushed the 26-3-6-multiple-wallets branch 4 times, most recently from 2869837 to 947d0fa Compare March 7, 2026 08:56
@rustaceanrob rustaceanrob marked this pull request as ready for review March 7, 2026 09:02
@rustaceanrob rustaceanrob force-pushed the 26-3-6-multiple-wallets branch from 947d0fa to 1e5a9cf Compare March 9, 2026 12:36
This commit implements the scaffolding such that the `UpdateSubscriber`
may handle either a single wallet or multiple wallets. The methods
available on the subscriber should change depending on the
configuration, but the syncing logic should remain the same. The
restriction is implemented here.
If there are multiple wallets configured, this commit updates each of
them via the `UpdateBuilder`. Each update is indexed on the
`DescriptorId` of the public descriptor for the external keychain. These
should be unique per wallet if I understand correctly.
Implements a way to create the `UpdateSubscriber<Multiple>`. Here we
need to take the lowest configured checkpoint for the scan. While this
is a _rescan_ for most wallets in the list, we will need to scan these
filters anyway for new wallets, and the `Wallet` should handle redundant
updates anyway.
Demonstrates the new API for users
This test takes the first wallet to a stale block, then shuts down the
node. A new wallet is introduced, and we assert that the first wallet
still detects and applies the reorganization.
@rustaceanrob rustaceanrob force-pushed the 26-3-6-multiple-wallets branch from 1e5a9cf to e246909 Compare March 12, 2026 16:11
@rustaceanrob
Copy link
Copy Markdown
Collaborator Author

Got some live feedback and I think this is good to go. The DescriptorId use to tag the wallets will probably be subject to change, but the core concepts are introduced here.

@rustaceanrob rustaceanrob merged commit 1c532fc into bitcoindevkit:master Mar 13, 2026
5 checks passed
@rustaceanrob rustaceanrob deleted the 26-3-6-multiple-wallets branch March 13, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reconsider multiple wallet approaches

1 participant