Skip to content

p2p: simple peer scoring#6277

Merged
tychoish merged 17 commits intotendermint:masterfrom
tychoish:peer-scoring
Mar 29, 2021
Merged

p2p: simple peer scoring#6277
tychoish merged 17 commits intotendermint:masterfrom
tychoish:peer-scoring

Conversation

@tychoish
Copy link
Contributor

@tychoish tychoish commented Mar 25, 2021

This is still up for discussion, but I thought a PR would be a
clearer format than a backwater branch.

@tychoish tychoish requested a review from cmwaters as a code owner March 25, 2021 20:31
if numVotes := ps.RecordVote(); numVotes%votesToContributeToBecomeGoodPeer == 0 { // nolint: staticcheck
// TODO: Handle peer quality via the peer manager.
// r.Switch.MarkPeerAsGood(peer)
if numVotes := ps.RecordVote(); numVotes%votesToContributeToBecomeGoodPeer == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good, but consider the case where we want different scores sent for different reasons. This is why I mentioned it might be beneficial for the reactor to send the numeric value.

Otherwise, in the future, if we want to do this, we have send unique Status types to the router and router has to switch on them. Which I guess is fine? But it seems like a code smell to me for the router to know about things like e.g. PeerScoreUpdateBadVote.

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 definitely see where you're coming from, and I think we have to balance the risk of putting reactor-specific code in the router (e.g. constants and score values) with the cost of putting routing impacting code (e.g. number values,) in the code. I'm more worried by the possibility of one reactor dominating the scoring for peers at the expense of other reactors, and having that distributed across the code base.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm more worried by the possibility of one reactor dominating the scoring for peers at the expense of other reactors, and having that distributed across the code base.

Wdym by dominating exactly? If a reactor deems that a peer is behaving very poorly or maliciously and consistently, it should be punished as so.

Thoughts @cmwaters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

while it seems important that a bad peer from the perspective of the consensus reactor is very-bad indeed, if a peer is fine from consensus, but bad from the perspective of blockchain or mempool, is that as bad as being bad at consensus?

if any badness is equal to any other badness, then we don't really need scores at all and the current "peerbad" status are fine. if some badness is worse than other badness, I guess I'm arguing that the router should be the one to judge relative levels of badness rather than letting one reactor decide it's badness (or goodness!) relative to other reactors.

Perhaps in other words: "pushing determination of actual scores into the router, means the router has to know something (very small) about all reactors, but pushing scoring into the reactors, means that every reactor needs to know about every other reactor. The former seems like the better option.

Perhaps, though, the best option is that we won't need weights at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

My two cents on this is that although I agree that the router perhaps shouldn't know reactor specific details, I do think from the perspective of code legibility and understanding the system it would be nice to list all the possible behaviours and the impact they would have on peer scoring in a single file, so someone reading that file can see exactly how peers are ranked. If we feel like there may be too many different behaviours to keep track of then I would also feel that it is valid to just have 5 or 6 different values that the individual reactors can decide on.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have enough to go on to wrap up this PR @tychoish? We can keep it simple for now I guess and just do +/- 1. But I do think ultimately, the reactors should be providing means to adjust scores directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I think the PR is pretty wrapped up at this point, aside from the (likely orthogonal) test failures.

@codecov
Copy link

codecov bot commented Mar 29, 2021

Codecov Report

Merging #6277 (c48358e) into master (cbae361) will increase coverage by 0.00%.
The diff coverage is 62.22%.

@@           Coverage Diff           @@
##           master    #6277   +/-   ##
=======================================
  Coverage   60.85%   60.85%           
=======================================
  Files         281      281           
  Lines       26628    26660   +32     
=======================================
+ Hits        16204    16225   +21     
- Misses       8741     8751   +10     
- Partials     1683     1684    +1     
Impacted Files Coverage Δ
consensus/reactor.go 67.18% <0.00%> (-0.22%) ⬇️
p2p/peermanager.go 83.75% <78.12%> (-0.64%) ⬇️
p2p/shim.go 55.63% <100.00%> (ø)
privval/signer_endpoint.go 72.72% <0.00%> (-6.07%) ⬇️
blockchain/v0/pool.go 77.18% <0.00%> (-4.57%) ⬇️
privval/signer_listener_endpoint.go 87.05% <0.00%> (-2.36%) ⬇️
blockchain/v2/reactor.go 32.04% <0.00%> (-1.06%) ⬇️
statesync/syncer.go 79.60% <0.00%> (-0.81%) ⬇️
consensus/state.go 66.57% <0.00%> (-0.28%) ⬇️
p2p/router.go 79.52% <0.00%> (ø)
... and 9 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants