Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 70b3a8a

Browse files
authored
fix(merkle-tree): Fix chunk recovery reporting during tree recovery (matter-labs#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`.
1 parent 0619ecc commit 70b3a8a

File tree

1 file changed

+10
-7
lines changed
  • core/node/metadata_calculator/src/recovery

1 file changed

+10
-7
lines changed

core/node/metadata_calculator/src/recovery/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,10 @@ impl AsyncTreeRecovery {
261261
.acquire()
262262
.await
263263
.context("semaphore is never closed")?;
264-
Self::recover_key_chunk(&tree, snapshot.l2_block, chunk, pool, stop_receiver).await?;
265-
options.events.chunk_recovered();
264+
if Self::recover_key_chunk(&tree, snapshot.l2_block, chunk, pool, stop_receiver).await?
265+
{
266+
options.events.chunk_recovered();
267+
}
266268
anyhow::Ok(())
267269
});
268270
future::try_join_all(chunk_tasks).await?;
@@ -338,20 +340,21 @@ impl AsyncTreeRecovery {
338340
Ok(output)
339341
}
340342

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

353356
if *stop_receiver.borrow() {
354-
return Ok(());
357+
return Ok(false);
355358
}
356359

357360
let entries_latency =
@@ -368,7 +371,7 @@ impl AsyncTreeRecovery {
368371
);
369372

370373
if *stop_receiver.borrow() {
371-
return Ok(());
374+
return Ok(false);
372375
}
373376

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

400403
if *stop_receiver.borrow() {
401-
return Ok(());
404+
return Ok(false);
402405
}
403406

404407
let extend_tree_latency =
@@ -408,7 +411,7 @@ impl AsyncTreeRecovery {
408411
tracing::debug!(
409412
"Extended Merkle tree with entries for chunk {key_chunk:?} in {extend_tree_latency:?}"
410413
);
411-
Ok(())
414+
Ok(true)
412415
}
413416
}
414417

0 commit comments

Comments
 (0)