Skip to content

Commit

Permalink
Fix misnomer and warn when StakedNodes fails to update. (solana-labs#130
Browse files Browse the repository at this point in the history
)

Co-authored-by: ben | mrgn <[email protected]>
  • Loading branch information
SOELTH and ben | mrgn authored May 11, 2024
1 parent d504075 commit c38d0d1
Showing 1 changed file with 15 additions and 6 deletions.
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);
}
_ => {}
}
}
})
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

0 comments on commit c38d0d1

Please sign in to comment.