Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Adding metrics - num_get_vote_accounts_voting, num_live_validator_histories #35

Merged
merged 5 commits into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions keepers/validator-keeper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::{

use anchor_lang::{AccountDeserialize, Discriminator};
use keeper_core::{
get_vote_accounts_with_retry, CreateUpdateStats, MultipleAccountsError, SubmitStats,
TransactionExecutionError,
get_multiple_accounts_batched, get_vote_accounts_with_retry, CreateUpdateStats,
MultipleAccountsError, SubmitStats, TransactionExecutionError,
};
use log::error;
use solana_account_decoder::UiDataSliceConfig;
Expand All @@ -25,6 +25,7 @@ use solana_net_utils::bind_in_range;
use solana_sdk::{
pubkey::Pubkey,
signature::{Keypair, Signer},
vote::program::id as get_vote_program_id,
};
use solana_streamer::socket::SocketAddrSpace;

Expand Down Expand Up @@ -149,6 +150,8 @@ pub async fn emit_validator_history_metrics(
let mut stakes = 0;
let num_validators = validator_histories.len();
let default = ValidatorHistoryEntry::default();

let mut all_history_vote_accounts = Vec::new();
for validator_history in validator_histories {
if let Some(entry) = validator_history.history.last() {
if entry.epoch as u64 != epoch.epoch {
Expand Down Expand Up @@ -179,6 +182,8 @@ pub async fn emit_validator_history_metrics(
stakes += 1;
}
}

all_history_vote_accounts.push(validator_history.vote_account);
}

let (cluster_history_address, _) =
Expand All @@ -196,15 +201,40 @@ pub async fn emit_validator_history_metrics(
}
}

let get_vote_accounts_count = get_vote_accounts_with_retry(client, MIN_VOTE_EPOCHS, None)
.await?
.len();
let get_vote_accounts = get_vote_accounts_with_retry(client, MIN_VOTE_EPOCHS, None).await?;

let get_vote_accounts_count = get_vote_accounts.len() as i64;

let vote_program_id = get_vote_program_id();
let live_validator_histories_count =
get_multiple_accounts_batched(&all_history_vote_accounts, client)
.await?
.iter()
.filter(|&account| {
account
.as_ref()
.map_or(false, |acc| acc.owner == vote_program_id)
})
.count();

let get_vote_accounts_voting = get_vote_accounts
.iter()
.filter(|x| {
// Check if the last epoch credit ( most recent ) is the current epoch
x.epoch_credits.last().unwrap().0 == epoch.epoch
})
.count();

let keeper_balance = get_balance_with_retry(client, keeper_address).await?;

datapoint_info!(
"validator-history-stats",
("num_validator_histories", num_validators, i64),
(
"num_live_validator_histories",
live_validator_histories_count,
i64
),
("num_ips", ips, i64),
("num_versions", versions, i64),
("num_client_types", types, i64),
Expand All @@ -219,6 +249,11 @@ pub async fn emit_validator_history_metrics(
get_vote_accounts_count,
i64
),
(
"num_get_vote_accounts_voting",
get_vote_accounts_voting,
i64
),
);

datapoint_info!(
Expand Down
Loading