From 44d1e6200702414694a2321dc621372ce5acf5f7 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Sat, 25 Jun 2022 17:27:43 +0100 Subject: [PATCH] Refactor: No need to return stake in Bank::get_vote_account (#26220) --- core/src/commitment_service.rs | 2 +- core/src/consensus.rs | 6 +++--- core/src/replay_stage.rs | 6 +++--- core/src/vote_simulator.rs | 2 +- runtime/src/bank.rs | 7 ++++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/core/src/commitment_service.rs b/core/src/commitment_service.rs index 2574f9e1b..1fd5d6586 100644 --- a/core/src/commitment_service.rs +++ b/core/src/commitment_service.rs @@ -489,7 +489,7 @@ mod tests { #[test] fn test_highest_confirmed_root_advance() { fn get_vote_account_root_slot(vote_pubkey: Pubkey, bank: &Arc) -> Slot { - let (_stake, vote_account) = bank.get_vote_account(&vote_pubkey).unwrap(); + let vote_account = bank.get_vote_account(&vote_pubkey).unwrap(); let slot = vote_account .vote_state() .as_ref() diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 300d61d81..16b7c3d20 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -438,7 +438,7 @@ impl Tower { } pub fn last_voted_slot_in_bank(bank: &Bank, vote_account_pubkey: &Pubkey) -> Option { - let (_stake, vote_account) = bank.get_vote_account(vote_account_pubkey)?; + let vote_account = bank.get_vote_account(vote_account_pubkey)?; let vote_state = vote_account.vote_state(); vote_state.as_ref().ok()?.last_voted_slot() } @@ -1239,7 +1239,7 @@ impl Tower { root: Slot, bank: &Bank, ) { - if let Some((_stake, vote_account)) = bank.get_vote_account(vote_account_pubkey) { + if let Some(vote_account) = bank.get_vote_account(vote_account_pubkey) { self.vote_state = vote_account .vote_state() .as_ref() @@ -2034,7 +2034,7 @@ pub mod test { .unwrap() .get_vote_account(&vote_pubkey) .unwrap(); - let state = observed.1.vote_state(); + let state = observed.vote_state(); info!("observed tower: {:#?}", state.as_ref().unwrap().votes); let num_slots_to_try = 200; diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 5d69896cb..1e2b4be3e 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -1916,7 +1916,7 @@ impl ReplayStage { ); return None; } - Some((_stake, vote_account)) => vote_account, + Some(vote_account) => vote_account, }; let vote_state = vote_account.vote_state(); let vote_state = match vote_state.as_ref() { @@ -2411,7 +2411,7 @@ impl ReplayStage { if !is_computed { // Check if our tower is behind, if so (and the feature migration flag is in use) // overwrite with the newer bank. - if let (true, Some((_, vote_account))) = ( + if let (true, Some(vote_account)) = ( Tower::is_direct_vote_state_update_enabled(bank), bank.get_vote_account(my_vote_pubkey), ) { @@ -6107,7 +6107,7 @@ pub(crate) mod tests { expired_bank.slot() + 1, )); expired_bank_child.process_transaction(vote_tx).unwrap(); - let (_stake, vote_account) = expired_bank_child + let vote_account = expired_bank_child .get_vote_account(&my_vote_pubkey) .unwrap(); assert_eq!( diff --git a/core/src/vote_simulator.rs b/core/src/vote_simulator.rs index a9c82a0f5..6fb3c9bf7 100644 --- a/core/src/vote_simulator.rs +++ b/core/src/vote_simulator.rs @@ -105,7 +105,7 @@ impl VoteSimulator { let vote_account = new_bank .get_vote_account(&keypairs.vote_keypair.pubkey()) .unwrap(); - let state = vote_account.1.vote_state(); + let state = vote_account.vote_state(); assert!(state .as_ref() .unwrap() diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 79178510f..7ef6d6871 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -7067,10 +7067,11 @@ impl Bank { Arc::from(stakes.vote_accounts()) } - /// Vote account for the given vote account pubkey along with the stake. - pub fn get_vote_account(&self, vote_account: &Pubkey) -> Option<(/*stake:*/ u64, VoteAccount)> { + /// Vote account for the given vote account pubkey. + pub fn get_vote_account(&self, vote_account: &Pubkey) -> Option { let stakes = self.stakes_cache.stakes(); - stakes.vote_accounts().get(vote_account).cloned() + let (_stake, ref vote_account) = stakes.vote_accounts().get(vote_account)?; + Some(vote_account.clone()) } /// Get the EpochStakes for a given epoch