Skip to content

Commit

Permalink
process_next_block -> peek_next_block
Browse files Browse the repository at this point in the history
  • Loading branch information
kpandl committed Jan 2, 2025
1 parent d6e4f73 commit 778961a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions node/bft/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl<N: Network> Sync<N> {
// 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 {
Expand All @@ -338,7 +338,7 @@ impl<N: Network> Sync<N> {
}

// 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 {
Expand Down
11 changes: 6 additions & 5 deletions node/sync/src/block_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,10 @@ impl<N: Network> BlockSync<N> {
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<Block<N>> {
pub fn peek_next_block(&self, next_height: u32) -> Option<Block<N>> {
// 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.
Expand Down Expand Up @@ -364,7 +365,7 @@ impl<N: Network> BlockSync<N> {

/// 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());
Expand Down Expand Up @@ -636,7 +637,7 @@ impl<N: Network> BlockSync<N> {
}

/// 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
Expand All @@ -653,7 +654,7 @@ impl<N: Network> BlockSync<N> {
/// 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.
Expand Down

0 comments on commit 778961a

Please sign in to comment.