Skip to content

fix(p2p): bound envelopes-by-range answers by bytes and read them as they are sent - #968

Merged
pablodeymo merged 1 commit into
release/v2.0.0from
backport/v2.0.0-pr-956
Dec 2, 2026
Merged

pablodeymo merged 1 commit into
release/v2.0.0from
backport/v2.0.0-pr-956

Conversation

@pablodeymo

Copy link
Copy Markdown
Collaborator

🗒️ Description / Motivation

Backport of #956 to release/v2.0.0, for v2.0.0-rc.2.

#956 is approved and not merged on main yet, so this is taken from its head (36232dcf) and not from a squash commit on main. If #956 changes before it merges, this branch has to be refreshed from the new head.

What Changed

The ten commits of #956 as one commit on top of release/v2.0.0 (3ed99c86): the diff from its branch point on main (e48246f8) to its head (36232dcf), applied with git apply --3way. It applied without conflicts and nothing was edited by hand. That includes #958, the by-root counterpart, which was merged into #956's branch.

What it does, from #956:

  • An execution_payload_envelopes_by_range answer stops once 16 MiB of SSZ has gone out, always carrying the first envelope its window has. Before, one request could make the node load and send about 1 GiB.
  • Envelopes are read as they are sent: the codec reads each row just before writing its chunk, and a row that fails to read or decode ends the answer where it is.
  • The requester asks the same peer again after an answer that stops short, for up to 30 s.
  • execution_payload_envelopes_by_root answers are bounded and read the same way (fix(p2p): bound envelopes-by-root answers by bytes and read them as they are sent #958).

Tests Added / Run

On this branch:

  • cargo fmt --all -- --check and make lint: clean.
  • cargo test -p ethlambda-p2p --profile release-fast --lib: 587 passed, 0 failed, 1 ignored.
  • cargo test -p ethlambda-storage --profile release-fast --features rocksdb: 256 passed, 0 failed, 2 ignored.

Not run locally: the rest of make test.

Related Issues / PRs

…they are sent

Backport of #956 to release/v2.0.0, taken from the PR's head (36232dc)
before it merged on main: its ten commits as one, with #958's by-root
counterpart, which was merged into its branch.

- An envelopes-by-range answer stops once 16 MiB of SSZ has gone out. It
  always carries the first envelope its window has, and what it sends is
  a prefix of the window in slot order.
- Envelopes are read as they are sent. The store plans the window
  without touching the envelope table, and the codec reads each row just
  before writing its chunk, so the answer is never in memory whole. A row
  that fails to read or decode ends the answer where it is.
- The requester asks the same peer again after an answer that stops
  short, for up to 30 s from the batch's first request.
- Envelopes-by-root answers are bounded and read the same way.
@pablodeymo

Copy link
Copy Markdown
Collaborator Author

Review of Antigravity:
PR #968 looks good to approve and merge into release/v2.0.0. All 13 CI jobs (including Test (node), Test (include-ethrex), and both
spec suites) are green.
──────

  1. Backport & Branch-Integration Verification

