Repository navigation
feat(p2p): reassemble blocks whose canister HTTP responses were stripped - #11718
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The reconstruction path validates fetched content and the final proposal hash, with focused coverage for pool, peer, and failure scenarios.
Review effort: Balanced
Findings: None
What changed in this PR
Extends stripped block assembly to restore canister HTTP response contents from the local pool or peers while preserving block-hash integrity.
Changes:
- Adds canister HTTP response hashes and message variants.
- Fetches, verifies, and reinserts stripped responses.
- Adds reconstruction tests and dependencies.
| File | Description |
|---|---|
Cargo.lock |
Records the test dependency update. |
rs/p2p/artifact_downloader/Cargo.toml |
Adds a development dependency. |
rs/p2p/artifact_downloader/BUILD.bazel |
Updates test and benchmark dependencies. |
assembler.rs |
Fetches and reconstructs stripped responses. |
canister_http.rs |
Implements payload response reinsertion. |
download.rs |
Adds response download and hash verification. |
stripper.rs |
Initializes response stripping metadata. |
test_utils.rs |
Adds canister HTTP fixtures. |
types.rs |
Adds response message variants. |
types/stripped.rs |
Serializes stripped response hashes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Consensus block reconstruction is operationally sensitive and warrants final human review despite comprehensive validation and tests.
Review effort: Balanced
Findings: None
Resolved since last review (2)
76dfe6f to
9f5ce48
Compare
Teaches a replica to hand a peer the content of a canister HTTP response that was stripped from a block proposal, which is the half of hashes in blocks that has to be in place before anything starts stripping. A new `/block/canister_http_response/rpc` endpoint answers a content hash with the matching `CanisterHttpResponse`, taken from the canister HTTP pool or, once the pool has dropped it, out of the block that delivers it. The new `canister_http` module knows how to walk the response slots of a canister HTTP payload, and documents why every response a payload delivers may be stripped from it: in each case the replicas that signed for it are already holding its content. Note that serving a response deliberately looks past the `ResponseVisibility` of its share. Withholding a fully replicated response only keeps us from *pushing* it at peers that can produce it themselves; it says nothing about answering a peer that is missing one and asks for it by hash. Nothing strips canister HTTP responses yet, so no peer asks and the endpoint is unreachable in practice. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Addresses the review finding that `FlexibleError::TooManyRejects` was the one response-bearing message kind the tests never exercised, even though the module claims to handle every response a payload delivers. Both `find_response` and the RPC now have a case that serves a reject out of such a message. Also narrows the module's claim that stripping "only ever removes bytes and never has to add any": that holds for the payload, whose response metadata already carries the content hash, but the stripped block proposal does spend a little to say which contents it is missing. The accurate statement of the whole invariant belongs with the commit that starts stripping. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Addresses the review finding that `fake_canister_http_payload` claimed to serialize every message it was given while `iterator_to_bytes` silently drops the ones that exceed `MAX_CANISTER_HTTP_PAYLOAD_SIZE`, so an oversized fixture would quietly exercise fewer responses than the test intended. The helper now decodes what it produced and asserts the count, via `assert_no_messages_dropped` so that the check is also available to callers that build a payload themselves. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The fake was defined twice, identically apart from its visibility: once in the library's own `test_utils`, and once in the benchmark, which is a separate target and so cannot see a `#[cfg(test)]` item. Adding the pool parameter to `FetchStrippedConsensusArtifact::new` broke the benchmark, and copying the fake was the wrong way to fix that. It now lives in `ic-p2p-test-utils` alongside `MockValidatedPoolReader` and the other p2p test doubles, which every consumer already imports from. Two identical trait impls that have to be kept in sync by hand is a trap: the same duplication of `fake_canister_http_payload` is what let one copy go on silently truncating payloads after the other had been fixed. It stays a hand-written fake rather than a `mock!` because `get_response_content_by_hash` returns a reference into the pool, which a mock cannot hand back for data it owns itself. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Teaches a replica to put the canister HTTP response contents back into a block proposal that was stripped of them, which is the other half that has to be in place before anything starts stripping. A stripped block proposal now declares the content hashes of the responses that were pruned from its canister HTTP payload, the way it already does for its ingress messages and IDKG dealings. For each of them the assembler looks in the canister HTTP pool, which is indexed by exactly that hash and holds the content until the outcall has been answered, and otherwise fetches it from a peer over the endpoint added in the previous commit. The response is checked against the hash that was asked for, and the reassembled block against the hash of the proposal that was claimed, so a wrong or missing response can only make the block unwanted, never mangle it. Nothing strips canister HTTP responses yet, so no block declares any and the new code paths stay unreached in practice; the tests exercise them by stripping a proposal by hand. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#11717 was squash-merged as b02df10, so this also brings in b443b73, the one commit of it this branch did not have yet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Teaches a replica to hand a peer the content of a canister HTTP response that was stripped from a block proposal — the half of hashes in blocks that has to be in place before anything starts stripping. A new `/block/canister_http_response/rpc` endpoint answers a content hash with the matching `CanisterHttpResponse`, taken from the canister HTTP pool or, once the pool has dropped it, out of the block that delivers it. The new `canister_http` module knows how to walk the response slots of a canister HTTP payload, and documents why **every** response a payload delivers may be stripped from it: in each case the replicas that signed for it are already holding its content. * A fully replicated response is proved by a quorum of `n - f` signatures, one per replica that ran the outcall itself and signed that very content. * A non-replicated or flexible response is produced by a single replica, which therefore gossips it to everyone along with its share. Note that serving a response deliberately looks past the `ResponseVisibility` of its share. Withholding a fully replicated response only keeps us from *pushing* it at peers that can produce it themselves; it says nothing about answering a peer that is missing one and asks for it by hash. Nothing strips canister HTTP responses yet, so no peer asks and the endpoint is unreachable in practice. ### Stack 1. dfinity#11716 — protobuf definitions 2. **dfinity#11717 — serve canister HTTP responses out of a block ← this PR** 3. dfinity#11718 — reassemble blocks whose canister HTTP responses were stripped 4. dfinity#11719 — strip canister HTTP responses from block proposals (turns it on) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
…y their id The block proposal assembler kept the stripped ingress messages and IDKG dealings in vectors, but the canister HTTP responses in a map. As the `PayloadAssembler` trait took a vector, the canister HTTP responses were converted from a map into a vector and back into a map on reassembly. The vectors date back to when the ingress payload was a byte buffer in block order, which the assembler had to reproduce. That order no longer matters since the ingress payload became a map keyed by message id. Keep every kind of stripped artifact in a `BTreeMap` keyed by its id, and hand that map to `try_reconstruct_payload` as is. Inserting a message is now a lookup rather than a linear scan. IDKG dealings are looked up by their dealer index together with their id, which is what they are keyed by, so the trait's `ArtifactId` and `MissingArtifactId` coincide and are merged into one. In the assembler benchmarks, assembling 1000 ingress messages gets up to 9% faster and assembling the largest IDKG payloads up to 7% faster; the other cases are unchanged within noise. Also trim a few comments. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep only the pruned proposal and the claimed id in the block proposal assembler, rather than the whole stripped proposal, whose lists of stripped message ids `new()` used to clone. Decode the responses to stripped message requests straight into their types, as `proxy_decode` already converts them. Test that a single content goes back into several slots of the canister HTTP payload, for both a successful flexible outcall and one that failed with too many rejects, and that a content declared once for each of its slots is fetched only once. Share the assembler test setup, and the fake RPC response between the assembler and download tests. Build the canister HTTP test fixture with `strip()`, use `fake_canister_http_stripped_message` in the download tests, and gather the stripped message ids of a fake stripped proposal in a single exhaustive match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
✅ No security or compliance issues detected. Reviewed everything up to 19937fa. Security Overview
Detected Code Changes
|
Orders the response parsers like the message kinds they handle: ingress, IDKG dealing, canister HTTP response. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#11718 was squash-merged as 3abf5fc. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ndant The assembler tests of #11718 stripped a proposal by hand, as nothing stripped canister HTTP responses yet. Now that stripping does, two of them repeat the round trips, and so do two payload-level tests. The round trips now also check which contents the stripped proposal declared, so that they fail if nothing is stripped, and the two tests that need a proposal the stripper would not produce start from the one it does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y#11719) **This is the PR that turns hashes in blocks on for canister HTTP responses.** A block proposal now goes out without the contents of the responses it delivers, naming them by the content hash it already carries alongside each of them. Receivers have been able to serve (dfinity#11717) and reassemble (dfinity#11718) those contents since the previous two PRs, so this is where the bandwidth saving starts. An outcall response can be up to 2 MB and the block used to carry it to every peer, on top of the copy the replicas already gossip to each other. A payload with nothing to strip is left untouched byte for byte, so a block without an outcall response never pays for being re-encoded. Declaring a stripped content costs 36 bytes in the stripped proposal, its 32-byte hash plus framing, and only contents of at least 64 bytes are stripped, each of which saves at least 70 bytes for every slot it is taken out of. So **stripping a response never makes the proposal that goes out bigger** than the stripped proposal that every data block already goes out as. Break-even is at about 30 bytes of content, and the threshold deliberately stays close to it: the declared hash and the content it replaces both go to every peer, so the comparison is the same whatever the subnet size, and with up to 500 responses per block each byte of slack is multiplied by five hundred — at a 1 KiB threshold a block could have carried half a megabyte of unstripped content to every peer. It also keeps the replica's own terse rejects in the block, which save little or nothing when stripped. A response is stripped whatever kind of outcall it answers, because in each case the replicas that signed for it are already holding its content — see the module docs of `canister_http.rs`. The assembler benchmark gains the canister HTTP dimension, parameterized by the number of signatures a response carries, since that is what dominates the cost of stripping and reassembling. At the 500-response cap with a 40-node quorum, stripping a block costs **5.4 ms** and reassembling one **9.8 ms**. That case uses 1 KiB responses and the 10-byte node ids of the test utilities; with real, 29-byte node ids, 500 responses with 27 signatures each only fit into the 2 MiB payload limit with bodies of about 800 bytes, but the signatures that dominate the cost stay the same. > Earlier revisions of this description quoted 3.4 ms and 6.4 ms for those cases. Two > benchmark cases exceeded `MAX_CANISTER_HTTP_PAYLOAD_SIZE`, and `iterator_to_bytes` > silently drops what does not fit, so they measured roughly 300 responses under a label > claiming 500. The cases are now sized to fit and `fake_canister_http_payload` panics > rather than let that happen again. ### Worth a reviewer's attention For a fully replicated outcall, a node whose own adapter has not produced the response yet when the block arrives used to get the bytes in the block and now does a round trip for them. It is bounded — at least `n - f` peers hold the content, and it is no worse on bandwidth — but it is a new dependency of block assembly on a peer fetch in the common outcall mode, not just the non-replicated one. A receiver puts the payload back together by encoding what it decodes, which only reproduces the bytes the block hash covers because payload validation accepts nothing but canonically encoded canister HTTP payloads (dfinity#11751). ### Stack 1. dfinity#11716 — protobuf definitions (merged) 2. dfinity#11717 — serve canister HTTP responses out of a block (merged) 3. dfinity#11718 — reassemble blocks whose canister HTTP responses were stripped (merged) 4. **this PR — strip canister HTTP responses from block proposals** 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>



