Skip to content

Commit

Permalink
Merge pull request #2212 from subspace/update-libp2p
Browse files Browse the repository at this point in the history
Update libp2p to 0.53.1
  • Loading branch information
nazar-pc authored Nov 14, 2023
2 parents 5380e3f + f749dbf commit b2f2b50
Show file tree
Hide file tree
Showing 38 changed files with 1,163 additions and 984 deletions.
991 changes: 622 additions & 369 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/pallet-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ subspace-verification = { version = "0.1.0", path = "../subspace-verification",

[dev-dependencies]
env_logger = "0.10.0"
futures = "0.3.28"
futures = "0.3.29"
pallet-balances = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "892bf8e938c6bd2b893d3827d1093cd81baa59a1" }
pallet-offences-subspace = { version = "0.1.0", path = "../pallet-offences-subspace" }
rand = { version = "0.8.5", features = ["min_const_gen"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
async-oneshot = "0.5.0"
futures = "0.3.28"
futures = "0.3.29"
futures-timer = "3.0.2"
jsonrpsee = { version = "0.16.3", features = ["server", "macros"] }
lru = "0.11.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-consensus-subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
async-trait = "0.1.73"
codec = { package = "parity-scale-codec", version = "3.6.5", features = ["derive"] }
futures = "0.3.28"
futures = "0.3.29"
log = "0.4.20"
lru = "0.11.0"
parking_lot = "0.12.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-proof-of-time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include = [
atomic = "0.5.3"
core_affinity = "0.8.1"
derive_more = "0.99.17"
futures = "0.3.28"
futures = "0.3.29"
lru = "0.11.0"
parity-scale-codec = { version = "3.6.1", features = ["derive"] }
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "892bf8e938c6bd2b893d3827d1093cd81baa59a1" }
Expand Down
2 changes: 1 addition & 1 deletion crates/sc-subspace-block-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async-channel = "1.9.0"
async-trait = "0.1.73"
codec = { package = "parity-scale-codec", version = "3.6.5", default-features = false, features = ["derive"] }
derive_more = "0.99.17"
futures = "0.3.28"
futures = "0.3.29"
parking_lot = "0.12.1"
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "892bf8e938c6bd2b893d3827d1093cd81baa59a1" }
sc-network = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "892bf8e938c6bd2b893d3827d1093cd81baa59a1" }
Expand Down
2 changes: 1 addition & 1 deletion crates/sp-domains-fraud-proof/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ thiserror = { version = "1.0.48", optional = true }
domain-block-builder = { version = "0.1.0", path = "../../domains/client/block-builder" }
domain-block-preprocessor = { version = "0.1.0", path = "../../domains/client/block-preprocessor" }
domain-test-service = { version = "0.1.0", path = "../../domains/test/service" }
futures = "0.3.28"
futures = "0.3.29"
pallet-balances = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "892bf8e938c6bd2b893d3827d1093cd81baa59a1" }
sc-cli = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "892bf8e938c6bd2b893d3827d1093cd81baa59a1", default-features = false }
sc-executor = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "892bf8e938c6bd2b893d3827d1093cd81baa59a1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/sp-lightclient/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ subspace-verification = { version = "0.1.0", path = "../subspace-verification",

[dev-dependencies]
frame-support = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "892bf8e938c6bd2b893d3827d1093cd81baa59a1" }
futures = "0.3.28"
futures = "0.3.29"
rand = { version = "0.8.5", features = ["min_const_gen"] }
sp-io = { version = "23.0.0", git = "https://github.com/subspace/polkadot-sdk", rev = "892bf8e938c6bd2b893d3827d1093cd81baa59a1" }
subspace-archiving = { version = "0.1.0", path = "../subspace-archiving"}
Expand Down
4 changes: 2 additions & 2 deletions crates/subspace-farmer-components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async-trait = "0.1.73"
backoff = { version = "0.4.0", features = ["futures", "tokio"] }
bitvec = "1.0.1"
fs2 = "0.4.3"
futures = "0.3.28"
futures = "0.3.29"
hex = "0.4.3"
libc = "0.2.146"
parity-scale-codec = "3.6.5"
Expand All @@ -44,7 +44,7 @@ winapi = "0.3.9"

