Skip to main content

ab_client_informer/
lib.rs

1//! Client informer, which logs node state periodically
2
3use ab_client_api::ChainInfo;
4use ab_core_primitives::block::header::owned::GenericOwnedBlockHeader;
5use ab_core_primitives::block::owned::GenericOwnedBlock;
6use ab_core_primitives::shard::RealShardKind;
7use std::time::Duration;
8use tracing::info;
9
10pub async fn run_informer<Block, CI>(chain_info: &CI, log_interval: Duration)
11where
12    Block: GenericOwnedBlock,
13    CI: ChainInfo<Block>,
14{
15    let shard = match Block::SHARD_KIND {
16        RealShardKind::BeaconChain => "BeaconChain".to_string(),
17        RealShardKind::IntermediateShard => {
18            format!(
19                "Intermediate[{}]",
20                u32::from(chain_info.best_header().header().prefix.shard_index)
21            )
22        }
23        RealShardKind::LeafShard => {
24            format!(
25                "Leaf[{}]",
26                u32::from(chain_info.best_header().header().prefix.shard_index)
27            )
28        }
29    };
30    #[expect(
31        clippy::infinite_loop,
32        reason = "Intentional loop is a part of a future that can be dropped"
33    )]
34    loop {
35        // TODO: Sync and networking status once implemented
36
37        let best_header = chain_info.best_header();
38        info!(
39            %shard,
40            best_number = %best_header.header().prefix.number,
41            best_root = %*best_header.root(),
42            "💤"
43        );
44
45        tokio::time::sleep(log_interval).await;
46    }
47}