Networking and syncing tweaks (#2990)
* Reduce periodic snapshot delay * Prevent connecting to peers over the min_peers limit * Smaller block requests for slower connections
This commit is contained in:
parent
d3a2f7dce9
commit
6931878ff1
@ -53,7 +53,7 @@ use url;
|
|||||||
const SNAPSHOT_PERIOD: u64 = 10000;
|
const SNAPSHOT_PERIOD: u64 = 10000;
|
||||||
|
|
||||||
// how many blocks to wait before starting a periodic snapshot.
|
// how many blocks to wait before starting a periodic snapshot.
|
||||||
const SNAPSHOT_HISTORY: u64 = 500;
|
const SNAPSHOT_HISTORY: u64 = 100;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct RunCmd {
|
pub struct RunCmd {
|
||||||
|
@ -29,7 +29,7 @@ use sync_io::SyncIo;
|
|||||||
use blocks::BlockCollection;
|
use blocks::BlockCollection;
|
||||||
|
|
||||||
const MAX_HEADERS_TO_REQUEST: usize = 128;
|
const MAX_HEADERS_TO_REQUEST: usize = 128;
|
||||||
const MAX_BODIES_TO_REQUEST: usize = 128;
|
const MAX_BODIES_TO_REQUEST: usize = 64;
|
||||||
const MAX_RECEPITS_TO_REQUEST: usize = 128;
|
const MAX_RECEPITS_TO_REQUEST: usize = 128;
|
||||||
const SUBCHAIN_SIZE: u64 = 256;
|
const SUBCHAIN_SIZE: u64 = 256;
|
||||||
const MAX_ROUND_PARENTS: usize = 32;
|
const MAX_ROUND_PARENTS: usize = 32;
|
||||||
|
@ -747,7 +747,7 @@ impl Host {
|
|||||||
let socket = match self.tcp_listener.lock().accept() {
|
let socket = match self.tcp_listener.lock().accept() {
|
||||||
Ok((sock, _addr)) => sock,
|
Ok((sock, _addr)) => sock,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Error accepting connection: {:?}", e);
|
debug!(target: "network", "Error accepting connection: {:?}", e);
|
||||||
break
|
break
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -801,9 +801,8 @@ impl Host {
|
|||||||
},
|
},
|
||||||
Ok(SessionData::Ready) => {
|
Ok(SessionData::Ready) => {
|
||||||
self.num_sessions.fetch_add(1, AtomicOrdering::SeqCst);
|
self.num_sessions.fetch_add(1, AtomicOrdering::SeqCst);
|
||||||
if !s.info.originated {
|
|
||||||
let session_count = self.session_count();
|
let session_count = self.session_count();
|
||||||
let (max_peers, reserved_only) = {
|
let (min_peers, max_peers, reserved_only) = {
|
||||||
let info = self.info.read();
|
let info = self.info.read();
|
||||||
let mut max_peers = info.config.max_peers;
|
let mut max_peers = info.config.max_peers;
|
||||||
for cap in s.info.capabilities.iter() {
|
for cap in s.info.capabilities.iter() {
|
||||||
@ -812,10 +811,12 @@ impl Host {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(max_peers, info.config.non_reserved_mode == NonReservedPeerMode::Deny)
|
(info.config.min_peers as usize, max_peers as usize, info.config.non_reserved_mode == NonReservedPeerMode::Deny)
|
||||||
};
|
};
|
||||||
|
|
||||||
if session_count >= max_peers as usize || reserved_only {
|
if reserved_only ||
|
||||||
|
(s.info.originated && session_count >= min_peers) ||
|
||||||
|
(!s.info.originated && session_count >= max_peers) {
|
||||||
// only proceed if the connecting peer is reserved.
|
// only proceed if the connecting peer is reserved.
|
||||||
if !self.reserved_nodes.read().contains(s.id().unwrap()) {
|
if !self.reserved_nodes.read().contains(s.id().unwrap()) {
|
||||||
s.disconnect(io, DisconnectReason::TooManyPeers);
|
s.disconnect(io, DisconnectReason::TooManyPeers);
|
||||||
@ -823,7 +824,8 @@ impl Host {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add it no node table
|
// Add it to the node table
|
||||||
|
if !s.info.originated {
|
||||||
if let Ok(address) = s.remote_addr() {
|
if let Ok(address) = s.remote_addr() {
|
||||||
let entry = NodeEntry { id: s.id().unwrap().clone(), endpoint: NodeEndpoint { address: address, udp_port: address.port() } };
|
let entry = NodeEntry { id: s.id().unwrap().clone(), endpoint: NodeEndpoint { address: address, udp_port: address.port() } };
|
||||||
self.nodes.write().add_node(Node::new(entry.id.clone(), entry.endpoint.clone()));
|
self.nodes.write().add_node(Node::new(entry.id.clone(), entry.endpoint.clone()));
|
||||||
|
Loading…
Reference in New Issue
Block a user