refactor(p2p): move node name registry into P2PServer#342
refactor(p2p): move node name registry into P2PServer#342conache wants to merge 6 commits intolambdaclass:mainfrom
Conversation
Greptile SummaryThis PR refactors the Confidence Score: 5/5Safe to merge — pure refactor with no behavioral changes to metrics labels, connection logic, or consensus paths. No P0 or P1 issues found. The refactor correctly balances gauge increments/decrements across all connection event paths. The memory leak via String::leak() is eliminated, global mutable state is removed, and the actor now owns all its state. Metric label values are unchanged for valid configs. No files require special attention.
|
| Filename | Overview |
|---|---|
| crates/net/p2p/src/lib.rs | Moves node-name registry into P2PServer state; adds resolve_node_name helper and public derive_peer_ids function; re-exports PeerId instead of populate_name_registry. |
| crates/net/p2p/src/metrics.rs | Removes global RwLock registry, leaked &'static str storage, and PeerId-resolving logic; metrics helpers now accept pre-resolved node_name &str directly. |
| bin/ethlambda/src/main.rs | load_node_names replaces populate_name_registry, returns HashMap<PeerId, String> which is passed to P2P::spawn; adds info! log with loaded count. |
Sequence Diagram
sequenceDiagram
participant main as main.rs
participant p2p as ethlambda_p2p
participant server as P2PServer
participant metrics as metrics.rs
main->>p2p: derive_peer_ids(names_and_privkeys)
p2p-->>main: HashMap<PeerId, String>
main->>p2p: P2P::spawn(built, store, node_names)
p2p->>server: construct P2PServer { node_names, ... }
Note over server: SwarmEvent::ConnectionEstablished
server->>server: resolve_node_name(Some(&peer_id)) → &str
server->>metrics: notify_peer_connected(node_name, direction, "success")
metrics->>metrics: LEAN_CONNECTED_PEERS[node_name].inc()
Note over server: SwarmEvent::ConnectionClosed
server->>server: resolve_node_name(Some(&peer_id)) → &str
server->>metrics: notify_peer_disconnected(node_name, direction, reason)
metrics->>metrics: LEAN_CONNECTED_PEERS[node_name].dec()
Reviews (1): Last reviewed commit: "Fix function doc comment" | Re-trigger Greptile
|
@conache can you please solve the conflicts? |
pablodeymo
left a comment
There was a problem hiding this comment.
Request solve the conflicts
@pablodeymo thanks for the heads-up! sure, just solved the conflicts! |
🗒️ Description / Motivation
The
PeerId -> node_namelookup lived in a globalRwLock<HashMap<PeerId, &'static str>>populated once at startup. This PR moves it intoP2PServerso the actor owns its own state.What Changed
crates/net/p2p/src/lib.rs: the registry is now a field on the P2P actor's state struct, with a small helper to resolve a peer's name.crates/net/p2p/src/metrics.rs: no longer owns the registry — its peer-event helpers take the resolved name directly.bin/ethlambda/src/main.rs: the loader now returns the map and hands it off toP2P::spawnat startup; it also logs how many entries it loaded.Correctness / Behavior Guarantees
lean_connected_peers{client="..."}) are unchanged for valid configs.validator-config.yaml(unparseable secp256k1 privkeys) used to be silently dropped; they now emit awarn!per drop and are still skipped. No new panics, no new failure paths.Tests Added / Run
make fmtmake lintmake testRelated Issues / PRs