Skip to content

Friglet cleanup 4/6: simplify daemon settings paths (SNB-661) - #70

Merged
setavenger merged 9 commits into
integrationfrom
snb-661-stack-04-daemon
Oct 11, 2026
Merged

setavenger merged 9 commits into
integrationfrom
snb-661-stack-04-daemon

Conversation

@setavenger

Copy link
Copy Markdown
Owner

Stacked on #69; review only this stage's commits and diff.

Purpose

Combine the daemon and settings cleanup into one review stage. It removes duplicate Electrum and config/control paths, ties console colour to stdout, keeps Start/Stop responsive while settings are prepared, reports restored outputs at startup, and moves blocking DNS validation off the async runtime with a deadline.

The stage preserves the original reviewed commits and authorship. It is cumulative with stages 1–3 for SNB-661.

Stack

  1. Predecessor: snb-661-stack-03-ipc (#69)
  2. This PR: snb-661-stack-04-daemon → snb-661-stack-03-ipc
  3. Successor: snb-661-stack-05-tray

Included original PRs, in merge order: #46 (SNB-665), #53 (SNB-664), #56 (SNB-682), #60 (SNB-685), #64 (SNB-689), #65 (SNB-690).

Verification

Full accumulated debug gate on this exact head:

  • cargo check --workspace --all-targets --all-features: clean, 0 warnings.
  • cargo check -p blindbit-lib --no-default-features --all-targets: 5 baseline warnings, no growth.
  • 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: 260 passed, 1 ignored, 0 failed.

The combined suite includes the pseudoterminal colour check and the source PRs' control-lock, settings-validation deadline, responsiveness, and restored-output regressions. This grouped stage did not add a live daemon scan, interactive control-session check, or external DNS failure injection beyond the repository tests.

Landing

Merge the six grouped PRs in numeric order with merge commits. After #69 lands, retarget this PR to integration, verify its base and diff, and only then merge it. Preserve the predecessor branch until this PR has been retargeted if necessary. After this PR lands, apply the same process to stage 5. Never merge a child PR into its feature-branch base.

@setavenger
setavenger added this pull request to stack #77 October 11, 2026 12:17
@setavenger
setavenger force-pushed the snb-661-stack-04-daemon branch 2 times, most recently from 43af12b to af67be2 Compare October 11, 2026 18:14
Base automatically changed from snb-661-stack-03-ipc to integration October 11, 2026 18:14
setavenger and others added 9 commits October 11, 2026 20:14
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>
…o (SNB-682)

The console log goes to stdout (tracing-subscriber's default writer),
but whether it is coloured was decided by looking at stderr. Run from a
terminal with stdout redirected (`friglet > out.log`), the file got ANSI
escapes. The layer now checks stdout and names stdout as its writer, so
the two cannot drift apart again; the comments that said stderr say
stdout.

Nothing changes when both streams go to the same place: a terminal still
gets colour, and a tray-spawned daemon (both piped) still gets none.

New test (Linux, needs util-linux `script` for a pseudo-terminal; skips
without it): with stdout redirected to a file and stderr on the
terminal, the file has no escapes. It fails on the old code.

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

"cannot write the log file; logging to stderr only" was missed in the
first commit: the console log is written to stdout. No tray or friglet-ui
code matches this text.

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

apply() took apply_lock first and then looked up a new wallet's
birthday at the oracle (up to 15 s) and resolved the P2P host name
(blocking DNS) while holding it, so a Stop or Start sent during an
ApplySettings with start_at_tip waited for both.

Both lookups now run in prepare(), before the lock. Under the lock
apply() still reads the current settings, compares, persists and
requests the restart, so a settings change still never interleaves with
Start/Stop or another apply. A SetScanKey (no config of its own) whose
settings snapshot was replaced by another apply while it waited for the
lock prepares again from the newer settings, as if the two had run one
after the other.

Tests: Stop and Start answer within a second while an apply waits on an
oracle that never answers (the old code timed out after 2 s); a
SetScanKey that waited behind another apply keeps that apply's settings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review: when a SetScanKey's settings snapshot had been replaced by
another apply while it waited for the lock, it prepared again (oracle
birthday lookup, blocking DNS) while holding apply_lock, so Start/Stop
could still wait behind the network in that case, and the field doc was
not true.

apply() now drops the lock, prepares again from the new settings and
takes the lock again to check; it persists only once the settings it
prepared from are the ones under the lock. Comparing and persisting
still happen under the lock only, so Start/Stop never see a half-applied
change and two applies never mix their writes.

New test: settings replaced (by a config whose preparation waits on an
oracle that never answers) while a SetScanKey waited for the lock; Stop
and Start still answer within a second, nothing is persisted. With the
re-prepare under the lock, Stop timed out after 2 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Initialize outputs_found from the restored scanner instead of parsing the
state JSON again. Legacy state files rebuild their owned-output records
on restore, so the startup status now reports the wallet's actual count.

Keep coverage for absent, invalid and bare-key legacy state files. The
regression test reports 0 instead of 2 with the old counter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the legacy fixture's wallet keys and abort the runtime-owned oracle
listener after restore, avoiding process-lifetime server threads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move full settings validation, including the system DNS lookup, to a
blocking worker with a ten-second response deadline. The worker owns a
private config copy, so a late result cannot persist settings or restart
the daemon after the request times out.

Keep birthday lookup and both prepare paths outside apply_lock. Verify
responsiveness on a single async worker and timeout handling independently
of real DNS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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