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

Fix misnomer and warn when StakedNodes fails to update. #130

Merged
merged 2 commits into from
May 11, 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
21 changes: 15 additions & 6 deletions core/src/staked_nodes_updater_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ use std::{
};

use jito_rpc::load_balancer::LoadBalancer;
use log::warn;
use solana_client::client_error;
use solana_sdk::pubkey::Pubkey;
use solana_streamer::streamer::StakedNodes;

const IP_TO_STAKE_REFRESH_DURATION: Duration = Duration::from_secs(5);
const PK_TO_STAKE_REFRESH_DURATION: Duration = Duration::from_secs(5);

pub struct StakedNodesUpdaterService {
thread_hdl: JoinHandle<()>,
Expand All @@ -33,13 +34,21 @@ impl StakedNodesUpdaterService {
let mut last_stakes = Instant::now();
while !exit.load(Ordering::Relaxed) {
let mut stake_map = Arc::new(HashMap::new());
if let Ok(true) = Self::try_refresh_ip_to_stake(
match Self::try_refresh_pk_to_stake(
&mut last_stakes,
&mut stake_map,
&rpc_load_balancer,
) {
let shared = StakedNodes::new(stake_map, staked_nodes_overrides.clone());
*shared_staked_nodes.write().unwrap() = shared;
Ok(true) => {
let shared =
StakedNodes::new(stake_map, staked_nodes_overrides.clone());
*shared_staked_nodes.write().unwrap() = shared;
}
Err(err) => {
warn!("Failed to refresh pk to stake map! Error: {:?}", err);
sleep(PK_TO_STAKE_REFRESH_DURATION);
jedleggett marked this conversation as resolved.
Show resolved Hide resolved
}
_ => {}
}
}
})
Expand All @@ -48,12 +57,12 @@ impl StakedNodesUpdaterService {
Self { thread_hdl }
}

fn try_refresh_ip_to_stake(
fn try_refresh_pk_to_stake(
last_stakes: &mut Instant,
pubkey_stake_map: &mut Arc<HashMap<Pubkey, u64>>,
rpc_load_balancer: &Arc<LoadBalancer>,
) -> client_error::Result<bool> {
if last_stakes.elapsed() > IP_TO_STAKE_REFRESH_DURATION {
if last_stakes.elapsed() > PK_TO_STAKE_REFRESH_DURATION {
let client = rpc_load_balancer.rpc_client();
let vote_accounts = client.get_vote_accounts()?;

Expand Down
Loading