From 480b95bb553cdd657a9bc6f6a39ac21c46757e5c Mon Sep 17 00:00:00 2001 From: Coach Chuck Date: Tue, 28 May 2024 09:33:32 -0600 Subject: [PATCH] fixed not firing and doing all vote accounts --- .../src/operations/cluster_history.rs | 4 +-- .../src/operations/stake_upload.rs | 4 +-- .../src/operations/vote_account.rs | 26 +++++++-------- .../src/state/keeper_state.rs | 33 +++++++++++++++---- 4 files changed, 43 insertions(+), 24 deletions(-) diff --git a/keepers/validator-keeper/src/operations/cluster_history.rs b/keepers/validator-keeper/src/operations/cluster_history.rs index 74d4f9bd..5a996ade 100644 --- a/keepers/validator-keeper/src/operations/cluster_history.rs +++ b/keepers/validator-keeper/src/operations/cluster_history.rs @@ -27,8 +27,8 @@ fn _get_operation() -> KeeperOperations { fn _should_run(epoch_info: &EpochInfo, runs_for_epoch: u64) -> bool { // Run at 0.1%, 50% and 90% completion of epoch - (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 * 1 / 1000 && runs_for_epoch < 1) + || (epoch_info.slot_index > epoch_info.slots_in_epoch * 5 / 10 && runs_for_epoch < 2) || (epoch_info.slot_index > epoch_info.slots_in_epoch * 9 / 10 && runs_for_epoch < 3) } diff --git a/keepers/validator-keeper/src/operations/stake_upload.rs b/keepers/validator-keeper/src/operations/stake_upload.rs index 8155eb5e..58cc6df0 100644 --- a/keepers/validator-keeper/src/operations/stake_upload.rs +++ b/keepers/validator-keeper/src/operations/stake_upload.rs @@ -27,8 +27,8 @@ fn _get_operation() -> KeeperOperations { fn _should_run(epoch_info: &EpochInfo, runs_for_epoch: u64) -> bool { // Run at 0.1%, 50% and 90% completion of epoch - (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 * 1 / 1000 && runs_for_epoch < 1) + || (epoch_info.slot_index > epoch_info.slots_in_epoch * 5 / 10 && runs_for_epoch < 2) || (epoch_info.slot_index > epoch_info.slots_in_epoch * 9 / 10 && runs_for_epoch < 3) } diff --git a/keepers/validator-keeper/src/operations/vote_account.rs b/keepers/validator-keeper/src/operations/vote_account.rs index fa09fc97..f33d9e86 100644 --- a/keepers/validator-keeper/src/operations/vote_account.rs +++ b/keepers/validator-keeper/src/operations/vote_account.rs @@ -27,8 +27,8 @@ fn _get_operation() -> KeeperOperations { fn _should_run(epoch_info: &EpochInfo, runs_for_epoch: u64) -> bool { // Run at 10%, 50% and 90% completion of epoch - (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 * 1 / 10 && runs_for_epoch < 1) + || (epoch_info.slot_index > epoch_info.slots_in_epoch * 5 / 10 && runs_for_epoch < 2) || (epoch_info.slot_index > epoch_info.slots_in_epoch * 9 / 10 && runs_for_epoch < 3) } @@ -84,21 +84,19 @@ pub async fn update_vote_accounts( keeper_state: &KeeperState, ) -> Result { let validator_history_map = &keeper_state.validator_history_map; - let closed_vote_accounts = &keeper_state.get_closed_vote_accounts(); let epoch_info = &keeper_state.epoch_info; - // Remove closed vote accounts from all vote accounts - // Remove vote accounts for which this instruction has been called within 50,000 slots - let mut vote_accounts_to_update = keeper_state.vote_account_map.keys().collect::>(); - + // Update all vote accounts, less they are closed + let mut vote_accounts_to_update = keeper_state.get_all_open_vote_accounts(); vote_accounts_to_update.retain(|vote_account| { - !closed_vote_accounts.contains(vote_account) - && !vote_account_uploaded_recently( - validator_history_map, - vote_account, - epoch_info.epoch, - epoch_info.absolute_slot, - ) + let should_update = !vote_account_uploaded_recently( + validator_history_map, + vote_account, + epoch_info.epoch, + epoch_info.absolute_slot, + ); + + should_update }); let entries = vote_accounts_to_update diff --git a/keepers/validator-keeper/src/state/keeper_state.rs b/keepers/validator-keeper/src/state/keeper_state.rs index 45bcc7e5..0a3a3dcc 100644 --- a/keepers/validator-keeper/src/state/keeper_state.rs +++ b/keepers/validator-keeper/src/state/keeper_state.rs @@ -74,14 +74,35 @@ impl KeeperState { pub fn get_closed_vote_accounts(&self) -> HashSet<&Pubkey> { self.all_history_vote_account_map .iter() - .filter(|(_, vote_account)| { - if let Some(account) = vote_account { - account.owner != get_vote_program_id() - } else { - true + .filter_map(|(vote_address, vote_account)| match vote_account { + Some(account) => { + if account.owner != get_vote_program_id() { + Some(vote_address) + } else { + None + } + } + _ => { + // If the account is not found, it is considered closed + Some(vote_address) } }) - .map(|(pubkey, _)| pubkey) + .collect() + } + + pub fn get_all_open_vote_accounts(&self) -> HashSet<&Pubkey> { + self.all_history_vote_account_map + .iter() + .filter_map(|(vote_address, vote_account)| match vote_account { + Some(account) => { + if account.owner == get_vote_program_id() { + Some(vote_address) + } else { + None + } + } + _ => None, + }) .collect() }