From 66b6a1d4648f3bbd5e2250e282af99ab89b41bb2 Mon Sep 17 00:00:00 2001 From: Krisztian Kovacs Date: Thu, 14 Apr 2022 10:15:35 +0200 Subject: [PATCH] fix(sync_status): do not busy-loop on deserialization failures Instead of silently ignoring the error and retrying immediately we now log it and then proceed to wait a bit before retrying. --- crates/pathfinder/src/state/sync.rs | 68 ++++++++++++++--------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/crates/pathfinder/src/state/sync.rs b/crates/pathfinder/src/state/sync.rs index 3f3836a7be..663a372430 100644 --- a/crates/pathfinder/src/state/sync.rs +++ b/crates/pathfinder/src/state/sync.rs @@ -318,42 +318,42 @@ async fn update_sync_status_latest( let poll_interval = l2::head_poll_interval(chain); loop { - // Work-around the sequencer block fetch being flakey. - let latest = loop { - if let Ok(block) = sequencer - .block_by_number(BlockNumberOrTag::Tag(Tag::Latest)) - .await - { - // Unwrap is safe as only pending blocks have None. - break block.block_hash.unwrap(); - } - }; - - // Update the sync status. - match &mut *state.status.write().await { - sync_status @ SyncStatus::False(_) => { - *sync_status = SyncStatus::Status(syncing::Status { - starting_block, - current_block: starting_block, - highest_block: latest, - }); - - tracing::debug!( - starting=%starting_block.0, - current=%starting_block.0, - highest=%latest.0, - "Updated sync status", - ); - } - SyncStatus::Status(status) => { - if status.highest_block != latest { - status.highest_block = latest; - tracing::debug!( - highest=%latest.0, - "Updated sync status", - ); + match sequencer + .block_by_number(BlockNumberOrTag::Tag(Tag::Latest)) + .await + { + Ok(block) => { + let latest = block.block_hash.unwrap(); + // Update the sync status. + match &mut *state.status.write().await { + sync_status @ SyncStatus::False(_) => { + *sync_status = SyncStatus::Status(syncing::Status { + starting_block, + current_block: starting_block, + highest_block: latest, + }); + + tracing::debug!( + starting=%starting_block.0, + current=%starting_block.0, + highest=%latest.0, + "Updated sync status", + ); + } + SyncStatus::Status(status) => { + if status.highest_block != latest { + status.highest_block = latest; + tracing::debug!( + highest=%latest.0, + "Updated sync status", + ); + } + } } } + Err(e) => { + tracing::error!(error=%e, "Failed to fetch latest block"); + } } tokio::time::sleep(poll_interval).await;