diff --git a/Cargo.lock b/Cargo.lock index 593f424f912f7..dd2259a19008e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1835,7 +1835,7 @@ dependencies = [ [[package]] name = "polkadot" -version = "0.2.11" +version = "0.2.12" dependencies = [ "ctrlc 1.1.1 (git+https://github.com/paritytech/rust-ctrlc.git)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1880,7 +1880,7 @@ dependencies = [ "polkadot-service 0.2.2", "polkadot-transaction-pool 0.1.0", "slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "substrate-cli 0.2.11", + "substrate-cli 0.2.12", "substrate-client 0.1.0", "substrate-codec 0.1.0", "substrate-extrinsic-pool 0.1.0", @@ -2674,7 +2674,7 @@ dependencies = [ [[package]] name = "substrate-cli" -version = "0.2.11" +version = "0.2.12" dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/substrate/network-libp2p/src/service.rs b/substrate/network-libp2p/src/service.rs index 0384508d11709..00f522faeedf9 100644 --- a/substrate/network-libp2p/src/service.rs +++ b/substrate/network-libp2p/src/service.rs @@ -38,7 +38,7 @@ use std::sync::Arc; use std::sync::mpsc as sync_mpsc; use std::thread; use std::time::{Duration, Instant}; -use futures::{future, Future, stream, Stream}; +use futures::{future, Future, stream, Stream, select_all}; use futures::sync::{mpsc, oneshot}; use tokio::runtime::current_thread; use tokio_io::{AsyncRead, AsyncWrite}; @@ -546,19 +546,24 @@ fn init_thread( // Start the process of pinging the active nodes on the network. let periodic = start_periodic_updates(shared.clone(), transport, swarm_controller); - // Merge all the futures into one! - Ok(swarm_events.for_each(|_| Ok(())) - .select(discovery).map_err(|(err, _)| err).and_then(|(_, rest)| rest) - .select(periodic).map_err(|(err, _)| err).and_then(|(_, rest)| rest) - .select(outgoing_connections).map_err(|(err, _)| err).and_then(|(_, rest)| rest) - .select(timeouts).map_err(|(err, _)| err).and_then(|(_, rest)| rest) - .select(close_rx.then(|_| Ok(()))).map(|_| ()).map_err(|(err, _)| err) - + let futures: Vec>> = vec![ + Box::new(swarm_events.for_each(|_| Ok(()))), + Box::new(discovery), + Box::new(periodic), + Box::new(outgoing_connections), + Box::new(timeouts), + Box::new(close_rx.map_err(|err| IoError::new(IoErrorKind::Other, err))), + ]; + + Ok( + select_all(futures) .and_then(move |_| { debug!(target: "sub-libp2p", "Networking ended ; disconnecting all peers"); shared.network_state.disconnect_all(); Ok(()) - })) + }) + .map_err(|(r, _, _)| r) + ) } /// Output of the common transport layer. diff --git a/substrate/network-libp2p/src/topology.rs b/substrate/network-libp2p/src/topology.rs index 3cd3456bea3e5..f11c9de5dbcc9 100644 --- a/substrate/network-libp2p/src/topology.rs +++ b/substrate/network-libp2p/src/topology.rs @@ -19,7 +19,7 @@ use parking_lot::Mutex; use libp2p::{Multiaddr, PeerId}; use serde_json; use std::{cmp, fs}; -use std::io::{Read, Cursor, Error as IoError, ErrorKind as IoErrorKind, Write}; +use std::io::{Read, Cursor, Error as IoError, ErrorKind as IoErrorKind, Write, BufReader, BufWriter}; use std::path::{Path, PathBuf}; use std::time::{Duration, Instant, SystemTime}; @@ -46,7 +46,7 @@ const FIRST_CONNECT_FAIL_BACKOFF: Duration = Duration::from_secs(2); /// Every time we fail to connect to an address, multiply the backoff by this constant. const FAIL_BACKOFF_MULTIPLIER: u32 = 2; /// We need a maximum value for the backoff, overwise we risk an overflow. -const MAX_BACKOFF: Duration = Duration::from_secs(60); +const MAX_BACKOFF: Duration = Duration::from_secs(30 * 60); // TODO: should be merged with the Kademlia k-buckets @@ -101,7 +101,7 @@ impl NetTopology { }; let file = fs::File::create(path)?; - serialize(file, &self.store) + serialize(BufWriter::with_capacity(1024 * 1024, file), &self.store) } /// Perform a cleanup pass, removing all obsolete addresses and peers. @@ -497,7 +497,7 @@ fn try_load(path: impl AsRef) -> FnvHashMap { } let mut file = match fs::File::open(path) { - Ok(f) => f, + Ok(f) => BufReader::with_capacity(1024 * 1024, f), Err(err) => { warn!(target: "sub-libp2p", "Failed to open peer storage file: {:?}", err); info!(target: "sub-libp2p", "Deleting peer storage file {:?}", path);