Skip to content

Commit

Permalink
FEATURE: Adding metrics - num_get_vote_accounts_voting, num_live_vali…
Browse files Browse the repository at this point in the history
…dator_histories (#35)

Added two new metrics to the `emit_validator_history_metrics` function:

- `num_live_validator_histories`: The number of validator history
accounts that have "live" vote accounts with the owner of said vote
account being the vote program
- `num_get_vote_accounts_voting`: The number of vote accounts actually
voting. More specifically, accounts that have voted in the current epoch
retrieved from `get_vote_accounts_with_retry`.
  • Loading branch information
coachchucksol authored May 10, 2024
1 parent 9017372 commit ea2543a
Showing 1 changed file with 40 additions and 5 deletions.
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

0 comments on commit ea2543a

Please sign in to comment.