Repository navigation
fix(p2p): bound envelopes-by-range answers by bytes and read them as they are sent - #956
Conversation
…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
|
/review |
AI security review: 2 finding(s) to checkReviewed by Opus, GPT, Kimi, GLM, DeepSeek. A judge model checked every one of the findings against the code.
DetailsM3. Pre-Gloas requests decode whole blocks before the byte budget applies (medium, DoS/resource)
M4. Corrupt FULL-head rows are transmitted instead of ending the answer (low, logic)
Pre-existing (real, but already on the base branch): 2
Housekeeping (not security): 1Stale docs, missing tests, leftovers and inconsistencies, from a separate cheap model. Not checked by the judge.
Cost of this review: ~$3.85 of a $30 budget (estimated from token counts). |
…ery row sent Two findings from the review of this branch. Planning an answer decodes the block after each one it looks at, for its bid. Before gloas that block carries a whole execution payload, and nothing kept a window out of those slots, so a peer asking for 128 pre-gloas slots had the P2P actor decode 128 full blocks to answer nothing, outside the byte budget. The envelope-table existence check this branch removed used to skip them. The plan now starts at the gloas fork's first slot; a window that ends before it, or any window on a chain that does not schedule gloas, reads nothing. The head's envelope was sent without being decoded, since no successor's bid needs a field out of it. A corrupt row there went out as a chunk, and the requester, failing to decode it, dropped the envelopes before it too. Every row is now decoded before it is sent, so a corrupt one ends the answer. Also corrects protocols.rs, which still said nothing requests the envelope protocols.
|
/review |
AI security review: 1 finding(s) to checkReviewed by Opus, GPT, Kimi, GLM, DeepSeek. A judge model checked every one of the findings against the code.
DetailsM4. Unbounded BlockRoots successor scan on crafted by-range window (medium, DoS/resource)
Duplicates folded into another finding: 1
Pre-existing (real, but already on the base branch): 2
Cost of this review: ~$4.69 of a $30 budget (estimated from token counts). |
Planning a by-range answer needs the canonical block after the window's last, to judge that block's payload by the bid built on it. It looked for it with one BlockRoots read per slot from the window's end to the head. The index has no row for an empty slot, so a window ending before a run of them cost a read per slot of the run, on the P2P actor, bounded by nothing in the request. Before this branch the scan ran only when the window's last block had an envelope row; without the envelope-table check it ran for every window that held a block. StorageReadView gains first_at_or_after, the first entry at or after a key in the table's key order (a RocksDB iterator seek; a minimum over the map in memory), and the planner asks it once. The backend test suite covers it on both backends.
…choice test view The previous commit did not pass lint: clippy rejects first_at_or_after's return type as too complex, and the read view the fork-choice tests wrap a backend in did not implement the new method, so the state-transition test target did not compile. The key and value pair is now `Entry` (exported as `StorageEntry`), and that view forwards the seek.
|
/review |
AI security review: 1 finding(s) to checkReviewed by Opus, GPT, Kimi, GLM, DeepSeek. A judge model checked every one of the findings against the code.
DetailsM3. A high-slot envelope suppresses follow-ups for earlier omissions (low, logic)
Pre-existing (real, but already on the base branch): 2
Housekeeping (not security): 1Stale docs, missing tests, leftovers and inconsistencies, from a separate cheap model. Not checked by the judge.
Cost of this review: ~$3.88 of a $30 budget (estimated from token counts). |
…why it is not asked for again A short `ExecutionPayloadEnvelopesByRange` answer is followed by a request for the slots after its last envelope. The code took the answer for a prefix of the window without checking, so a peer that left an envelope out before its last one was not noticed, and the comments said the answer is a prefix. Every canonical payload builds on the one before it (`payload.parent_hash` is `state.latest_block_hash`), so two neighbouring envelopes that do not link have one missing between them. `unlinked_neighbours` finds that and the handler logs it at `debug`. The follow-up is unchanged, on purpose: only the tail is asked for again. The peer was asked for those slots and sent what lies on both sides of them, so another request to it would only keep range sync's next batch waiting, and a peer set on withholding can answer empty just as well. What is left out comes by root from other peers, as soon as the chain actor holds the child of a block missing its payload. An answer that skips the window's first envelopes cannot be told from any other. The comments and `docs/beacon_wire.md` now say all of this. Also corrects the doc of `ResponsePayload::ExecutionPayloadEnvelopes`, which no longer answers the by-range protocol on the sending side.
On M3 (a high-slot envelope suppresses follow-ups for earlier omissions)The mechanism is right: the follow-up is computed from the answer's last envelope, and nothing checked that the answer is a prefix of the window. What changed
Why the same peer is not asked again for the gap
What is not covered An answer that skips the window's first envelopes (for example, only the last slot's) cannot be told from an honest one this way: there is no earlier envelope in the answer to link to. It falls back to the same by-root path. Asking a different peer by range for just the gap would be a real recovery, but it needs more than one outstanding request under the gate that holds the next batch. Not done here. |
…hey are sent (#958) Stacked on #956. Review and merge that one first; this PR's diff is only the by-root part. ## Motivation #956 bounds `execution_payload_envelopes_by_range` (#895). `execution_payload_envelopes_by_root` has the same shape and was left open there: - It collected up to `MAX_REQUEST_PAYLOADS` (128) decoded envelopes in the P2P actor, with no bound on their total size. - It answered a root once per mention. A request naming one large block's root 128 times loaded about 1 GiB from a single stored envelope. ## What changed **The by-root answer uses the by-range mechanism** (`req_resp/envelopes.rs`, `storage/src/store.rs`) - The answer stops once `ENVELOPES_BY_ROOT_BYTE_BUDGET` has gone out. It is the range's 16 MiB of SSZ, for the same reasons. The specification allows it ("Clients MAY limit the number of payload envelopes in the response") and asks for "at least one payload envelope, if they have it", which stopping only once the budget is spent gives. - The handler only resolves each root to its block's slot (`Store::execution_payload_envelopes_of`). The codec reads each envelope row as it writes that chunk (`EnvelopesByRoot`), so the answer is never in memory whole and the P2P actor reads no envelope. - `EnvelopeAnswer<I>` is the budgeted answer both protocols now share. `EnvelopesByRange` and `EnvelopesByRoot` are aliases over where the envelopes come from. The budget, the oversized-envelope skip and the end-on-read-failure rule are written once. - A row is not decoded on the by-root path, since there is no chain rule to apply. It goes on the wire as stored. **A repeated root is answered once**, at its first place. The answer is "a list [...] whose length is less than or equal to the number of requested" envelopes either way. **The requester stops reading an answer at a byte budget** (`req_resp/encoding.rs`, `beacon/encoding.rs`) - A peer may send `MAX_REQUEST_PAYLOADS` chunks of `MAX_PAYLOAD_SIZE` to either envelope protocol, whatever was asked, and the reader held every decoded envelope until the stream ended: about 1.25 GiB for one request. The automated review listed this as present on `main`. - `ChunkLimits` gains `max_bytes`. Envelope answers are read under `ENVELOPE_RESPONSE_BYTE_BUDGET`, the servers' 16 MiB: the envelope that crosses it is kept, so the first always is, and one answer holds under 26 MiB. - A longer answer is cut, not refused, and reads as a short one. By range the requester already asks again for the slots after its last envelope (#956); by root this node names one root a request. **Docs.** `docs/beacon_wire.md` and `CLAUDE.md`. ## Behaviour preserved - Unknown roots are left out, the answer follows the order asked, and no more than `MAX_REQUEST_PAYLOADS` roots are looked at. - By root there is still no chain rule: an envelope the canonical chain did not build on is served when asked for by name. - This node's own by-root requests name a single root, so its requester is never cut short and needs no change. ## Limits - Another client that asks for many large envelopes by root in one request now gets a short answer and has to ask again for the rest. The specification allows the short answer; how each client handles it was not checked. - A by-root row goes out as stored, without the decode a by-range row gets in #956, so a corrupt row would be sent as a chunk the requester cannot decode. - The block and data-column readers still read to their chunk limits with no byte cap; only the envelope reader is bounded here. - Not run against a live peer or a devnet. ## Testing - `make fmt`, `make lint` and `make test-node` pass (2,853 passed, 0 failed, 9 ignored). `make test-consensus` and `make test-ethrex` were not run locally; the changed crates (`ethlambda-storage`, `ethlambda-p2p`) are in the `test-node` half. - New storage test: planning a by-root answer makes no read or existence check on the envelope table, each step reads one row in the order named, and roots with no block or no envelope are passed over. - New serving tests: a repeated root is answered once, the budget boundary and the first envelope under any budget, an envelope the chain did not build on is still served by name, and the answer round-trips through `Codec::write_response` and `read_response`. - New reader test: a four-envelope answer read under a budget exactly on an envelope boundary, one byte under, one byte over, and near zero; the first envelope is always read.
|
/review |
AI security review: 1 finding(s) to checkReviewed by Opus, GPT, Kimi. A judge model checked every one of the findings against the code.
DetailsM2. By-root answers send stored envelope rows without decoding them, so one corrupt row makes the requester throw away the whole answer (low, logic)
Pre-existing (real, but already on the base branch): 1
Housekeeping (not security): 1Stale docs, missing tests, leftovers and inconsistencies, from a separate cheap model. Not checked by the judge.
Cost of this review: ~$4.81 of a $30 budget (estimated from token counts). |
`EnvelopesOfBlocks` handed a stored row over as it was: a by-root answer applies no chain rule, so nothing is read out of the envelope. The bytes go on the wire as stored, and a requester that cannot decode one chunk drops the whole answer, so a corrupt row cost a peer asking for several roots every envelope sent before it. The by-range reader already decodes each row for this reason. Both readers now go through `decode_stored_envelope`, and a by-root row that does not decode is an error its answer ends at.
The envelopes of a range batch were asked for over the whole span the batch requested, so an answer that stopped at the batch's last block was followed up for slots holding no block, and so no envelope: the batch at the peer's head, or one ending in missed slots, cost a request that could only come back empty, with range sync held meanwhile. The span now ends at the highest block handed to the chain actor. The server still judges that block's payload by its successor past the span, so nothing is lost. Also: - `decode_stored_envelope` names the block with `ShortRoot`, as the log rule asks, where it formatted the full root. - `write_stored_envelopes_response` says why the reads stay on the connection's task: they are paced by the peer taking each chunk, like every response's encoding and compression, and moving them alone to the blocking pool would not pay off. - The repeated-root test gets its doc comment back from the test placed between them.
- A by-range answer passes over a row deleted after it was planned, or one too large for a chunk, and goes on: it is a prefix of the window only without those. - An envelope row can be written again (a re-delivered envelope is recorded again). Reading rows after the plan is still sound because a row's payload hash is pinned by its block's bid. - The reader's 16 MiB budget counts SSZ bytes, not memory: decoded, envelopes packed with empty transactions take about six times as much.
…they are sent (#968) ## 🗒️ 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 (#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 - Original: #956 (closes #895 on `main`), with #958. - The other PRs open against the release branch: #954, #962 (backport of #950) and #965 (backport of #952). This one merges with each of them without conflicts (checked with `git merge-tree`), though it shares `crates/net/p2p/src/lib.rs`, `CLAUDE.md` and `docs/beacon_wire.md` with some of them. - Release checklist: #943.
Closes #895.
Motivation
execution_payload_envelopes_by_rangeanswered with every canonical envelope in the window, up toMAX_REQUEST_PAYLOADS(128), and the P2P actor collected them all in memory before responding. Nothing bounded their total size.What changed
A byte budget on the answer (
req_resp/envelopes.rs)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".Envelopes are read as they are sent (
storage/src/store.rs,req_resp/codec.rs,beacon/encoding.rs)Store::canonical_execution_payload_envelopesnow returns a plan (CanonicalEnvelopes): the canonical blocks of the window and theparent_block_hasheach successor builds on, from one view. It reads rows one at a time as an iterator.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.Table::ExecutionPayloadEnvelopes, not even for an existence check: on RocksDBcontainsis a pinned get, which loads the value. A block with no envelope is passed over at its turn, for one point read that misses.BlockRoots(StorageReadView::first_at_or_after, new on both backends). It was a read per slot up to the head, so a window ending before a run of empty slots cost a read per slot of the run on the P2P actor.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)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.release_envelope_requests_of) and names no session from then.end_range_session) is not followed up, and neither is any span once another session is running.Docs.
docs/beacon_wire.mdandCLAUDE.md.Behaviour preserved
mainserved: the successor's bidparent_block_hashmust equal the payload'sblock_hash, the head's envelope is served only on the FULL node, and the successor of the window's last block is searched for pastend_slot.countisINVALID_REQUEST, astart_slotbelow the anchor isRESOURCE_UNAVAILABLE, and acountoverMAX_REQUEST_PAYLOADSis truncated.payload.slot_number. The two are equal for a stored envelope.Limits
execution_payload_envelopes_by_rootstill 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; fix(p2p): bound envelopes-by-root answers by bytes and read them as they are sent #958, stacked on this PR, fixes it.MAX_PAYLOAD_SIZEwith no total cap. Unchanged here.Context. The pieces on either side are tested.Testing
make fmt,make lintandmake test-nodepass (2,846 passed, 0 failed, 9 ignored).make test-consensusandmake test-ethrexwere not run locally; the changed crates (ethlambda-storage,ethlambda-p2p) are in thetest-nodehalf. CI runs all three.CountingBackend), each step reads one row, and a corrupt row is an error rather than a panic.Codec::write_responseandread_response.48d959b8), both findings of the automated review: a window before gloas reads no block (read counts throughCountingBackend; the test fails without the clamp), a chain with no gloas scheduled answers empty, and a corrupt row at a FULL head is an error.fa8aa614,f496f53d): planning a window whose next block is 100,000 slots on makes one seek and no read for the gap (counted throughCountingBackend), and the shared backend suite runsfirst_at_or_afteron RocksDB and in memory.