Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 12 additions & 16 deletions rust/cardano-chain-follower/src/chain_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,13 @@ async fn live_sync_backfill_and_purge(
return;
};

stats::new_mithril_update(cfg.chain, update.tip.slot_or_default());

debug!(
"Before Backfill: Size of the Live Chain is: {} Blocks",
live_chain_length(cfg.chain)
);

let live_chain_head: Point;

loop {
// We will re-attempt backfill, until its successful.
// Backfill is atomic, it either fully works, or none of the live-chain is changed.
Expand All @@ -467,23 +467,15 @@ async fn live_sync_backfill_and_purge(
sleep(Duration::from_secs(10)).await;
}

if let Some(head_point) = get_live_head_point(cfg.chain) {
live_chain_head = head_point;
if get_live_head_point(cfg.chain).is_some() {
break;
}
}

stats::new_mithril_update(
cfg.chain,
update.tip.slot_or_default(),
live_chain_length(cfg.chain) as u64,
live_chain_head.slot_or_default(),
);
let new_live_chain_length = live_chain_length(cfg.chain);
stats::new_live_total_blocks(cfg.chain, new_live_chain_length as u64);

debug!(
"After Backfill: Size of the Live Chain is: {} Blocks",
live_chain_length(cfg.chain)
);
debug!("After Backfill: Size of the Live Chain is: {new_live_chain_length} Blocks",);

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

stats::new_mithril_update(cfg.chain, update.tip.slot_or_default());

debug!("Mithril Tip has advanced to: {update:?} : PURGE NEEDED");

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

let new_live_chain_length = live_chain_length(cfg.chain);
stats::new_live_total_blocks(cfg.chain, new_live_chain_length as u64);

debug!(
"After Purge: Size of the Live Chain is: {} Blocks: Triggering Sleeping Followers.",
live_chain_length(cfg.chain)
"After Purge: Size of the Live Chain is: {new_live_chain_length} Blocks: Triggering Sleeping Followers.",
);

// Trigger any sleeping followers that data has changed.
Expand Down
21 changes: 18 additions & 3 deletions rust/cardano-chain-follower/src/stats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ pub(crate) fn new_live_block(
pub(crate) fn new_mithril_update(
chain: Network,
mithril_tip: Slot,
total_live_blocks: u64,
tip_slot: Slot,
) {
// This will actually always succeed.
let Some(stats) = lookup_stats(chain) else {
Expand All @@ -209,8 +207,25 @@ pub(crate) fn new_mithril_update(

chain_stats.mithril.updates = chain_stats.mithril.updates.saturating_add(1);
chain_stats.mithril.tip = mithril_tip;
}

/// Track the current total live blocks count
pub(crate) fn new_live_total_blocks(
chain: Network,
total_live_blocks: u64,
) {
// This will actually always succeed.
let Some(stats) = lookup_stats(chain) else {
return;
};

let Ok(mut chain_stats) = stats.write() else {
// Worst case if this fails (it never should) is we stop updating stats.
error!("Stats RwLock should never be able to error.");
return;
};

chain_stats.live.blocks = total_live_blocks;
chain_stats.live.tip = tip_slot;
}

/// When did we start the backfill.
Expand Down
Loading