-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Honor --max-peers if --min-peers is not specified #8087
Conversation
It looks like @niklasad1 signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
7b68b15
to
49ac1f0
Compare
Sorry for adding a reviewer, mouse click error. |
57cdbd9
to
b9de9f3
Compare
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.
Looks good, left a suggestion to simplify the code.
parity/configuration.rs
Outdated
@@ -467,7 +474,13 @@ impl Configuration { | |||
} | |||
|
|||
fn min_peers(&self) -> u32 { | |||
self.args.arg_peers.unwrap_or(self.args.arg_min_peers) as u32 | |||
match (self.args.arg_max_peers, self.args.arg_min_peers) { |
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.
why not:
self.args.arg_min_peers
.or(self.args.arg_max_peers)
.unwrap_or(DEFAULT_MIN_PEERS) as u32
?
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.
yepp, that is way cleaner
parity/configuration.rs
Outdated
@@ -455,8 +457,13 @@ impl Configuration { | |||
} | |||
|
|||
fn max_peers(&self) -> u32 { | |||
let peers = self.args.arg_max_peers as u32; | |||
max(self.min_peers(), peers) | |||
match (self.args.arg_max_peers, self.args.arg_min_peers) { |
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.
self.args.arg_max_peers
.or(self.args.arg_min_peers)
.unwrap_or(DEFAULT_MAX_PEERS) as u32
b9de9f3
to
211b832
Compare
parity/cli/usage.rs
Outdated
// Skip loading config file if no_config flag is specified | ||
if raw_args.flag_no_config { | ||
return Ok(raw_args.into_args(Config::default())); | ||
else if raw_args.flag_no_config { |
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.
This else
is fishy, why do we ignore no-config
flag if max_peers or min_peers are not provided?
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.
Yes, I also think this else
is a mistake.
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.
Yepp, you’re right it should be s/else if/if.
I made a faulty assumption that first if statement catches only errors!
parity/cli/usage.rs
Outdated
// Skip loading config file if no_config flag is specified | ||
if raw_args.flag_no_config { | ||
return Ok(raw_args.into_args(Config::default())); | ||
else if raw_args.flag_no_config { |
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.
Yes, I also think this else
is a mistake.
parity/configuration.rs
Outdated
max(self.min_peers(), peers) | ||
self.args.arg_max_peers | ||
.or(self.args.arg_min_peers) | ||
.unwrap_or(DEFAULT_MAX_PEERS) as u32 |
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.
In case max_peers
isn't defined can we set it to max(min_peers, DEFAULT_MAX_PEERS)
? With the current code if you start parity with just --min-peers 5
, max peers will also be set to 5 (I'd expect it to use the default value).
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.
Yepp, I'll buy that
@@ -467,7 +470,9 @@ impl Configuration { | |||
} | |||
|
|||
fn min_peers(&self) -> u32 { | |||
self.args.arg_peers.unwrap_or(self.args.arg_min_peers) as u32 | |||
self.args.arg_min_peers |
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.
Same as above but with min(max_peers, DEFAULT_MIN_PEERS)
.
* Only min specified -> Set min to that value and max to default * Only max specified -> Set min and max to that value * Both specified -> Set min the smallest value and max to the largest value
211b832
to
9d421ab
Compare
let peers = self.args.arg_max_peers as u32; | ||
max(self.min_peers(), peers) | ||
self.args.arg_max_peers | ||
.or(max(self.args.arg_min_peers, Some(DEFAULT_MAX_PEERS))) |
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.
This will always return T
as long at least one of the arguments is Some
but I kept unwrap_or
if somebody reacts if we use raw unwrapping
self.args.arg_peers.unwrap_or(self.args.arg_min_peers) as u32 | ||
self.args.arg_min_peers | ||
.or(min(self.args.arg_max_peers, Some(DEFAULT_MIN_PEERS))) | ||
.unwrap_or(DEFAULT_MIN_PEERS) as u32 | ||
} |
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.
same here!
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!
Attempt to solve #7576
This PR changes the following:
cli/mod.rs
toOption<u16>
I'm not sure if this is the right approach but seemed most straight-forward to me