Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node_workflow/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ lazy_static! {
static ref CALL_ROUTER_CONTEXT: RwLock< HashMap<u32, Router>> = RwLock::new(HashMap::new());
}

/// Stot the server jobs and release the server
/// Stop the server jobs and release the server
pub fn release_server(context_id: u32) {
if let Some(server) = SERVER_CONTEXT
.write()
Expand Down
5 changes: 3 additions & 2 deletions p2p/src/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ impl Peers {
);
}

let mut peers = self.peers.write().unwrap_or_else(|e| e.into_inner());
for peer in peers.values() {
self.update_stop_healthy_state(&peer.info.addr);
peer.stop();
Expand All @@ -673,9 +672,11 @@ impl Peers {
}
}

let context_id = self.store.get_context_id();

let need_count = self
.config
.peer_min_preferred_outbound_count(self.is_sync_mode());
.peer_min_preferred_outbound_count(context_id, self.is_sync_mode());
if self.is_sync_mode() {
count >= need_count
} else {
Expand Down
22 changes: 16 additions & 6 deletions p2p/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use crate::tor::arti;
use crate::util::secp::pedersen::RangeProof;
use mwc_chain::txhashset::Segmenter;
use mwc_chain::types::HEADERS_PER_BATCH;
use mwc_core::global::{get_chain_type, ChainTypes};
use std::sync::RwLock;

/// Maximum number of block headers a peer should ever send
Expand All @@ -67,10 +68,13 @@ const PEER_MAX_INBOUND_COUNT: u32 = 128;
const PEER_MAX_OUTBOUND_COUNT: u32 = 10;

/// The min preferred outbound peer count
const PEER_MIN_PREFERRED_OUTBOUND_COUNT: u32 = 8;
const PEER_MIN_PREFERRED_OUTBOUND_COUNT_MAIN: u32 = 8;
const PEER_MIN_PREFERRED_OUTBOUND_COUNT_FLOO: u32 = 3;

/// During sync process we want to boost peers discovery.
const PEER_BOOST_OUTBOUND_COUNT: u32 = 20;
const PEER_BOOST_OUTBOUND_COUNT_MAIN: u32 = 20;
/// Booost for floonet is much smaller, there are not many servers
const PEER_BOOST_OUTBOUND_COUNT_FLOO: u32 = 8;

/// The peer listener buffer count. Allows temporarily accepting more connections
/// than allowed by PEER_MAX_INBOUND_COUNT to encourage network bootstrapping.
Expand Down Expand Up @@ -548,7 +552,7 @@ impl P2PConfig {
/// return maximum outbound peer connections count
pub fn peer_max_outbound_count(&self, peers_sync_mode: bool) -> u32 {
if peers_sync_mode {
PEER_BOOST_OUTBOUND_COUNT
PEER_BOOST_OUTBOUND_COUNT_MAIN + PEER_MIN_PREFERRED_OUTBOUND_COUNT_MAIN
} else {
match self.peer_max_outbound_count {
Some(n) => n,
Expand All @@ -558,13 +562,19 @@ impl P2PConfig {
}

/// return minimum preferred outbound peer count
pub fn peer_min_preferred_outbound_count(&self, peers_sync_mode: bool) -> u32 {
pub fn peer_min_preferred_outbound_count(&self, context_id: u32, peers_sync_mode: bool) -> u32 {
if peers_sync_mode {
PEER_BOOST_OUTBOUND_COUNT
match get_chain_type(context_id) {
ChainTypes::Mainnet => PEER_BOOST_OUTBOUND_COUNT_MAIN,
_ => PEER_BOOST_OUTBOUND_COUNT_FLOO,
}
} else {
match self.peer_min_preferred_outbound_count {
Some(n) => n,
None => PEER_MIN_PREFERRED_OUTBOUND_COUNT,
None => match get_chain_type(context_id) {
ChainTypes::Mainnet => PEER_MIN_PREFERRED_OUTBOUND_COUNT_MAIN,
_ => PEER_MIN_PREFERRED_OUTBOUND_COUNT_FLOO,
},
}
}
}
Expand Down