-
Notifications
You must be signed in to change notification settings - Fork 990
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
Improve checking for p2p connection limits #2985
Changes from all commits
47c90b0
a0145a5
1e3ed81
7bfb54e
fb9b06e
d06a8e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,12 +274,18 @@ fn comments() -> HashMap<String, String> { | |
#how long a banned peer should stay banned | ||
#ban_window = 10800 | ||
|
||
#maximum number of peers | ||
#peer_max_count = 125 | ||
#maximum number of inbound peer connections | ||
#peer_max_inbound_count = 128 | ||
|
||
#preferred minimum number of peers (we'll actively keep trying to add peers | ||
#until we get to at least this number | ||
#peer_min_preferred_count = 8 | ||
#maximum number of outbound peer connections | ||
#peer_max_outbound_count = 8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the point of this? If this is greater than peer_min_preferred_outbound_count, do we continue to connect to more outbound peers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But let's say you have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may not after future refactoring to better clean up distinguishing incoming and outgoing connections. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😕 You're saying we open outbound connections when broadcasting compact blocks? Where in the code does that take place, and what for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After taking a closer look new outbound connections are not open when broadcasting, my mistake. During testing there were cases where logic allowed opening new connections beyond the outgoing limit which got closed shortly after during |
||
|
||
#preferred minimum number of outbound peers (we'll actively keep trying to add peers | ||
#until we get to at least this number) | ||
#peer_min_preferred_outbound_count = 8 | ||
|
||
#amount of incoming connections temporarily allowed to exceed peer_max_inbound_count | ||
#peer_listener_buffer_count = 8 | ||
|
||
# 15 = Bit flags for FULL_NODE | ||
#This structure needs to be changed internally, to make it more configurable | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,9 +185,12 @@ fn monitor_peers( | |
); | ||
|
||
// maintenance step first, clean up p2p server peers | ||
peers.clean_peers(config.peer_max_count() as usize); | ||
peers.clean_peers( | ||
config.peer_max_inbound_count() as usize, | ||
config.peer_max_outbound_count() as usize, | ||
); | ||
|
||
if peers.healthy_peers_mix() { | ||
if peers.enough_outbound_peers() { | ||
return; | ||
} | ||
|
||
|
@@ -230,7 +233,7 @@ fn monitor_peers( | |
let new_peers = peers.find_peers( | ||
p2p::State::Healthy, | ||
p2p::Capabilities::UNKNOWN, | ||
config.peer_max_count() as usize, | ||
config.peer_max_outbound_count() as usize, | ||
); | ||
|
||
for p in new_peers.iter().filter(|p| !peers.is_known(p.addr)) { | ||
|
@@ -296,15 +299,18 @@ fn listen_for_addrs( | |
let addrs: Vec<PeerAddr> = rx.try_iter().collect(); | ||
|
||
// If we have a healthy number of outbound peers then we are done here. | ||
if peers.peer_count() > peers.peer_outbound_count() && peers.healthy_peers_mix() { | ||
if peers.enough_outbound_peers() { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. They don't quite check the same thing but I think we only want the Removed in fb9b06e unless there is a good reason to keep this as is. |
||
} | ||
|
||
// Try to connect to (up to max peers) peer addresses. | ||
// Try to connect to (up to max outbound peers) peer addresses. | ||
// Note: We drained the rx queue earlier to keep it under control. | ||
// Even if there are many addresses to try we will only try a bounded number of them. | ||
let connect_min_interval = 30; | ||
for addr in addrs.into_iter().take(p2p.config.peer_max_count() as usize) { | ||
for addr in addrs | ||
.into_iter() | ||
.take(p2p.config.peer_max_outbound_count() as usize) | ||
{ | ||
// ignore the duplicate connecting to same peer within 30 seconds | ||
let now = Utc::now(); | ||
if let Some(last_connect_time) = connecting_history.get(&addr) { | ||
|
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.
👍