You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(p2p): serve canister HTTP responses out of a block - #11717
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.
find_response fully decodes and allocates every response in the (up to 2 MiB) payload for each lookup. A block may contain 500 response slots, and the assembler fetches missing objects concurrently, so the block fallback can make a serving replica perform hundreds of identical full decodes and transiently allocate roughly a payload copy per request. Please avoid reparsing per hash—for example, cache/index the decoded responses per block or support a batched lookup; streaming decoding alone would reduce allocation but not the repeated-scan cost.
Detect silently truncated payloads in iterator_to_bytes
iterator_to_bytes silently drops messages that do not fit the limit, so this helper can return a truncated payload while claiming to serialize all supplied messages. That can make tests and benchmarks exercise fewer responses than intended (the linked #11719 description notes this exact failure mode). Assert that the decoded message count matches the input count so oversized fixtures fail loudly.
Thanks — going through the two "previously missed" findings.
Truncated fixtures in fake_canister_http_payload: fixed in a918eb9. The helper
now decodes what it produced and asserts the message count, so an oversized fixture
fails loudly instead of quietly exercising fewer responses. Extracted as assert_no_messages_dropped so a caller that builds a payload itself can use it too.
This also caught a real instance of the failure mode in the benchmark further up the
stack, which had its own copy of the helper.
find_response re-decoding the payload per lookup: accepted for now, knowingly.
The analysis is right — a serving replica that falls back to the block decodes up to
2 MiB per requested hash, and the assembler fetches concurrently, so one block can
trigger many identical decodes. Ingress and IDKG avoid this because they can index
directly (get_serialized_by_id, the transcript map); the canister HTTP payload is an
opaque byte string, so a scan is the only option without extra machinery.
Two things bound it: the canister HTTP pool is consulted first, so the block path only
comes into play once the response has been delivered and the content purged, and the
handler already runs on the blocking pool rather than an async worker.
The fixes we considered and deferred, in case this needs revisiting: a one-entry cache
of the decoded payload keyed by block id, which would collapse a burst of requests for
the same block into a single decode for around twenty lines; or a batched RPC that
answers several hashes per request, which is the better shape but changes the protocol.
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]>
…nity#11716)
Adds the protobuf definitions that stripping the canister HTTP responses
from a
block proposal needs, without using any of them yet.
* `GetCanisterHttpResponseInBlock{Request,Response}` — the RPC a replica
will use
to fetch a response content that was stripped from a block it is
reassembling.
* `StrippedBlockProposal::stripped_canister_http_responses` — the
content hashes
of the responses that were stripped from a block proposal.
The one Rust change is the struct literal that the new field forces,
which leaves
it empty: nothing strips canister HTTP responses yet.
### Stack
1. **dfinity#11716 — protobuf definitions ← this PR**
2. dfinity#11717 — serve canister HTTP responses out of a block
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]>
Addresses review comments on serving canister HTTP responses out of a block.
`find_response` now decodes the payload one message at a time and stops at the
one that delivers the response, instead of decoding the whole payload first.
`parse` and the error type, which only it used, go until reassembly needs them.
The docs now give the actual reason why a stripped response can always be
found: the peers that advertise a block hold it in full and serve a response
out of it once their canister HTTP pool has dropped it, so the receiver's own
pool merely saves the round trip. The module doc no longer claims that taking
a response out of a payload requires putting nothing in its place.
Test fixtures that nothing else uses are private, and a test covers a response
that a later message than the first delivers.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
► rs/p2p/artifact_downloader/benches/assembler.rs Extend mocks to include FakeCanisterHttpPool, adjust imports
Enhancement
► rs/p2p/artifact_downloader/src/fetch_stripped_artifact/assembler.rs Update to use CanisterHttpPool in imports and struct, inject canister_http_pool, adjust tests to include FakeCanisterHttpPool
Enhancement
► rs/p2p/artifact_downloader/src/fetch_stripped_artifact/canister_http.rs (new file) Implement canister HTTP payload handling: find_response, response_slots, flexible_response_slots, tests for canister http payload parsing
Enhancement
► rs/p2p/artifact_downloader/src/fetch_stripped_artifact/download.rs Extend Pools with canister_http_pool and get_canister_http_response logic Add CanisterHttpPoolAccessError enum and related handling in download flow Add AXUM route and handler for canister_http_response RPC Update imports to include canister_http and related types
Enhancement
► rs/p2p/artifact_downloader/src/fetch_stripped_artifact/mod.rs Add mod canister_http; expose canister_http functionality
Enhancement
► rs/p2p/artifact_downloader/src/fetch_stripped_artifact/test_utils.rs Extend test utilities to support canister HTTP payloads, responses, and helpers (fake_canister_http_payload, fake_canister_http_response, etc.)
Enhancement
► rs/p2p/artifact_downloader/src/fetch_stripped_artifact/types.rs Add CanisterHttpResponseContentHash type alias and related imports
Addresses review comments on serving canister HTTP responses out of a block.
`ic_types::batch::slice_to_messages_iter` decodes a payload one message at a
time, as a lazy counterpart of `slice_to_messages`, which now collects it.
`find_response` decodes through it, so this crate no longer needs to know how
the payload is framed, and no longer depends on prost.
`for_each_response_slot` becomes `response_slots`, which returns the slots of a
single message, so that `find_response` is a plain search that stops at the
slot delivering the response. It lists every kind of flexible error, so that a
new kind fails to compile until it is handled. A response that cannot be
decoded no longer ends the search, as another slot may deliver the same
content.
The doc of the slots now only says what they are; why a block does not need to
carry the responses moved into the module doc. The canister HTTP pool fake can
fail a test that looks up a response content, which the tests serving an
ingress message or an IDKG dealing now do.
Co-Authored-By: Claude Opus 5.5 <[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]>
AleDema
pushed a commit
to AleDema/ic
that referenced
this pull request
Oct 18, 2026
…ped (dfinity#11718)
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
dfinity#11717.
Declaring the hashes rather than re-deriving them from the payload
matters for cost: a
fully replicated response leaves its `n - f` signatures 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
1. dfinity#11716 — protobuf definitions
2. dfinity#11717 — serve canister HTTP responses out of a block
3. **this PR — reassemble blocks whose canister HTTP responses were
stripped**
4. next — 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]>
AleDema
pushed a commit
to AleDema/ic
that referenced
this pull request
Oct 18, 2026
…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]>
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
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.
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/rpcendpoint answers a content hash with thematching
CanisterHttpResponse, taken from the canister HTTP pool or, once the poolhas dropped it, out of the block that delivers it. The new
canister_httpmoduleknows 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.
n - fsignatures, one perreplica that ran the outcall itself and signed that very content.
therefore gossips it to everyone along with its share.
Note that serving a response deliberately looks past the
ResponseVisibilityof itsshare. 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
🤖 Generated with Claude Code