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

Remove support for multiple network protocols #2005

Merged
merged 4 commits into from
Mar 19, 2019

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Mar 15, 2019

In preparation for the addition of the peerset, this PR removes support for multiple custom protocols.
In practice we were only ever using one anyway.

Also in practice I don't think multiple protocols were working. It's an untested feature, and I can think of a few possible situations that we may not handle properly.

Support for multiple protocols can be added back in the future if there's a need.

While the diff is quite large, it is mostly renames, removing the protocol_id field, and moving a few functions around. No logic has been touched.

@tomaka tomaka added the A0-please_review Pull request needs code review. label Mar 15, 2019
@tomaka
Copy link
Contributor Author

tomaka commented Mar 15, 2019

This slightly modifies what the system_networkState RPC produces, and the state that it sent to the telemetry. (cc @gterzian @maciejhirsz)

@@ -77,8 +77,8 @@ impl<TMessage, TSubstream> Behaviour<TMessage, TSubstream> {
/// Also note that even we have a valid open substream, it may in fact be already closed
/// without us knowing, in which case the packet will not be received.
#[inline]
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth updating the comment here as well.


/// Topology of the network.
topology: NetTopology,

/// List of custom protocols that we have open with remotes.
open_protocols: Vec<(PeerId, ProtocolId)>,
opened_peers: FnvHashSet<PeerId>,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@@ -302,11 +288,10 @@ impl<TMessage, TSubstream> CustomProtos<TMessage, TSubstream> {
///
/// Also note that even we have a valid open substream, it may in fact be already closed
/// without us knowing, in which case the packet will not be received.
pub fn send_packet(&mut self, target: &PeerId, protocol_id: ProtocolId, message: TMessage) {
pub fn send_packet(&mut self, target: &PeerId, message: TMessage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

));
let event = CustomProtosOut::CustomMessage {
CustomProtoHandlerOut::CustomMessage { message } => {
let event = CustomProtoOut::CustomMessage {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could keep the debug assert as self.is_open(&source)

Copy link
Contributor

Choose a reason for hiding this comment

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

There are two more removed asserts nearby - in CustomProtoHandlerOut::CustomProtocolOpen (opposite assert) && in CustomProtoHandlerOut::Clogged (the same assert). Probably worth keep these as well?

/// different enum that doesn't contain any `protocol_id`, and the caller would inject
/// the ID itself, but that's a ton of code for not much gain.
fn poll(&mut self) -> Option<CustomProtoHandlerOut<TMessage>> {
for n in (0..self.pending_response.len()).rev() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be while let Some(_) = self.pending_response.pop() {? Any advantages of this approach that I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're calling self.pending_response.push(...) within the loop. By doing it this way we only process each element once.

}
},
Ok(Async::Ready(Some(RegisteredProtocolEvent::Clogged { .. }))) =>
unreachable!("Cannot receive Clogged message with new protocol version; QED"),
Copy link
Contributor

Choose a reason for hiding this comment

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

As I'm reading the entire code for the first time it seem that it could be a bit more elaborate, might be good to give some hints (roughly) what parts of the code guarantees that.

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 was going to add a code comment, but it would be redundant with the message. Basically there's a backwards-compatible version of the protocol and a new version that we're going to enable in the future. The new version doesn't generate Clogged events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the Clogged event is the next step in #1692.

let mut substream = self.incoming_substreams.swap_remove(n);
match substream.poll() {
Ok(Async::Ready(Some(RegisteredProtocolEvent::Message(message)))) => {
if let CustomMessageId::Request(id) = message.request_id() {
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 match?

});
} else {
self.shutdown.push(substream);
return Some(CustomProtoHandlerOut::ProtocolError {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could return the entire if-else expression, would be clearer that this branch always returns.

shutdown_list(&mut self.shutdown);
None
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed that entire code was just moved, so feel free to disregards the comments.

@maciejhirsz
Copy link
Contributor

Telemetry currently is completely agnostic on what network state JSON is.

@tomaka tomaka merged commit 48b185d into paritytech:master Mar 19, 2019
@tomaka tomaka deleted the multi-proto-remove branch March 19, 2019 10:57
MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Apr 12, 2019
* Remove support multiple network protocols

* Address concerns

* Add back debug_asserts
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.

5 participants