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

Update to latest libp2p #1386

Merged
merged 8 commits into from
Jan 14, 2019
Merged

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Jan 10, 2019

Another networking rewrite.
Switches to libp2p 0.2 and moves a lot of code from Substrate to libp2p.

This fixes quite a lot of issues:

  • Substreams were not closed gracefully when disconnecting.
  • Kademlia substreams are now unidirectional, similar to what go-libp2p and js-libp2p do (fixes Kademlia is in fact unidirectional #901)
  • Kademlia in general should be more robust.
  • At initialization, we start by performing lots of random Kademlia queries, then the delay increases over time.
  • Fixes the fact that the dialing address of nodes (ie. the TCP dialing port) was added in the topology as well.
  • If nodes are full, they will refuse Substrate connections ("custom protocols") but will still accept Kademlia requests. This means that nodes will now be able to join the network even if bootnodes are full.
  • Fixes a race between the two nodes for the one which will open the Substrate substream the first. Now only the dialing side of the connection opens the substream.

@gnunicorn gnunicorn requested a review from bkchr January 11, 2019 10:48
Copy link
Contributor

@twittner twittner left a comment

Choose a reason for hiding this comment

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

LGTM

(custom_proto::upgrade::RegisteredProtocols::find_protocol is never used)

self.banned_peers.shrink_to_fit();

if !self.events.is_empty() {
return Async::Ready(self.events.remove(0))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should self.events be a VecDeque to allow a more efficient pop? Removing the head of a vector will always shift the remaining elements. Now I guess there will not be too many of those, but still.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now it's a SmallVec, and since the elements are quite small I think it shouldn't be very expensive to remove the first element.

I think we should eventually remove this events system, but that requires some big modifications of the NetworkBehaviour trait.

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Overall it looks good, just some nitpicks.

@@ -0,0 +1,262 @@
// Copyright 2018 Parity Technologies (UK) Ltd.
Copy link
Member

Choose a reason for hiding this comment

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


impl<TSubstream> Behaviour<TSubstream> {
/// Builds a new `Behaviour`.
// TODO: redundancy between config and local_peer_id
Copy link
Member

Choose a reason for hiding this comment

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

Please create a github issue and put a link into the comment.

@@ -0,0 +1,471 @@
// Copyright 2018 Parity Technologies (UK) Ltd.
Copy link
Member

Choose a reason for hiding this comment

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

}
}

/// Try to add a reserved peer.
Copy link
Member

Choose a reason for hiding this comment

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

Why try? The function does seem to try anything.

self.next_connect_to_nodes = Delay::new(Instant::now());
}

/// Try to remove a reserved peer.
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

// Check whether peer is banned.
if !is_reserved {
if let Some((_, expire)) = self.banned_peers.iter().find(|(p, _)| p == &peer_id) {
if *expire < Instant::now() {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be *expire > Instant::now(). Because when expire < Instant::now() the ban is over?

@@ -0,0 +1,327 @@
// Copyright 2018 Parity Technologies (UK) Ltd.
Copy link
Member

Choose a reason for hiding this comment

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

@@ -0,0 +1,22 @@
// Copyright 2018 Parity Technologies (UK) Ltd.
Copy link
Member

Choose a reason for hiding this comment

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

.map(|(id, muxer), _| (id, StreamMuxerBox::new(muxer)));
let peer_id2 = peer_id.clone();
let upgrade = core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex_config)
// TODO: use a single `.map` instead of two maps
Copy link
Member

Choose a reason for hiding this comment

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

Please create and link a github issue.

@bkchr bkchr added A8-looksgood and removed A0-please_review Pull request needs code review. labels Jan 14, 2019
@gavofyork gavofyork merged commit 75c3b51 into paritytech:master Jan 14, 2019
@tomaka tomaka deleted the update-libp2p-20190107 branch January 14, 2019 12:40
MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Apr 12, 2019
* Update to latest libp2p

* Fix indentations

* Add basic test

* Apply suggestions from code review

Co-Authored-By: tomaka <[email protected]>

* Remove Mutex from topology

* Remove unused method

* Fix concerns
liuchengxu added a commit to liuchengxu/substrate that referenced this pull request May 31, 2023
…raud-proof-window-is-closed

Finalize domains when the fraud proof period is over
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kademlia is in fact unidirectional
4 participants