Skip to content

refactor(networking): drop tests-only PeerInfo fields#756

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/drop-buffered-events-peer-fields
May 22, 2026
Merged

refactor(networking): drop tests-only PeerInfo fields#756
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/drop-buffered-events-peer-fields

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

Summary

PeerInfo.last_seen (field), PeerInfo.update_last_seen (method), and PeerInfo.fork_digest (property) had no production callers — every read or write came from test_peer.py. The spec code that needs a peer's fork-digest reads it from the cached ENR's eth2 data directly.

  • src/lean_spec/subspecs/networking/peer.py (−19): three members removed plus the now-unused field/time imports and ForkDigest re-export.
  • tests/lean_spec/subspecs/networking/test_peer.py rewritten:
    • Three test_fork_digest_* tests retire along with the property.
    • Two duplicate test_update_last_seen* tests retire along with the field.
    • The _make_enr_with_eth2 helper retires (only those tests used it).
    • Five now-unused imports drop (time, ENR, FAR_FUTURE_EPOCH, EnrKey, Bytes64, SeqNumber).
    • test_enr_and_status_fields and test_status_can_be_set stay since enr and status fields stay.

Why not the sibling audit item

The other half of the audit entry (transport/quic/connection.py:208-256_buffered_events / _replay_buffered_events) is annotated "refactor connection assignment to remove need". It is not a mechanical delete: the buffer exists to handle a real race where peer-initiated streams arrive between HandshakeCompleted and the QuicConnection wrapper assignment on the client path. The proper fix is to mirror the server's pattern and assign the wrapper synchronously inside quic_event_received via an _on_handshake callback. That refactor would retire 5+ buffer-specific tests and rewrite ~6 others, so it belongs in its own PR.

Test plan

  • ruff check src/lean_spec/subspecs/networking/peer.py tests/lean_spec/subspecs/networking/test_peer.py — clean.
  • uv run pytest tests/lean_spec/subspecs/networking/test_peer.py — 12 tests pass.
  • grep -rn "\.last_seen\|update_last_seen\|PeerInfo.*fork_digest" across src/, tests/, packages/ — no remaining references outside the test file.

🤖 Generated with Claude Code

The last_seen field, update_last_seen method, and fork_digest
property had no production callers. Grep confirmed every read or
write came from test_peer.py; the spec code that needs a peer's
fork-digest reads it from the cached ENR's eth2 data directly.

Test file rewritten:

- Three fork_digest tests retire along with the property.
- Two duplicate update_last_seen tests retire along with the field.
- The _make_enr_with_eth2 helper retires (only those tests used it).
- Five now-unused imports drop (time, ENR, FAR_FUTURE_EPOCH, EnrKey,
  Bytes64, SeqNumber).
- test_enr_and_status_fields and test_status_can_be_set stay since
  the enr and status fields stay.

The audit's sibling item (transport/quic/connection.py
_buffered_events / _replay_buffered_events) is a real architectural
refactor with deep test impact; it stays for a separate PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tcoratger tcoratger merged commit 363797e into leanEthereum:main May 22, 2026
12 of 13 checks passed
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.

1 participant