THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Wallet Scanning Explained: Gap Limits, Rescans, and Recovery

permalink THAMER
#address-discovery#bitcoin-wallet-gap-limit#descriptor-range#recovery#rescan

A Bitcoin wallet may control many addresses derived from a seed or descriptor. Finding its history requires two separate tasks: deriving the right scripts and scanning the blockchain for activity involving those scripts.

What is a gap limit?

A gap limit is a wallet discovery heuristic: after encountering a configured number of consecutive unused derived addresses, the wallet may stop scanning further indices. It is not a Bitcoin consensus rule, and different wallets can implement discovery differently.

If a user previously generated addresses far beyond the scanned range, a restore that stops too early can miss funds even when the seed is correct.

How do descriptors affect recovery?

Output descriptors specify how scripts are constructed, often including derivation paths and ranged keys. A seed phrase alone may not reveal the wallet's address type, account selection, derivation path, range, or additional script conditions. Recovery should reproduce the correct descriptor or equivalent wallet policy.

What is a rescan?

A rescan examines historical blockchain data for scripts the wallet controls. A full node with access to the required historical blocks can scan those blocks. A pruned node may lack older block data, so older rescans can require retrieving historical data from elsewhere or using a node with sufficient history.

Compact filters can help a lightweight wallet decide which blocks to fetch. They do not generate missing derivation paths or repair a too-small address discovery range.

How should developers handle reorganizations?

Associate discovered transactions with block hashes and confirmation state. When a block disconnects, roll back its effects and apply the new active chain. Persist scanning progress carefully, but never mistake a scan cursor for proof that no earlier wallet activity exists.

Recovery checklist

Confirm the network and wallet type, recover the correct seed and optional passphrase, reconstruct the correct descriptor paths and ranges, then scan enough historical blocks. Verify the results against independent data when correctness matters.

Primary references

BIP32 — Hierarchical Deterministic Wallets: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
BIP380 — Output Script Descriptors: https://github.com/bitcoin/bips/blob/master/bip-0380.mediawiki
Bitcoin Core — importdescriptors RPC: https://bitcoincore.org/en/doc/

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects