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);
|
||||
|
Reference in New Issue
Block a user