Skip to content

Commit

Permalink
Merge pull request #239 from eqlabs/krisztian/remove-sync-status-busy…
Browse files Browse the repository at this point in the history
…-loop

fix(sync_status): do not busy-loop on deserialization failures
  • Loading branch information
kkovaacs authored Apr 14, 2022
2 parents 7773c03 + 66b6a1d commit 1ae33fb
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions crates/pathfinder/src/state/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1ae33fb

Please sign in to comment.