Skip to content

Commit

Permalink
Log failure to insert block request
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Oct 28, 2023
1 parent 78d0d93 commit 8427047
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 1 addition & 3 deletions node/bft/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ impl<N: Network> Sync<N> {
// Perform the sync routine.
let communication = &self_.gateway;
// let communication = &node.router;
if let Err(error) = self_.block_sync.try_block_sync(communication).await {
warn!("Sync error - {error}");
}
self_.block_sync.try_block_sync(communication).await;
}
}));

Expand Down
4 changes: 1 addition & 3 deletions node/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ impl<N: Network, C: ConsensusStorage<N>> Client<N, C> {
// Sleep briefly to avoid triggering spam detection.
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
// Perform the sync routine.
if let Err(error) = node.sync.try_block_sync(&node).await {
warn!("Sync error - {error}");
}
node.sync.try_block_sync(&node).await;
}
}));
}
Expand Down
42 changes: 23 additions & 19 deletions node/sync/src/block_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<N: Network> BlockSync<N> {

/// Performs one iteration of the block sync.
#[inline]
pub async fn try_block_sync<C: CommunicationService>(&self, communication: &C) -> Result<()> {
pub async fn try_block_sync<C: CommunicationService>(&self, communication: &C) {
// Prepare the block requests, if any.
// In the process, we update the state of `is_block_synced` for the sync module.
let block_requests = self.prepare_block_requests();
Expand All @@ -218,27 +218,31 @@ impl<N: Network> BlockSync<N> {
// Process the block requests.
'outer: for (height, (hash, previous_hash, sync_ips)) in block_requests {
// Insert the block request into the sync pool.
let result = self.insert_block_request(height, (hash, previous_hash, sync_ips.clone()));

// If the block request was inserted, send it to the peers.
if result.is_ok() {
// Construct the message.
let message = C::prepare_block_request(height, height + 1);
// Send the message to the peers.
for sync_ip in sync_ips {
// If the send fails for any peer, remove the block request from the sync pool.
if communication.send(sync_ip, message.clone()).await.is_none() {
// Remove the entire block request.
self.remove_block_request(height);
// Break out of the loop.
break 'outer;
}
if let Err(error) = self.insert_block_request(height, (hash, previous_hash, sync_ips.clone())) {
warn!("Block sync failed - {error}");
// Break out of the loop.
break 'outer;
}

/* Send the block request to the peers */

// Construct the message.
let message = C::prepare_block_request(height, height + 1);
// Send the message to the peers.
for sync_ip in sync_ips {
let sender = communication.send(sync_ip, message.clone()).await;
// If the send fails for any peer, remove the block request from the sync pool.
if sender.is_none() {
warn!("Failed to send block request to peer '{sync_ip}'");
// Remove the entire block request from the sync pool.
self.remove_block_request(height);
// Break out of the loop.
break 'outer;
}
// Sleep for 10 milliseconds to avoid triggering spam detection.
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
}
// Sleep for 10 milliseconds to avoid triggering spam detection.
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
}
Ok(())
}

/// Processes the block response from the given peer IP.
Expand Down

0 comments on commit 8427047

Please sign in to comment.