[dev-dependencies]
criterion = "0.5.1"
futures = "0.3.28"
futures = "0.3.29"
parking_lot = "0.12.1"
subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" }
subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space" }
Expand Down
4 changes: 2 additions & 2 deletions crates/subspace-farmer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ criterion = { version = "0.5.1", default-features = false, features = ["rayon",
derive_more = "0.99.17"
event-listener-primitives = "2.0.1"
fdlimit = "0.2"
futures = "0.3.28"
futures = "0.3.29"
hex = { version = "0.4.3", features = ["serde"] }
jsonrpsee = { version = "0.16.3", features = ["client"] }
lru = "0.11.0"
mimalloc = "0.1.39"
parity-scale-codec = "3.6.5"
parking_lot = "0.12.1"
prometheus-client = "0.21.2"
prometheus-client = "0.22.0"
rand = "0.8.5"
rayon = "1.8.0"
schnorrkel = "0.9.1"
Expand Down
9 changes: 4 additions & 5 deletions crates/subspace-networking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ derive_more = "0.99.17"
either = "1.8.1"
event-listener-primitives = "2.0.1"
fs2 = "0.4.3"
futures = "0.3.28"
futures = "0.3.29"
futures-timer = "3.0.2"
hex = "0.4.3"
lru = "0.11.0"
Expand All @@ -35,7 +35,7 @@ nohash-hasher = "0.2.0"
parity-scale-codec = "3.6.5"
parking_lot = "0.12.1"
pin-project = "1.1.3"
prometheus-client = "0.21.2"
prometheus-client = "0.22.0"
rand = "0.8.5"
serde = { version = "1.0.183", features = ["derive"] }
serde_json = "1.0.106"
Expand All @@ -49,8 +49,7 @@ unsigned-varint = { version = "0.7.1", features = ["futures", "asynchronous_code
void = "1.0.2"

[dependencies.libp2p]
git = "https://github.com/subspace/rust-libp2p"
rev = "7a9328fc0a5f9e28575192d5f4f8663fde6752af"
version = "0.53.1"
default-features = false
features = [
"autonat",
Expand All @@ -73,4 +72,4 @@ features = [

[dev-dependencies]
rand = "0.8.5"
libp2p-swarm-test = { git = "https://github.com/subspace/rust-libp2p", rev = "7a9328fc0a5f9e28575192d5f4f8663fde6752af" }
libp2p-swarm-test = "0.3.0"
2 changes: 1 addition & 1 deletion crates/subspace-networking/src/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use libp2p::gossipsub::{
Behaviour as Gossipsub, Config as GossipsubConfig, Event as GossipsubEvent, MessageAuthenticity,
};
use libp2p::identify::{Behaviour as Identify, Config as IdentifyConfig, Event as IdentifyEvent};
use libp2p::kad::{Kademlia, KademliaConfig, KademliaEvent};
use libp2p::kad::{Behaviour as Kademlia, Config as KademliaConfig, Event as KademliaEvent};
use libp2p::ping::{Behaviour as Ping, Event as PingEvent};
use libp2p::swarm::behaviour::toggle::Toggle;
use libp2p::swarm::NetworkBehaviour;
Expand Down
56 changes: 36 additions & 20 deletions crates/subspace-networking/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ use libp2p::gossipsub::{
use libp2p::identify::Config as IdentifyConfig;
use libp2p::kad::store::RecordStore;
use libp2p::kad::{
store, KademliaBucketInserts, KademliaConfig, KademliaStoreInserts, Mode, ProviderRecord,
Record, RecordKey,
store, BucketInserts, Config as KademliaConfig, Mode, ProviderRecord, Record, RecordKey,
StoreInserts,
};
use libp2p::metrics::Metrics;
use libp2p::multiaddr::Protocol;
use libp2p::swarm::SwarmBuilder;
use libp2p::yamux::Config as YamuxConfig;
use libp2p::{identity, Multiaddr, PeerId, StreamProtocol, TransportError};
use libp2p::{identity, Multiaddr, PeerId, StreamProtocol, SwarmBuilder, TransportError};
use parking_lot::Mutex;
use std::borrow::Cow;
use std::iter::Empty;
Expand All @@ -61,6 +60,8 @@ const SPECIAL_CONNECTED_PEERS_PROTOCOL_LOG_TARGET: &str = "special-connected-pee
/// Defines max_negotiating_inbound_streams constant for the swarm.
/// It must be set for large plots.
const SWARM_MAX_NEGOTIATING_INBOUND_STREAMS: usize = 100000;
/// How long will connection be allowed to be open without any usage
const IDLE_CONNECTION_TIMEOUT: Duration = Duration::from_secs(10);
/// The default maximum established incoming connection number for the swarm.
const SWARM_MAX_ESTABLISHED_INCOMING_CONNECTIONS: u32 = 100;
/// The default maximum established incoming connection number for the swarm.
Expand Down Expand Up @@ -306,8 +307,8 @@ where
.expect("Manual protocol name creation.")])
.disjoint_query_paths(true)
.set_max_packet_size(2 * Piece::SIZE)
.set_kbucket_inserts(KademliaBucketInserts::Manual)
.set_record_filtering(KademliaStoreInserts::FilterBoth)
.set_kbucket_inserts(BucketInserts::Manual)
.set_record_filtering(StoreInserts::FilterBoth)
// We don't use records and providers publication.
.set_provider_record_ttl(None)
.set_provider_publication_interval(None)
Expand Down Expand Up @@ -397,6 +398,11 @@ pub enum CreationError {
/// I/O error.
#[error("I/O error: {0}")]
Io(#[from] io::Error),
/// Transport creation error.
#[error("Transport creation error: {0}")]
// TODO: Restore `#[from] TransportError` once https://github.com/libp2p/rust-libp2p/issues/4824
// is resolved
TransportCreationError(Box<dyn std::error::Error + Send + Sync>),
/// Transport error when attempting to listen on multiaddr.
#[error("Transport error when attempting to listen on multiaddr: {0}")]
TransportError(#[from] TransportError<io::Error>),
Expand Down Expand Up @@ -453,18 +459,6 @@ where
} = config;
let local_peer_id = peer_id(&keypair);

let temporary_bans = Arc::new(Mutex::new(TemporaryBans::new(
temporary_bans_cache_size,
temporary_ban_backoff,
)));
let transport = build_transport(
allow_non_global_addresses_in_dht,
&keypair,
Arc::clone(&temporary_bans),
timeout,
yamux_config,
)?;

info!(
%allow_non_global_addresses_in_dht,
peer_id = %local_peer_id,
Expand Down Expand Up @@ -521,8 +515,30 @@ where
}),
});

let mut swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id)
.max_negotiating_inbound_streams(SWARM_MAX_NEGOTIATING_INBOUND_STREAMS)
let temporary_bans = Arc::new(Mutex::new(TemporaryBans::new(
temporary_bans_cache_size,
temporary_ban_backoff,
)));

let mut swarm = SwarmBuilder::with_existing_identity(keypair)
.with_tokio()
.with_other_transport(|keypair| {
Ok(build_transport(
allow_non_global_addresses_in_dht,
keypair,
Arc::clone(&temporary_bans),
timeout,
yamux_config,
)?)
})
.map_err(|error| CreationError::TransportCreationError(error.into()))?
.with_behaviour(move |_keypair| Ok(behaviour))
.expect("Not fallible; qed")
.with_swarm_config(|config| {
config
.with_max_negotiating_inbound_streams(SWARM_MAX_NEGOTIATING_INBOUND_STREAMS)
.with_idle_connection_timeout(IDLE_CONNECTION_TIMEOUT)
})
.build();

// Setup listen_on addresses
Expand Down
17 changes: 7 additions & 10 deletions crates/subspace-networking/src/constructor/transport.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::constructor::temporary_bans::TemporaryBans;
use crate::CreationError;
use futures::future::Either;
use libp2p::core::multiaddr::{Multiaddr, Protocol};
use libp2p::core::muxing::StreamMuxerBox;
use libp2p::core::transport::{Boxed, ListenerId, TransportError, TransportEvent};
use libp2p::core::Transport;
use libp2p::dns::TokioDnsConfig;
use libp2p::dns::tokio::Transport as TokioTransport;
use libp2p::quic::tokio::Transport as QuicTransport;
use libp2p::quic::Config as QuicConfig;
use libp2p::tcp::tokio::Transport as TokioTcpTransport;
Expand All @@ -27,7 +26,7 @@ pub(super) fn build_transport(
temporary_bans: Arc<Mutex<TemporaryBans>>,
timeout: Duration,
yamux_config: YamuxConfig,
) -> Result<Boxed<(PeerId, StreamMuxerBox)>, CreationError> {
) -> io::Result<Boxed<(PeerId, StreamMuxerBox)>> {
let wrapped_tcp = {
let tcp_config = GenTcpConfig::default().nodelay(true);

Expand All @@ -50,10 +49,10 @@ pub(super) fn build_transport(
.boxed()
};

#[cfg(not(windows))]
let quic_config = QuicConfig::new(keypair);
#[cfg(windows)]
let quic_config = QuicConfig::new(keypair).path_mtu_discovery_config(None);
let mut quic_config = QuicConfig::new(keypair);
if cfg!(windows) {
quic_config = quic_config.disable_path_mtu_discovery();
}

let quic = QuicTransport::new(quic_config)
.map(|(peer_id, muxer), _| (peer_id, StreamMuxerBox::new(muxer)));
Expand All @@ -68,9 +67,7 @@ pub(super) fn build_transport(
Either::Right((peer_id, muxer)) => (peer_id, muxer),
});

let dns_wrapped_upgraded_quic_tcp = TokioDnsConfig::system(quic_tcp)?;

Ok(dns_wrapped_upgraded_quic_tcp.boxed())
Ok(TokioTransport::system(quic_tcp)?.boxed())
}

#[derive(Debug, Clone)]
Expand Down
11 changes: 6 additions & 5 deletions crates/subspace-networking/src/node_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ use libp2p::core::{address_translation, ConnectedPoint};
use libp2p::gossipsub::{Event as GossipsubEvent, TopicHash};
use libp2p::identify::Event as IdentifyEvent;
use libp2p::kad::{
BootstrapOk, GetClosestPeersError, GetClosestPeersOk, GetProvidersError, GetProvidersOk,
GetRecordError, GetRecordOk, InboundRequest, Kademlia, KademliaEvent, Mode, PeerRecord,
ProgressStep, PutRecordOk, QueryId, QueryResult, Quorum, Record,
Behaviour as Kademlia, BootstrapOk, Event as KademliaEvent, GetClosestPeersError,
GetClosestPeersOk, GetProvidersError, GetProvidersOk, GetRecordError, GetRecordOk,
InboundRequest, Mode, PeerRecord, ProgressStep, PutRecordOk, QueryId, QueryResult, Quorum,
Record,
};
use libp2p::metrics::{Metrics, Recorder};
use libp2p::swarm::{DialError, SwarmEvent};
Expand Down Expand Up @@ -410,7 +411,7 @@ where
.remove_address(&event.peer_id, &remove_p2p_suffix(event.address));
}

async fn handle_swarm_event<E: Debug>(&mut self, swarm_event: SwarmEvent<Event, E>) {
async fn handle_swarm_event(&mut self, swarm_event: SwarmEvent<Event>) {
match swarm_event {
SwarmEvent::Behaviour(Event::Identify(event)) => {
self.handle_identify_event(event).await;
Expand Down Expand Up @@ -1488,7 +1489,7 @@ where
.remove_all_known_peer_addresses(peer_id);
}

fn register_event_metrics<E: Debug>(&mut self, swarm_event: &SwarmEvent<Event, E>) {
fn register_event_metrics(&mut self, swarm_event: &SwarmEvent<Event>) {
if let Some(ref mut metrics) = self.metrics {
match swarm_event {
SwarmEvent::Behaviour(Event::Ping(ping_event)) => {
Expand Down
Loading

0 comments on commit b2f2b50

Please sign in to comment.