Skip to content

friglet: drop control/config leftovers, wrappers and duplicate tests (SNB-664) - #53

Closed
setavenger wants to merge 2 commits into
integrationfrom
snb-664-control-config-leftovers
Closed

setavenger wants to merge 2 commits into
integrationfrom
snb-664-control-config-leftovers

Conversation

@setavenger

Copy link
Copy Markdown
Owner

Stacked on #46; review only the commits after it.

Part of the friglet cleanup (SNB-661). Implements SNB-664. Net −179 lines, no behaviour change.

What was removed and why

  • std::sync::Mutex around ControlCtx::electrum_index and label_addresses: nothing has written them since the live rebuild-and-swap was removed (feat: restart friglet on settings changes and after crashes; start at login (SNB-624, SNB-52) #29). They are now plain fields. The Start comment that still talked about "rebuild + swap" is fixed.
  • Pass-through wrappers around friglet-ipc: config::default_config_path, default_key_file, write_config_file, write_key_file, replace_scan_key. apply() already parses the new key, so it writes hex::encode(secret) with friglet_ipc::write_key_file(.., true) (the same call replace_scan_key made after parsing the key a second time).
  • pick_tip was oracle.or(electrum); it is inlined and its test removed.
  • control::unix_now was a copy of pending::now_secs.
  • Key-file "first non-empty line" parsing was written twice; it is now key_file_line().
  • ResolvedConfig no longer copies oracle_url, max_label_num, http_addr, electrum_addr out of raw; callers read cfg.raw.*. state_file stays separate because main replaces it with the per-wallet path.
  • sp_start_height was set again in main right after rebuild_electrum_index_from_graph(cfg.start_height) had set it. Nothing touches the index between the two.
  • control::run was generic over a handler only so get_status_roundtrip_over_control_socket could pass a stub. That test (and dummy_status) repeated friglet-ipc's roundtrip test and every serve_ctx test. run now takes the ControlCtx.
  • supervisor::stop_during_a_download_pauses_at_once repeated the cooperative-cancel tests and left a 30 s thread behind. The real-download version through the control socket (stop_during_a_stalled_p2p_download_pauses_within_a_second) stays.
  • fake_peer::Seen (one field) is now a Vec<String>.
  • Stale comments: types.rs (only the HTTP server uses those types), the --oracle-url default (it follows the network), and electrum::run (the scan task is no longer scan_block_range).

Why behaviour is unchanged

Startup was checked with the real daemon (debug builds of #46's head and this branch) on copies of two state files:

  • blindbit-lib/src/scanner/testdata/state_before_owned_outputs.json, the old format without owned_outputs records.
  • A state file the tests produce: the same fixture restored and saved again in the current format.

Setup: signet oracle, fixture keys. Time from spawn until the control socket answered GetStatus, with outputs_found at that moment and again 3 s later, 3 runs each:

state file before: ms (median) after: ms (median) outputs_found before → after
old-format fixture 73.9 / 117.5 / 74.9 (74.9) 76.1 / 75.0 / 80.9 (76.1) 0 → 0 (and 0 → 0 after 3 s)
test-produced, current format 68.9 / 74.6 / 69.9 (69.9) 74.8 / 74.1 / 60.0 (74.1) 2 → 2 (and 2 → 2 after 3 s)

The count's tolerant reader (owned_outputs_count) and its test are unchanged.

Verification

  • cargo check --workspace --all-targets --all-features: 0 warnings
  • 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: 251 passed, 1 ignored, 0 failed. Base had 254; the 3 tests removed as duplicates are pick_tip_prefers_oracle_then_electrum, get_status_roundtrip_over_control_socket and stop_during_a_download_pauses_at_once. friglet's binary: 71 tests in 5.59 s.

Left out on purpose

  • owned_outputs_count re-reading the state JSON: kept. Taking the count from the restored scanner changes what is reported for old-format files. On the fixture, the JSON gives 0, while the restored scanner holds 2 outputs, because sync_owned_outputs fills them in from the indexer. Avoiding the second read without that change would need a blindbit-lib API.
  • Oracle GetInfo-with-timeout written twice (config::fetch_oracle_tip vs the status poller): kept. The two use different timeouts (15 s vs 5 s), and only the poller reuses its client. They also produce different error texts, and the poller's reach the tray as oracle_error. A shared helper would need all three as parameters and would remove no lines.
  • The 4.5 s control "stopping" test: kept. It is the only test of ControlCtx::pause_scanning's timeout branch (OkWithNote("stopping: …"), with the background save) and of Start's StillStopping → Response::Error answer. The supervisor test covers only the supervisor's states.

setavenger and others added 2 commits October 3, 2026 08:47
The Electrum server built the same things in several places. One copy
of each now:

- notification(): the JSON-RPC notification line (was written out four
  times); sp_subscription(): the SP subscription object and its
  notification, shared by the push task and the subscribe handler.
- invalid_param(): the -32602 answer for a missing or mistyped first
  parameter (block.header, scripthash.subscribe/get_history,
  transaction.get); the messages are unchanged.
- save_header_sidecar(): the header-sidecar write after a backfill and
  after a reorg.
- Peer::header_by_hash() takes one hash (its only caller passed a
  one-element slice) and returns only a header with that hash, so the
  two re-checks of the same hash in ChainSource::header and
  backfill_header go.
- relay: connect_settled() (connect + settle, the 2 s literal is now
  p2p::SETTLE_WAIT, also used by ChainSource::fee_filter),
  Candidate::wire_tx() and Signals::announce() replace two or three
  copies each.
- index_unconfirmed_tx: two match arms that both did nothing are one
  condition.
- Two tests build their request with call() like the others.

The bytes on the wire are unchanged: a scripted session of 52 requests
and 8 push batches gives byte-identical output before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(SNB-664)

Leftovers from the live scanner swap and from earlier refactors:

- ControlCtx keeps the Electrum index and the label addresses directly;
  the std Mutex around each was never written after the live
  rebuild-and-swap went away (#29). The Start comment that still
  described the swap is fixed.
- One-line wrappers around friglet-ipc are gone (default_config_path,
  default_key_file, write_config_file, write_key_file, replace_scan_key);
  apply() writes the key it already parsed instead of having
  replace_scan_key parse it again.
- pick_tip was `oracle.or(electrum)`; inlined, with its test.
- control's unix_now duplicated pending::now_secs.
- The key file's "first non-empty line" is read by one helper.
- ResolvedConfig no longer copies oracle_url, max_label_num, http_addr
  and electrum_addr out of `raw`.
- main no longer sets sp_start_height a second time right after
  rebuild_electrum_index_from_graph set it.
- control::run takes the ControlCtx instead of a generic handler; its
  only other user was get_status_roundtrip_over_control_socket, which
  repeated friglet-ipc's roundtrip test and every serve_ctx test.
- supervisor: stop_during_a_download_pauses_at_once repeated the
  cooperative-cancel tests and left a 30 s thread behind.
- fake_peer: the single-field Seen struct is a Vec.
- Stale comments: types.rs, the --oracle-url default, electrum::run.

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

Copy link
Copy Markdown
Owner Author

Merged into integration through #70 on 2026-10-11 (the user live-tested the combined stack first). GitHub's stacked-PR merge rebased the stack, so this PR's commits landed with new IDs and GitHub can't mark it merged itself. The code is identical: integration now has the same tree as the tested branch friglet-deslop-live-test (08bf11d), which contains this PR's head. Closing as merged via #70.

@setavenger setavenger closed this Oct 11, 2026
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