Skip to content

feat(transfer): populate DeltaChunk.expected_strong from basis signature (BR-3i.d) - #4646

Merged
oferchen merged 1 commit into
masterfrom
feat/transfer-populate-expected-strong-br3id
May 21, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/transfer-populate-expected-strong-br3id

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Closes the receiver-side verify gap left open by BR-3i.c (feat(engine): implement real verify_chunk in ParallelDeltaApplier (BR-3i.c) #4640). That PR added DeltaChunk::expected_strong: Option<ChecksumDigest>, the with_expected_strong() builder, and a real verify_chunk that compares strategy.compute(&chunk.data) against expected_strong. With no receiver populating the field, every basis-match chunk slipped through verify in "compute digest, skip comparison" mode and corrupted basis bytes could commit silently. This PR wires the basis signature's stored strong digest into DeltaChunk::expected_strong for every COPY-equivalent token.
  • Adds delta_pipeline::chunk_builder (crates/transfer/src/delta_pipeline/chunk_builder.rs), a wire-token to DeltaChunk adapter. For DeltaToken::BlockRef (the receiver-side equivalent of upstream's COPY token) it looks up the referenced block in the negotiated FileSignature, copies its stored strong digest into a ChecksumDigest, and stamps it via with_expected_strong. For DeltaToken::Literal it leaves expected_strong = None because the sender does not embed per-literal digests. DeltaToken::End produces no chunk.
  • Adapter is wire-protocol-free and feature-gated behind parallel-receive-delta (the same gate that exposes DeltaChunk). It takes already-resolved literal bytes or already-mapped basis bytes - I/O stays in the existing receiver pipeline; the builder is a pure function from (FileSignature, token, basis-bytes) to Option<DeltaChunk>. The public API of ParallelDeltaApplier is unchanged.
  • Typed ChunkBuilderError::{BlockIndexOutOfBounds, BasisLenMismatch} surface malformed-stream conditions before the verify step, so the receiver does not mis-attribute basis-resolution bugs as checksum mismatches.

Background

Test plan

  • cargo fmt --all -- --check clean
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings clean
  • cargo nextest run -p transfer --features "parallel-receive-delta incremental-flist" -E 'test(chunk_builder)' - 7 new tests, all green
  • cargo nextest run -p engine --features parallel-receive-delta -E 'test(verify)' - 27 tests, all green (BR-3i.c tests still pass)
  • cargo nextest run -p protocol --all-features -E 'test(golden)' - 407 tests, all green (wire format unchanged)
  • cargo nextest run -p transfer --features incremental-flist - new tests merged into the suite (2 pre-existing failures unrelated to this change: relative_absolute_source_preserves_full_prefix is a macOS /var symlink quirk and empty_file_checksum_verification_sha1 was already failing on this branch's HEAD before this PR)

New tests in chunk_builder::tests

  • receiver_populates_expected_strong_for_copy_chunks - asserts a BlockRef token produces a DeltaChunk whose expected_strong equals signature.blocks()[block_index].strong().
  • receiver_leaves_expected_strong_none_for_literal_chunks - asserts Literal tokens leave expected_strong = None.
  • end_to_end_corrupted_basis_fails_verify - synthetic basis whose mapped bytes disagree with the signature's stored digest; ParallelDeltaApplier::apply_chunk_parallel surfaces ChecksumMismatch and bytes_written == 0 because the writer is never touched.
  • block_index_out_of_bounds_surfaces_typed_error - typed error path; sequence counter does not bump.
  • basis_len_mismatch_surfaces_typed_error_before_verify - guards against the receiver feeding mismatched bytes into verify and misattributing the failure to a checksum mismatch.
  • next_chunk_dispatches_each_variant - smoke test for the dispatch helper.
  • from_block_ref_filters_non_blockref_tokens - convenience constructor only accepts BlockRef.

…ure (BR-3i.d)

Add a wire-token to `DeltaChunk` adapter in `delta_pipeline::chunk_builder`
that looks up the basis signature's strong digest for every `BlockRef`
(COPY-equivalent) token and stamps it into `DeltaChunk::expected_strong`
via the builder added on the applier side by BR-3i.c (#4640). Literal
tokens leave the field as `None`: the sender does not embed per-literal
digests, and the applier already skips comparison when nothing is set.

Without this wiring, every basis-match chunk produced for the parallel
receive-delta path slips through `ParallelDeltaApplier::verify_chunk` in
"compute digest, skip comparison" mode, so corrupted basis bytes commit
silently to the destination. With the wiring in place, the receiver-side
verify-chain end-to-end gate added in BR-3i.c finally fires: a basis
whose actual bytes differ from the digest the receiver shipped surfaces
as `ParallelApplyError::ChecksumMismatch` before the per-file mutex is
taken, leaving the destination writer untouched.

The adapter is wire-protocol-free - it never touches the network reader,
the decompressor dictionary, or the disk-commit thread. The caller hands
in already-resolved literal bytes or already-mapped basis bytes, and the
builder produces a `DeltaChunk` with the per-file sequence number bumped
exactly once per emitted chunk. Out-of-bounds block indices and
basis-length disagreements surface as typed `ChunkBuilderError` variants
so the receiver can abort the file without ever feeding mismatched bytes
into the verify step (which would otherwise be reported as a
checksum-mismatch for the wrong reason).

No wire-protocol changes - `DeltaChunk` is purely a receiver-side staging
structure and the expected digest is held in-memory only. Public API of
`ParallelDeltaApplier` is unchanged.

Tests cover the BR-3i.d acceptance criteria:
- copy chunks populate `expected_strong` from the signature
- literal chunks leave `expected_strong = None`
- end-to-end: a corrupted basis surfaces `ChecksumMismatch` and never
  reaches the destination writer
- out-of-bounds block index surfaces typed error without bumping the
  sequence counter
- basis-length mismatch surfaces typed error before verify
- `next_chunk` dispatches each token variant correctly
- `TokenForBuild::from_block_ref` filters non-BlockRef tokens
@github-actions github-actions Bot added the enhancement New feature or request label May 21, 2026
@oferchen
oferchen merged commit 6907fc9 into master May 21, 2026
55 checks passed
@oferchen
oferchen deleted the feat/transfer-populate-expected-strong-br3id branch May 21, 2026 07:18
oferchen added a commit that referenced this pull request Aug 24, 2026
…ure (BR-3i.d) (#4646)

Add a wire-token to `DeltaChunk` adapter in `delta_pipeline::chunk_builder`
that looks up the basis signature's strong digest for every `BlockRef`
(COPY-equivalent) token and stamps it into `DeltaChunk::expected_strong`
via the builder added on the applier side by BR-3i.c (#4640). Literal
tokens leave the field as `None`: the sender does not embed per-literal
digests, and the applier already skips comparison when nothing is set.

Without this wiring, every basis-match chunk produced for the parallel
receive-delta path slips through `ParallelDeltaApplier::verify_chunk` in
"compute digest, skip comparison" mode, so corrupted basis bytes commit
silently to the destination. With the wiring in place, the receiver-side
verify-chain end-to-end gate added in BR-3i.c finally fires: a basis
whose actual bytes differ from the digest the receiver shipped surfaces
as `ParallelApplyError::ChecksumMismatch` before the per-file mutex is
taken, leaving the destination writer untouched.

The adapter is wire-protocol-free - it never touches the network reader,
the decompressor dictionary, or the disk-commit thread. The caller hands
in already-resolved literal bytes or already-mapped basis bytes, and the
builder produces a `DeltaChunk` with the per-file sequence number bumped
exactly once per emitted chunk. Out-of-bounds block indices and
basis-length disagreements surface as typed `ChunkBuilderError` variants
so the receiver can abort the file without ever feeding mismatched bytes
into the verify step (which would otherwise be reported as a
checksum-mismatch for the wrong reason).

No wire-protocol changes - `DeltaChunk` is purely a receiver-side staging
structure and the expected digest is held in-memory only. Public API of
`ParallelDeltaApplier` is unchanged.

Tests cover the BR-3i.d acceptance criteria:
- copy chunks populate `expected_strong` from the signature
- literal chunks leave `expected_strong = None`
- end-to-end: a corrupted basis surfaces `ChecksumMismatch` and never
  reaches the destination writer
- out-of-bounds block index surfaces typed error without bumping the
  sequence counter
- basis-length mismatch surfaces typed error before verify
- `next_chunk` dispatches each token variant correctly
- `TokenForBuild::from_block_ref` filters non-BlockRef tokens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant