Repository navigation
feat(protocol,node)!: sender-chosen ChunkData frames and the Tier-1 extension seam - #1804
Merged
Merged
Conversation
`CHUNK_SIZE` pinned every `ChunkData` payload at 1,024 bytes, so a served MiB cost 1,024 iterations of validate + copy + postcard encode + QUIC write. The constant tracked iroh-blobs' internal granularity, which ADR 038 superseded with 16 KiB bao chunk groups verified independently of frame boundaries. ADR 038 already specified 1 MiB framing; the implementation never followed it. `ChunkData` is now bounded only as non-empty, with the framing layer's 16 MiB `MAX_MESSAGE_SIZE` as the effective ceiling. `CHUNK_SIZE` and `MessageValidationError::ChunkTooLarge` are deleted. A serving node coalesces to the new `payment.frame_target_bytes` (default 1 MiB). The deleted ceiling protected nothing it claimed to: `read_frame` allocates up to `MAX_MESSAGE_SIZE` before postcard decode, and `ChunkData::new` only runs during decode, so the check was always post-allocation. A frame never crosses a `CHUNK_BYTES` payment boundary. The old size got that for free (1,024 divides 1 MiB); at any other size it must be arranged, or the payer settles a residual with a signed voucher per frame instead of releasing one hash-chain preimage per interval. The frame request is also capped by the credit window's remaining room — load-bearing on the miss leg, where the producer is fed by an upstream pull paced against this stream's own served-and-paid frontier, so asking a closed window for a full frame parks on bytes only recouping can unblock. Also in scope: - `encode_chunk_frame` in `decdn-protocol` encodes a frame body straight from its payload, one copy instead of two (#1791 item 2, partial — the remaining copy needs the vectored-write path in item 3). Byte-identical to the generic encoder, pinned by an agreement test and an exact-byte golden vector. - `serve_leg` re-ramps its credit window per iteration instead of pinning it once, so a cache-miss stream is no longer stuck at stop-and-wait while the hit path ramps for the same client (#1769). Wire-breaking new-sender-to-old-receiver; both sides change here per the pre-launch policy. Closes #1796 Closes #1769 Refs #1791 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013RT61oBVimX8KSZ4q2viV7
…; verify probe signatures
Two requester-side obligations the ADRs state and the code did not meet.
## 1. The Tier-1 extension seam
ADR 013 §Tier 1 defines how an unsigned field is added after launch without an
ALPN bump: it trails the frozen base as a separately-encoded `*Ext` struct,
decoded two-phase. Postcard fills no defaults for absent trailing fields, so a
separate value is the ONLY way to append one — an `Option<T>` added to an
existing struct fails to decode against an older sender that never wrote it.
That seam was built exactly once, for `StreamRequestExt`. Everywhere else the
ADRs described it, the code did something else:
- `ProbeResponse.total_bytes` and `StreamResponse.error` were plain fields
embedded between `body` and `slash_sig`, despite ADR 013 §295 stating they
trail `body + signature`.
- `cdn/dht/v1` had no extension at all, despite ADR 013 §10 requiring the
pattern be uniform across the three ALPNs.
So a new unsigned field on any response was a Tier-3 change, and the window for
fixing that closes at first deployment.
`ProbeResponse` is now `{body, slash_sig}` with `total_bytes` in
`ProbeResponseExt`; `StreamResponse` is `{body, slash_sig}` with `error` in
`StreamResponseExt`. `dht.rs` gains `FindValueResponseExt` and `StoreRequestExt`,
empty today — the seam has to exist before the field does.
`StreamResponse::validate` no longer checks `ok`/`error` agreement, because it
can no longer see `error`. That rule spans the signed base and the unsigned
extension, so it moved to `StreamResponseExt::validate`, which takes `ok`; a
receiver calls both.
No contract change, verified by `contracts/` carrying no diff: `SlashJudge` is
coupled to the signed FIELD SET, not the wire encoding — the challenger
re-encodes the four signed fields as a fresh ABI blob, so an unsigned extension
is invisible on-chain.
Also corrects two ADR 013 claims the code contradicts: the signature is EIP-712
typed data over a field set, not a signature over postcard bytes, which is why
an unsigned field's wire position never affected validity.
## 2. Probe `slash_sig` was never verified
`ProbeSlashData::verify_signer` had no production caller. The requester checked
only the signature's LENGTH, so a node could return 65 bytes of anything and be
selected on the `has_blob` and `rate_per_mb` it claimed — and face nothing for
abandoning a rate it never committed to, since an unrecovered signature is not
evidence of anything.
`decdn_client_pull::probe::verify_probe_response` runs the value invariants, the
echoed-field correlation, and recovery to the candidate's registered operator
address (ADR 014 §1). `fetch` and `bundle pull` call it before a response can
influence candidate order; the address was already on `NodeCandidate`, so this
needs no new chain read.
A failure is requester-local policy: drop the response, skip the candidate, as
for a timeout. It is never scored against the peer — a signature that does not
recover attributes nothing to anyone.
The node's own probe-collection loop (`node_origin`) still does not verify: its
candidate carries no operator address and `StakerSet` exposes no reverse
`NodeId -> address` lookup, though the projection holds the pairs. Left for a
follow-up rather than widened into this change.
## Not done, deliberately
Widening `MAX_CHAIN_LENGTH` to `u16`. ADR 003 already weighed and rejected it,
and the cost is higher than a type change — `PaymentPool`'s `uint8` cast is the
ONLY bound on the on-chain keccak walk, so widening needs a new explicit bound
or the walk reaches ~4.2M gas. ADR 003 now records that argument, which it did
not previously state.
Refs ADR 013, ADR 005, ADR 014
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013RT61oBVimX8KSZ4q2viV7
Ten findings from a multi-agent review of the two preceding commits, plus the verification gap that let the first one through. **The anvil-e2e job did not compile.** `pool_floor_credit_bound.rs` still read `resp.error`, which moved to `StreamResponseExt`. Default `nextest` and `clippy --all-targets` are both green on it — only the `anvil e2e` job builds those targets, and it fails before a test runs. **The cache-miss prefetch rested on an undocumented margin.** A serve leg reads one frame past its own shut credit window, and on a miss those bytes can only come from the upstream pull. `PULL_WINDOW_FLOOR` carried two chunk groups, both of which its liveness invariant already spends on the two roundings between paid wire and drawable content — so the prefetch was living on whatever those roundings happened not to use. Measured: a 16 KiB request survives, 64 KiB parks. The floor now carries a third group for the prefetch and the invariant says so, with `frame_target_room_floor_matches_the_pull_reservation` pinning the two sides together. Both are hangs when violated, not failed assertions, which is why they are asserted rather than left to an integration test's timeout. **`payment.frame_target_bytes` above 1 MiB was a silent no-op.** `frame_target` clamps to the payment-chunk remainder, so a frame can never exceed one interval; the config docs promised a 16 MiB ceiling and the resolver declined an upper bound on that basis. Now rejected with a message that says why. **The daemon's own probe path did not verify `slash_sig`.** The preceding commit wired verification into the CLI and left `node_origin` — which reads `rate_per_mb` off a probe and then pays the winner — checking only the shape, while amending ADR 005 to a MUST. `deps.addr_resolver` already resolves the operator address, so this needed no new plumbing. **A wrong `slash_judge_address` reported "none of the probed nodes hold the blob".** Every honest node fails verification under a bad domain, which is a local misconfiguration wearing the costume of missing content. The two buckets are now counted and named separately. **The DHT third of the extension seam was dead code.** Zero callers; the handler still encoded with `encode_message` and discarded the remainder. Wired through both paths, and the untyped `encode_dht_message(msg, Option<&[u8]>)` replaced by per-variant encoders so an extension cannot be attached to the wrong message. Also: `credit_window`'s doc comment had been orphaned onto `frame_target` by an insertion between the two; `frame_target` degraded to one-byte frames rather than surfacing a broken `unvouchered` invariant, and saturated toward `usize::MAX` — unbounded buffering — on a conversion failure; `is_delivery_side` had no non-test caller and now backs the mid-stream exclusion it documents; the `ok`/`error` and `ChunkData` invariant docs pointed at validators and doors that no longer hold them; ADR 005 and 014 still showed `error?` inline in `StreamResponse`; and `pool_floor_credit_bound.rs` claimed to exercise `serve_via_backend_origin`, which it does not — it seeds no outboard, so the lane degrades to the buffered fill path. Not fixed, deliberately: #1769's re-ramp still has no regression test. Two attempts failed for the same structural reason — on the miss path the serve window is always coupled to the upstream pull window, since a node can only front bytes it has itself fetched and paid for, so no client-side observable isolates the serve-side window. A guard needs either control of the upstream pacer or the window derivation extracted from both loops. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013RT61oBVimX8KSZ4q2viV7
There was a problem hiding this comment.
Pull request overview
This PR makes pre-launch, wire-breaking protocol updates across cdn/client/v1, cdn/probe/v1, and cdn/dht/v1 to (1) remove the fixed 1 KiB ChunkData framing constraint, (2) standardize ADR-013 Tier‑1 “trailing extension” evolution seams across all ALPNs, and (3) ensure probe slash_sig is verified before responses influence provider selection.
Changes:
- Protocol: remove
CHUNK_SIZE/ChunkTooLarge, introduce sender-chosenChunkDataframe sizing, and add fast-pathencode_chunk_frame. - Protocol: move unsigned fields into trailing
*Extstructs with typed encode/parse helpers for probe/client/dht messages; adjust validation accordingly. - Node / client-pull / CLI: plumb two-phase decoding/encoding, add probe signature verification to selection paths, and introduce
payment.frame_target_byteswith config resolution/validation.
Reviewed changes
Copilot reviewed 47 out of 47 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/protocol/tests/snapshots/public_api__public_api.snap | Updates public API snapshot for new *Ext types and encode/parse helpers; removes CHUNK_SIZE. |
| crates/protocol/src/message.rs | Implements ProbeResponseExt and two-phase encode/parse helpers; updates docs and tests. |
| crates/protocol/src/lib.rs | Re-exports new extension types and encode/parse helpers; drops CHUNK_SIZE. |
| crates/protocol/src/framing.rs | Extends framing tests to cover Tier‑1 trailing extension remainder behavior. |
| crates/protocol/src/dht.rs | Adds empty Tier‑1 extension structs and typed encode/parse helpers for DHT variants. |
| crates/protocol/src/client.rs | Removes fixed chunk size, adds StreamResponseExt, adds encode_chunk_frame, and shifts ok/error validation to the extension. |
| crates/node/tests/support/mod.rs | Adds helper to read StreamResponse + trailing StreamResponseExt in tests. |
| crates/node/tests/sighup_signal.rs | Updates test config seed to include frame_target_bytes. |
| crates/node/tests/probe_warm_reconnect.rs | Adapts probe helper return shape to include ProbeResponseExt. |
| crates/node/tests/probe_loopback.rs | Updates probe loopback tests to parse ProbeResponseExt.total_bytes from trailing bytes. |
| crates/node/tests/origin_range_pull.rs | Adjusts refusal assertions for moved StreamResponse.error into trailing extension. |
| crates/node/tests/node_to_node_pull_through.rs | Updates stream open/refusal assertions; adapts hostile upstream fixtures to new encoding/ext. |
| crates/node/tests/node_origin_pull.rs | Updates hostile server fixtures for two-phase probe/stream responses and sender-chosen frame sizing. |
| crates/node/tests/client_loopback.rs | Updates client loopback tests to read StreamResponseExt and to handle two-phase open frames. |
| crates/node/tests/anvil_bringup_shutdown_e2e.rs | Updates e2e config construction to include frame_target_bytes. |
| crates/node/src/runtime/reload.rs | Adds frame_target_bytes to runtime config defaults and restart-required warning text. |
| crates/node/src/runtime/mod.rs | Plumbs payment.frame_target_bytes into ClientHandlerDeps. |
| crates/node/src/node_origin/mod.rs | Verifies probe slash_sig (via verify_probe_response) before a probe result influences selection. |
| crates/node/src/handlers/probe.rs | Encodes probe responses two-phase with ProbeResponseExt trailing bytes. |
| crates/node/src/handlers/dht.rs | Wires DHT Tier‑1 seam: two-phase encode for FindValueResponse and parses store-request ext on read. |
| crates/node/src/handlers/client/wire.rs | Splits signed base vs unsigned extension for StreamResponse; adds a dedicated writer for two-phase responses. |
| crates/node/src/handlers/client/window.rs | Switches open-stage StreamResponse writes to two-phase writer. |
| crates/node/src/handlers/client/serve_leg.rs | Implements per-iteration credit-window re-ramp and frame targeting; uses encode_chunk_frame fast path. |
| crates/node/src/handlers/client/serve_encoder.rs | Updates coherent framing producer to accept caller-provided per-frame targets. |
| crates/node/src/handlers/client/mod.rs | Adds frame_target_bytes to handler deps/state and implements frame_target logic + tests. |
| crates/node/src/handlers/client/dispatch.rs | Switches stream open response to two-phase writer. |
| crates/node/src/handlers/client/delivery.rs | Generalizes framing to variable targets and uses encode_chunk_frame fast path on the cache-hit path. |
| crates/e2e/tests/pool_floor_credit_bound.rs | Updates open-stage parsing to read StreamResponseExt from trailing bytes. |
| crates/e2e/src/client.rs | Adapts probe calls to new (resp, ext, rtt) return shape; adjusts refusal messaging. |
| crates/common/src/config/types.rs | Adds payment.frame_target_bytes to config schema. |
| crates/common/src/config/resolved.rs | Adds resolved frame_target_bytes field. |
| crates/common/src/config/mod.rs | Introduces DEFAULT_FRAME_TARGET_BYTES and validates payment.frame_target_bytes in resolution. |
| crates/client-pull/src/probe.rs | Returns ProbeResponseExt from probes and adds verify_probe_response (invariants + correlation + signature recovery). |
| crates/client-pull/src/pacer.rs | Raises PULL_WINDOW_FLOOR to reserve an extra chunk group for miss-path prefetch; updates liveness test. |
| crates/client-pull/src/lib.rs | Implements two-phase open-stage read + StreamResponseExt validation; updates refusal handling accordingly. |
| crates/cli/tests/config_validate.rs | Updates sample resolved config to include frame_target_bytes. |
| crates/cli/src/commands/probe.rs | Threads ProbeResponseExt into CLI output (total_bytes now comes from the extension). |
| crates/cli/src/commands/node.rs | Updates probe ranking to match new probe return tuple shape. |
| crates/cli/src/commands/fetch.rs | Verifies probe signatures before ordering candidates; improves “none hold blob” vs “unverifiable/misconfig” error reporting. |
| crates/cli/src/commands/config.rs | Documents payment.frame_target_bytes in the default config template. |
| crates/cli/src/commands/bundle_pull.rs | Passes slash domain into probe selection for signature verification. |
| CHANGELOG.md | Documents wire-breaking extension relocation, sender-chosen frames + new config, credit-window re-ramp fix, and probe signature verification. |
| adr/038-bao-verified-range-streaming.md | Updates wire-format text to sender-sized framing (bounded by payment interval). |
| adr/014-on-chain-verification.md | Updates signed-field inventory to reflect base + extension split. |
| adr/013-schema-evolution.md | Clarifies Tier‑1 extension mechanics and notes large ChunkData framing behavior under the cap. |
| adr/005-protocol.md | Updates diagrams and rules for extension split, sender-sized frames, and mandatory probe signature recovery. |
| adr/003-payments.md | Adds explicit rationale about the uint8 cast being the on-chain hash-walk bound. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 81.71% (was 81.66%, ▲ +0.05%) — 65769/80495 lines
History
|
…se extension Both from review of #1804, both artefacts of edits in the preceding commits. `ChunkData`'s doc carried "A shorter final frame" twice — a phrase replacement left the original stub in front of its own replacement. `origin_range_pull`'s paid-pull fixture still read the open frame with `read_client_msg`, discarding the trailing `StreamResponseExt`, and asserted `ok` with a placeholder string that could not name the refusal code. It now reads two-phase via `read_stream_response`, so a refusal reports the code that caused it. This fixture was meant to move with its siblings in the extension commit; the edit did not match and was not re-checked. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013RT61oBVimX8KSZ4q2viV7
thiras
added a commit
that referenced
this pull request
Aug 26, 2026
…ites (#1791) Group D serve-path hot path: the per-MiB cost is per-frame validation + copies + allocations + QUIC writes. 1 KiB frames were already lifted to sender-chosen ≤1 MiB in #1804; this finishes items 2 and 3 without a wire change (pre-launch, but byte-identical so no ALPN bump needed). - protocol: add CHUNK_DATA_HEADER_MAX / CHUNK_FRAME_HEADERS_MAX, encode_chunk_data_header / encode_chunk_frame_headers on a stack [u8;11] (framing varint + discriminant + varint(payload_len)) validated against MAX_MESSAGE_SIZE (new ChunkTooLarge), reusing framing::encode_varint_u32; add ChunkTooLarge to MessageValidationError; validate encode_chunk_frame as well (crates/protocol/src/client.rs, framing.rs, message.rs). - node: replace BytesMut coalescer with VecDeque<Bytes> queue + queued in ChunkFramer (delivery.rs) and CoherentFrameProducer (serve_encoder.rs); next_frame_chunks returns Vec<Bytes> slices via Bytes::split_to (zero-copy spanning), next_frame kept #[cfg(test)] for framing_matches_slice_chunks_at_every_target. - node: wire.rs add write_chunk_payload{_multi} — header on stack (≤11 B) + payload Bytes via SendStream::write_all_chunks (noq-1.0.0 vectored, reference-counted). sum(payload_chunks) == total_len checked, empty rejected. serve_leg + delivery loops switched to next_frame_chunks + write_chunk_payload_multi; credit window accounting unchanged, faulted is now terminal on the miss leg (mirrors hit path). Verified: cargo build/clippy clean, cargo nextest -p decdn-protocol (145), -p decdn-node lib/framing (4) + client_loopback (110) + node_to_node (4); vectored header == old postcard+framing bytes (1 MiB golden via /tmp/vec_test). Refs #1791
thiras
added a commit
that referenced
this pull request
Aug 26, 2026
…ites (#1791) Group D serve-path hot path: the per-MiB cost is per-frame validation + copies + allocations + QUIC writes. 1 KiB frames were already lifted to sender-chosen ≤1 MiB in #1804; this finishes items 2 and 3 without a wire change (pre-launch, but byte-identical so no ALPN bump needed). - protocol: add CHUNK_DATA_HEADER_MAX / CHUNK_FRAME_HEADERS_MAX, encode_chunk_data_header / encode_chunk_frame_headers on a stack [u8;11] (framing varint + discriminant + varint(payload_len)) validated against MAX_MESSAGE_SIZE (new ChunkTooLarge), reusing framing::encode_varint_u32; add ChunkTooLarge to MessageValidationError; validate encode_chunk_frame as well (crates/protocol/src/client.rs, framing.rs, message.rs). - node: replace BytesMut coalescer with VecDeque<Bytes> queue + queued in ChunkFramer (delivery.rs) and CoherentFrameProducer (serve_encoder.rs); next_frame_chunks returns Vec<Bytes> slices via Bytes::split_to (zero-copy spanning), next_frame kept #[cfg(test)] for framing_matches_slice_chunks_at_every_target. - node: wire.rs add write_chunk_payload{_multi} — header on stack (≤11 B) + payload Bytes via SendStream::write_all_chunks (noq-1.0.0 vectored, reference-counted). sum(payload_chunks) == total_len checked, empty rejected. serve_leg + delivery loops switched to next_frame_chunks + write_chunk_payload_multi; credit window accounting unchanged, faulted is now terminal on the miss leg (mirrors hit path). Verified: cargo build/clippy clean, cargo nextest -p decdn-protocol (145), -p decdn-node lib/framing (4) + client_loopback (110) + node_to_node (4); vectored header == old postcard+framing bytes (1 MiB golden via /tmp/vec_test). Refs #1791
thiras
added a commit
that referenced
this pull request
Aug 26, 2026
…ites (#1791) Group D serve-path hot path: the per-MiB cost is per-frame validation + copies + allocations + QUIC writes. 1 KiB frames were already lifted to sender-chosen ≤1 MiB in #1804; this finishes items 2 and 3 without a wire change (pre-launch, but byte-identical so no ALPN bump needed). - protocol: add CHUNK_DATA_HEADER_MAX / CHUNK_FRAME_HEADERS_MAX, encode_chunk_data_header / encode_chunk_frame_headers on a stack [u8;11] (framing varint + discriminant + varint(payload_len)) validated against MAX_MESSAGE_SIZE (new ChunkTooLarge), reusing framing::encode_varint_u32; add ChunkTooLarge to MessageValidationError; validate encode_chunk_frame as well (crates/protocol/src/client.rs, framing.rs, message.rs). - node: replace BytesMut coalescer with VecDeque<Bytes> queue + queued in ChunkFramer (delivery.rs) and CoherentFrameProducer (serve_encoder.rs); next_frame_chunks returns Vec<Bytes> slices via Bytes::split_to (zero-copy spanning), next_frame kept #[cfg(test)] for framing_matches_slice_chunks_at_every_target. - node: wire.rs add write_chunk_payload{_multi} — header on stack (≤11 B) + payload Bytes via SendStream::write_all_chunks (noq-1.0.0 vectored, reference-counted). sum(payload_chunks) == total_len checked, empty rejected. serve_leg + delivery loops switched to next_frame_chunks + write_chunk_payload_multi; credit window accounting unchanged, faulted is now terminal on the miss leg (mirrors hit path). Verified: cargo build/clippy clean, cargo nextest -p decdn-protocol (145), -p decdn-node lib/framing (4) + client_loopback (110) + node_to_node (4); vectored header == old postcard+framing bytes (1 MiB golden via /tmp/vec_test). Refs #1791
thiras
added a commit
that referenced
this pull request
Aug 26, 2026
…ites (#1791) (#1828) * perf(node,protocol): zero-copy ChunkData framing via vectored QUIC writes (#1791) Group D serve-path hot path: the per-MiB cost is per-frame validation + copies + allocations + QUIC writes. 1 KiB frames were already lifted to sender-chosen ≤1 MiB in #1804; this finishes items 2 and 3 without a wire change (pre-launch, but byte-identical so no ALPN bump needed). - protocol: add CHUNK_DATA_HEADER_MAX / CHUNK_FRAME_HEADERS_MAX, encode_chunk_data_header / encode_chunk_frame_headers on a stack [u8;11] (framing varint + discriminant + varint(payload_len)) validated against MAX_MESSAGE_SIZE (new ChunkTooLarge), reusing framing::encode_varint_u32; add ChunkTooLarge to MessageValidationError; validate encode_chunk_frame as well (crates/protocol/src/client.rs, framing.rs, message.rs). - node: replace BytesMut coalescer with VecDeque<Bytes> queue + queued in ChunkFramer (delivery.rs) and CoherentFrameProducer (serve_encoder.rs); next_frame_chunks returns Vec<Bytes> slices via Bytes::split_to (zero-copy spanning), next_frame kept #[cfg(test)] for framing_matches_slice_chunks_at_every_target. - node: wire.rs add write_chunk_payload{_multi} — header on stack (≤11 B) + payload Bytes via SendStream::write_all_chunks (noq-1.0.0 vectored, reference-counted). sum(payload_chunks) == total_len checked, empty rejected. serve_leg + delivery loops switched to next_frame_chunks + write_chunk_payload_multi; credit window accounting unchanged, faulted is now terminal on the miss leg (mirrors hit path). Verified: cargo build/clippy clean, cargo nextest -p decdn-protocol (145), -p decdn-node lib/framing (4) + client_loopback (110) + node_to_node (4); vectored header == old postcard+framing bytes (1 MiB golden via /tmp/vec_test). Refs #1791 * fix(protocol): report frame length in ChunkTooLarge and cap encode_chunk_data_header at MAX_MESSAGE_SIZE * fix(protocol): report frame length in encode_chunk_data_header buffer-guard errors * fix(node,protocol): close the #1828 review findings on the zero-copy frame path The vectored path was correct on the wire but had converted several loud failures into silent ones, and left the invariant docs naming a door the serve paths no longer use. - protocol: the ChunkData type doc and MessageValidationError::EmptyChunk enumerate every route to a frame body; both now name all three encode_chunk_* helpers, and encode_chunk_frame_headers rather than encode_chunk_frame as the door the serve paths use. encode_chunk_frame's own doc no longer describes a delivery loop that does not call it. - protocol: encode_chunk_data_header / chunk_frame_postcard_len / CHUNK_DATA_HEADER_MAX / encode_varint_u32 are pub(crate) — the node uses only CHUNK_FRAME_HEADERS_MAX and encode_chunk_frame_headers. Their guards now error rather than write a short header, and the u32 clamp is a map_err, so a MAX_MESSAGE_SIZE change cannot turn one into a wrong length prefix. The stated buffer maxima say what they actually bound. - node: chunk_frame_bufs assembles a frame's write buffers as a pure function and write_chunk_bufs does only I/O, so serve_leg no longer meters a node-side framing fault as node_pull_through_client_abandoned (#856). The <= 4 stack fast path is gone: export items are 64 B proof nodes and 16 KiB leaves, so a 1 MiB frame spans ~130 chunks and never took it, and its guards returned Ok(()) having written nothing. - node: both framers refuse a zero target instead of answering None, which the serve loops read as a fully delivered blob and follow with StreamEnd. drain_frame is shared by both rather than duplicated, and reports a queued/queue desync rather than an end of blob. - node: write_chunk_payload is deleted (unused). Tests: chunk_frame_bufs against encode_chunk_frame + write_frame at 1, 2, 4, 5 and 130 chunks; its length-mismatch and empty refusals; drain_frame boundaries; a zero target on both framers; CoherentFrameProducer's fault is terminal (the twin of a_mid_export_fault_propagates); the header golden test gains the framing-varint boundaries (125/126, 16_381/16_382, 2_097_149/2_097_150) and the 2^21 payload width; EmptyChunk and ChunkTooLarge at the new doors; chunk_frame_postcard_len against the encoded header. Refs #1791 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: yigitdot <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.
Three commits, all pre-launch wire work that stops being cheap the moment
v0.1.0ships binaries to peers that aren't ours.1.
ChunkDataframes become sender's choice (#1796)CHUNK_SIZEpinned every payload at 1,024 bytes, so a served MiB cost 1,024 iterations of validate + copy + postcard encode + QUIC write. The constant tracked iroh-blobs' internal granularity, which ADR 038 superseded with 16 KiB bao chunk groups verified independently of frame boundaries.This is a spec/code divergence, not an optimization —
adr/038:34already specified 1 MiB framing and the implementation never followed it.CHUNK_SIZEandMessageValidationError::ChunkTooLargeare deleted; a serving node coalesces to the newpayment.frame_target_bytes.The deleted ceiling protected nothing it claimed to:
read_frameallocates up toMAX_MESSAGE_SIZEbefore postcard decode, so the check was always post-allocation.Two constraints that are not obvious and are now tested:
CHUNK_BYTESpayment boundary. The old size got that free (1,024 divides 1 MiB). At any other size it must be arranged, or the payer settles residuals with a signed voucher per frame instead of releasing one hash-chain preimage per interval. Caught by three loopback failures mid-development.Folds in #1769:
serve_legre-ramps its credit window per iteration instead of pinning it once, so a cache-miss stream is no longer stuck at stop-and-wait while the hit path ramps for the same client.2. Tier-1 extension seam on all three ALPNs; probe signatures verified
ADR 013 §Tier 1 defines how an unsigned field is added post-launch without an ALPN bump: it trails the frozen base as a separately-encoded
*Ext, decoded two-phase. That seam was built exactly once, forStreamRequestExt. Everywhere else the ADRs described it, the code did something else —ProbeResponse.total_bytesandStreamResponse.errorwere plain fields embedded betweenbodyandslash_sig, andcdn/dht/v1had no extension at all.ProbeResponseandStreamResponseare now{body, slash_sig}with their unsigned fields in trailing*Extstructs;dht.rsgains the same seam, wired through the handler.StreamResponse::validateno longer checksok/erroragreement — that rule spans the signed base and the unsigned extension, so it moved toStreamResponseExt::validate(ok); a receiver calls both.No contract change, verified by
contracts/carrying no diff:SlashJudgeis coupled to the signed field set, not the wire encoding.Separately,
ProbeSlashData::verify_signerhad no production caller. The requester length-checkedslash_sigand never recovered it, so a node could return 65 bytes of anything and be selected on thehas_blobandrate_per_mbit claimed. Now verified on the CLI fetch path and the daemon's own provider selection.Also corrects two ADR 013 claims the code contradicts: the signature is EIP-712 typed data over a field set, not over postcard bytes — which is why an unsigned field's wire position never affected validity.
3. Review fallout
A multi-agent review found ten issues, including one that mattered: the branch did not compile under
--features anvil-e2e. Defaultnextestandclippy --all-targetsare both green on those targets; only theanvil e2ejob builds them, and it fails before a test runs.The other substantive one: the cache-miss prefetch rested on an undocumented margin. Measured rather than argued — a 16 KiB request survives, 64 KiB parks.
PULL_WINDOW_FLOORnow carries a third chunk group for the prefetch, with a test tying it to the serve side's room floor. Both are hangs when violated, not failed assertions, which is why they are asserted rather than left to a timeout.Plus:
frame_target_bytesabove 1 MiB was a silent no-op (now rejected); a wrongslash_judge_addressreported "none of the probed nodes hold the blob" (a config fault dressed as missing content); the DHT seam was dead code (now wired, with per-variant typed encoders); and a set of stale invariant docs pointing at validators and doors that no longer hold them.Not done, deliberately
MAX_CHAIN_LENGTHtou16— ADR 003 already weighed and rejected it, andPaymentPool'suint8cast is the only bound on the on-chain keccak walk, so widening needs a new explicit bound or the walk reaches ~4.2M gas. ADR 003 now records that argument, which it did not previously state.Verification
2,976 tests pass; clippy clean on default and
--features anvil-e2e(CI omits the latter);cargo docclean; public-API snapshot regenerated;contracts/carries no diff.Closes #1796
Closes #1769
Refs #1791
🤖 Generated with Claude Code
https://claude.ai/code/session_013RT61oBVimX8KSZ4q2viV7