diff --git a/rust/cardano-chain-follower/src/chain_sync.rs b/rust/cardano-chain-follower/src/chain_sync.rs index 916fe9638b..e2c6bc6156 100644 --- a/rust/cardano-chain-follower/src/chain_sync.rs +++ b/rust/cardano-chain-follower/src/chain_sync.rs @@ -421,13 +421,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. @@ -437,23 +437,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(); @@ -471,6 +463,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(); @@ -480,9 +474,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. diff --git a/rust/cardano-chain-follower/src/stats/mod.rs b/rust/cardano-chain-follower/src/stats/mod.rs index 31e1ed014a..de60cca440 100644 --- a/rust/cardano-chain-follower/src/stats/mod.rs +++ b/rust/cardano-chain-follower/src/stats/mod.rs @@ -181,9 +181,7 @@ pub(crate) fn new_live_block( } /// Track the end of the current mithril update -pub(crate) fn new_mithril_update( - chain: Network, mithril_tip: Slot, total_live_blocks: u64, tip_slot: Slot, -) { +pub(crate) fn new_mithril_update(chain: Network, mithril_tip: Slot) { // This will actually always succeed. let Some(stats) = lookup_stats(chain) else { return; @@ -197,8 +195,22 @@ 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.