Repository navigation
blindbit-lib: count earlier outputs as confirmed in "balance after scan" (SNB-687) - #61
Closed
setavenger wants to merge 9 commits into
Closed
setavenger wants to merge 9 commits into
setavenger wants to merge 9 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>
…SNB-666) The test wallet's keys, the Tokio runner, the never-connecting oracle client, state-file paths, TempState and the scanner constructors were defined again in five to six test modules. They now live in scanner/test_support.rs: - oracle_client() uses the caller's runtime when there is one and a process-wide one otherwise, so it serves both the async tests and the synchronous owned-output and BIP-352 tests. All tests now point at 127.0.0.1:1, where nothing listens (two modules used [::1]:50051 and 127.0.0.1:8333). - state_file(tag) returns a path no other call returns, so modules can no longer collide on a tag (reorg and owned-output tests both used "restart"). - scanner(tag), scanner_at(path, max_label_num) and restore_from(path) replace stream_safety's scanner, reorg's wallet/restart, owned_outputs' scanner/restore, witness' restart and state_file's new_scanner/client. bip352_vectors keeps its own constructor (vector keys, mainnet) on the shared client and paths. Also: - a_fetched_block_keeps_its_witnesses is dropped: the next test fetches the same kind of block whole on its second connection and compares the whole block, witnesses included. - p2p_tests' Node has three constructors instead of four, and the witness-stripping loop is one helper (stripped) used by the fake node and the witness tests. - The stale allow(dead_code) on the vectors' `sending` field goes (the field is read). - The pre-owned-outputs restore test restores the file it just saved instead of a re-serialised copy, so it leaves no file behind. Test count: 254 -> 253 passed (the one duplicate removed), 1 ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…an" (SNB-687) The end-of-range "balance after scan" line computed the balance with the last block matched in that range as the chain tip, and with genesis when no block in the range paid the wallet. bdk_chain cannot place an anchor above the tip it is given, so it counted every output as pending: the line logged confirmed=0 and the whole balance as trusted_pending. That is every range while the daemon follows the tip, as a rule. The balance is now counted up to the highest checkpoint. When the range matched a block above every earlier checkpoint (any forward scan), that block is the highest checkpoint, so the logged values are the same as before. The message and field names are unchanged; friglet-ui matches the line by its text. balance_after_scan_counts_earlier_outputs_as_confirmed scans a paying block, then a block that pays nobody, and checks the fields of both lines. Before the fix the second line read confirmed="0 BTC", trusted_pending="0.00011800 BTC". 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>
…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>
- owned_outputs_labels_and_spends_survive_restart builds its scanner on the state file it saves, restores and removes. state_file() returns a new path on every call, so the second call gave the scanner a different file than the one the test checks. - default_scanner in the BIP-352 vectors points its P2P peer at 127.0.0.1:1 like every other test (it is never contacted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 3, 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 #57; review only the commits after it.
Bug fix for SNB-687. It changes logged values only.
What was wrong
At the end of each range,
scan_block_stream_fromlogs "balance after scan". It computed the balance withlast_block_idas the chain tip. That is the last block in the range that paid the wallet, or genesis when none did. bdk_chain cannot place an anchor that sits above the tip it is given, so every output was counted as pending. The line then readconfirmed=0 BTCand put the whole balance intrusted_pending. While the daemon follows the tip, most ranges contain no paying block, so this was the usual case.Fix
The balance is now counted up to the highest checkpoint, which always exists because the genesis checkpoint is never removed.
last_block_idand thegenesis_hashimport go away; they had no other use.confirmed, nottrusted_pending.totaldoes not change.rescan_for_missed_spends): this rescans below checkpoints that already exist. Outputs above the rescanned block are now logged as confirmed here too.Log format is unchanged. friglet-ui in blindbit-node-apps parses "balance after scan" by its text (
classify.rs,redact.rs). The message, the field names and their order are identical. Only the values become correct.Reproduction
New test:
stream_safety_tests::balance_after_scan_counts_earlier_outputs_as_confirmed. It scans a paying block (height 1800), then a block that pays nobody (1801). It records the fields of both "balance after scan" events with a tracing layer.Before the fix, it fails on the second range:
After the fix it passes, with and without the
serdefeature.Verification (debug build, this branch)
cargo check --workspace --all-targets --all-features: 0 warnings.cargo check -p blindbit-lib --no-default-features --all-targets: 5 warnings. The baseline is 5, all inload.rs/scanner.rs.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, 68 s wall. blindbit-lib tests: one shared fixture module, drop duplicate tests (SNB-666) #57 has 253; the extra test is the new one.After blindbit-lib tests: one shared fixture module, drop duplicate tests (SNB-666) #57 received its review nits and blindbit-lib: one code path in the scan loop (SNB-669) #52's follow-up, the latest
snb-666-shared-test-fixtures(6cde6b1) was merged in with a merge commit (no rebase). All of the checks above were re-run: same results,cargo test --workspace254 passed, 1 ignored, 0 failed.Left out
The per-block "balance" line, logged right after a matched block, still uses that block as the tip. During a format-0 rescan, outputs above the rescanned block show as pending in that line. friglet-ui does not parse it (it matches "balance after scan"). It is a different log line from the one in this issue, so it is not changed here.