From 931bd375771cea6a0ad72336138e117efa13672f Mon Sep 17 00:00:00 2001 From: Stanimal Date: Fri, 14 Jan 2022 15:03:12 +0400 Subject: [PATCH] connectivity fixes + review comments --- .../base_node/comms_interface/comms_request.rs | 6 +++--- .../comms_interface/outbound_interface.rs | 3 +-- .../core/src/mempool/reorg_pool/reorg_pool.rs | 6 ++---- comms/dht/src/connectivity/mod.rs | 17 ++++++++++++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/base_layer/core/src/base_node/comms_interface/comms_request.rs b/base_layer/core/src/base_node/comms_interface/comms_request.rs index 92aaa7c039..c233bc3473 100644 --- a/base_layer/core/src/base_node/comms_interface/comms_request.rs +++ b/base_layer/core/src/base_node/comms_interface/comms_request.rs @@ -86,7 +86,7 @@ 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()), @@ -94,8 +94,8 @@ impl Display for NodeCommsRequest { 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), diff --git a/base_layer/core/src/base_node/comms_interface/outbound_interface.rs b/base_layer/core/src/base_node/comms_interface/outbound_interface.rs index 2545b0ed9d..6db4d2ca77 100644 --- a/base_layer/core/src/base_node/comms_interface/outbound_interface.rs +++ b/base_layer/core/src/base_node/comms_interface/outbound_interface.rs @@ -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, diff --git a/base_layer/core/src/mempool/reorg_pool/reorg_pool.rs b/base_layer/core/src/mempool/reorg_pool/reorg_pool.rs index 65ff4a5c89..bcd68e4b69 100644 --- a/base_layer/core/src/mempool/reorg_pool/reorg_pool.rs +++ b/base_layer/core/src/mempool/reorg_pool/reorg_pool.rs @@ -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, @@ -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, diff --git a/comms/dht/src/connectivity/mod.rs b/comms/dht/src/connectivity/mod.rs index c396e6155b..a3d8042521 100644 --- a/comms/dht/src/connectivity/mod.rs +++ b/comms/dht/src/connectivity/mod.rs @@ -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(), ); @@ -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() @@ -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 {