Repository navigation
blindbit-lib: one code path in the scan loop (SNB-669) - #52
Closed
setavenger wants to merge 4 commits into
Closed
setavenger wants to merge 4 commits into
setavenger wants to merge 4 commits into
Conversation
Remove public items nothing calls, in this workspace or in the other repos that use blindbit-lib (blindbit-node-apps, testkit, the talk benchmark): - broadcast_tx: its only caller, friglet's Electrum broadcast, uses friglet's own relay since #26. - Scanner::from_config, get_last_scanned_block_height_rescan, staged_mut, take_staged and the commented-out get_outputs. - watch_chain: friglet calls watch_chain_until; its doc moves there. - BlockIdentifierDisplay (only .0.block_height was read), OwnedOutput (never built), ProbableMatch::new, _match_short_pubkey_bytes and the commented-out ScannerConfig Default. electrum_index becomes a private module; its items stay re-exported. - The spent-outpoint and probabilistic-match channels and the code that only fed them. They had no subscribers and never sent anything: the sends were guarded by Sender::is_empty(), which means "no queued value", so they were always skipped. The malformed-hash branch that guarded them cannot run: check_block_identifier rejects such a block before scan_short_block_data sees it. The "possible spend of owned output" log line stays. - save_to_file's back-fill of keys and max_label_num: stage holds them from construction on and only take_staged could clear them. A test run with assertions in place of the back-fill passed every workspace test. - P2P: TimeoutParams setters the handshake never reads (it only uses the ping interval; the socket timeouts are set directly), history notes about deleted code, and a retry doc that predates the witness-stripped and bad-block retries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Scanner::new and from_changeset each wrote out the whole struct; both now hand their staged changeset to one private constructor, from_stage, which derives the rest (checkpoints with genesis, owned outputs, remembered hashes, Electrum index) from it. - "New indexer, labels 0..=max, then apply_changeset" was written in from_changeset and in the reorg rollback; it is restored_indexer now, with the reason the labels must come first. - The genesis checkpoint hash was built in three places; genesis_hash(). - new() merged add_label(0..=max) into the stage a second time after initial_changeset() already carried those labels (label_lookup is a set, so the merge changed nothing); dropped. - The remembered-hash lookup in reorg.rs is one helper. - Scanner.last_scanned_block_height_rescan was only restored, lowered on rollback and copied into every save. The stage already holds the same value, so the field goes; the ChangeSet field and the state format stay as they are. A probe (not committed) dumped stage, saved file and full scanner state for fresh scanners, a test-produced wallet, the old-format fixture, restores and rollbacks of each, before and after this change: all 42 outputs identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The scan loop's two arms (no match / matched block) each advanced the scanned height, recorded the block hash and notified Electrum; that now happens once after the optional matched-block step, in the same order as before. The periodic checkpoint still runs only for blocks without a match (a matched block is saved earlier). - The oracle's display-order block hash is decoded once: check_block_identifier returns it (via health.rs's indexed_block_hash, the same length and all-zero rules), and the P2P fetch uses it instead of decoding the bytes again. block_hash_from_oracle goes. - The balance over the sparse checkpoints is one helper, balance_at, used for the per-block "balance" log, the "balance after scan" log and the owned-output tests (which had a third copy). - The matched block's scan_progress write is dropped; the progress notification right after it writes the same value. - The debug loop that logged every graph transaction after each matched block is dropped. - apply_matched_block computed every transaction's txid once per matched txid; it now builds a txid map and hashes each transaction once. - OracleStreams only delegated to the oracle client: the client now implements BlockStreamSource itself (it already implemented OracleProbe). An identity match in probabilistic_match goes. - Stale TODOs and comments (notifications that no longer exist, a config-constructor TODO the talk benchmark rules out, Electrum index docs that missed the restore and broadcast writers). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A block fetched only because an owned output may be spent carries no matched txids. The txid filter still hashed every transaction of it (about 2 ms per block); the code before #52 did nothing there. Skip the filter when there are no matched txids. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setavenger
added a commit
that referenced
this pull request
Oct 3, 2026
…NB-666) Brings #52's spend-only fix (skip the txid filter when no txid matched) into this stacked branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 3, 2026
This was referenced Oct 11, 2026
Owner
Author
|
Merged into |
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.
Stacked on #47 (itself on #44); review only the commits after it.
Linear: SNB-669
Net: 249 insertions, 366 deletions (−117 lines). Most of the scan-loop diff is re-indentation; with whitespace hidden it is 92 / 209. Please review with "Hide whitespace".
What was merged or removed, and why
if let Some(..)step, and the shared tail runs once, in the same order as before:check_block_identifiernow returns the hash, decoded byhealth.rs'sindexed_block_hash. Its rules are the ones the check used: 32 bytes and not all zero, with the same error and message. The P2P fetch uses that hash instead of reversing the bytes again.block_hash_from_oracle(reorg.rs) is gone.balance_at(tip)replaces the two copies in the loop (the per-block "balance" log and the "balance after scan" log; both texts are unchanged) and the third copy inowned_outputs_tests.rs.scan_progresswrite dropped. The matched arm setidx.scan_progress, and the progress notification right after it wrote the same value.apply_matched_blockcomputedtx.compute_txid()once per transaction per matched txid, and converted each matched txid twice. It now builds aTxid → tweakmap once and hashes each block transaction once. The result is the same map: only matched txids found in the block, and for a repeated txid the last tweak wins, as before. A block fetched only for a possible spend has no matched txids; then the filter is skipped and nothing is hashed (72104e0, after review).OracleStreamsnewtype removed. It only delegated toOracleServiceClient, which now implementsBlockStreamSourceitself; it already implementedOracleProbeinhealth.rs. The identitymatchinprobabilistic_matchis also gone.todos inmod.rsand inscan_short_block_data(the notifications they mention were removed in blindbit-lib: remove dead scanner API and P2P leftovers (SNB-663) #44);Scanner::new(the talk benchmark keeps that signature);byte_array_to_txidand on the balance test helper;WalletElectrumIndex::txs/headersdocs, which missed restore, broadcast and friglet's header writers.Why behaviour is unchanged
Measurement in release (after review)
blindbit-cli --release(workspace release profile: LTO, one codegen unit) built atorigin/integration(a9ff4d6) and at this branch's head72104e0. Same signet range, peer, keys and method as below: 274010..=276010, fresh state file per run,/usr/bin/time -v, 6 runs each, interleaved.Reviewer's micro-benchmark of
apply_matched_block's txid filter (per block):72104e0Measurement in debug (hot path)
blindbit-clidebug build (dev profile; libsecp256k1 at -O3 as configured), signet oraclehttps://signet.oracle.setor.dev, peer152.53.151.148:38333, smoke keys (secret…01, pubkeyG), blocks 274010..=276010 (2,001 blocks), fresh state file each run,/usr/bin/time -v. Runs were interleaved old/new to cancel network drift; there were 8 of each (the 3 asked for, plus 5 more because the first 3 were close).Verification
cargo check --workspace --all-targets --all-features→ 0 warnings.cargo check -p blindbit-lib --no-default-features --all-targets→ 5 warnings (baseline 5).cargo clippy --no-deps -p friglet -p friglet-ipc -p friglet-tray --all-targets -- -D warnings→ clean.cargo fmt -p friglet -p friglet-ipc -p friglet-tray -- --check→ clean.cargo test --workspace→ 254 passed, 1 ignored, 0 failed. This includes the stream_safety, reorg, witness, cancel and owned_outputs suites.72104e0: the same results (0 warnings; 5 with--no-default-features; clippy and fmt clean; 254 passed, 1 ignored, 0 failed).Left out
ReorgTooDeepdecided in two places (scan_range_from's_arm andscan_block_stream_from's first-block check). The issue says to do this only if the reorg suite proves equivalence.ReorgBelowStreamStartreturn and ran every blindbit-lib test. None of the three is reached by any test; the onlyReorgTooDeeptest goes throughlocate_fork.