Skip to content

Commit

Permalink
linted
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed May 15, 2024
1 parent f9eb300 commit fc37ab1
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 126 deletions.
10 changes: 5 additions & 5 deletions keepers/validator-keeper/src/entries/gossip_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ impl GossipEntry {
let validator_history_account = derive_validator_history_address(vote_account, program_id);
let config = derive_validator_history_config_address(program_id);
Self {
vote_account: vote_account.clone(),
vote_account: *vote_account,
validator_history_account,
config,
signature: signature.clone(),
signature: *signature,
message: message.to_vec(),
program_id: program_id.clone(),
identity: identity.clone(),
signer: signer.clone(),
program_id: *program_id,
identity: *identity,
signer: *signer,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions keepers/validator-keeper/src/entries/mev_commission_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ impl ValidatorMevCommissionEntry {
let config = derive_validator_history_config_address(program_id);

Self {
vote_account: vote_account.clone(),
vote_account: *vote_account,
tip_distribution_account,
validator_history_account,
config,
program_id: program_id.clone(),
signer: signer.clone(),
program_id: *program_id,
signer: *signer,
epoch,
}
}
Expand Down
10 changes: 5 additions & 5 deletions keepers/validator-keeper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ pub fn get_create_validator_history_instructions(
let config_account = derive_validator_history_config_address(program_id);

let mut ixs = vec![Instruction {
program_id: program_id.clone(),
program_id: *program_id,
accounts: validator_history::accounts::InitializeValidatorHistoryAccount {
validator_history_account,
vote_account: vote_account.clone(),
vote_account: *vote_account,
system_program: solana_program::system_program::id(),
signer: signer.pubkey(),
}
Expand All @@ -271,10 +271,10 @@ pub fn get_create_validator_history_instructions(
let num_reallocs = (ValidatorHistory::SIZE - MAX_ALLOC_BYTES) / MAX_ALLOC_BYTES + 1;
ixs.extend(vec![
Instruction {
program_id: program_id.clone(),
program_id: *program_id,
accounts: validator_history::accounts::ReallocValidatorHistoryAccount {
validator_history_account: validator_history_account,
vote_account: vote_account.clone(),
validator_history_account,
vote_account: *vote_account,
config: config_account,
system_program: solana_program::system_program::id(),
signer: signer.pubkey(),
Expand Down
65 changes: 35 additions & 30 deletions keepers/validator-keeper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct Args {
cluster: Cluster,
}

fn should_update(tick: u64, intervals: &Vec<u64>) -> bool {
fn should_update(tick: u64, intervals: &[u64]) -> bool {
intervals.iter().any(|interval| tick % interval == 0)
}

Expand All @@ -87,7 +87,7 @@ async fn sleep_and_tick(tick: &mut u64) {
advance_tick(tick);
}

async fn run_loop(
struct RunLoopConfig {
client: Arc<RpcClient>,
keypair: Arc<Keypair>,
program_id: Pubkey,
Expand All @@ -96,7 +96,19 @@ async fn run_loop(
gossip_entrypoint: Option<SocketAddr>,
validator_history_interval: u64,
metrics_interval: u64,
) {
}

async fn run_loop(config: RunLoopConfig) {
let RunLoopConfig {
client,
keypair,
program_id,
tip_distribution_program_id,
oracle_authority_keypair,
gossip_entrypoint,
validator_history_interval,
metrics_interval,
} = config;
let intervals = vec![validator_history_interval, metrics_interval];

// Stateful data
Expand Down Expand Up @@ -214,7 +226,7 @@ async fn run_loop(
keeper_state.set_runs_and_errors_for_epoch(
operations::stake_upload::fire_and_emit(
&client,
&oracle_authority_keypair,
oracle_authority_keypair,
&program_id,
&keeper_state,
)
Expand All @@ -229,7 +241,7 @@ async fn run_loop(
keeper_state.set_runs_and_errors_for_epoch(
operations::gossip_upload::fire_and_emit(
&client,
&oracle_authority_keypair,
oracle_authority_keypair,
&program_id,
&gossip_entrypoint,
&keeper_state,
Expand Down Expand Up @@ -266,39 +278,32 @@ async fn main() {

let keypair = Arc::new(read_keypair_file(args.keypair).expect("Failed reading keypair file"));

let oracle_authority_keypair = {
if let Some(oracle_authority_keypair) = args.oracle_authority_keypair {
Some(Arc::new(
let oracle_authority_keypair = args
.oracle_authority_keypair
.map(|oracle_authority_keypair| {
Arc::new(
read_keypair_file(oracle_authority_keypair)
.expect("Failed reading stake keypair file"),
))
} else {
None
}
};

let gossip_entrypoint = {
if let Some(gossip_entrypoint) = args.gossip_entrypoint {
Some(
solana_net_utils::parse_host_port(&gossip_entrypoint)
.expect("Failed to parse host and port from gossip entrypoint"),
)
} else {
None
}
};
});

let gossip_entrypoint = args.gossip_entrypoint.map(|gossip_entrypoint| {
solana_net_utils::parse_host_port(&gossip_entrypoint)
.expect("Failed to parse host and port from gossip entrypoint")
});

info!("Starting validator history keeper...");

run_loop(
let config = RunLoopConfig {
client,
keypair,
args.program_id,
args.tip_distribution_program_id,
program_id: args.program_id,
tip_distribution_program_id: args.tip_distribution_program_id,
oracle_authority_keypair,
gossip_entrypoint,
args.validator_history_interval,
args.metrics_interval,
)
.await;
validator_history_interval: args.validator_history_interval,
metrics_interval: args.metrics_interval,
};

run_loop(config).await;
}
13 changes: 5 additions & 8 deletions keepers/validator-keeper/src/operations/cluster_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ use std::sync::Arc;
use super::keeper_operations::KeeperOperations;

fn _get_operation() -> KeeperOperations {
return KeeperOperations::ClusterHistory;
KeeperOperations::ClusterHistory
}

fn _should_run(epoch_info: &EpochInfo, runs_for_epoch: u64) -> bool {
// Run at 0.1%, 50% and 90% completion of epoch
let should_run = (epoch_info.slot_index > epoch_info.slots_in_epoch / 1000
&& runs_for_epoch < 1)
(epoch_info.slot_index > epoch_info.slots_in_epoch / 1000 && runs_for_epoch < 1)
|| (epoch_info.slot_index > epoch_info.slots_in_epoch / 2 && runs_for_epoch < 2)
|| (epoch_info.slot_index > epoch_info.slots_in_epoch * 9 / 10 && runs_for_epoch < 3);

should_run
|| (epoch_info.slot_index > epoch_info.slots_in_epoch * 9 / 10 && runs_for_epoch < 3)
}

async fn _process(
Expand Down Expand Up @@ -65,7 +62,7 @@ pub async fn fire_and_emit(
let (mut runs_for_epoch, mut errors_for_epoch) =
keeper_state.copy_runs_and_errors_for_epoch(operation.clone());

let should_run = _should_run(&epoch_info, runs_for_epoch.clone());
let should_run = _should_run(epoch_info, runs_for_epoch);

let mut stats = SubmitStats::default();
if should_run {
Expand Down Expand Up @@ -117,7 +114,7 @@ pub fn get_update_cluster_info_instructions(
accounts: validator_history::accounts::CopyClusterInfo {
cluster_history_account,
slot_history: solana_program::sysvar::slot_history::id(),
signer: keypair.clone(),
signer: *keypair,
}
.to_account_metas(None),
data: validator_history::instruction::CopyClusterInfo {}.data(),
Expand Down
19 changes: 6 additions & 13 deletions keepers/validator-keeper/src/operations/gossip_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ use validator_history::ValidatorHistoryEntry;
use super::keeper_operations::KeeperOperations;

fn _get_operation() -> KeeperOperations {
return KeeperOperations::GossipUpload;
KeeperOperations::GossipUpload
}

fn _should_run(epoch_info: &EpochInfo, runs_for_epoch: u64) -> bool {
// Run at 0%, 50% and 90% completion of epoch
let should_run = runs_for_epoch < 1
runs_for_epoch < 1
|| (epoch_info.slot_index > epoch_info.slots_in_epoch / 2 && runs_for_epoch < 2)
|| (epoch_info.slot_index > epoch_info.slots_in_epoch * 9 / 10 && runs_for_epoch < 3);

should_run
|| (epoch_info.slot_index > epoch_info.slots_in_epoch * 9 / 10 && runs_for_epoch < 3)
}

async fn _process(
Expand Down Expand Up @@ -255,13 +253,8 @@ pub async fn upload_gossip_values(
gossip_port,
);
let exit: Arc<AtomicBool> = Arc::new(AtomicBool::new(false));
let (_gossip_service, cluster_info) = start_spy_server(
entrypoint.clone(),
gossip_port,
spy_socket_addr,
&keypair,
&exit,
);
let (_gossip_service, cluster_info) =
start_spy_server(*entrypoint, gossip_port, spy_socket_addr, keypair, &exit);

// Wait for all active validators to be received
sleep(Duration::from_secs(150)).await;
Expand All @@ -284,7 +277,7 @@ pub async fn upload_gossip_values(
validator_history_account,
&crds,
*program_id,
&keypair,
keypair,
)
})
.flatten()
Expand Down
2 changes: 1 addition & 1 deletion keepers/validator-keeper/src/operations/metrics_emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use validator_history::ValidatorHistoryEntry;
use super::keeper_operations::KeeperOperations;

fn _get_operation() -> KeeperOperations {
return KeeperOperations::EmitMetrics;
KeeperOperations::EmitMetrics
}

fn _should_run() -> bool {
Expand Down
9 changes: 3 additions & 6 deletions keepers/validator-keeper/src/operations/mev_commission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use validator_history::ValidatorHistoryEntry;
use super::keeper_operations::KeeperOperations;

fn _get_operation() -> KeeperOperations {
return KeeperOperations::MevCommission;
KeeperOperations::MevCommission
}

fn _should_run() -> bool {
Expand Down Expand Up @@ -120,15 +120,12 @@ pub async fn update_mev_commission(

let existing_entries = current_epoch_tip_distribution_map
.iter()
.filter_map(|(pubkey, account)| match account {
Some(_) => Some(pubkey.clone()),
None => None,
})
.filter_map(|(pubkey, account)| account.as_ref().map(|_| *pubkey))
.collect::<Vec<_>>();

let entries_to_update = existing_entries
.into_iter()
.filter(|entry| !mev_commission_uploaded(&validator_history_map, entry, epoch_info.epoch))
.filter(|entry| !mev_commission_uploaded(validator_history_map, entry, epoch_info.epoch))
.collect::<Vec<Pubkey>>();

let update_instructions = entries_to_update
Expand Down
4 changes: 2 additions & 2 deletions keepers/validator-keeper/src/operations/mev_earned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use validator_history::ValidatorHistoryEntry;
use super::keeper_operations::KeeperOperations;

fn _get_operation() -> KeeperOperations {
return KeeperOperations::MevEarned;
KeeperOperations::MevEarned
}

fn _should_run() -> bool {
Expand Down Expand Up @@ -129,7 +129,7 @@ pub async fn update_mev_earned(
let mut data: &[u8] = &account_data.data;
let tda = TipDistributionAccount::try_deserialize(&mut data).ok()?;
if tda.merkle_root.is_some() {
Some(address.clone())
Some(*address)
} else {
None
}
Expand Down
13 changes: 5 additions & 8 deletions keepers/validator-keeper/src/operations/stake_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ use validator_history::{ValidatorHistory, ValidatorHistoryEntry};
use super::keeper_operations::KeeperOperations;

fn _get_operation() -> KeeperOperations {
return KeeperOperations::StakeUpload;
KeeperOperations::StakeUpload
}

fn _should_run(epoch_info: &EpochInfo, runs_for_epoch: u64) -> bool {
// Run at 0.1%, 50% and 90% completion of epoch
let should_run = (epoch_info.slot_index > epoch_info.slots_in_epoch / 1000
&& runs_for_epoch < 1)
(epoch_info.slot_index > epoch_info.slots_in_epoch / 1000 && runs_for_epoch < 1)
|| (epoch_info.slot_index > epoch_info.slots_in_epoch / 2 && runs_for_epoch < 2)
|| (epoch_info.slot_index > epoch_info.slots_in_epoch * 9 / 10 && runs_for_epoch < 3);

should_run
|| (epoch_info.slot_index > epoch_info.slots_in_epoch * 9 / 10 && runs_for_epoch < 3)
}

async fn _process(
Expand Down Expand Up @@ -136,7 +133,7 @@ pub async fn update_stake_history(
let rank = stake_rank_map[&vote_account.vote_pubkey.clone()];
let is_superminority = rank <= superminority_threshold;

if stake_entry_uploaded(&validator_history_map, vote_account, epoch_info.epoch) {
if stake_entry_uploaded(validator_history_map, vote_account, epoch_info.epoch) {
return None;
}

Expand Down Expand Up @@ -191,7 +188,7 @@ Calculates ordering of validators by stake, assigning a 0..N rank (validator 0 h
and returns the index at which all validators before are in the superminority. 0-indexed.
*/
fn get_stake_rank_map_and_superminority_count(
vote_accounts: &Vec<&RpcVoteAccountInfo>,
vote_accounts: &[&RpcVoteAccountInfo],
) -> (HashMap<String, u32>, u32) {
let mut stake_vec = vote_accounts
.iter()
Expand Down
Loading

0 comments on commit fc37ab1

Please sign in to comment.