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

Split Substrate messages into multiple substreams #1796

Merged
merged 2 commits into from
Feb 25, 2019

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Feb 14, 2019

Next two items of #1692
Fix #1517
See the comment here for a description: #1517 (comment)

This PR still uses the old behaviour by default. Once the network has upgraded to a version of Substrate/Polkadot that contains this PR, I'll try if everything works correctly (if we can still sync), then switch to the new behaviour by default, then eventually remove the old behaviour in the future.

While this PR adds a lot of code, removing the old behaviour would remove almost all of the custom_protos module, as we would switch to helpers that are inside libp2p.

I marked as "onice" because we need to publish a new version of the yamux crate that fixes some issues, but other than that the PR is ready.

@tomaka tomaka added A0-please_review Pull request needs code review. A1-onice labels Feb 14, 2019
@tomaka tomaka removed the A1-onice label Feb 18, 2019
@gavofyork
Copy link
Member

@tomaka who is capable of reviewing this?

@tomaka
Copy link
Contributor Author

tomaka commented Feb 21, 2019

@twittner, I suppose.

@tomaka tomaka requested a review from twittner February 21, 2019 09:28
pending_send_back: SmallVec<[(u64, RegisteredProtocolSubstream<TMessage, TSubstream>); 4]>,

/// List of messages waiting for a substream to open in order to be sent.
pending_messages: SmallVec<[TMessage; 6]>,
Copy link
Contributor

@twittner twittner Feb 21, 2019

Choose a reason for hiding this comment

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

I wonder if there should be some back pressure mechanism if this grows a lot? My understanding is that the current version measures the send queue of the RegisteredProtocolSubstream and issues CustomProtosHandlerOut::Clogged events if it becomes too large. The new approach instead requests substreams as necessary and buffers messages here. If the connection becomes congested would it be useful to issue a Clogged event based on the length of this buffer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory, opening a substream is an asynchronous operation, but in practice it's not and they open instantly. Therefore I'm not really worried about this queue growing very large.
Instead we're moving the problem to the multiplexing layer, which to me is a more appropriate layer to handle network congestion.

You're right that this pretty much makes the Clogged event useless, as it will never fire with the new system. This is why "remove the clogged event" is the next item on the list in #1692.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are substreams not made available to CustomProtocolsHandler only after protocol negotiation which requires at least a full round trip via multistream-select? Would that not take a while over a congested connection?

Copy link
Contributor Author

@tomaka tomaka Feb 21, 2019

Choose a reason for hiding this comment

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

Ah, you're right, I'll add back some clogging verification here.
In a future PR we can embed the message to send directly in the RegisteredProtocolSubstream so that sending it is part of the upgrade, which will greatly simplify the code and delegate the problem to libp2p.

@gavofyork gavofyork added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Feb 21, 2019
@bkchr bkchr merged commit 4a5b7d9 into paritytech:master Feb 25, 2019
@tomaka tomaka deleted the fix-1517 branch February 25, 2019 12:31
MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Apr 12, 2019
* Split Substrate messages into multiple substreams

* Add back Clogged event
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A3-in_progress Pull request is in progress. No review needed at this stage.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rework network/src/protocol.rs to use libp2p's multiplexing
4 participants