Repository navigation
feat(p2p): strip canister HTTP responses from block proposals - #11719
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
One benchmark silently truncates its workload, and the implementation does not uphold the stated always-smaller wire-size guarantee.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Enables stripping and reassembly of canister HTTP response bodies to reduce block proposal bandwidth.
Changes:
- Strips response bodies while retaining content hashes.
- Adds round-trip tests for all response variants.
- Extends assembler benchmarks with canister HTTP workloads.
| File | Description |
|---|---|
test_utils.rs |
Adds HTTP reject, error, and timeout fixtures. |
stripper.rs |
Activates canister HTTP response stripping. |
canister_http.rs |
Implements stripping and tests round-trip behavior. |
assembler.rs |
Adds end-to-end assembly tests. |
benches/assembler.rs |
Adds canister HTTP benchmarks. |
features/src/lib.rs |
Updates feature documentation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Good catch, and it invalidated a claim in the previous revision of this description. The earlier commit added the count assertion to With the check genuinely active, all cases run clean, so the resized ones do fit. The |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The 64-byte threshold does not guarantee the claimed whole-proposal size invariant, and documentation incorrectly states that all responses are stripped.
Review effort: Balanced
Findings: 2
Open (2)
Resolved since last review (1)
49331c6 to
841544e
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]>
The assembler's tests now encode the RPC responses through `rpc_response` and no longer import `ProtoProxy`, which the size tests of this branch still need. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#11718 was squash-merged as 3abf5fc. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The payload that the round trips strip and reassemble now also carries a divergence response, an out-of-cycles error, an asynchronous receipt, the timeout, too-large and out-of-cycles errors of a flexible outcall, the extra shares of a flexible group and of too many rejects, and a reject delivered by a plain response. Stripping re-encodes every message of the payload, so all of them have to come back byte for byte, not only the ones that deliver a response. 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]>
|
✅ No security or compliance issues detected. Reviewed everything up to 59017bc. Security Overview
Detected Code Changes
|
The fake reject is built from `MIN_STRIPPED_CONTENT_BYTES` rather than from a message long enough to exceed it, and the crate exports the constant, so that the benchmark no longer keeps a copy of it. The test of identical responses no longer carries a response too small to be stripped, which `tiny_responses_are_not_stripped_test` covers, and a new test checks that putting the contents back into a payload is idempotent. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p2p (dfinity#11872) The persistent consensus pool loads a block proposal's payload lazily: the first time the payload is accessed, in a read transaction of its own. It deletes the payload together with the block. p2p reads block proposals from the pool through `ValidatedPoolReader`, and touches their payload only after letting go of the lock on the pool: - the stripped-message RPC handlers (`/block/ingress/rpc`, `/block/idkg_dealing/rpc` and `/block/canister_http_response/rpc`) look up the message in the block that the requesting peer names; - a summary block that a peer pulls goes out unstripped, and is encoded after the lookup; - the initial broadcast hands the block proposals it collected to the sender, which strips them once the artifact processor is running. The purger deletes non-finalized blocks once their height is finalized, and old blocks after each CUP. If it deletes the block in between, loading the payload panics on the `unwrap()` in the payload loader in `lmdb_pool.rs`, and the replica aborts, as it does on any panic. `ConsensusPoolImpl` now loads a block proposal's payload in `ValidatedPoolReader::get` and `get_all_for_initial_broadcast`, while the caller still holds the lock. Every caller needs the payload anyway; it just no longer loads it after letting go of the lock. The new test `test_block_proposals_for_peers_come_with_their_payload` gets a proposal both ways, removes the block from the pool and then reads the payloads. On master it panics in the payload loader. With the payload already loaded, stripping a block proposal no longer needs the lock, so `ConsensusPoolWrapper::get` strips it after letting go. Since dfinity#11719 that includes re-encoding the canister HTTP payload, up to 5.4 ms for a block at the 500-response cap. ### Worth a reviewer's attention - The stripped-message handlers now hold the read lock while the payload loads. It is the same work as before, but it now holds up the consensus thread's next write for that long. - The initial broadcast now loads the payloads of all validated block proposals above the latest CUP when it collects them, and keeps them until each has been sent, rather than loading one at a time as the sender strips them. That is more memory at startup, up to a DKG interval of block payloads, before consensus starts. Consensus itself is not affected: it reads blocks through `ConsensusPool`, not `ValidatedPoolReader`, so its caches keep loading payloads lazily. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>



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 (#11717) and reassemble (#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.
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 - fpeers hold the content, and it is no worse onbandwidth — 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 (#11751).
Stack
🤖 Generated with Claude Code