Skip to content

test: run the testkit scenarios at T0 through the live receive path (SNB-517) - #22

Merged
setavenger merged 7 commits into
masterfrom
snb-517-t0-rust
Oct 30, 2026
Merged

setavenger merged 7 commits into
masterfrom
snb-517-t0-rust

Conversation

@setavenger

@setavenger setavenger commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Update 2026-10-30: merged with master

master now carries the Friglet Deslop cleanup (#67–#76), #18, #80 and #81. The merge had no textual conflicts. Two follow-up commits make it build and pass:

  • 4cdc1c0: the deslop moved TempState and run from stream_safety_tests into test_support, so testkit_t0 imports them from there.
  • ca21273: with the nine T0 scenarios scanning on other test threads, balance_after_scan_counts_earlier_outputs_as_confirmed saw no "balance after scan" events in 12 of 12 runs. tracing caches a call site's interest when it is first hit. While exactly one scoped dispatcher exists, it consults only the current thread's dispatcher, so a call site first hit on a thread with no subscriber is cached as "never". The test now keeps a second dispatcher alive, so the interest stays "sometimes": 0 of 12 runs fail.

Verified locally on ca21273 (debug, private target dir):

  • cargo test --workspace: 264 passed, 0 ignored (master's 254 plus the 10 T0 tests).
  • cargo test -p blindbit-lib --features serde testkit_t0: 10 passed.
  • cargo check --workspace --all-targets --all-features: 0 warnings.
  • cargo fmt --all --check and clippy -D warnings on friglet/friglet-ipc/friglet-tray: clean.

The original description follows.


What

This is the Rust half of SNB-517 (T0, the in-process library tier). blindbit-lib/src/scanner/testkit_t0.rs replays the blindbit-testkit scenarios in-process through blindbit-lib's live receive path. Every block goes through Scanner::scan_block_stream, which is the per-block loop that scan_block_range and watch_chain run. Only the gRPC stream and the P2P block fetch are replaced: the stream is an in-process stream, and full blocks are served from memory using #20/#21's stream-safety test hooks. The loop's steps are not copied anywhere in the test, so they cannot drift:

  1. In-process oracle. Derives the BlockScanDataShortResponse from the transactions and their prevouts: tweak input_hash·A via bdk_sp::receive::compute_tweak_data, the 8-byte prefixes of taproot outputs, and the 8-byte prefixes of spent taproot outputs.
  2. scan_short_block_data. scan_transaction_short / match_short_pubkey plus the spent-prefix check decide whether to fetch the block.
  3. Indexing. Only a fetched block reaches apply_matched_block (→ apply_block_relevant). The loop then records owned outputs and their spends (sync_owned_outputs), checks the chain, saves state and keeps the block as a checkpoint.

Each wallet's found-set is read from the indexer the way the balance reads it: by_shared_secret, the graph txout, by_label, and spends in the graph. It is judged against the testkit's answer key:

  • every must_find output is present with the constructed amount, label and spent status;
  • no other output is reported.

A scanner restart rescans from block 1 and must reproduce the live found-set. An oracle restart recomputes the served data and must reproduce it.

No second sender. The transactions come from the testkit's vector-gated sender through testkit export-fixture (blindbit-testkit PR #25). They are committed under blindbit-lib/tests/data/testkit-t0/, pinned by SHA-256 in the test, and must also match the exported SHA256SUMS. The regeneration command is in the module docs. The fixture's Go-computed tweak is used only as a cross-check: the Rust tweak must equal it for every transaction, and on these nine scenarios it does, input-types included (NUMS script-path and uncompressed P2PKH exclusions).

Scenarios: plain-payment, labelled-multi, k-gap, label-parity, k-counter, spent-outputs, input-types, rescan, dust-boundary. These are the nine the testkit runs at T0, all under full-basic.

Production change: apply_matched_block is extracted from scan_block_range with the same body as in #17 and #19, so the test calls the function that production calls.

Why T0-rust is not redundant with T1/T2

The testkit already runs a real blindbit-cli at T1 and friglet at T2, but only against the repos.lock pin, in the testkit's CI, after the fact. This test runs in blindbit-rs's own CI on every PR, in about 0.1 s, with no Go, binary or Docker. #17's vectors cover the BIP-352 math. They do not cover multi-block wallet state: spends in later blocks, rescans, labels plus change, or k-gaps across a whole scenario.

Spends (update 2026-10-01)

This branch now merges the fix stack: #21, which carries #19, #17 and #20. All 9 scenarios pass with their spends, and KNOWN_SPEND_GAP is gone.

On integration the test caught that spends were never detected: owned_outputs was never written, which is the bug #19 fixes. When this was first written, the harness copied the loop's per-block steps by hand. That copy had already fallen behind #19, because the loop now calls sync_owned_outputs() after apply_matched_block. That is why the harness now drives the loop itself.

Negative check: removing the sync_owned_outputs() call from the production loop turns exactly the nine former spend rows red again, in k-gap, labelled-multi, spent-outputs, dust-boundary and rescan.

Fixture provenance now names testkit 68f9f1c, the merge of testkit #25 into master. The fixtures are byte-identical to that export.

Red (mutations applied temporarily, then reverted)

Mutation Result
Short path: skip label iteration in scan_transaction_short label-parity, labelled-multi, spent-outputs and rescan fail, e.g. MISSING bob-l3-a: wallet bob did not report 9871a3c8…:0 (40700 sat), MISSING change-a (m = 0)
Apply: apply_matched_block passes no tweaks 8 of 9 scenarios fail, e.g. MISSING big-k1: wallet carol did not report 077e72c1…:1 (40000 sat)
On #19: drop the spent-prefix match in scan_short_block_data 5 scenarios fail, e.g. MISMATCHED spent-k0 (carol, 19c7dbd6…:0): spent expected true, reported false
Empty KNOWN_SPEND_GAP on integration the same 9 spent mismatches, each named
On the fix stack: drop sync_owned_outputs() from the scan loop the same 9 spent mismatches, each named

Verification

On the fix stack (head after merging #21 824613f):

Original verification, against integration:

  • cargo test -p blindbit-lib: 22 passed (10 new).
  • cargo test --workspace: all ok.
  • cargo clippy --no-deps -p friglet -p friglet-ipc -p friglet-tray --all-targets -- -D warnings (the CI lint step): clean.
  • cargo clippy -p blindbit-lib --all-targets: no warnings in testkit_t0.rs. testkit_t0.rs is rustfmt-clean (file-scoped). scanning.rs was not reformatted.

…SNB-517)

The testkit exports each scenario's T0 run (signed transactions with
prevouts, wallet keys, the expected found-set) as a pinned JSON fixture.
testkit_t0 replays those chains in-process through exactly the per-block
steps scan_block_range takes: an in-process oracle computes the short data
(tweak via compute_tweak_data, cross-checked against the Go index; output
and spent 8-byte prefixes), scan_short_block_data decides the fetch, and
apply_matched_block feeds apply_block_relevant. Each wallet's found-set is
judged against the answer key: amount, label, spent, nothing extra.

apply_matched_block is extracted from scan_block_range (same body as in
#17 and #19) so the test drives the function production calls.

All nine T0 scenarios pass except spent status: every spend the scenarios
make goes undetected, because owned_outputs is never written. Those rows
are pinned in KNOWN_SPEND_GAP and must keep failing exactly so; #19 fixes
them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
setavenger and others added 3 commits October 1, 2026 14:27
Brings in the fix stack (#17, #20, #19, #21) so the T0 harness runs
against the receive path that records owned outputs.

scanning.rs: both sides extracted apply_matched_block; kept #21's
sync_owned_outputs() call after it in the scan loop and its doc line,
and kept both test modules (owned_outputs_tests from #21, testkit_t0
from this branch).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The T0 harness replayed each block through a hand copy of the scan loop's
per-block steps, and that copy had already fallen behind: the loop on the
fix stack records owned outputs (sync_owned_outputs) after
apply_matched_block and the copy did not, so nine spends were carried as
KNOWN_SPEND_GAP.

process_block now drives Scanner::scan_block_stream, the per-block loop
scan_block_range and watch_chain run, with the oracle's message streamed
in-process and the full block served in place of the P2P fetch (the
stream-safety test hooks from #20/#21). There is no copy left to drift: a
step added to the loop is exercised here. State files the loop now saves
are removed when a scenario ends.

KNOWN_SPEND_GAP and its assertions are gone; all nine scenarios must pass
with their spends. Dropping the sync_owned_outputs() call from the loop
turns exactly those nine spends red again (k-gap, labelled-multi,
spent-outputs, dust-boundary, rescan).

Fixture provenance now names testkit 68f9f1c, the merge of testkit PR #25
into master; the fixtures are byte-identical to the export at b1f962e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in the blindbit-cli error display fix from #20.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setavenger and others added 3 commits October 30, 2026 08:18
Brings #22 up to date with master (Friglet Deslop #67-#76, #18, #80, #81).
No textual conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The deslop moved TempState and run from stream_safety_tests into
test_support; TestStream and serve stay where they were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rently

With the T0 testkit scenarios scanning on other test threads, the
"balance after scan" call site is often first hit on a thread with no
subscriber. While only one scoped dispatcher exists, tracing caches that
call site's interest from the current thread alone, so it was cached as
"never" and balance_after_scan_counts_earlier_outputs_as_confirmed saw
no events (12 of 12 runs). A second live dispatcher makes tracing combine
every dispatcher's interest; 0 of 12 runs fail with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@setavenger
setavenger merged commit 929419b into master Oct 30, 2026
1 check passed
@setavenger
setavenger deleted the snb-517-t0-rust branch October 30, 2026 08:50
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.

1 participant