Repository navigation
friglet-ipc: replace the scan key atomically (SNB-683) - #59
Closed
setavenger wants to merge 2 commits into
Closed
setavenger wants to merge 2 commits into
setavenger wants to merge 2 commits into
Conversation
friglet-ipc items only its own module uses are private now:
write_message, read_message, SpDescriptor::scan_pubkey,
descriptor_checksum, the log-file constants and RotatingLog::with_limit.
No other crate in the workspace uses them, and neither does friglet-ui
(it uses Request/Response/StatusInfo, Client, listen, accept,
read_config_toml and DaemonConfig).
Comments: no frigletctl tool exists; state_file documents the per-wallet
file name; OkWithNote's example is what the daemon sends today;
oracle_connected describes the background poll, not a cache TTL. The
default oracle_url uses the same constant as hosted_oracle_url("bitcoin")
instead of repeating the URL. The roundtrip test sets scan_health twice;
blindbit-cli has four comments that restate the next line.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
write_key_file(.., overwrite = true) truncated scan.key and then wrote
it. A crash between the two left an empty key file, and the daemon would
not start until the key was entered again. It now writes
`<name>.tmp` in the same directory (0600 from creation, enforced again
for a leftover temp file), syncs it and renames it over the key file,
like write_config_toml. The file format ("<hex>\n") and the 0600 mode
are unchanged; creating a new key (overwrite = false) still fails when
the file exists.
New test: a reader thread rereads the key while it is replaced 200
times and must only ever see the old or the new key. On the old code it
sees an empty file (failed 13 of 13 runs).
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 #55; review only the commits after it.
Fixes SNB-683 (Bug). Part of the friglet cleanup (SNB-661).
The bug
friglet_ipc::write_key_file(path, hex, overwrite = true)openedscan.keywithtruncateand then wrote the key. A crash between the two left an empty key file, and the daemon would not start ("key file … is empty") until the key was entered again. The callers are the daemon'sSetScanKey/ApplySettings, the descriptor-key migration at startup and the tray's first-run setup.The fix (minimal)
overwrite = truenow replaces the key the waywrite_config_tomlalready writes the config:<name>.tmpin the same directory, 0600 from creation (and enforced again, in case a crash left an old temp file).sync_all, thenrenameit over the key file.The format (
<hex>\n) and the 0600 mode are unchanged.overwrite = false(first key) is unchanged:create_new, fails if the file exists.One edge-case difference, the same as for the config file: a key file that is a symlink is now replaced by a regular file instead of having its target rewritten.
Test
replacing_the_key_file_never_exposes_an_empty_file(Unix): a reader thread rereads the key file while it is replaced 200 times. It may only see the old key or the new one. Afterwards the mode is still 0600 and no.tmpfile is left. The test applied to the oldwrite_key_filefailed 13 of 13 runs (a reader saw ""); with the fix it passes (0.5 s).Verification
cargo check --workspace --all-targets --all-features: 0 warningscargo clippy --no-deps -p friglet -p friglet-ipc -p friglet-tray --all-targets -- -D warnings: cleancargo fmt -p friglet -p friglet-ipc -p friglet-tray -- --check: cleancargo test --workspace: 255 passed, 1 ignored, 0 failed (254 + the new test)x86_64-pc-windows-gnustd is not installed here). The Windows path uses the samestd::fs::renameaswrite_config_toml.