Upgrade to libp2p 0.51.3 (#13587)

* client/network: upgrade to libp2p 0.51.0

* make discovery.rs compile

* make peer_info.rs compile

* changes to notifications and request-response proto

* make service.rs compile

* towards making request_responses.rs compile

* make request_responses.rs compile

* make request_responses.rs compile

* fix notifications/behaviour.rs tests

* fix warnings

* remove old code

* allow deprecated code (temporary)

* upgrade to libp2p 0.51.1

* add TODO for behaviour tests

* return empty vec if peer_id is absent

https://github.com/paritytech/substrate/pull/13587#discussion_r1141695167

fyi: I don't really know what the old behaviour was.

* update comment to reflect new defaults

Closes #13338

* Revert "update comment to reflect new defaults"

This reverts commit 7a981abd69308e9d522ec94905f181439a1b1dba.

* remove config.rs (from wrong merge)

* upgrade to libp2p 0.51.2

* fix formatting

* use handle_pending_outbound_connection in networt_state RPC

* update deps

* use re-exports when we use other libp2p packages

* Apply suggestions from code review

Co-authored-by: Dmitry Markin <dmitry@markin.tech>

* format code

* handle potential errors in network_state RPC

* only update libp2p crate

* update libp2p-core

* fix docs

* use libp2p-identity instead of libp2p

where it's possible. libp2p-identity is much smaller, hence makes sense
to use it instead of larger libp2p crate.

* Update client/network/src/discovery.rs

Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com>

* update Cargo.lock

* add comment for per_connection_event_buffer_size

current value is somewhat arbitrary and needs to be tweaked depending on
memory usage and network worker sleep stats.

* fix link format

* update Cargo.lock

* upgrade to libp2p 0.51.3

* deprecate mplex

* Revert "deprecate mplex"

This reverts commit 9e25820e706e464a0e962a8604861fcb2a7641eb.

* Revert "upgrade to libp2p 0.51.3"

This reverts commit 6544dd4138e2f89517bd7c7281fc78a638ec7040.

* use new libp2p version in `statement` crate

* pin version temporarily

* libp2p 0.51.3

* deprecate mplex

* deprecate legacy noise handshake

* fix build error

* update libp2p-identity

* enable libp2p-identity:ed25519 feature in sc-consensus

* enable ed25519 for peerset as well

---------

Co-authored-by: Dmitry Markin <dmitry@markin.tech>
Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com>
Co-authored-by: parity-processbot <>
This commit is contained in:
Anton
2023-05-12 11:12:51 +04:00
committed by GitHub
parent 56940bc874
commit e4b1aa1811
48 changed files with 1005 additions and 927 deletions
+11 -39
View File
@@ -16,20 +16,18 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use either::Either;
use libp2p::{
bandwidth,
core::{
self,
either::EitherTransport,
muxing::StreamMuxerBox,
transport::{Boxed, OptionalTransport},
upgrade,
},
dns, identity, mplex, noise, tcp, websocket, PeerId, Transport,
dns, identity, noise, tcp, websocket, PeerId, Transport, TransportExt,
};
use std::{sync::Arc, time::Duration};
pub use self::bandwidth::BandwidthSinks;
pub use libp2p::bandwidth::BandwidthSinks;
/// Builds the transport that serves as a common ground for all connections.
///
@@ -59,7 +57,7 @@ pub fn build_transport(
let tcp_trans = tcp::tokio::Transport::new(tcp_config.clone());
let dns_init = dns::TokioDnsConfig::system(tcp_trans);
EitherTransport::Left(if let Ok(dns) = dns_init {
Either::Left(if let Ok(dns) = dns_init {
// WS + WSS transport
//
// Main transport can't be used for `/wss` addresses because WSS transport needs
@@ -68,47 +66,21 @@ pub fn build_transport(
let tcp_trans = tcp::tokio::Transport::new(tcp_config);
let dns_for_wss = dns::TokioDnsConfig::system(tcp_trans)
.expect("same system_conf & resolver to work");
EitherTransport::Left(websocket::WsConfig::new(dns_for_wss).or_transport(dns))
Either::Left(websocket::WsConfig::new(dns_for_wss).or_transport(dns))
} else {
// In case DNS can't be constructed, fallback to TCP + WS (WSS won't work)
let tcp_trans = tcp::tokio::Transport::new(tcp_config.clone());
let desktop_trans = websocket::WsConfig::new(tcp_trans)
.or_transport(tcp::tokio::Transport::new(tcp_config));
EitherTransport::Right(desktop_trans)
Either::Right(desktop_trans)
})
} else {
EitherTransport::Right(OptionalTransport::some(
libp2p::core::transport::MemoryTransport::default(),
))
Either::Right(OptionalTransport::some(libp2p::core::transport::MemoryTransport::default()))
};
let (transport, bandwidth) = bandwidth::BandwidthLogging::new(transport);
let authentication_config =
{
// For more information about these two panics, see in "On the Importance of
// Checking Cryptographic Protocols for Faults" by Dan Boneh, Richard A. DeMillo,
// and Richard J. Lipton.
let noise_keypair = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&keypair)
.expect("can only fail in case of a hardware bug; since this signing is performed only \
once and at initialization, we're taking the bet that the inconvenience of a very \
rare panic here is basically zero");
// Legacy noise configurations for backward compatibility.
let noise_legacy =
noise::LegacyConfig { recv_legacy_handshake: true, ..Default::default() };
let mut xx_config = noise::NoiseConfig::xx(noise_keypair);
xx_config.set_legacy_config(noise_legacy);
xx_config.into_authenticated()
};
let authentication_config = noise::Config::new(&keypair).expect("Can create noise config. qed");
let multiplexing_config = {
let mut mplex_config = mplex::MplexConfig::new();
mplex_config.set_max_buffer_behaviour(mplex::MaxBufferBehaviour::Block);
mplex_config.set_max_buffer_size(usize::MAX);
let mut yamux_config = libp2p::yamux::YamuxConfig::default();
let mut yamux_config = libp2p::yamux::Config::default();
// Enable proper flow-control: window updates are only sent when
// buffered data has been consumed.
yamux_config.set_window_update_mode(libp2p::yamux::WindowUpdateMode::on_read());
@@ -118,7 +90,7 @@ pub fn build_transport(
yamux_config.set_receive_window_size(yamux_window_size);
}
core::upgrade::SelectUpgrade::new(yamux_config, mplex_config)
yamux_config
};
let transport = transport
@@ -128,5 +100,5 @@ pub fn build_transport(
.timeout(Duration::from_secs(20))
.boxed();
(transport, bandwidth)
transport.with_bandwidth_logging()
}