fix(p2p): warn when peer status is ahead#432
Conversation
Greptile SummaryThis PR adds structured
Confidence Score: 4/5The handler change is safe — it adds a log statement with no effect on sync logic — but the unexplained Cargo.lock dependency changes deserve a second look before merging. The core handlers.rs change is a read-only observability addition that cannot affect correctness. The Cargo.lock modifications (windows-sys downgrades, spin upgrade, new Plonky3 commit) are unrelated to the stated scope of the PR and could have downstream build or runtime effects on non-Linux platforms or on code that depends on Plonky3 internals. Cargo.lock — the unrelated dependency changes need to be verified as intentional; handlers.rs is otherwise straightforward.
|
| Filename | Overview |
|---|---|
| crates/net/p2p/src/req_resp/handlers.rs | Adds a warn! log in handle_status_response when a peer's head slot exceeds our local head; arithmetic is safe and fields are accurate, but the warning fires on every status response while behind, which may be noisier than intended. |
| Cargo.lock | Contains unexplained changes unrelated to the stated feature: windows-sys version downgrades, a spin upgrade, and a new Plonky3 git commit hash — these should be reviewed separately or explained. |
Sequence Diagram
sequenceDiagram
participant Peer
participant P2PServer
participant Store
participant RangeSyncState
Peer->>P2PServer: Status response (head_slot)
P2PServer->>Store: head_slot()
Store-->>P2PServer: our_head_slot
alt "peer head <= our head"
P2PServer-->>Peer: return early, no action
else "peer head > our head"
P2PServer->>P2PServer: "gap = peer_head - our_head"
Note over P2PServer: warn!(peer, peer_head_slot, local_head_slot, slot_gap) NEW
P2PServer->>RangeSyncState: merge_peer() or new RangeSyncState
P2PServer->>Peer: BlocksByRange request
P2PServer->>P2PServer: info! Long-range sync started
end
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
crates/net/p2p/src/req_resp/handlers.rs:174-180
**Warning fires on every status response, not just once at sync start**
The `warn!` is placed unconditionally after the early-return guard, so it fires on every call to `handle_status_response` where the peer is ahead — including calls that arrive while a range sync is already in progress (the `Some(state) => state.merge_peer(...)` branch on line 186). With multiple peers and periodic status exchanges, a node that is 1 000 slots behind could emit dozens of identical warnings before catching up, making the `warn` level noisy and harder to distinguish from genuine problems. Consider gating the `warn!` on `server.range_sync_state.is_none()` so it only fires when the first sync session is initiated, or downgrading to `debug!` when sync is already in progress.
### Issue 2 of 2
Cargo.lock:174-188
**Unrelated dependency changes included in a logging-only PR**
The lock file contains changes that go beyond what a logging-only addition would require: `windows-sys` is downgraded from `0.61.2` to `0.60.2` in four crates and to `0.52.0` in three others; `spin` is upgraded from `0.10.0` to `0.11.0`; and all Plonky3 packages are pinned to a different upstream git commit (`3f67d136` → `82cfad73`). If these were pulled in incidentally (e.g., a rebase or local `cargo update`), they should be separated into a dedicated dependency-update PR or documented here so reviewers can verify the changes are intentional and safe.
Reviews (1): Last reviewed commit: "fix(p2p): warn when peer status is ahead" | Re-trigger Greptile
| warn!( | ||
| %peer, | ||
| peer_head_slot = status.head.slot, | ||
| local_head_slot = our_head_slot, | ||
| slot_gap = gap, | ||
| "Peer status head is ahead of local head" | ||
| ); |
There was a problem hiding this comment.
Warning fires on every status response, not just once at sync start
The warn! is placed unconditionally after the early-return guard, so it fires on every call to handle_status_response where the peer is ahead — including calls that arrive while a range sync is already in progress (the Some(state) => state.merge_peer(...) branch on line 186). With multiple peers and periodic status exchanges, a node that is 1 000 slots behind could emit dozens of identical warnings before catching up, making the warn level noisy and harder to distinguish from genuine problems. Consider gating the warn! on server.range_sync_state.is_none() so it only fires when the first sync session is initiated, or downgrading to debug! when sync is already in progress.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/net/p2p/src/req_resp/handlers.rs
Line: 174-180
Comment:
**Warning fires on every status response, not just once at sync start**
The `warn!` is placed unconditionally after the early-return guard, so it fires on every call to `handle_status_response` where the peer is ahead — including calls that arrive while a range sync is already in progress (the `Some(state) => state.merge_peer(...)` branch on line 186). With multiple peers and periodic status exchanges, a node that is 1 000 slots behind could emit dozens of identical warnings before catching up, making the `warn` level noisy and harder to distinguish from genuine problems. Consider gating the `warn!` on `server.range_sync_state.is_none()` so it only fires when the first sync session is initiated, or downgrading to `debug!` when sync is already in progress.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| @@ -185,7 +185,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" | |||
| dependencies = [ | |||
| "anstyle", | |||
| "once_cell_polyfill", | |||
| "windows-sys 0.61.2", | |||
| "windows-sys 0.60.2", | |||
There was a problem hiding this comment.
Unrelated dependency changes included in a logging-only PR
The lock file contains changes that go beyond what a logging-only addition would require: windows-sys is downgraded from 0.61.2 to 0.60.2 in four crates and to 0.52.0 in three others; spin is upgraded from 0.10.0 to 0.11.0; and all Plonky3 packages are pinned to a different upstream git commit (3f67d136 → 82cfad73). If these were pulled in incidentally (e.g., a rebase or local cargo update), they should be separated into a dedicated dependency-update PR or documented here so reviewers can verify the changes are intentional and safe.
Prompt To Fix With AI
This is a comment left during a code review.
Path: Cargo.lock
Line: 174-188
Comment:
**Unrelated dependency changes included in a logging-only PR**
The lock file contains changes that go beyond what a logging-only addition would require: `windows-sys` is downgraded from `0.61.2` to `0.60.2` in four crates and to `0.52.0` in three others; `spin` is upgraded from `0.10.0` to `0.11.0`; and all Plonky3 packages are pinned to a different upstream git commit (`3f67d136` → `82cfad73`). If these were pulled in incidentally (e.g., a rebase or local `cargo update`), they should be separated into a dedicated dependency-update PR or documented here so reviewers can verify the changes are intentional and safe.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
🗒️ Description / Motivation
What Changed
crates/net/p2p/src/req_resp/handlers.rs.Correctness / Behavior Guarantees
BlocksByRangesynchronization behavior is unchanged.Tests Added / Run
cargo fmt --all -- --check— clean.git diff --check— clean.Related Issues / PRs
✅ Verification Checklist
make fmt— cleanmake lint(clippy with-D warnings) — cleancargo test --workspace --release— all passing