Skip to content

SEC-130: Harden attended snapshot bootstrap downloads#530

Open
huangminghuang wants to merge 8 commits into
masterfrom
fix/sec-130
Open

SEC-130: Harden attended snapshot bootstrap downloads#530
huangminghuang wants to merge 8 commits into
masterfrom
fix/sec-130

Conversation

@huangminghuang

@huangminghuang huangminghuang commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Problem

Remote snapshot bootstrap previously buffered an unbounded response in memory and lacked explicit response-size, disk-capacity, and partial-file guarantees. The first hardening pass added network deadlines, but request-write coverage was incomplete and fixed time limits do not fit the trusted, attended bootstrap model.

Solution

  • stream snapshot bodies through fixed 64 KiB parser/read buffers with one ceiling for fixed-length, chunked, and lengthless responses
  • centralize decoded body increments so the bounded error diagnostic and main download loop share buffer setup, parser-read, need_buffer normalization, and byte accounting
  • use the existing chain-state-db-size-mb value as the response-size ceiling; add no snapshot-specific timeout, size, or disk-reserve options
  • keep the always-on 64 MiB disk-safety margin internal instead of exposing an unused per-download reserve field; deterministic disk tests inject only the free-space query through private test access
  • report connection/request phases and five-second transfer updates with bytes, percentage, rate, and ETA when Content-Length is available
  • keep network phases operator-controlled and make Ctrl+C cancel pending resolve, connect, request-write, response-header, metadata, and body-read operations
  • preflight and periodically recheck disk capacity with a 64 MiB concurrent-consumer margin, then atomically rename successful downloads and remove .downloading files on failure or cancellation
  • preserve up to 200 decoded bytes from non-200 response bodies in operator diagnostics without unbounded buffering
  • reuse the metadata connection with one opt-in stale-connection retry for the idempotent download request
  • require explicit download resource options and remove the unused legacy unbounded post_to_file overload

Validation

  • 20 focused HTTP cases covering cancellation in write/header/body/metadata phases, progressing transfers without a total deadline, fixed/chunked response ceilings, bounded non-200 diagnostics, truncated fixed-length cleanup, progress totals, stale keep-alive reuse/retry, and disk budgets
  • full test_chain_plugin suite: 14 cases passed
  • focused chain-plugin option registration/removal and response-size validation
  • snapshot_api_test coverage for latest and block-specific snapshot bootstrap; Python syntax validation passed after removing the obsolete option
  • git diff --check

The system-contract e2e gate is not applicable because the PR diff does not change contracts/sysio.*.

Operational note

The selected snapshot endpoint is trusted and bootstrap is attended. Network phases therefore have no automatic deadline; a stalled provider waits for the operator to press Ctrl+C. Response bytes and disk usage remain bounded independently of that policy.

@huangminghuang
huangminghuang marked this pull request as ready for review July 20, 2026 23:46
@huangminghuang
huangminghuang requested a review from heifner July 20, 2026 23:46
Comment thread docs/snapshot-serving-plan.md Outdated
@huangminghuang huangminghuang changed the title SEC-130: Bound snapshot bootstrap downloads SEC-130: Harden attended snapshot bootstrap downloads Jul 22, 2026
@huangminghuang
huangminghuang requested a review from heifner July 22, 2026 19:55
Comment thread docs/snapshot-serving-plan.md Outdated

@heifner heifner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three low-severity cleanup notes on the bounded download path — none blocking. The size ceiling, disk-headroom checks, cancellation, and stale-connection retry all look correct and are well covered by the new tests.

Comment thread libraries/libfc/src/network/http/http_client.cpp
Comment thread libraries/libfc/src/network/http/http_client.cpp Outdated
Comment thread libraries/libfc/src/network/http/http_client.cpp Outdated
Comment thread plugins/chain_plugin/src/chain_plugin.cpp Outdated
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.

2 participants