Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fix a division by zero in light client RPC handler #7917

Merged
merged 1 commit into from
Feb 17, 2018

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Feb 16, 2018

Accidentally introduced in #7844

@parity-cla-bot
Copy link

It looks like @tomaka signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@tomaka tomaka added F2-bug 🐞 The client fails to follow expected behavior. A0-pleasereview 🤓 Pull request needs code review. B0-patch M4-core ⛓ Core client code / Rust. labels Feb 16, 2018
@debris debris added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 16, 2018
Copy link
Contributor

@andresilva andresilva left a 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);
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

@5chdn 5chdn added P2-asap 🌊 No need to stop dead in your tracks, however issue should be addressed as soon as possible. and removed F2-bug 🐞 The client fails to follow expected behavior. labels Feb 16, 2018
@5chdn 5chdn added this to the 1.10 milestone Feb 16, 2018
@debris debris merged commit 364a1fa into openethereum:master Feb 17, 2018
@5chdn
Copy link
Contributor

5chdn commented Feb 17, 2018

@tomaka could you backport #7844 and #7917 to beta? cheers 🍻

@tomaka tomaka deleted the fix-div-0 branch February 19, 2018 10:00
5chdn pushed a commit that referenced this pull request Feb 19, 2018
* Randomize the peer we dispatch to

* Fix a division by zero in light client RPC handler
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust. P2-asap 🌊 No need to stop dead in your tracks, however issue should be addressed as soon as possible.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants