Repository navigation
friglet: make the P2P block download cancellable, so Stop / Stop daemon / Quit act within a second (SNB-660) - #40
Merged
Conversation
"Stop scanning", "Stop daemon" and Quit now take effect within milliseconds, also in the middle of a block download from a node that went silent. Before, blindbit-lib downloaded blocks with blocking socket I/O inside the scan future (up to 90 s per attempt, 5 attempts), so the status could say "stopping" for minutes and an exiting daemon gave up waiting for the scan after about 12 s. blindbit-lib: - BlockFetcher::with_cancel(token): the TCP connect is async, the handshake and download run on a thread of their own and the fetch awaits their answer under select! with the token; on cancellation (or drop) the socket is shut down, which wakes the blocked read at once. The backoff sleeps between attempts are cancellable too. A cancelled fetch fails with FetchFailure::Cancelled. - Scanner::watch_chain_until(token) (watch_chain keeps its behaviour): the token also ends the poll and retry waits, the oracle requests and the wait for the next block of the stream. The scan stops only between blocks or while it waits, never part way through applying a block, and returns the new ScanCancelled error: no stall, no backoff. A block whose download is cancelled is not applied at all; the next run resumes at it. A witness restore cut short is taken up again on the next start instead of after 5 min. friglet: - ScanSupervisor hands each run's token to the scan and waits for it to stop by itself; only a task still running CANCEL_GRACE (2 s) after the cancellation is dropped, as before. An error a stopping task returns is not recorded as a scan failure. - Exit waits at most 3 s (was 2 + 10 s) for the scan; the stop messages no longer blame a blocking download. Tests: a scripted P2P peer that stalls mid-block (scan ends within 1 s of the stall, no partial commit, resume at that block), the backoff and poll waits, a stalled witness restore, and a control-socket Stop during a stalled download through the real supervisor (paused within 1 s). With the fetch's cancellation removed, all five fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-660) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Linear: SNB-660 (related: SNB-658 / #37)
Problem
After #37, "Stop scanning" is honest: the daemon says "stopping…" until the scan loop really ends. But blindbit-lib downloaded blocks with blocking socket I/O inside the scan future: up to 90 s per attempt, 5 attempts with backoff. So the stop could take minutes, and an exiting daemon gave up on the scan after about 12 s. Live, against a node stalled mid-block, the
integrationdaemon took 88.5 s to answer Stop.What changes
blindbit-lib
BlockFetcher::with_cancel(token)(p2p.rs). The TCP connect is now async. The handshake and download run on a thread of their own, and the fetch waits for that thread underselect!against the token. On cancel, or when the fetch future is dropped, a second handle shuts the socket down, which wakes the blocked read at once. The backoff sleeps between attempts are cancellable too. A cancelled fetch fails withFetchFailure::Cancelled.Scanner::watch_chain_until(token)(scanning.rs).watch_chain()behaves as before. The token also ends:ScanCancelled, which is not a stall and causes no backoff.friglet
ScanSupervisorhands each run's token to the scan and waits for it to stop by itself. Only a task still running 2 s (CANCEL_GRACE) after the cancel is dropped, as before. An error a stopping task returns is not recorded as a scan failure.Verification
Tests (
cargo test --workspace, debug):cancel_tests::a_stop_during_a_stalled_block_download_ends_the_scan_at_once_and_it_resumes_therecancel_tests::a_stop_ends_the_wait_between_download_attempts: cancels during a 30 s backoff wait.cancel_tests::a_stop_ends_the_wait_for_the_next_poll: runs the realwatch_chain_untiland cancels during its 10 s poll wait.witness_tests::a_stop_during_a_witness_restore_retries_it_when_scanning_resumescontrol::tests::stop_during_a_stalled_p2p_download_pauses_within_a_second: the realBlockFetcheragainst a silent node, under the real supervisor, through the controlStophandler.with_cancelmade a no-op (and the poll sleep un-cancellable), all five new stop tests fail: 11.5 s, 29.7 s, 9.5 s, > 1 s, and Stop 2.0 s (the grace fallback).Live check, signet:
signet.oracle.setor.dev:38333behind a proxy that forwards theblockmessage header and half its payload, then goes silent.Ok)pausedafter StopNot touched: friglet-tray, friglet-ipc.