• Exact patch match: git patch-id --stable between #956 (36232dc, currently in main's merge queue) and #968 (10e9dd5) is identical
(317d718b520047763ded742ae95ddea9ae41eda0). It includes #958 (by-root byte budget, duplicate-root dedup, inbound reader budget) plus
all review follow-ups from #956 (pre-Gloas window clamp, first_at_or_after seek across empty-slot gaps, unlinked_neighbours detection,
and decode_stored_envelope on by-root).
• Clean merges: Verified with git merge-tree --write-tree that #968 merges cleanly with:
• current origin/release/v2.0.0 (ded3fcc, with #967 merged), and
• every other open PR targeting release/v2.0.0 (#954, #962, #965).
• No missing main dependencies: The only commits on main not on release/v2.0.0 touching overlapping files (#732 and #952) do not
interact with the req/resp codec, storage, or range-sync envelope paths.
──────
2. Design & Correctness Check
• Storage & RocksDB seek (crates/storage/src/backend/rocksdb.rs, crates/storage/src/store.rs):
• first_at_or_after is sound: no column family configures a prefix extractor, RocksDB uses the default bytewise comparator, and
every Table::BlockRoots key is an 8-byte big-endian u64 slot (encode_block_root_key).
• Clamping start_slot to first_gloas_slot() prevents a peer from forcing full pre-Gloas block decodes on the P2P actor, and
planning touches only BlockRoots / BlockHeaders without pinning megabyte ExecutionPayloadEnvelopes values.
• Decoding rows in both CanonicalEnvelopes and EnvelopesOfBlocks before sending ensures a corrupt row terminates the answer
cleanly instead of sending a malformed chunk that causes the requester to discard earlier valid chunks, and replaces the previous
.expect(...) panic on the connection task.
• Wire budgets & streaming (crates/net/p2p/src/beacon/encoding.rs, crates/net/p2p/src/req_resp/encoding.rs,
crates/net/p2p/src/req_resp/envelopes.rs):
• Stopping after budget saturates to 0 (chunks > 0 on the reader) guarantees at least the first valid envelope is always sent and
read (< 26 MiB SSZ worst case), satisfying both protocols' spec requirements.
• Charging non-SUCCESS chunks against payload_bytes in read_chunked_response prevents an attacker from bypassing max_bytes with
large error chunks.
• Short-answer follow-ups & range gate (crates/net/p2p/src/req_resp/envelope_client.rs, crates/net/p2p/src/req_resp/handlers.rs):
• retain_envelopes_in_range filters to start_slot..=end_slot before unanswered_tail, so next_start = last_slot + 1 strictly
advances on every follow-up, out-of-range junk cannot trigger follow-ups, and follow_ups_until (30s) is preserved across follow-
ups rather than reset.
• Clamping the initial envelope span to highest (rather than end_slot) avoids wasted empty follow-up round trips when a batch
ends in missed slots or at the peer's head.
• may_follow_up + release_envelope_requests_of cleanly distinguish an exhausted session's final batch (session: None) from a
session ended for cause (end_range_session) or superseded by a newer session.

──────
3. Two Minor Non-Blocking Notes (optional follow-ups on main)

  1. Check server.connected_peers.contains_key(&peer) in follow_up_envelope_range (crates/net/p2p/src/req_resp/envelope_client.rs):
    • ResumeRangeAfterEnvelopes runs asynchronously after envelope_checks::check_and_forward_then finishes on its worker task. If
    peer disconnected in the meantime — while either another peer remains in range_sync_state.peer_set (so leave_range_session kept
    the session alive) or the batch had just exhausted the session (session == None) — may_follow_up still returns true and
    send_envelopes_by_range_request calls swarm_handle.send_request(peer, ...).
    • In libp2p_request_response, calling send_request for an unconnected PeerId initiates an outbound dial (ToSwarm::Dial) and keeps
    envelopes_pending = true until OutboundFailure::DialFailure fires (or redials a peer that just disconnected). Returning false
    early when !server.connected_peers.contains_key(&peer) lets resume_range_after_envelopes release the gate immediately.
  2. first_gloas_slot() saturation at u64::MAX (crates/storage/src/store.rs):
    • self.config.gloas_fork_epoch.saturating_mul(slots_per_epoch()) saturates to u64::MAX when Gloas is unscheduled
    (FAR_FUTURE_EPOCH == u64::MAX). For an attacker-supplied overflowing window (start_slot = u64::MAX - 2, count = 5 -> end_slot =
    u64::MAX), start_slot.max(u64::MAX) > end_slot is false, causing one harmless BlockRoots[u64::MAX] miss instead of returning
    before begin_read(). Using checked_mul avoids even that single probe.

Neither blocks #968 for v2.0.0-rc.2 — #968 is ready to merge once #956 lands on main.

@pablodeymo
pablodeymo merged commit ae54a86 into release/v2.0.0 Dec 2, 2026
14 checks passed
@pablodeymo
pablodeymo deleted the backport/v2.0.0-pr-956 branch December 2, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants