Skip to content

feat(p2p): strip canister HTTP responses from block proposals - #11719

Merged
eichhorl merged 29 commits into
masterfrom
eichhorl/ch-hib-4-strip
Oct 16, 2026
Merged

eichhorl merged 29 commits into
masterfrom
eichhorl/ch-hib-4-strip

Conversation

@eichhorl

@eichhorl eichhorl commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

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.

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 (#11751).

Stack

  1. chore(protobuf): add the canister HTTP hashes-in-blocks messages #11716 — protobuf definitions (merged)
  2. feat(p2p): serve canister HTTP responses out of a block #11717 — serve canister HTTP responses out of a block (merged)
  3. feat(p2p): reassemble blocks whose canister HTTP responses were stripped #11718 — reassemble blocks whose canister HTTP responses were stripped (merged)
  4. this PR — strip canister HTTP responses from block proposals

🤖 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

One benchmark silently truncates its workload, and the implementation does not uphold the stated always-smaller wire-size guarantee.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

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.

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 benchmark helper still silently truncates oversized payloads despite the stated safeguard.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
Resolved since last review (1)

@eichhorl

Copy link
Copy Markdown
Contributor Author

Good catch, and it invalidated a claim in the previous revision of this description.

The earlier commit added the count assertion to test_utils::fake_canister_http_payload,
but the benchmark is a separate target and cannot use a #[cfg(test)] helper, so it has
its own copy — which still truncated silently. That means the "validated every case, no
assertion fired" statement was worthless: the assertion was never in the benchmark's
path. Fixed in edb6b76; the benchmark helper now decodes what it produced and asserts
the count.

With the check genuinely active, all cases run clean, so the resized ones do fit. The
5.4 ms / 9.8 ms figures in the description were unaffected, for a separate reason: they
came from a harness that went through the test_utils helper and reported the real
encoded size as 1.51 MB against the 2 MiB limit. The payload was complete; I just had
not actually proved it the way I said I had.

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

Activating consensus-critical stripping and a new peer-fetch dependency warrants final human review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (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

Activating a consensus networking path with a new peer-fetch dependency warrants final human review.

Review effort: Balanced
Findings: 1 Medium 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

🟡 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 Low severity

Open (2)
Resolved since last review (1)

Comment thread rs/consensus/features/src/lib.rs Resolved

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

It activates consensus-path payload transformation and introduces peer-dependent block reassembly, warranting final human review.

Review effort: Balanced
Findings: None

Resolved since last review (2)

@eichhorl
eichhorl force-pushed the eichhorl/ch-hib-4-strip branch from 49331c6 to 841544e Compare October 1, 2026 12:35
@eichhorl
eichhorl requested a balanced review from Copilot October 1, 2026 12:36

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 consensus-critical wire-format and peer-fetch behavior warrants final human review despite comprehensive tests.

Review effort: Balanced
Findings: None

eichhorl and others added 2 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]>
eichhorl and others added 4 commits October 14, 2026 09:23
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]>

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.

🔵 Needs a closer look

It changes consensus block propagation and introduces a common-path peer-fetch dependency requiring final human review.

2 open findings

🧠 Review effort: Balanced

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.

🔵 Needs a closer look

The consensus transport change introduces peer-fetch dependency and exact-byte reconstruction requirements that warrant final human review.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

@eichhorl
eichhorl marked this pull request as ready for review October 14, 2026 12:53
@eichhorl
eichhorl requested a review from a team as a code owner October 14, 2026 12:53
@eichhorl eichhorl added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Oct 14, 2026
@zeropath-ai

zeropath-ai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

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

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/consensus/features/src/lib.rs
    Update HASHES_IN_BLOCKS_ENABLED documentation and behavior to include canister HTTP responses in block stripping
Enhancement ► rs/p2p/artifact_downloader/BUILD.bazel
    Add dependencies for protobuf and cycles types in bench/artifact_downloader build
Enhancement ► rs/p2p/artifact_downloader/benches/assembler.rs
    Extend benchmarks to cover canister HTTP payload stripping/assembly; add MIN_STRIPPED_CONTENT_BYTES and related helpers; integrate canister HTTP payload processing in benchmarks; adjust test utilities and data structures
Enhancement ► rs/p2p/artifact_downloader/src/fetch_stripped_artifact/assembler.rs
    Expand test utilities and roundtrip tests to include canister HTTP payload handling; introduce canister HTTP payload stripping/assembly tests and support functions; enhance tests for various canister HTTP scenarios
Enhancement ► rs/p2p/artifact_downloader/src/fetch_stripped_artifact/canister_http.rs
    Introduce canister HTTP payload stripping logic (strip_responses), constants like MIN_STRIPPED_CONTENT_BYTES, content_size calculation, and reinsert logic; update imports and related types; add extensive tests for stripping and reassembling CanisterHttp payloads

@pierugo-dfinity pierugo-dfinity 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.

Nice work! 🚀 🚀

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]>

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.

🔵 Needs a closer look

Enabling peer-dependent response retrieval during consensus block assembly warrants human review of rollout compatibility and liveness.

0 open findings

🧠 Review effort: Balanced

@eichhorl
eichhorl added this pull request to the merge queue Oct 16, 2026
Merged via the queue into master with commit 886c2fd Oct 16, 2026
39 checks passed
@eichhorl
eichhorl deleted the eichhorl/ch-hib-4-strip branch October 16, 2026 08:36
dfinityianblenke added a commit that referenced this pull request Oct 19, 2026
maksym-arutyunyan pushed a commit to maksym-arutyunyan/ic that referenced this pull request Oct 20, 2026
…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]>
dfinityianblenke added a commit that referenced this pull request Nov 2, 2026
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