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

Peer status peer scorer #7480

Merged
merged 66 commits into from
Nov 18, 2020
Merged

Peer status peer scorer #7480

merged 66 commits into from
Nov 18, 2020

Conversation

farazdagi
Copy link
Contributor

@farazdagi farazdagi commented Oct 9, 2020

What type of PR is this?

Feature

What does this PR do? Why is it needed?

  • Implements PeerStatusScorer (scores peer on chain status - fork digest and head slot). This scorer can be used as base for more p2p scorers.
  • Scoring is done using:
    • Validation error, that can be injected into scorer (on ErrWrongForkDigestVersion peer is marked as bad)
    • Head slot (scorer keeps track of the highest known head slot, and scores peers using that highest slot as a baseline).

Which issues(s) does this PR fix?

Part of #6622

Other notes for review

@farazdagi farazdagi self-assigned this Oct 9, 2020
@codecov
Copy link

codecov bot commented Oct 9, 2020

Codecov Report

Merging #7480 into master will decrease coverage by 0.03%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #7480      +/-   ##
==========================================
- Coverage   61.99%   61.96%   -0.04%     
==========================================
  Files         424      423       -1     
  Lines       29798    30081     +283     
==========================================
+ Hits        18473    18639     +166     
- Misses       8424     8507      +83     
- Partials     2901     2935      +34     

@stale
Copy link

stale bot commented Oct 22, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale There hasn't been any activity here in some time... label Oct 22, 2020
@farazdagi farazdagi removed the Stale There hasn't been any activity here in some time... label Oct 28, 2020
@stale
Copy link

stale bot commented Nov 5, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale There hasn't been any activity here in some time... label Nov 5, 2020
@farazdagi farazdagi mentioned this pull request Nov 5, 2020
7 tasks
@farazdagi farazdagi marked this pull request as ready for review November 18, 2020 12:51
@farazdagi farazdagi requested a review from a team as a code owner November 18, 2020 12:51
@farazdagi farazdagi added Ready For Review A pull request ready for code review OK to merge labels Nov 18, 2020
@@ -58,6 +58,9 @@ func (s *BadResponsesScorer) Score(pid peer.ID) float64 {

// score is a lock-free version of Score.
func (s *BadResponsesScorer) score(pid peer.ID) float64 {
if s.isBadPeer(pid) {
return BadPeerScore
Copy link
Member

@nisdas nisdas Nov 18, 2020

Choose a reason for hiding this comment

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

in that case, you only return -1 . Isn't that a very low negative score for a 'bad' peer ? Shouldn't it be more in absolute terms

Copy link
Contributor Author

@farazdagi farazdagi Nov 18, 2020

Choose a reason for hiding this comment

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

All the scores will be within [0..1] range (signed). Then you can change scorer's weight (in aggregate service we have weights), and turn that into anything you want (for example bad responses scorer can have a magnifying coefficient x10, and turn that into -10).

return false
}
// Mark peer as bad, if the latest error is one of the terminal ones.
terminalErrs := []error{
Copy link
Member

Choose a reason for hiding this comment

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

maybe store this out of the function and in the general file. Rather than initializing it in the function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I address this in the next PR (I will extend that field to include other errors there anyway)?

s.p2p.Peers().Scorers().PeerStatusScorer().SetPeerStatus(id, msg, err)
if s.p2p.Peers().IsBad(id) {
s.disconnectBadPeer(s.ctx, id)
return s.p2p.Peers().Scorers().ValidationError(id)
Copy link
Member

Choose a reason for hiding this comment

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

no need to return validation error here, we can just allow the function to exit with the error below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

@prylabs-bulldozer prylabs-bulldozer bot merged commit 095c4d5 into master Nov 18, 2020
@delete-merged-branch delete-merged-branch bot deleted the p2p-peer-scoring branch November 18, 2020 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants