Skip to content

Commit

Permalink
log blocktime
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Apr 29, 2024
1 parent eb964e3 commit 28c3041
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions examples/bench_geyser_grpc_accounts.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::{HashMap, VecDeque};

Check warning on line 1 in examples/bench_geyser_grpc_accounts.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/geyser-grpc-connector/geyser-grpc-connector/examples/bench_geyser_grpc_accounts.rs
use futures::{Stream, StreamExt};
use log::info;
use solana_sdk::clock::Slot;
use solana_sdk::clock::{Slot, UnixTimestamp};
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::pubkey::Pubkey;

Check warning on line 6 in examples/bench_geyser_grpc_accounts.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/geyser-grpc-connector/geyser-grpc-connector/examples/bench_geyser_grpc_accounts.rs
use std::env;
use std::pin::pin;
use std::time::{SystemTime, UNIX_EPOCH};
use itertools::Itertools;

Check warning on line 10 in examples/bench_geyser_grpc_accounts.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/geyser-grpc-connector/geyser-grpc-connector/examples/bench_geyser_grpc_accounts.rs
use tokio::sync::mpsc::Receiver;

Expand Down Expand Up @@ -55,9 +56,9 @@ pub async fn main() {
exit_notify.resubscribe(),
);

let _slots_task = create_geyser_autoconnection_task_with_mpsc(
let _blocksmeta_task = create_geyser_autoconnection_task_with_mpsc(
config.clone(),
GeyserFilter(CommitmentConfig::processed()).slots(),
GeyserFilter(CommitmentConfig::processed()).blocks_meta(),
autoconnect_tx.clone(),
exit_notify.resubscribe(),
);
Expand All @@ -82,6 +83,8 @@ fn start_tracking_account_consumer(mut geyser_messages_rx: Receiver<Message>) {
// slot from slot stream
let mut actual_slot: Slot = 0;

// seconds since epoch
let mut block_time_per_slot = HashMap::<Slot, UnixTimestamp>::new();
let mut recent_slot_deltas: VecDeque<i64> = VecDeque::with_capacity(RECENT_SLOTS_LIMIT);

loop {
Expand All @@ -91,6 +94,7 @@ fn start_tracking_account_consumer(mut geyser_messages_rx: Receiver<Message>) {
let account_info = update.account.unwrap();
let account_pk = Pubkey::try_from(account_info.pubkey).unwrap();
let slot = update.slot;
let account_receive_time = get_epoch_sec();

if actual_slot != slot {
if actual_slot != 0 {
Expand Down Expand Up @@ -135,13 +139,19 @@ fn start_tracking_account_consumer(mut geyser_messages_rx: Receiver<Message>) {
info!("Deltas slots list: {:?}", recent_slot_deltas);
info!("Deltas histogram: {}", deltas_histogram);

if let Some(actual_block_time) = block_time_per_slot.get(&current_slot) {
let now = get_epoch_sec();
info!("Block time for slot {}: delta {} seconds", current_slot, *actual_block_time - now);
}

}
current_slot = slot;
}

}
Some(UpdateOneof::Slot(update)) => {
Some(UpdateOneof::BlockMeta(update)) => {
actual_slot = update.slot;
block_time_per_slot.insert(actual_slot, update.block_time.unwrap().timestamp);
}
None => {}
_ => {}
Expand All @@ -155,3 +165,10 @@ fn start_tracking_account_consumer(mut geyser_messages_rx: Receiver<Message>) {
}
});
}

fn get_epoch_sec() -> UnixTimestamp {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as UnixTimestamp
}

0 comments on commit 28c3041

Please sign in to comment.