Skip to content

wollet: skip unchanged blocking scans - #197

Open
ethicnology wants to merge 3 commits into
Blockstream:masterfrom
SatoshiPortal:wollet/skip-unchanged-scans
Open

ethicnology wants to merge 3 commits into
Blockstream:masterfrom
SatoshiPortal:wollet/skip-unchanged-scans

Conversation

@ethicnology

Copy link
Copy Markdown
Contributor

Motivation

An identical blocking full-history scan returned another Update whenever no wallet transaction was confirmed at the tip, because the tip header was re-downloaded on every scan and every downloaded timestamp counted as a change. Callers that persist and publish each update (Bull Bitcoin's Liquid wallet) did so after every idle sync.

API

  • BlockchainBackend::full_scan / full_scan_to_index now return None for identical rescans. Real changes still return Some: new, removed or re-heighted transactions, tip changes including a same-height replacement, new scripts, index growth and missing or replaced timestamps.
  • UTXO-only scans keep returning Some, because they replace the unspent snapshot and WolletState exposes nothing to compare it with.
  • WolletState gains timestamp(height); it is crate-private in practice (not re-exported), and WolletConciseState now carries the cached timestamps. No persistence or Update format change. Asynchronous scanning is unchanged.

Tests

  • test_scan_unchanged (Electrum, regtest) fails on master at the first identical rescan and passes with the fix. The same sequence checks funded and empty wallets, index expansion, a mempool transaction, a confirmation with the tip already applied, timestamp repair and replacement, a same-height tip replacement, a transaction below the tip after a new block, and reload from the legacy store. Alternative states are prepared with the public Update API.
  • cargo test -p lwk_wollet --lib: 140 passed, 23 ignored. cargo clippy -p lwk_wollet --all-targets --features electrum,esplora -- -D warnings and cargo fmt --check: clean. Rust 1.91.0, Elements 23.3.3, electrs-liquid 0.4.1.

Base: master 7747af34, 2026-11-09.

An identical blocking full scan returned Some(Update) whenever no
wallet transaction was confirmed at the tip: the tip header was
re-downloaded on every scan and every downloaded timestamp counted
as a change. Callers persisting and publishing each update did so
on every poll.

- download a header only when its timestamp is missing or its height
  is new, take the tip timestamp from the tip header already fetched,
  and keep only timestamps that differ from the cached ones
- compute transaction height additions and deletions before deciding
  whether to return an update, so a confirmation whose tip was
  already applied is still reported
- treat derivation indices as monotonic, as apply_update does
- keep returning an update for UTXO-only scans, which replace the
  unspent snapshot
- expose cached timestamps through WolletState and copy them into
  WolletConciseState
Regression for the blocking scanner returning an update on identical
rescans. The same regtest sequence checks that new transactions,
confirmations, new blocks, index expansion, missing or replaced
timestamps and a same-height tip replacement still produce one.

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WolletState is a public trait, and this PR adds timestamp(&self, Height) as a required method. Downstream implementations outside this workspace will stop compiling, even though the scanner can conservatively treat an unavailable cached timestamp as None. Could this method have a default implementation returning None, with the built-in states overriding it as they do here? That keeps external implementations source-compatible while still downloading headers when a custom state cannot supply timestamps.

WolletState is public and implemented outside this workspace. Adding
timestamp() as a required method broke those implementations, while
the scanner can treat an unavailable cached timestamp conservatively.

- return None by default: the header is downloaded again and the
  timestamp counts as changed, as before this optimization
- keep the overrides of Wollet and WolletConciseState
@ethicnology

Copy link
Copy Markdown
Contributor Author

updated

@ethicnology
ethicnology requested a review from agammann November 11, 2026 19:26

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I rechecked head aa1d67c. The default WolletState::timestamp() keeps downstream implementations source-compatible, while the built-in states use cached timestamps for the no-op scan path. The new regtest sequence covers no-op scans, tip and confirmation changes, timestamp repair, and persistence reload. My earlier concern is addressed; I found no further change-specific issue in this diff. I reviewed the code and tests but did not run the regtest suite locally. CI still needs maintainer approval. AI-assisted review.

@LeoComandini

Copy link
Copy Markdown
Contributor

can you please rebase on top of master, we had some related changes touching the same code and conflicting

This branch has not been deployed

No deployments
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.

4 participants