Skip to content

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

Open
pablodeymo wants to merge 1 commit into
mainfrom
fix/envelopes-by-range-byte-budget
Open

pablodeymo wants to merge 1 commit into
mainfrom
fix/envelopes-by-range-byte-budget

Conversation

@pablodeymo

Copy link
Copy Markdown
Collaborator

Closes #895.

Motivation

execution_payload_envelopes_by_range answered with every canonical envelope in the window, up to MAX_REQUEST_PAYLOADS (128), and the P2P actor collected them all in memory before responding. Nothing bounded their total size.

  • An execution block may be 8 MiB of RLP (EIP-7934), so one request could make the node load and send about 1 GiB.
  • The requester has the request-response layer's 10 seconds for the whole exchange, so an answer that large could not arrive anyway, and one that misses the timeout is lost entirely.

What changed

A byte budget on the answer (req_resp/envelopes.rs)

  • The answer stops once ENVELOPES_BY_RANGE_BYTE_BUDGET (16 MiB of SSZ, before compression) has gone out. The specification allows it: "Clients MAY limit the number of payload envelopes in the response".
  • It always carries the first envelope the window has ("Clients MUST respond with at least the first [...] that exists in the range"), and overshoots by less than one envelope, so one answer sends under 26 MiB.
  • What it sends is a prefix of the window, in slot order.
  • The 16 MiB value is a judgement call, not from the issue: sending less and being asked again costs a round trip, where sending too much costs the whole answer.

Envelopes are read as they are sent (storage/src/store.rs, req_resp/codec.rs, beacon/encoding.rs)

  • Store::canonical_execution_payload_envelopes now returns a plan (CanonicalEnvelopes): the canonical blocks of the window and the parent_block_hash each successor builds on, from one view. It reads rows one at a time as an iterator.
  • The handler hands the codec that plan in a write-only ResponsePayload::ExecutionPayloadEnvelopesByRange, and the codec reads each row just before writing its chunk. The answer is never in memory whole, the P2P actor reads no envelope, and a peer that stops reading stops the reads.
  • Planning does not touch Table::ExecutionPayloadEnvelopes, not even for an existence check: on RocksDB contains is a pinned get, which loads the value. A block with no envelope is passed over at its turn, for one point read that misses.
  • The rows go on the wire as stored, without a decode and re-encode.
  • A row that fails to read or decode ends the answer where it is. It used to be an expect, and it now runs on the connection task, where a panic takes the swarm down.

The requester asks again after a short answer (req_resp/envelope_client.rs)

  • An answer that stops before the end of the span is followed by a request to the same peer for the slots after its last envelope, once the first answer has been checked and forwarded. Range sync's next batch stays held meanwhile.
  • Before, a short answer released the batch and left the rest to by-root lookups, one per held block.
  • Each follow-up starts past the last envelope received, so a span takes at most one request per slot.
  • Follow-ups stop ENVELOPE_FOLLOW_UP_WINDOW (30 s) after the batch's envelopes were first asked for. They hold the next batch back, and an envelope counts as progress before any check of it, so unbounded, a peer answering one envelope per request could hold a 128-slot batch for about 21 minutes.
  • A session's last batch is followed up too. That batch exhausts the session, so its envelope request is handed on (release_envelope_requests_of) and names no session from then.
  • A session ended for cause (end_range_session) is not followed up, and neither is any span once another session is running.

Docs. docs/beacon_wire.md and CLAUDE.md.

Behaviour preserved

  • With an unlimited budget, the set and order of envelopes served for a window is what main served: the successor's bid parent_block_hash must equal the payload's block_hash, the head's envelope is served only on the FULL node, and the successor of the window's last block is searched for past end_slot.
  • Refusals are unchanged: a zero count is INVALID_REQUEST, a start_slot below the anchor is RESOURCE_UNAVAILABLE, and a count over MAX_REQUEST_PAYLOADS is truncated.
  • The context epoch of a by-range chunk now comes from the row's key (the block's slot) instead of payload.slot_number. The two are equal for a stored envelope.

Limits

  • execution_payload_envelopes_by_root still collects up to 128 envelopes with no byte bound, and does not deduplicate roots, so a request naming one large block's root 128 times loads about 1 GiB. Out of this issue's scope; a follow-up PR covers it.
  • The requester's reader still accepts up to 128 chunks of MAX_PAYLOAD_SIZE with no total cap. Unchanged here.
  • No test drives the full path from a received short answer through the completion callback to the follow-up request, because that needs a live actor Context. The pieces on either side are tested.
  • Not run against a live peer or a devnet. Whether a full-budget answer fits the 10 s exchange on a slow uplink is not measured.

Testing

  • make fmt, make lint and make test-node pass (2,843 passed, 0 failed, 9 ignored). make test-consensus and make test-ethrex were not run; neither half builds the changed code paths' tests.
  • New storage test: planning makes no read or existence check on the envelope table (counted through CountingBackend), each step reads one row, and a corrupt row is an error rather than a panic.
  • New serving tests: the budget boundary (one byte under, exactly, one byte over), the first envelope under any budget, a row rewritten after planning is read at send time, a corrupt row ends the answer, an oversized envelope is skipped without being charged, and the answer round-trips through Codec::write_response and read_response.
  • New requester tests: the unanswered tail of an answer, the follow-up request and its deadline, the last batch of a session, a session ended for cause, and a span meeting another session.

…they are sent

`execution_payload_envelopes_by_range` answered with every canonical
envelope in the window, up to `MAX_REQUEST_PAYLOADS` (128), collected in
memory by the P2P actor before responding. An execution block may be
8 MiB, so one request could make the node load and send about 1 GiB.

Server:
- The answer stops once `ENVELOPES_BY_RANGE_BYTE_BUDGET` (16 MiB of SSZ)
  has gone out. It always carries the first envelope the window has and
  overshoots by less than one envelope.
- The handler only plans the answer. The codec reads each envelope row as
  it writes that chunk (`EnvelopesByRange`, `CanonicalEnvelopes`), so the
  answer is never in memory whole and the P2P actor reads no envelope.
  Planning does not touch the envelope table: on RocksDB an existence
  check loads the value it finds.
- A row that fails to read ends the answer where it is, instead of a
  panic.

Requester:
- An answer that stops short of the span is followed by a request to the
  same peer for the slots after its last envelope, with range sync's next
  batch still held, for up to `ENVELOPE_FOLLOW_UP_WINDOW` (30 s).
- A session's last batch is followed up too; a session ended for cause is
  not, and neither is a span once another session runs.

Closes #895

This branch has not been deployed

No deployments
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.

Envelopes by range: bound the response by bytes, not only by count

1 participant