-
Notifications
You must be signed in to change notification settings - Fork 864
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
Making sure that the resolved DNS lists get used in full #3071
Conversation
@@ -376,6 +377,7 @@ void attemptPeerConnections() { | |||
public Stream<DiscoveryPeer> streamDiscoveredPeers() { | |||
List<DiscoveryPeer> peers = dnsPeers.get(); | |||
if (peers != null) { | |||
Collections.shuffle(peers); | |||
return Stream.concat(peerDiscoveryAgent.streamDiscoveredPeers(), peers.stream()); | |||
} | |||
return peerDiscoveryAgent.streamDiscoveredPeers(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can also shuffle this part ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, unfortunately streams don't have a convenient method to shuffle the elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shuffling a stream goes against the "lazy" nature of a stream I would say. To shuffle it you would need to process all elements at least once. So you need to collect, shuffle, and convert result to another stream.
I am going to add a test covering the |
Signed-off-by: Jiri Peinlich <jiri.peinlich@gmail.com>
Previously we would always process the list from the beginning. We would only try maximumpeers elements from the list and never try more. This PR firstly shuffles the peers list each time before applying it and then also takes from the list for as long as there are free peers slots available. Signed-off-by: Jiri Peinlich <jiri.peinlich@gmail.com>
I added a test to check the takeWhile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
SonarCloud Quality Gate failed. |
…#3071) * Checking that we try hard enough to get peers from dns-discovery Signed-off-by: Jiri Peinlich <jiri.peinlich@gmail.com> * Making sure that the resolved DNS lists get used in full Previously we would always process the list from the beginning. We would only try maximumpeers elements from the list and never try more. This PR firstly shuffles the peers list each time before applying it and then also takes from the list for as long as there are free peers slots available. Signed-off-by: Jiri Peinlich <jiri.peinlich@gmail.com> Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
Signed-off-by: Jiri Peinlich jiri.peinlich@gmail.com
PR description
Previously we would always process the list of DNS resolved peers from the beginning. We would
at most only try
maxConnections
valid elements from the list and never try more. So the eachtime we might be trying the same 25 peers, we connect with them and then drop them. This PR
firstly shuffles the peers list each time before applying it and then also takes from the list for
as long as there are free peers slots available as opposed to guess the limit upfront and hope
that all the peers connect.
Changelog