diff --git a/node/bft/src/sync/mod.rs b/node/bft/src/sync/mod.rs index 0e008d5469..a99ef26999 100644 --- a/node/bft/src/sync/mod.rs +++ b/node/bft/src/sync/mod.rs @@ -314,7 +314,7 @@ impl Sync { // Determine if we can sync the ledger without updating the BFT first. if current_height <= max_gc_height { // Try to advance the ledger *to tip* without updating the BFT. - while let Some(block) = self.block_sync.process_next_block(current_height) { + while let Some(block) = self.block_sync.peek_next_block(current_height) { info!("Syncing the ledger to block {}...", block.height()); // Sync the ledger with the block without BFT. match self.sync_ledger_with_block_without_bft(block).await { @@ -338,7 +338,7 @@ impl Sync { } // Try to advance the ledger with sync blocks. - while let Some(block) = self.block_sync.process_next_block(current_height) { + while let Some(block) = self.block_sync.peek_next_block(current_height) { info!("Syncing the BFT to block {}...", block.height()); // Sync the storage with the block. match self.sync_storage_with_block(block).await { diff --git a/node/sync/src/block_sync.rs b/node/sync/src/block_sync.rs index 330373777b..dd8663485a 100644 --- a/node/sync/src/block_sync.rs +++ b/node/sync/src/block_sync.rs @@ -322,9 +322,10 @@ impl BlockSync { Ok(()) } - /// Returns the next block to process, if one is ready. + /// Returns the next block for the given `next_height` if the request is complete, + /// or `None` otherwise. This does not remove the block from the `responses` map. #[inline] - pub fn process_next_block(&self, next_height: u32) -> Option> { + pub fn peek_next_block(&self, next_height: u32) -> Option> { // Acquire the requests write lock. // Note: This lock must be held across the entire scope, due to asynchronous block responses // from multiple peers that may be received concurrently. @@ -364,7 +365,7 @@ impl BlockSync { /// Handles the block responses from the sync pool. fn try_advancing_with_block_responses(&self, mut current_height: u32) { - while let Some(block) = self.process_next_block(current_height + 1) { + while let Some(block) = self.peek_next_block(current_height + 1) { // Ensure the block height matches. if block.height() != current_height + 1 { warn!("Block height mismatch: expected {}, found {}", current_height + 1, block.height()); @@ -636,7 +637,7 @@ impl BlockSync { } /// Removes the block response for the given height - /// This may only be called after `process_next_block`, which checked if the request for the given height was complete. + /// This may only be called after `peek_next_block`, which checked if the request for the given height was complete. pub fn remove_block_response(&self, height: u32) { // Acquire the requests write lock. // Note: This lock must be held across the entire scope, due to asynchronous block responses @@ -653,7 +654,7 @@ impl BlockSync { /// Removes the block request for the given peer IP, if it exists. #[allow(dead_code)] fn remove_block_request_to_peer(&self, peer_ip: &SocketAddr, height: u32) { - let mut can_revoke = self.process_next_block(height).is_none(); + let mut can_revoke = self.peek_next_block(height).is_none(); // Remove the peer IP from the request entry. If the request entry is now empty, // and the response entry for this height is also empty, then remove the request entry altogether.