Skip to content
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

feat(census): add peer scoring #1579

Merged
merged 1 commit into from
Nov 2, 2024
Merged

Conversation

morph-dev
Copy link
Collaborator

@morph-dev morph-dev commented Nov 1, 2024

What was wrong?

Census doesn't use information about previous successful/failed requests when selecting peers (instead, it selects them randomly).
Previous PRs made this information available.

Part of #1501

How was it fixed?

Added Weight trait that can be used to calculate peers weights, and PeerSelector that picks peers based on weights.

Current implementation of Weight is based on Piper's suggestion:

  • starting weight is 200
  • we keep track of up to 255 latest requests per peer
  • each successful request in the last 15 min increases weight by 5
  • each failed request in the last 15 min decreases weight by 10
  • final weight is restricted to [0, 400] range

In the future, we can implement multiple versions of Weight, make them configurable via cli flags, and compare them in practice.

@morph-dev morph-dev added the portal-bridge Portal bridge label Nov 1, 2024
@morph-dev morph-dev self-assigned this Nov 1, 2024

weighted_peers
.choose_multiple_weighted(&mut thread_rng(), self.limit, |(_peer, weight)| *weight)
.expect("choosing random sample shouldn't fail")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fail if there are zero peers?

Copy link
Collaborator Author

@morph-dev morph-dev Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't.
That can fail if weight is negative (api allows any type that can be converted to f64), which can't happen in our case because we use u32.

Weight 0 would also be picked, but only if there isn't enough weights that are non-zero, which is what we want.

One thing that we don't differentiate at the moment is that weight can be 0 if:

  • content doesn't fall within radius
  • peer has very negative weight

It might be better to never select peer whose radius doesn't include content. But I left that for future optimization

Copy link
Member

@KolbyML KolbyML left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: looks good

Comment on lines +20 to +23
#[allow(dead_code)]
pub content_value_size: usize,
#[allow(dead_code)]
pub duration: Duration,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there plans to use these in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
Idea is to measure bandwidth and prefer peers that are faster than average.

But I didn't want to complicate initial work, and I don't think it works well with current implementation of "Weight" because peers that are working would quickly increase their weight to maximum and this wouldn't make a difference.

@morph-dev morph-dev merged commit 8314365 into ethereum:master Nov 2, 2024
9 checks passed
@morph-dev morph-dev deleted the scoring branch November 2, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
portal-bridge Portal bridge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants