Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use the lowest latency peer for light protocols #1511

Closed
wants to merge 6 commits into from

Conversation

danisharora099
Copy link
Collaborator

@danisharora099 danisharora099 commented Aug 28, 2023

Problem

During selection of peers to be used for light protocols, the selection currently happens randomly. This is not ideal, as we might potentially be communicating with a higher latency node, while an option to use a faster node might exist.

Ref: #1465 #1497

Solution

Instead of randomly selecting peers, ping all peers and select the peer with the lowest latency.

Notes

  • this might potentially mean that pinging could take longer than randomly selecting a peer:

TODO

@github-actions
Copy link

github-actions bot commented Aug 28, 2023

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku core 84.94 KB (+176.22% 🔺) 1.7 s (+176.22% 🔺) 317 ms (+51.43% 🔺) 2.1 s
Waku Simple Light Node 317.45 KB (+1.67% 🔺) 6.4 s (+1.67% 🔺) 584 ms (-9.09% 🔽) 7 s
ECIES encryption 28.68 KB (0%) 574 ms (0%) 219 ms (-0.55% 🔽) 793 ms
Symmetric encryption 28.69 KB (0%) 574 ms (0%) 207 ms (-21.96% 🔽) 780 ms
DNS discovery 116.43 KB (0%) 2.4 s (0%) 501 ms (+71.85% 🔺) 2.9 s
Privacy preserving protocols 126.7 KB (+2.86% 🔺) 2.6 s (+2.86% 🔺) 505 ms (+35.62% 🔺) 3.1 s
Light protocols 85.79 KB (+180.99% 🔺) 1.8 s (+180.99% 🔺) 298 ms (+129.73% 🔺) 2.1 s
History retrieval protocols 85.05 KB (+186.15% 🔺) 1.8 s (+186.15% 🔺) 209 ms (+29.89% 🔺) 2 s
Deterministic Message Hashing 5.78 KB (0%) 116 ms (0%) 59 ms (-6.8% 🔽) 174 ms

we now maybe pinging a peer from two different places: KeepAliveManager and while finding lowest latency peer
there doesn't seem to be a direct way to reuse a stream for pinging
packages/core/src/lib/store/index.ts Show resolved Hide resolved
@@ -16,6 +19,30 @@ export function selectRandomPeer(peers: Peer[]): Peer | undefined {
return peers[index];
}

/**
*
* @param ping The libp2p ping service's ping function
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, I'd just re-use the keep alive functionality at this point in time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1520 :D

@danisharora099
Copy link
Collaborator Author

superseded by #1520

@danisharora099 danisharora099 deleted the feat/fastest-peer-connection branch December 18, 2023 11:39
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.

2 participants