-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix a division by zero in light client RPC handler #7917
Conversation
It looks like @tomaka signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
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.
👍
@@ -366,7 +367,7 @@ impl OnDemand { | |||
.filter_map(|pending| { | |||
// the peer we dispatch to is chosen randomly | |||
let num_peers = peers.len(); | |||
let rng = rand::random::<usize>() % num_peers; | |||
let rng = rand::random::<usize>() % cmp::max(num_peers, 1); |
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 it should be a question to the previous PR, but why are we always skipping the same peers from the front of peers
?
Wouldn't it be better to randomly partition the collection instead?
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.
I'm not sure I get it.
The code only chooses one node to dispatch the request to (not a range of nodes). And since we go through the list of nodes twice, each node has an equal chance to be chosen if I'm not mistaken.
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.
I see, misread the code below. Looks good.
Accidentally introduced in #7844