Skip to content

Commit

Permalink
fix(merkle-tree): Fix chunk recovery reporting during tree recovery (#…
Browse files Browse the repository at this point in the history
…2348)

## What ❔

Fixes logging / observing metrics in the case a termination signal was
received during tree recovery.

## Why ❔

Logging / observing metrics in this case is misleading.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
slowli authored Jun 28, 2024
1 parent 0619ecc commit 70b3a8a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions core/node/metadata_calculator/src/recovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,10 @@ impl AsyncTreeRecovery {
.acquire()
.await
.context("semaphore is never closed")?;
Self::recover_key_chunk(&tree, snapshot.l2_block, chunk, pool, stop_receiver).await?;
options.events.chunk_recovered();
if Self::recover_key_chunk(&tree, snapshot.l2_block, chunk, pool, stop_receiver).await?
{
options.events.chunk_recovered();
}
anyhow::Ok(())
});
future::try_join_all(chunk_tasks).await?;
Expand Down Expand Up @@ -338,20 +340,21 @@ impl AsyncTreeRecovery {
Ok(output)
}

/// Returns `Ok(true)` if the chunk was recovered, `Ok(false)` if the recovery process was interrupted.
async fn recover_key_chunk(
tree: &Mutex<AsyncTreeRecovery>,
snapshot_l2_block: L2BlockNumber,
key_chunk: ops::RangeInclusive<H256>,
pool: &ConnectionPool<Core>,
stop_receiver: &watch::Receiver<bool>,
) -> anyhow::Result<()> {
) -> anyhow::Result<bool> {
let acquire_connection_latency =
RECOVERY_METRICS.chunk_latency[&ChunkRecoveryStage::AcquireConnection].start();
let mut storage = pool.connection_tagged("metadata_calculator").await?;
acquire_connection_latency.observe();

if *stop_receiver.borrow() {
return Ok(());
return Ok(false);
}

let entries_latency =
Expand All @@ -368,7 +371,7 @@ impl AsyncTreeRecovery {
);

if *stop_receiver.borrow() {
return Ok(());
return Ok(false);
}

// Sanity check: all entry keys must be distinct. Otherwise, we may end up writing non-final values
Expand Down Expand Up @@ -398,7 +401,7 @@ impl AsyncTreeRecovery {
lock_tree_latency.observe();

if *stop_receiver.borrow() {
return Ok(());
return Ok(false);
}

let extend_tree_latency =
Expand All @@ -408,7 +411,7 @@ impl AsyncTreeRecovery {
tracing::debug!(
"Extended Merkle tree with entries for chunk {key_chunk:?} in {extend_tree_latency:?}"
);
Ok(())
Ok(true)
}
}

Expand Down

0 comments on commit 70b3a8a

Please sign in to comment.