Skip to content

Commit baca327

Browse files
authored
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 bf8dcba commit baca327

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,13 @@ async fn live_sync_backfill_and_purge(
451451
return;
452452
};
453453

454+
stats::new_mithril_update(cfg.chain, update.tip.slot_or_default());
455+
454456
debug!(
455457
"Before Backfill: Size of the Live Chain is: {} Blocks",
456458
live_chain_length(cfg.chain)
457459
);
458460

459-
let live_chain_head: Point;
460-
461461
loop {
462462
// We will re-attempt backfill, until its successful.
463463
// Backfill is atomic, it either fully works, or none of the live-chain is changed.
@@ -467,23 +467,15 @@ async fn live_sync_backfill_and_purge(
467467
sleep(Duration::from_secs(10)).await;
468468
}
469469

470-
if let Some(head_point) = get_live_head_point(cfg.chain) {
471-
live_chain_head = head_point;
470+
if get_live_head_point(cfg.chain).is_some() {
472471
break;
473472
}
474473
}
475474

476-
stats::new_mithril_update(
477-
cfg.chain,
478-
update.tip.slot_or_default(),
479-
live_chain_length(cfg.chain) as u64,
480-
live_chain_head.slot_or_default(),
481-
);
475+
let new_live_chain_length = live_chain_length(cfg.chain);
476+
stats::new_live_total_blocks(cfg.chain, new_live_chain_length as u64);
482477

483-
debug!(
484-
"After Backfill: Size of the Live Chain is: {} Blocks",
485-
live_chain_length(cfg.chain)
486-
);
478+
debug!("After Backfill: Size of the Live Chain is: {new_live_chain_length} Blocks",);
487479

488480
// Once Backfill is completed OK we can use the Blockchain data for Syncing and Querying
489481
sync_ready.signal();
@@ -501,6 +493,8 @@ async fn live_sync_backfill_and_purge(
501493
update_sender = get_chain_update_tx_queue(cfg.chain).await;
502494
}
503495

496+
stats::new_mithril_update(cfg.chain, update.tip.slot_or_default());
497+
504498
debug!("Mithril Tip has advanced to: {update:?} : PURGE NEEDED");
505499

506500
let update_point: Point = update.tip.clone();
@@ -510,9 +504,11 @@ async fn live_sync_backfill_and_purge(
510504
error!("Mithril Purge Failed: {}", error);
511505
}
512506

507+
let new_live_chain_length = live_chain_length(cfg.chain);
508+
stats::new_live_total_blocks(cfg.chain, new_live_chain_length as u64);
509+
513510
debug!(
514-
"After Purge: Size of the Live Chain is: {} Blocks: Triggering Sleeping Followers.",
515-
live_chain_length(cfg.chain)
511+
"After Purge: Size of the Live Chain is: {new_live_chain_length} Blocks: Triggering Sleeping Followers.",
516512
);
517513

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

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ pub(crate) fn new_live_block(
193193
pub(crate) fn new_mithril_update(
194194
chain: Network,
195195
mithril_tip: Slot,
196-
total_live_blocks: u64,
197-
tip_slot: Slot,
198196
) {
199197
// This will actually always succeed.
200198
let Some(stats) = lookup_stats(chain) else {
@@ -209,8 +207,25 @@ pub(crate) fn new_mithril_update(
209207

210208
chain_stats.mithril.updates = chain_stats.mithril.updates.saturating_add(1);
211209
chain_stats.mithril.tip = mithril_tip;
210+
}
211+
212+
/// Track the current total live blocks count
213+
pub(crate) fn new_live_total_blocks(
214+
chain: Network,
215+
total_live_blocks: u64,
216+
) {
217+
// This will actually always succeed.
218+
let Some(stats) = lookup_stats(chain) else {
219+
return;
220+
};
221+
222+
let Ok(mut chain_stats) = stats.write() else {
223+
// Worst case if this fails (it never should) is we stop updating stats.
224+
error!("Stats RwLock should never be able to error.");
225+
return;
226+
};
227+
212228
chain_stats.live.blocks = total_live_blocks;
213-
chain_stats.live.tip = tip_slot;
214229
}
215230

216231
/// When did we start the backfill.

0 commit comments

Comments
 (0)