test(l1): cover discv5 IP-voting guard and restore stale-entry cleanup trace#6633
Conversation
🤖 Kimi Code ReviewReview of PR #6633 The changes are straightforward and generally look good. Two minor notes: 1. Defensive arithmetic (
|
Lines of code reportTotal lines added: Detailed view |
Greptile SummaryThis PR adds a focused integration test for the
Confidence Score: 5/5The changes are safe to merge: one restores an observability log that was inadvertently dropped in a refactor, and the other adds a targeted integration test closing a known test gap. Both changes are narrow and well-scoped. The trace restoration uses safe arithmetic (retain can only shrink the maps) and is guarded against noise. The new test correctly drives No files require special attention.
|
| Filename | Overview |
|---|---|
| crates/networking/p2p/discv5/server.rs | Restores the stale-entry cleanup trace by capturing before/after sizes around both retain calls; the subtraction is safe since retain can only remove entries, and the log is guarded by total_removed > 0 to avoid noise. |
| test/tests/p2p/discovery/discv5_server_tests.rs | Adds test_handle_pong_same_ip_does_not_bump_enr_seq which correctly exercises the winning_ip != self.local_node.ip guard via discv5_handle_pong; the seq assertion is the meaningful check since update_local_ip always increments seq, while the ip assertion is a harmless complementary check. |
Sequence Diagram
sequenceDiagram
participant Test
participant DiscoveryServer
participant Discv5State
participant PeerTable
loop "i = 1, 2, 3 (i = 3 triggers threshold)"
Test->>DiscoveryServer: "discv5_handle_pong(PongMessage{ip=original_ip}, sender_id=i)"
DiscoveryServer->>PeerTable: record_pong_received(sender_id, req_id)
PeerTable-->>DiscoveryServer: Ok (no-op, unknown node)
DiscoveryServer->>PeerTable: get_contact(sender_id)
PeerTable-->>DiscoveryServer: None
DiscoveryServer->>Discv5State: record_ip_vote(original_ip, sender_id)
alt "i < 3"
Discv5State-->>DiscoveryServer: None (below threshold)
else "i = 3"
Discv5State-->>DiscoveryServer: Some(original_ip) (round ended)
DiscoveryServer->>DiscoveryServer: "guard: winning_ip != local_node.ip? FALSE"
Note over DiscoveryServer: update_local_ip NOT called, ENR seq unchanged
end
DiscoveryServer-->>Test: Ok(())
end
Test->>Test: "assert local_node.ip == original_ip"
Test->>Test: "assert local_node_record.seq == original_seq"
Reviews (1): Last reviewed commit: "test(l1): cover discv5 IP-voting guard a..." | Re-trigger Greptile
🤖 Codex Code Review
Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
🤖 Claude Code ReviewNow I have all the context I need. Let me write the review. PR Review:
|
|
Addressed feedback from bot reviews in 87de359 and 4cddfb0:
Not addressed:
|
|
…p trace (lambdaclass#6633) **Motivation** Follow-up to [lambdaclass#6449](lambdaclass#6449) (unified DiscoveryServer). Addresses two non-blocking items from edg-l's review: 1. **Test gap on IP voting guard** — `test_ip_voting_no_update_if_same_ip` calls `Discv5State::record_ip_vote` directly, which never mutates `server.local_node`, so the assertion at `local_node.ip == original_ip` trivially passes. The actual guard at `discv5_handlers.rs:379` (`winning_ip != self.local_node.ip`, gating `update_local_ip`) was unexercised. 2. **Observability regression on stale-entry cleanup** — the old `discv5::cleanup_stale_entries` emitted `trace!("Cleaned up N stale entries (M messages, K challenges)")`; the new `Discv5State::cleanup_stale_entries` no longer did. **Description** - Added `test_handle_pong_same_ip_does_not_bump_enr_seq` in `test/tests/p2p/discovery/discv5_server_tests.rs`. Drives `server.discv5_handle_pong` three times with `recipient_addr.ip()` equal to `server.local_node.ip` and distinct sender IDs. After the threshold is reached the new test asserts that `server.local_node_record.seq` is unchanged — directly locking in the guard at `discv5_handlers.rs:379`. - Restored the cleanup trace in `Discv5State::cleanup_stale_entries`, only emitted when something was actually removed (avoids per-tick noise). **Checklist** - [x] No `Store` schema change.
Motivation
Follow-up to #6449 (unified DiscoveryServer). Addresses two non-blocking items from edg-l's review:
Test gap on IP voting guard —
test_ip_voting_no_update_if_same_ipcallsDiscv5State::record_ip_votedirectly, which never mutatesserver.local_node, so the assertion atlocal_node.ip == original_iptrivially passes. The actual guard atdiscv5_handlers.rs:379(winning_ip != self.local_node.ip, gatingupdate_local_ip) was unexercised.Observability regression on stale-entry cleanup — the old
discv5::cleanup_stale_entriesemittedtrace!("Cleaned up N stale entries (M messages, K challenges)"); the newDiscv5State::cleanup_stale_entriesno longer did.Description
test_handle_pong_same_ip_does_not_bump_enr_seqintest/tests/p2p/discovery/discv5_server_tests.rs. Drivesserver.discv5_handle_pongthree times withrecipient_addr.ip()equal toserver.local_node.ipand distinct sender IDs. After the threshold is reached the new test asserts thatserver.local_node_record.seqis unchanged — directly locking in the guard atdiscv5_handlers.rs:379.Discv5State::cleanup_stale_entries, only emitted when something was actually removed (avoids per-tick noise).Checklist
Storeschema change.