Teaches a replica to put the canister HTTP response contents back into a block
proposal that was stripped of them — the other half that has to be in place before
anything starts stripping.
A stripped block proposal now declares the content hashes of the responses that were
pruned from its canister HTTP payload, the way it already does for its ingress
messages and IDKG dealings. For each of them the assembler looks in the canister HTTP
pool, which is indexed by exactly that hash and holds the content until the outcall
has been answered, and otherwise fetches it from a peer over the endpoint added in
#11717.
Declaring the hashes rather than re-deriving them from the payload matters for cost: a
fully replicated response leaves its
n - fsignatures behind in the stripped payload,and scanning those back out of it measured 2.4 ms per block on a full 2 MiB payload
of fully replicated responses with a 40-node quorum — about 26% of block assembly, in a
back-to-back A/B with the scan added back (p = 0.00). Recovering the hashes needs a full
decode, since prost cannot decode part of a message, and the cost is dominated by the
per-field allocations rather than the payload size.
A wrong or missing response can only make the block unwanted, never mangle it: the
fetched response is checked against the hash that was asked for, and the reassembled
block against the hash of the proposal that was claimed.
Nothing strips canister HTTP responses yet, so no block declares any and the new code
paths stay unreached in practice; the tests exercise them by stripping a proposal by
hand.
Stack
🤖 Generated with Claude Code