P2P: fix handshake race, harden conn pooling, and speed up cascade hot-path#148
Merged
mateeullahmalik merged 9 commits intomasterfrom Sep 2, 2025
Merged
P2P: fix handshake race, harden conn pooling, and speed up cascade hot-path#148mateeullahmalik merged 9 commits intomasterfrom
mateeullahmalik merged 9 commits intomasterfrom
Conversation
98e1e20 to
cb2ceab
Compare
j-rafique
previously approved these changes
Sep 1, 2025
The merge-base changed after approval.
978ab0a to
5e0df94
Compare
afc1bb9 to
1970313
Compare
j-rafique
previously approved these changes
Sep 2, 2025
fd4a959 to
95af05f
Compare
j-rafique
approved these changes
Sep 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
P2P: fix handshake race, harden conn pooling, sanitize addresses, and speed up cascade hot-path
Summary
This PR removes the intermittent timeouts and “remote identity mismatch” on healthy peers and makes the cascade hot-path (BatchFindNode + BatchStoreData) consistently fast under churn.
Themes
What changed
TLS creds (handshake)
LumeraTC.Clone()(deep copiesProtocolInfo, clearsremoteIdentity).NewSecureClientConnnow clones creds per dial and setsremoteIdentityon the clone beforeClientHandshake(no shared mutation/race).Connection pooling / RPC pipeline
base58(Receiver.ID)@ip:port(no raw-byte strings).connWrapper, we lock across write+read (prevents response cross-talk).SetWriteDeadline(now+3s)→WriteSetReadDeadline(now+timeout)→decodeSetDeadline(time.Time{})after success (clear for reuse)Address hygiene
0.0.0.0, loopback, link-local, and (public overlay) RFC1918/private IPs on ingest (addKnownNodes).newMessage; prefer configured Advertise IP (never broadcast0.0.0.0).Hot-path tuning
BatchStoreData→ 12s (from 60s),BatchFindNode→ 12–15s.batchFindNodeup to 64 in-flight;batchStoreNetworkup to 16 in-flight.Why this helps
Risks & mitigations
Clone()deep-copiesProtocolInfoand doesn’t share mutable state.Clone(); code review focus here.Testing
Clone()deep-copy behavior;remoteIdentitynot retained.-race.0.0.0.0/loopback/private IPs in routing tables.TL;DR: Eliminates the handshake race, hardens pooling & deadlines, sanitizes addresses, and dials in concurrency/timeouts. Expect a big drop in false timeouts and a seconds-level cascade hot path.