Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(merkle-tree): Fix chunk recovery reporting during tree recovery #2348

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading