Skip to content

Commit 67d22d5

Browse files
committed
fix(rust/cardano-chain-follower): Fixing missing updating mithril stats with the new snapshot (#467)
* update new_mithril_update and live_sync_backfill_and_purge * wip * wip
1 parent cbd70c4 commit 67d22d5

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

rust/cardano-chain-follower/src/chain_sync.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,13 @@ async fn live_sync_backfill_and_purge(
421421
return;
422422
};
423423

424+
stats::new_mithril_update(cfg.chain, update.tip.slot_or_default());
425+
424426
debug!(
425427
"Before Backfill: Size of the Live Chain is: {} Blocks",
426428
live_chain_length(cfg.chain)
427429
);
428430

429-
let live_chain_head: Point;
430-
431431
loop {
432432
// We will re-attempt backfill, until its successful.
433433
// Backfill is atomic, it either fully works, or none of the live-chain is changed.
@@ -437,23 +437,15 @@ async fn live_sync_backfill_and_purge(
437437
sleep(Duration::from_secs(10)).await;
438438
}
439439

440-
if let Some(head_point) = get_live_head_point(cfg.chain) {
441-
live_chain_head = head_point;
440+
if get_live_head_point(cfg.chain).is_some() {
442441
break;
443442
}
444443
}
445444

446-
stats::new_mithril_update(
447-
cfg.chain,
448-
update.tip.slot_or_default(),
449-
live_chain_length(cfg.chain) as u64,
450-
live_chain_head.slot_or_default(),
451-
);
445+
let new_live_chain_length = live_chain_length(cfg.chain);
446+
stats::new_live_total_blocks(cfg.chain, new_live_chain_length as u64);
452447

453-
debug!(
454-
"After Backfill: Size of the Live Chain is: {} Blocks",
455-
live_chain_length(cfg.chain)
456-
);
448+
debug!("After Backfill: Size of the Live Chain is: {new_live_chain_length} Blocks",);
457449

458450
// Once Backfill is completed OK we can use the Blockchain data for Syncing and Querying
459451
sync_ready.signal();
@@ -471,6 +463,8 @@ async fn live_sync_backfill_and_purge(
471463
update_sender = get_chain_update_tx_queue(cfg.chain).await;
472464
}
473465

466+
stats::new_mithril_update(cfg.chain, update.tip.slot_or_default());
467+
474468
debug!("Mithril Tip has advanced to: {update:?} : PURGE NEEDED");
475469

476470
let update_point: Point = update.tip.clone();
@@ -480,9 +474,11 @@ async fn live_sync_backfill_and_purge(
480474
error!("Mithril Purge Failed: {}", error);
481475
}
482476

477+
let new_live_chain_length = live_chain_length(cfg.chain);
478+
stats::new_live_total_blocks(cfg.chain, new_live_chain_length as u64);
479+
483480
debug!(
484-
"After Purge: Size of the Live Chain is: {} Blocks: Triggering Sleeping Followers.",
485-
live_chain_length(cfg.chain)
481+
"After Purge: Size of the Live Chain is: {new_live_chain_length} Blocks: Triggering Sleeping Followers.",
486482
);
487483

488484
// Trigger any sleeping followers that data has changed.

rust/cardano-chain-follower/src/stats/mod.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ pub(crate) fn new_live_block(
181181
}
182182

183183
/// Track the end of the current mithril update
184-
pub(crate) fn new_mithril_update(
185-
chain: Network, mithril_tip: Slot, total_live_blocks: u64, tip_slot: Slot,
186-
) {
184+
pub(crate) fn new_mithril_update(chain: Network, mithril_tip: Slot) {
187185
// This will actually always succeed.
188186
let Some(stats) = lookup_stats(chain) else {
189187
return;
@@ -197,8 +195,22 @@ pub(crate) fn new_mithril_update(
197195

198196
chain_stats.mithril.updates = chain_stats.mithril.updates.saturating_add(1);
199197
chain_stats.mithril.tip = mithril_tip;
198+
}
199+
200+
/// Track the current total live blocks count
201+
pub(crate) fn new_live_total_blocks(chain: Network, total_live_blocks: u64) {
202+
// This will actually always succeed.
203+
let Some(stats) = lookup_stats(chain) else {
204+
return;
205+
};
206+
207+
let Ok(mut chain_stats) = stats.write() else {
208+
// Worst case if this fails (it never should) is we stop updating stats.
209+
error!("Stats RwLock should never be able to error.");
210+
return;
211+
};
212+
200213
chain_stats.live.blocks = total_live_blocks;
201-
chain_stats.live.tip = tip_slot;
202214
}
203215

204216
/// When did we start the backfill.

0 commit comments

Comments
 (0)