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

Switch to new light client protocol #5472

Merged
merged 5 commits into from
Apr 1, 2020

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Mar 31, 2020

(built on top of #5461)

In #3520, we introduced a second light client protocol with the intent of replacing the current one.
This PR switches to this new protocol by default for all light client requests.

Summary of the changes:

  • Removes the light_dispatch module entirely, as it was responsible for the old protocol. Also removes the code paths in protocol.rs that handles receiving responses on the old protocol. Note that we still answer requests, so this doesn't break backwards compatibility.

  • The code in on_demand_layer now generates light_client_handler::Requests instead of light_dispatch::RequestDatas for the network service to pick up. These two types are equivalent except that the new one uses the new protocol.

  • When the code in protocol.rs detects a new best block for a peer, it reports it as a CustomMessageOutcome::PeerNewBest event so that we can update the state of the LightClientHandler. This is mandatory for it to know who to dispatch requests to.

  • Here's probably the biggest change: lights nodes must also be able to perform block requests, and block requests are done on the wire through the regular sync-ing protocol. Unfortunately the LightClientHandler before this PR cannot handle these queries, as it is not "its" protocol. After discussion with @twittner, I changed light_client_handler to also be able to emit BlockRequests and receive back BlockResponses. While this is not a great solution, it is in my opinion the cleanest thing to do.

  • Moves light_dispatch::AlwaysBadChecker to the on_demand module and light_dispatch::TIMEOUT_REPUTATION_CHANGE to light_client_handler.

  • Adds a Prometheus counter to the number of light requests that have been issued out.

Compatibility

After this PR, light clients will no longer be able to make queries to nodes that don't include #3520 (which was merged on February 12th).

Considering that this concerns the light client I don't think that this is a serious problem to anyone, but let me know if I'm wrong.

@tomaka tomaka added A0-please_review Pull request needs code review. B1-clientnoteworthy labels Mar 31, 2020
@tomaka tomaka requested a review from twittner March 31, 2020 14:31
@tomaka tomaka changed the title Switch new proto Switch to new light client protocol Mar 31, 2020
who: PeerId,
response: message::RemoteCallResponse
_: PeerId,
_: message::RemoteCallResponse
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not removing this and the other empty methods?

@@ -897,7 +912,11 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
// Check for new incoming light client requests.
if let Some(light_client_rqs) = this.light_client_rqs.as_mut() {
while let Poll::Ready(Some(rq)) = light_client_rqs.poll_next_unpin(cx) {
this.network_service.user_protocol_mut().add_light_client_request(rq);
// This can error if there are too many queued requests already.
let _ = this.network_service.light_client_request(rq);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not log a message here if an error has been returned? Are there plans to replace those unbounded channels with something that can exercise back pressure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are there plans to replace those unbounded channels with something that can exercise back pressure?

That would be #3230

@gavofyork gavofyork merged commit f68d22f into paritytech:master Apr 1, 2020
@tomaka tomaka deleted the switch-new-proto branch April 1, 2020 17:46
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants