diff --git a/rust/cardano-chain-follower/src/chain_sync.rs b/rust/cardano-chain-follower/src/chain_sync.rs index f590a3df3a..6cbea0ca44 100644 --- a/rust/cardano-chain-follower/src/chain_sync.rs +++ b/rust/cardano-chain-follower/src/chain_sync.rs @@ -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. @@ -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(); @@ -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(); @@ -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. diff --git a/rust/cardano-chain-follower/src/stats/mod.rs b/rust/cardano-chain-follower/src/stats/mod.rs index bdc51a25b3..85cc6f389f 100644 --- a/rust/cardano-chain-follower/src/stats/mod.rs +++ b/rust/cardano-chain-follower/src/stats/mod.rs @@ -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 { @@ -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.