Skip to content

feat(p2p): serve canister HTTP responses out of a block - #11717

Merged
eichhorl merged 7 commits into
masterfrom
eichhorl/ch-hib-2-serve
Oct 8, 2026
Merged

eichhorl merged 7 commits into
masterfrom
eichhorl/ch-hib-2-serve

Conversation

@eichhorl

@eichhorl eichhorl commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

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. chore(protobuf): add the canister HTTP hashes-in-blocks messages #11716 — protobuf definitions
  2. feat(p2p): serve canister HTTP responses out of a block #11717 — serve canister HTTP responses out of a block ← this PR
  3. feat(p2p): reassemble blocks whose canister HTTP responses were stripped #11718 — reassemble blocks whose canister HTTP responses were stripped
  4. feat(p2p): strip canister HTTP responses from block proposals #11719 — strip canister HTTP responses from block proposals (turns it on)

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The response traversal lacks coverage for the TooManyRejects payload path.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds peer serving for canister HTTP response content sourced from the HTTP pool or retained blocks.

Changes:

  • Adds the canister HTTP response RPC and protobuf conversions.
  • Extracts response content from all supported payload layouts.
  • Wires the HTTP pool into the downloader and adds tests/fixtures.
File Description
rs/​replica/​setup_ic_network/​src/​lib.rs Supplies the HTTP pool to the assembler.
rs/​p2p/​artifact_downloader/​src/​fetch_stripped_artifact/​types/​rpc.rs Defines RPC request/response conversions.
rs/​p2p/​artifact_downloader/​src/​fetch_stripped_artifact/​types.rs Adds response hash and message type definitions.
rs/​p2p/​artifact_downloader/​src/​fetch_stripped_artifact/​test_utils.rs Adds HTTP payload and pool fixtures.
rs/​p2p/​artifact_downloader/​src/​fetch_stripped_artifact/​mod.rs Registers the payload helper module.
rs/​p2p/​artifact_downloader/​src/​fetch_stripped_artifact/​download.rs Implements and tests the serving endpoint.
rs/​p2p/​artifact_downloader/​src/​fetch_stripped_artifact/​canister_http.rs Parses payloads and locates response content.
rs/​p2p/​artifact_downloader/​src/​fetch_stripped_artifact/​assembler.rs Threads the HTTP pool through construction.
rs/​p2p/​artifact_downloader/​Cargo.toml Adds the test cycles dependency.
rs/​p2p/​artifact_downloader/​BUILD.bazel Mirrors the test dependency for Bazel.
rs/​p2p/​artifact_downloader/​benches/​assembler.rs Updates benchmark setup for the new pool.
Cargo.lock Records the dependency update.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The fallback repeatedly decodes full payloads, and the test helper silently truncates oversized fixtures.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Avoid repeated full payload decoding for each response lookup

rs/​p2p/​artifact_downloader/​src/​fetch_stripped_artifact/​canister_http.rs:42

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.

Low severity Detect silently truncated payloads in iterator_to_bytes

rs/​p2p/​artifact_downloader/​src/​fetch_stripped_artifact/​test_utils.rs:450

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.

@eichhorl

Copy link
Copy Markdown
Contributor Author

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Repeated peer requests can trigger costly full-payload decoding without concurrency bounds or caching.

Review effort: Balanced
Findings: 1 High severity

Open (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Per-response full-payload decoding can create quadratic work and substantial allocation during block reconstruction.

Review effort: Balanced
Findings: 1 High severity

Open (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The endpoint, payload traversal, dependency wiring, and relevant response variants are consistently implemented and tested.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@eichhorl
eichhorl force-pushed the eichhorl/ch-hib-2-serve branch from 2971555 to 61c4e5a Compare October 1, 2026 12:00
Base automatically changed from eichhorl/ch-hib-1-protos to master October 1, 2026 13:10
eichhorl and others added 4 commits October 1, 2026 13:10
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]>
@eichhorl
eichhorl force-pushed the eichhorl/ch-hib-2-serve branch from 61c4e5a to f26d1cc Compare October 1, 2026 13:10
valorjesson-commits pushed a commit to Marketearth/ic that referenced this pull request Oct 3, 2026
…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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The endpoint, payload traversal, dependency wiring, and supported response variants are consistently implemented and tested.

Review effort: Balanced
Findings: None

@eichhorl
eichhorl marked this pull request as ready for review October 5, 2026 14:27
@eichhorl
eichhorl requested a review from a team as a code owner October 5, 2026 14:27
@zeropath-ai

zeropath-ai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to b443b73.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/p2p/artifact_downloader/cargo.toml
Add ic-error-types dependency and ic-types-cycles to workspace dependencies
Enhancement ► Cargo.lock
Add ic-error-types 0.2.0 and ic-types-cycles to dependencies
Enhancement ► rs/p2p/artifact_downloader/BUILD.bazel
Add //packages/ic-error-types as a dependency for ic_artifact_downloader tests
Enhancement ► rs/p2p/artifact_downloader/Cargo.toml
Add ic-error-types path dependency
Add ic-types-cycles path dependency
Enhancement ► 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The endpoint, payload lookup, wiring, serialization, and edge cases are implemented consistently with comprehensive tests.

0 open findings

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

…ng error

Addresses a review comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The endpoint preserves validated hash-to-content binding and is comprehensively covered by focused tests.

0 open findings

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@eichhorl
eichhorl added this pull request to the merge queue Oct 8, 2026
Merged via the queue into master with commit b02df10 Oct 8, 2026
39 checks passed
@eichhorl
eichhorl deleted the eichhorl/ch-hib-2-serve branch October 8, 2026 15:41
eichhorl added a commit that referenced this pull request Oct 9, 2026
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants