feat: unify full_scan and sync into a single scan API#2181
Closed
noahjoeris wants to merge 5 commits intobitcoindevkit:masterfrom
Closed
feat: unify full_scan and sync into a single scan API#2181noahjoeris wants to merge 5 commits intobitcoindevkit:masterfrom
noahjoeris wants to merge 5 commits intobitcoindevkit:masterfrom
Conversation
evanlinjin
requested changes
Apr 17, 2026
Member
There was a problem hiding this comment.
Concept NACK
First off, thanks for working on this. However, I think full_scan and sync should remain separate APIs. They have different inputs and use cases, and merging them adds complexity without adding capability.
The underlying issue (#2057) is valid, but the fix should be targeted: give full_scan awareness of last_revealed so the stop gap only applies beyond that point. See #2057 (comment).
Author
|
Appreciate the feedback! 👍 Yep I can do that too. My idea was to address this comment by @ValuedMammal #2057 (comment) which @luisschwab also upvoted. |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Proposal: unify
full_scanandsyncinto a singlescanAPI.scan(...)combines explicit sync and keychain discovery in one request/call, so callers no longer need to stitch togethersync(...)+full_scan(...). Open to naming/API changes. I also tried to increase DX a bit.Fixes #2057. The old
spks_from_indexer(...)used an unbounded iterator starting at index 0. A single stop-gap scan therefore covered both revealed and unrevealed scripts in one pass, which could cause it to terminate before reaching a higher revealed address.test_scan_revealed_scripts_beyond_stop_gapcovers this now.scansplits the old behavior along the right seam:revealed_spks_from_indexer(...): explicit sync of the already revealed range0..=last_revealeddiscover_from_indexer(...): discovery starting atlast_revealed + 1, withstop_gapapplied only to the unrevealed partOther changes:
discover_keychain(...)instead ofspks_for_keychain(...)(renamed for clarity)stop_gapmoved onto the builder. Defaults to 20 (matches BIP44/Electrum/Sparrow defaults). I assume most callers use the default unless they need something custom.ScanItem/ScanProgress.full_scan(...)andsync(...)kept in place for gradual migration.API changes
scan(...)sync(...)+full_scan(...); new unified entrypoint for explicit sync and discoveryScanRequest/ScanResponseSyncRequest/SyncResponse+FullScanRequest/FullScanResponse; new unified request/response typesScanRequestBuilder::discover_keychain(...)+stop_gap(...)FullScanRequestBuilder::spks_for_keychain(...)+full_scan(..., stop_gap, ...); same discovery input, butstop_gapmoved onto the builderScanRequestBuilderExt::revealed_spks_from_indexer(...)+discover_from_indexer(...)FullScanRequestBuilderExt::spks_from_indexer(...); split into explicit sync of revealed scripts plus discovery starting atlast_revealed + 1Notes to the reviewers
Waiting for concept (N)ACK before filling in more tests, example updates, or deprecations.
Other findings while working on this:
stop_gapto 1 via.max(1)but electrum did not. I aligned electrum here.parallel_requestsin Esplora, the scan can overshootstop_gap. Same behavior as the previousfull_scan, no harm, keeping as-is.Limitations:
expected_spk_txidscurrently applies only to explicitly synced scripts (spks/spks_with_indexes), not to discovery scripts (discover_keychain/discover_from_indexer). This matches the current design where expected txids are associated with known scripts rather than the unrevealed discovery suffix. Extending to discovery is possible if we want it to be agnostic later.Follow-ups (post concept-ACK):
scansync/full_scanas#[deprecated]Changelog notice
scanAPI inbdk_core::spk_client:ScanRequest,ScanResponse,ScanRequestBuilder,ScanRequestBuilderExt,ScanItem,ScanProgress.BdkElectrumClient::scan,EsploraExt::scan, andEsploraAsyncExt::scan.full_scanbehavior #2057).Checklists
All Submissions:
New Features:
Bugfixes: