//! this service asynchronously reports CostTracker stats use { crossbeam_channel::Receiver, solana_ledger::blockstore::Blockstore, solana_runtime::bank::Bank, std::{ sync::Arc, thread::{self, Builder, JoinHandle}, }, }; pub enum CostUpdate { FrozenBank { bank: Arc }, } pub type CostUpdateReceiver = Receiver; pub struct CostUpdateService { thread_hdl: JoinHandle<()>, } impl CostUpdateService { #[allow(clippy::new_ret_no_self)] pub fn new(blockstore: Arc, cost_update_receiver: CostUpdateReceiver) -> Self { let thread_hdl = Builder::new() .name("solCostUpdtSvc".to_string()) .spawn(move || { Self::service_loop(blockstore, cost_update_receiver); }) .unwrap(); Self { thread_hdl } } pub fn join(self) -> thread::Result<()> { self.thread_hdl.join() } fn service_loop(_blockstore: Arc, cost_update_receiver: CostUpdateReceiver) { for cost_update in cost_update_receiver.iter() { match cost_update { CostUpdate::FrozenBank { bank } => { bank.read_cost_tracker().unwrap().report_stats(bank.slot()); } } } } }