2022-11-22 09:55:56 -08:00
|
|
|
//! this service asynchronously reports CostTracker stats
|
2021-07-01 09:32:41 -07:00
|
|
|
|
2021-12-03 09:00:31 -08:00
|
|
|
use {
|
2022-01-11 02:44:46 -08:00
|
|
|
crossbeam_channel::Receiver,
|
2021-12-03 09:00:31 -08:00
|
|
|
solana_ledger::blockstore::Blockstore,
|
2022-11-22 09:55:56 -08:00
|
|
|
solana_runtime::bank::Bank,
|
2021-12-03 09:00:31 -08:00
|
|
|
std::{
|
2022-11-22 09:55:56 -08:00
|
|
|
sync::Arc,
|
2021-12-03 09:00:31 -08:00
|
|
|
thread::{self, Builder, JoinHandle},
|
2021-07-01 09:32:41 -07:00
|
|
|
},
|
|
|
|
};
|
2021-10-24 20:19:23 -07:00
|
|
|
pub enum CostUpdate {
|
2022-11-22 09:55:56 -08:00
|
|
|
FrozenBank { bank: Arc<Bank> },
|
2021-10-24 20:19:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub type CostUpdateReceiver = Receiver<CostUpdate>;
|
2021-07-01 09:32:41 -07:00
|
|
|
|
|
|
|
pub struct CostUpdateService {
|
|
|
|
thread_hdl: JoinHandle<()>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CostUpdateService {
|
2022-11-22 09:55:56 -08:00
|
|
|
pub fn new(blockstore: Arc<Blockstore>, cost_update_receiver: CostUpdateReceiver) -> Self {
|
2021-07-01 09:32:41 -07:00
|
|
|
let thread_hdl = Builder::new()
|
2022-08-17 08:40:23 -07:00
|
|
|
.name("solCostUpdtSvc".to_string())
|
2021-07-01 09:32:41 -07:00
|
|
|
.spawn(move || {
|
2022-11-22 09:55:56 -08:00
|
|
|
Self::service_loop(blockstore, cost_update_receiver);
|
2021-07-01 09:32:41 -07:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
Self { thread_hdl }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn join(self) -> thread::Result<()> {
|
|
|
|
self.thread_hdl.join()
|
|
|
|
}
|
|
|
|
|
2022-11-22 09:55:56 -08:00
|
|
|
fn service_loop(_blockstore: Arc<Blockstore>, cost_update_receiver: CostUpdateReceiver) {
|
2022-03-14 08:31:14 -07:00
|
|
|
for cost_update in cost_update_receiver.iter() {
|
|
|
|
match cost_update {
|
|
|
|
CostUpdate::FrozenBank { bank } => {
|
|
|
|
bank.read_cost_tracker().unwrap().report_stats(bank.slot());
|
|
|
|
}
|
|
|
|
}
|
2021-12-30 18:21:42 -08:00
|
|
|
}
|
|
|
|
}
|
2021-07-01 09:32:41 -07:00
|
|
|
}
|