Skip to content

Commit

Permalink
connectivity fixes + review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Jan 14, 2022
1 parent e6bb606 commit 931bd37
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ impl Display for NodeCommsRequest {
FetchHeaders(range) => {
write!(f, "FetchHeaders ({:?})", range)
},
FetchHeadersByHashes(v) => write!(f, "FetchHeadersWithHashes (n={})", v.len()),
FetchHeadersByHashes(v) => write!(f, "FetchHeadersByHashes (n={})", v.len()),
FetchHeadersAfter(v, _hash) => write!(f, "FetchHeadersAfter (n={})", v.len()),
FetchMatchingUtxos(v) => write!(f, "FetchMatchingUtxos (n={})", v.len()),
FetchMatchingTxos(v) => write!(f, "FetchMatchingTxos (n={})", v.len()),
FetchMatchingBlocks(range) => {
write!(f, "FetchMatchingBlocks ({:?})", range)
},
FetchBlocksByHash(v) => write!(f, "FetchBlocksByHash (n={})", v.len()),
FetchBlocksByKernelExcessSigs(v) => write!(f, "FetchBlocksWithKernels (n={})", v.len()),
FetchBlocksByUtxos(v) => write!(f, "FetchBlocksWithUtxos (n={})", v.len()),
FetchBlocksByKernelExcessSigs(v) => write!(f, "FetchBlocksByKernelExcessSigs (n={})", v.len()),
FetchBlocksByUtxos(v) => write!(f, "FetchBlocksByUtxos (n={})", v.len()),
GetHeaderByHash(v) => write!(f, "GetHeaderByHash({})", v.to_hex()),
GetBlockByHash(v) => write!(f, "GetBlockByHash({})", v.to_hex()),
GetNewBlockTemplate(v) => write!(f, "GetNewBlockTemplate ({}) with weight {}", v.algo, v.max_weight),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ impl OutboundNodeCommsInterface {
}
}

/// Fetch the Blocks corresponding to the provided block hashes from a specific base node. The requested blocks
/// could be chain blocks or orphan blocks.
/// Fetch the Blocks corresponding to the provided excess_sig from the given peer `NodeId`.
pub async fn request_transactions_by_excess_sig(
&mut self,
node_id: NodeId,
Expand Down
6 changes: 2 additions & 4 deletions base_layer/core/src/mempool/reorg_pool/reorg_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ type TransactionId = usize;

/// The ReorgPool consists of all transactions that have recently been added to blocks.
/// When a potential blockchain reorganization occurs the transactions can be recovered from the ReorgPool and can be
/// added back into the UnconfirmedPool. Transactions in the ReOrg pool have a limited Time-to-live and will be removed
/// from the pool when the Time-to-live thresholds is reached. Also, when the capacity of the pool has been reached, the
/// oldest transactions will be removed to make space for incoming transactions.
/// added back into the UnconfirmedPool. Transactions in the ReOrg pool expire as block height moves on.
pub struct ReorgPool {
config: ReorgPoolConfig,
key_counter: usize,
Expand All @@ -64,7 +62,7 @@ pub struct ReorgPool {
}

impl ReorgPool {
/// Create a new ReorgPoolwith the specified configuration
/// Create a new ReorgPool with the specified configuration
pub fn new(config: ReorgPoolConfig) -> Self {
Self {
config,
Expand Down
17 changes: 14 additions & 3 deletions comms/dht/src/connectivity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl DhtConnectivity {
async fn refresh_peer_pools(&mut self) -> Result<(), DhtConnectivityError> {
info!(
target: LOG_TARGET,
"Reinitializing neighbour pool. Draining neighbour list (len={})",
"Reinitializing neighbour pool. (size={})",
self.neighbours.len(),
);

Expand Down Expand Up @@ -311,6 +311,15 @@ impl DhtConnectivity {
.fetch_neighbouring_peers(self.config.num_neighbouring_nodes, &[])
.await?;

if new_neighbours.is_empty() {
info!(
target: LOG_TARGET,
"Unable to refresh neighbouring peer pool because there are insufficient known/online peers",
);
self.redial_neighbours_as_required().await?;
return Ok(());
}

let (intersection, difference) = self
.neighbours
.iter()
Expand Down Expand Up @@ -465,13 +474,15 @@ impl DhtConnectivity {
conn.peer_node_id().short_str()
);

if let Some(node_id) = self.insert_neighbour(conn.peer_node_id().clone()) {
let peer_to_insert = conn.peer_node_id().clone();
self.insert_connection_handle(conn);
if let Some(node_id) = self.insert_neighbour(peer_to_insert.clone()) {
// If we kicked a neighbour out of our neighbour pool but the random pool is not full.
// Add the neighbour to the random pool, otherwise remove the handle from the connection pool
if self.random_pool.len() < self.config.num_random_nodes {
debug!(
target: LOG_TARGET,
"Moving peer '{}' from neighbouring pool to random pool", conn
"Moving peer '{}' from neighbouring pool to random pool", peer_to_insert
);
self.random_pool.push(node_id);
} else {
Expand Down

0 comments on commit 931bd37

Please sign in to comment.