Conversation
🤖 Kimi Code ReviewGeneral Assessment Specific Feedback 1. Magic Number Maintainability ( 2. Integer Underflow Risk ( // Suggested:
if encoded.len().saturating_add(1024) > MAX_PAYLOAD_SIZE {Or ensure 3. Silent Data Omission (
4. Error Handling Consistency ( 5. Documentation Summary Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
Greptile SummaryThis PR adds defensive size checks to the P2P request/response layer: Confidence Score: 4/5Safe to merge; the only finding is a minor ordering inconsistency in the Status response path that has no practical impact. Changes are small and well-reasoned. The BlocksByRoot fix correctly prevents stream corruption. The write_payload guard is consistent with the receiver's decode limit. The one P2 note (Status path still writes the byte before encoding) is a theoretical concern only — Status payloads are always tiny. No files require special attention.
|
| Filename | Overview |
|---|---|
| crates/net/p2p/src/req_resp/codec.rs | Moves BlocksByRoot encoding before writing the SUCCESS byte, adding a pre-check to skip oversized blocks; Status response path retains old write-then-check ordering (low-risk but inconsistent). |
| crates/net/p2p/src/req_resp/encoding.rs | Adds a guard in write_payload rejecting uncompressed payloads larger than MAX_PAYLOAD_SIZE - 1024; logic is correct and consistent with the receiver's decode limit. |
Sequence Diagram
sequenceDiagram
participant Sender as Codec (write_response)
participant WP as write_payload
participant Peer as Remote Peer
Note over Sender,Peer: BlocksByRoot response (new flow)
loop for each block
Sender->>Sender: encoded = block.to_ssz()
alt encoded.len() > MAX_PAYLOAD_SIZE - 1024
Sender->>Sender: warn + continue (skip block)
else size ok
Sender->>Peer: write SUCCESS byte
Sender->>WP: write_payload(encoded)
WP->>WP: size guard check
WP->>Peer: varint + snappy-compressed payload
end
end
Note over Sender,Peer: write_payload guard (all callers)
Sender->>WP: write_payload(encoded)
alt uncompressed > MAX_PAYLOAD_SIZE - 1024
WP-->>Sender: Err(InvalidData)
else size ok
WP->>Peer: varint + snappy payload
end
Comments Outside Diff (1)
-
crates/net/p2p/src/req_resp/codec.rs, line 105-110 (link)Status response path still writes SUCCESS byte before
write_payloadThe PR correctly moves the SUCCESS byte write after the size check for
BlocksByRoot, but theStatusresponse path retains the old ordering: the SUCCESS code byte is written beforewrite_payloadis called. Ifwrite_payloadnow returns anInvalidDataerror for any reason, that byte is already on the wire and the stream is technically corrupted. In practice Status messages are tiny so this path can't be triggered, but for consistency with the pattern introduced here consider encoding before writing:Prompt To Fix With AI
This is a comment left during a code review. Path: crates/net/p2p/src/req_resp/codec.rs Line: 105-110 Comment: **Status response path still writes SUCCESS byte before `write_payload`** The PR correctly moves the SUCCESS byte write after the size check for `BlocksByRoot`, but the `Status` response path retains the old ordering: the SUCCESS code byte is written before `write_payload` is called. If `write_payload` now returns an `InvalidData` error for any reason, that byte is already on the wire and the stream is technically corrupted. In practice Status messages are tiny so this path can't be triggered, but for consistency with the pattern introduced here consider encoding before writing: How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: crates/net/p2p/src/req_resp/codec.rs
Line: 105-110
Comment:
**Status response path still writes SUCCESS byte before `write_payload`**
The PR correctly moves the SUCCESS byte write after the size check for `BlocksByRoot`, but the `Status` response path retains the old ordering: the SUCCESS code byte is written before `write_payload` is called. If `write_payload` now returns an `InvalidData` error for any reason, that byte is already on the wire and the stream is technically corrupted. In practice Status messages are tiny so this path can't be triggered, but for consistency with the pattern introduced here consider encoding before writing:
```suggestion
ResponsePayload::Status(status) => {
let encoded = status.to_ssz();
io.write_all(&[ResponseCode::SUCCESS.into()]).await?;
write_payload(io, &encoded).await
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: skip big payloads in BlocksByRoot r..." | Re-trigger Greptile
🤖 Codex Code Review
No consensus-state-transition or fork-choice logic is touched here; the review risk is in req/resp interoperability and peer-handling semantics. I couldn’t run Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
🤖 Claude Code ReviewHere is the review: PR 264 Review — Handle big messages in P2P layerSummaryThe approach is sound: encoding before writing the IssuesSilent skip instead of
The fix is straightforward — instead of io.write_all(&[ResponseCode::RESOURCE_UNAVAILABLE.into()]).await?;
// (then write an error message payload with write_payload)The existing Duplicate magic threshold — extract a named constant
// in encoding.rs
/// Conservative headroom to prevent write_payload from being called
/// with a payload that would exceed MAX_PAYLOAD_SIZE after protocol framing.
pub const MAX_SAFE_PAYLOAD_SIZE: usize = MAX_PAYLOAD_SIZE - 1024;Then both checks become Misleading comment in
Warning log is missing the block slot
warn!(
size = encoded.len(),
slot = %block.block.slot,
"Skipping oversized block in BlocksByRoot response"
);Minor / Non-issues
VerdictTwo items worth addressing before merge: Item 1 (silent skip vs. Automated review by Claude (Anthropic) · sonnet · custom prompt |
This PR adds additional "big message" checks in the P2P layer:
BlocksByRootrequests, skip big blocksNone of these code paths should be triggered during normal operation, but they improve network stability by keeping errors local.