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

client/network: Report reputation changes via response #7958

Merged
5 commits merged into from
Jan 26, 2021

Conversation

mxinden
Copy link
Contributor

@mxinden mxinden commented Jan 22, 2021

When handling a request by a remote peer in a request response handler,
one might want to in- or de-crease the reputation of the peer. E.g. one
might want to decrease the reputation slightly for each request, given
that it forces the local node to do work, or one might want to issue a
larger reputation change due to a malformed request by the remote peer.

Instead of having to pass a peerset handle to each request response
handler, this commit suggests to allow handlers to isssue reputation
changes via the provided pending_response oneshot channel.

A reputation change issued by a request response handler via the
pending_response channel is received by the
RequestResponsesBehaviour which passes the reputation change up as an
event to eventually be send to a peerset via a peerset handle.


Particular use-case for this change is #7895 more specifically the light client request response handler. See #7895 for details.

While I think the API proposed here is decent, I would be happy to see alternative suggestions.

When handling a request by a remote peer in a request response handler,
one might want to in- or de-crease the reputation of the peer. E.g. one
might want to decrease the reputation slightly for each request, given
that it forces the local node to do work, or one might want to issue a
larger reputation change due to a malformed request by the remote peer.

Instead of having to pass a peerset handle to each request response
handler, this commit suggests to allow handlers to isssue reputation
changes via the provided `pending_response` `oneshot` channel.

A reputation change issued by a request response handler via the
`pending_response` channel is received by the
`RequestResponsesBehaviour` which passes the reputation change up as an
event to eventually be send to a peerset via a peerset handle.
@mxinden mxinden added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Jan 22, 2021
@mxinden mxinden requested a review from tomaka January 22, 2021 19:01
Copy link
Contributor

@tomaka tomaka left a comment

Choose a reason for hiding this comment

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

You also need to update the sc-finality-grandpa-warp-sync handler.

Other than that, looks good to me.

pub result: Result<Vec<u8>, ()>,
/// Reputation changes accrued while handling the request. To be applied to the reputation of
/// the peer sending the request.
pub reputation_changes: Option<Vec<ReputationChange>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub reputation_changes: Option<Vec<ReputationChange>>,
pub reputation_changes: Vec<ReputationChange>,

I don't understand why this Option is needed, since None and Vec::new() represent the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Somehow thought Vec::new allocates. Done in 3abb27a.

@mxinden
Copy link
Contributor Author

mxinden commented Jan 26, 2021

bot merge

@ghost
Copy link

ghost commented Jan 26, 2021

Trying merge.

@ghost ghost merged commit addf203 into paritytech:master Jan 26, 2021
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants