Repository navigation
Description
This issue will be edited frequently to reflect the current status of the project.
What should I review now?
This project is currently on standby. Looking for contributors who want to see it happen and are willing to be part of the work (not only coding, reviewing it is even more important). Please leave a comment if you are interested.
The goal of this project is to enable complete blockchain rescan capability on prune nodes, allowing these storage-limited nodes to import new wallet descriptors and update existing ones at any time, as well as loading external and un-synced wallets with a birth-time older than 48 hours. This, in turn, enables the monitoring of new addresses/scripts and tracking balance changes without the need to repeatedly download the entire blockchain.
The first project milestone introduces the feature for prune nodes that construct and maintain a local block filters set database. The node will request and keep track of the missing historical blocks that match the wallet scripts filters set to subsequently perform the rescan.
The following sections are ordered by their PRs dependencies:
Net: Single Block Requests Tracking System and On Download Failure Retry Mechanism
- p2p: adaptive connections services flags #28170
- p2p: make block download logic aware of limited peers threshold #28120
- test: improve robustness of connect_nodes() #30118
- net: introduce block tracker to retry to download blocks after failure #27837
Indexes Stability and Performance Improvements
- index: make startup more efficient #27607
- index: prevent race by calling 'CustomInit' prior setting 'synced' flag #27720
- index: block filters sync, reduce disk read operations by caching last header #28955
- index: initial sync speedup, parallelize process #26966
Wallet Rescan (depends on the net section)
- wallet: improve IBD sync time by skipping block scanning prior birth time #27469
- Cache wallet filters' set and connect it to the current wallet rescan functionality. (Pending)
- Wallet: implement "rescan status" class to track the progress and retrieve it via an RPC command. (Pending)
- Wallet: introduce prune node rescan functionality. (Pending - depends on net changes)
Issues Solved By This Work
- Allow for rescan using block filters with pruned node #21267
- Make rescans faster #23727
- Use of a wallet shouldn't be blocked in prune mode ("wallet loading failed... beyond pruned data") #27188
- Allow getblockfrompeer to use any peer #27652
- Optimization: utilize 100% resources of a computer in long operations like rescan/initial block download #27939
- BIP157 / neutrino mode sparrowwallet/sparrow#1111 (comment)
Activity
chrisguida commentedon Jan 23, 2024
Does
scanblockswork on pruned nodes yet? If not, does this project aim to add that capability?furszy commentedon Jan 23, 2024
scanblocksalways worked on pruned nodes. Just need to enable-blockfilterindexsince the node's inception.chrisguida commentedon Jan 24, 2024
Excellent, thanks!!
chrisguida commentedon Jan 24, 2024
What's the process for building the blockfilterindex on an already-synced pruned node? Enable blockfilterindex, reindex?
furszy commentedon Jan 24, 2024
Yes. For further node support, please come to IRC or use bitcoin.stackexchange. This is a project tracking issue.
shovas commentedon Feb 8, 2024
Here from #27188. I'm presently experimenting with wallets for bitcoin, litecoin, dogecoin, and bitcoin cash using linux cli tools so if I can help I'll try.
AndySchroder commentedon Aug 1, 2024
Wondering if it makes sense to have a prune witness data only mode? Can't #25957 work without witness data? Seems like pruning all witness data after the last 2,000 blocks would be a technically easy option with a high reward in disk space savings. I thought that was the reason we had the segwit discount (to encourage more prunable data be placed in the witness), but is that discount doesn't even seem to be used by bitcoin core in a meaningful way in terms of pruning? Is there any open issue for pruning witness data?
furszy commentedon Aug 29, 2024
Something like that wouldn't be easy to implement with the current storage model. The witness data is tied to the transaction on disk in its serialized form, which is then tied to the block on disk in its serialized form. So, in order to discard the witness data, we would need to create a process that rewrites the block files entirely.
murchandamus commentedon Jan 23, 2025
Rescan functionality for the wallet on the basis of client-side block filters would be an enormous win. Concept ACK
AndySchroder commentedon Jan 23, 2025
One thing I have been thinking about this approach: Since we do need to selectively re-download specific blocks, it might be prudent to have an option only re-download those specific blocks from peers only over TOR. Since the total amount of data that needs to be downloaded is substantially lower than doing an IBD, this may not be that slow. Also, can the re-downloaded blocks be re-downloaded in parallel since we will know what blocks they are?
furszy commentedon Feb 10, 2025
Thats possible for sure. Could also request a few extra blocks to make the guess harder.
Yes. Thats how #27837 was implemented (blocks are requested in parallel - block processing is sync due to current net processing structure).
darosior commentedon Feb 18, 2026
I'm curious if a first step of simply downloading blocks for the desired interval, instead of using block filters, was considered. We already have access to a validated tip and a header chain, so we could download past blocks and scan them without re-validating them again. A second step could weigh whether introducing the complexity of client side filtering is worth the reduction in bandwidth usage. Finally, because this method would indiscriminately download blocks like in IBD, it would not be necessary to try and use an anonymization network.
Sjors commentedon Feb 18, 2026
Essentially just unpruning all the way to the block where the wallet was last synced? That seems reasonable, but you'd want some user interaction if it's a big download.
Perhaps a simple
unprune HEIGHTRPC could be added? And then when wallet loading fails, it could suggest something likeTry the unprune HEIGHT rpc if you have X GB of free space(anything is better than the current reindex suggestion).The
unpruneRPC could prevent pruning while the node is running, so the user can do their wallet rescan. At the next restart things get pruned back, unless they change the-prunesetting.darosior commentedon Feb 18, 2026
Not really, what i had in mind was rather to only temporarily download those blocks. That could be done in chunks of a day worth of blocks for instance (144 blocks), or anything that would be minimal disk space overhead anyways compared to the current size of the chainstate.
Sjors commentedon Feb 18, 2026
Oh you mean a rolling window of ephemeral downloads during the rescan? That makes sense too, though we also wouldn't want to do that without prompting the user, since it can be a long and slow download.
furszy commentedon Feb 18, 2026
The next unmerged step along this path adds the ability to request, track, and re-attempt block downloads (#27837), which is essentially what you are asking for, just extended with an interval locator on top.
The idea there was to separate the logic responsible for downloading best-chain blocks up to the tip from the logic responsible for downloading specific blocks, with the goal of having two structures answering the same question "what should download next" in different ways and with different priorities.
Re "simply download blocks from the desired interval" approach:
I have always felt this wasn't really a complete feature, but more of a half-baked implementation of the real one, mainly because of the excessive bandwidth it would consume for older wallets. That said, it is doable.
The rolling/ephemeral window approach wouldn't work as you imagine. The wallet isn't loaded (we fail during load on prune nodes), so we can't notify and discard the blocks.
There is a good way we can implement this that is way more space-efficient than that. Basically, irrelevant blocks can be discarded immediately by storing the wallet's elements set (scripts hash-mapped into the filter space) within the interval tracking mechanism. This doesn't require a wallet to be loaded at all, and it enables additional use cases like running
scanblockson prune nodes and letting users query for txs relevant to given script(s) on the fly on prune nodes too.If we have enough review power for this, I can update+rework #27837 (or open a new PR) to move us one step closer to the requested functionality, but we should coordinate to make sure we are using our time wisely.
AndySchroder commentedon Feb 19, 2026
With blocks already downloaded, I can do a a full chain re-scan in a fairly short amount of time. See sparrowwallet/sparrow#1368 (comment) for some data. It seems to me if we are just re-scanning a specific wallet, the time would be much shorter. If a wallet only has 200 transactions and does need to download some blocks, I would think that would mean only 200 blocks need to be downloaded at most, right?
Sjors commentedon Jun 23, 2026
Can you update the review now PR in the description?
I would be fine with something that works and isn't space efficient, then improve it later.
I think I understand the need for #27837 now. When I implement a simple blocking
unprune :height :peercall, it only succeeds if the node is reliable. Still, such a dumb method might be a good start, with the documentaiton pointing out the shortcoming. Then, once they experience the problem, people might be more motivated to review the other PRs.furszy commentedon Jun 23, 2026
Done. Added a "looking for commitment" sentence there. If we manage to gather a working group, I could organize + distribute the workload to move it forward.
No problem.