Remove get_confirmation_timestamp() from HashQueue
This commit is contained in:
		| @@ -319,11 +319,31 @@ impl Bank { | ||||
|     /// tick that has achieved confirmation | ||||
|     pub fn get_confirmation_timestamp( | ||||
|         &self, | ||||
|         ticks_and_stakes: &mut [(u64, u64)], | ||||
|         mut slots_and_stakes: Vec<(u64, u64)>, | ||||
|         supermajority_stake: u64, | ||||
|     ) -> Option<u64> { | ||||
|         let hash_queue = self.tick_hash_queue.read().unwrap(); | ||||
|         hash_queue.get_confirmation_timestamp(ticks_and_stakes, supermajority_stake) | ||||
|         // Sort by slot height | ||||
|         slots_and_stakes.sort_by(|a, b| a.0.cmp(&b.0)); | ||||
|  | ||||
|         let max_slot = self.slot_height(); | ||||
|         let min_slot = | ||||
|             max_slot.saturating_sub(MAX_RECENT_TICK_HASHES as u64 / self.ticks_per_slot()); | ||||
|  | ||||
|         let mut total_stake = 0; | ||||
|         for (slot, stake) in slots_and_stakes.iter() { | ||||
|             if *slot >= min_slot && *slot <= max_slot { | ||||
|                 total_stake += stake; | ||||
|                 if total_stake > supermajority_stake { | ||||
|                     return self | ||||
|                         .tick_hash_queue | ||||
|                         .read() | ||||
|                         .unwrap() | ||||
|                         .hash_height_to_timestamp(slot * self.ticks_per_slot()); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         None | ||||
|     } | ||||
|  | ||||
|     /// Tell the bank which Entry IDs exist on the ledger. This function | ||||
|   | ||||
| @@ -88,32 +88,8 @@ impl HashQueue { | ||||
|         self.last_hash = Some(*hash); | ||||
|     } | ||||
|  | ||||
|     /// Looks through a list of hash heights and stakes, and finds the latest | ||||
|     /// hash that has achieved confirmation | ||||
|     pub fn get_confirmation_timestamp( | ||||
|         &self, | ||||
|         hashes_and_stakes: &mut [(u64, u64)], | ||||
|         supermajority_stake: u64, | ||||
|     ) -> Option<u64> { | ||||
|         // Sort by hash height | ||||
|         hashes_and_stakes.sort_by(|a, b| a.0.cmp(&b.0)); | ||||
|         let current_hash_height = self.hash_height; | ||||
|         let mut total = 0; | ||||
|         for (hash_height, stake) in hashes_and_stakes.iter() { | ||||
|             if current_hash_height >= *hash_height | ||||
|                 && ((current_hash_height - hash_height) as usize) < MAX_RECENT_TICK_HASHES | ||||
|             { | ||||
|                 total += stake; | ||||
|                 if total > supermajority_stake { | ||||
|                     return self.hash_height_to_timestamp(*hash_height); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         None | ||||
|     } | ||||
|  | ||||
|     /// Maps a hash height to a timestamp | ||||
|     fn hash_height_to_timestamp(&self, hash_height: u64) -> Option<u64> { | ||||
|     pub fn hash_height_to_timestamp(&self, hash_height: u64) -> Option<u64> { | ||||
|         for entry in self.entries.values() { | ||||
|             if entry.hash_height == hash_height { | ||||
|                 return Some(entry.timestamp); | ||||
|   | ||||
| @@ -37,30 +37,22 @@ impl LeaderConfirmationService { | ||||
|         // the vote states | ||||
|         let vote_states = bank.vote_states(|_, vote_state| leader_id != vote_state.delegate_id); | ||||
|  | ||||
|         let mut ticks_and_stakes: Vec<(u64, u64)> = vote_states | ||||
|         let slots_and_stakes: Vec<(u64, u64)> = vote_states | ||||
|             .iter() | ||||
|             .filter_map(|(_, vote_state)| { | ||||
|                 let validator_stake = bank.get_balance(&vote_state.delegate_id); | ||||
|                 total_stake += validator_stake; | ||||
|                 // Filter out any validators that don't have at least one vote | ||||
|                 // by returning None | ||||
|                 vote_state | ||||
|                     .votes | ||||
|                     .back() | ||||
|                     // A vote for a slot is like a vote for the last tick in that slot | ||||
|                     .map(|vote| { | ||||
|                         ( | ||||
|                             (vote.slot_height + 1) * bank.ticks_per_slot() - 1, | ||||
|                             validator_stake, | ||||
|                         ) | ||||
|                     }) | ||||
|                     .map(|vote| (vote.slot_height, validator_stake)) | ||||
|             }) | ||||
|             .collect(); | ||||
|  | ||||
|         let super_majority_stake = (2 * total_stake) / 3; | ||||
|  | ||||
|         if let Some(last_valid_validator_timestamp) = | ||||
|             bank.get_confirmation_timestamp(&mut ticks_and_stakes, super_majority_stake) | ||||
|             bank.get_confirmation_timestamp(slots_and_stakes, super_majority_stake) | ||||
|         { | ||||
|             return Ok(last_valid_validator_timestamp); | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user