ab_client_informer/
lib.rs1use 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 u32::from(chain_info.best_header().header().prefix.shard_index)
22 )
23 }
24 RealShardKind::LeafShard => {
25 format!(
26 "Leaf[{}]",
27 u32::from(chain_info.best_header().header().prefix.shard_index)
28 )
29 }
30 };
31 loop {
32 let best_header = chain_info.best_header();
35 info!(
36 %shard,
37 best_number = %best_header.header().prefix.number,
38 best_root = %*best_header.header().root(),
39 "💤"
40 );
41
42 tokio::time::sleep(log_interval).await;
43 }
44}