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::GenericBlockHeader;
5use ab_core_primitives::block::header::owned::GenericOwnedBlockHeader;
6use ab_core_primitives::block::owned::GenericOwnedBlock;
7use ab_core_primitives::shard::RealShardKind;
8use std::time::Duration;
9use tracing::info;
10
11pub async fn run_informer<Block, CI>(chain_info: &CI, log_interval: Duration)
12where
13    Block: GenericOwnedBlock,
14    CI: ChainInfo<Block>,
15{
16    let shard = match Block::SHARD_KIND {
17        RealShardKind::BeaconChain => "BeaconChain".to_string(),
18        RealShardKind::IntermediateShard => {
19            format!(
20                "Intermediate[{}]",
21                chain_info
22                    .best_header()
23                    .header()
24                    .prefix
25                    .shard_index
26                    .as_u32()
27            )
28        }
29        RealShardKind::LeafShard => {
30            format!(
31                "Leaf[{}]",
32                chain_info
33                    .best_header()
34                    .header()
35                    .prefix
36                    .shard_index
37                    .as_u32()
38            )
39        }
40    };
41    loop {
42        // TODO: Sync and networking status once implemented
43
44        let best_header = chain_info.best_header();
45        info!(
46            %shard,
47            best_number = %best_header.header().prefix.number,
48            best_root = %*best_header.header().root(),
49            "💤"
50        );
51
52        tokio::time::sleep(log_interval).await;
53    }
54}