remove max_tick_height replicode (#3765)

This commit is contained in:
Rob Walker 2019-04-14 19:15:31 -07:00 committed by GitHub
parent bd1db51e07
commit de52747950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -45,7 +45,7 @@ impl Broadcast {
) -> Result<()> {
let timer = Duration::new(1, 0);
let (mut bank, entries) = receiver.recv_timeout(timer)?;
let mut max_tick_height = (bank.slot() + 1) * bank.ticks_per_slot() - 1;
let mut max_tick_height = bank.max_tick_height();
let now = Instant::now();
let mut num_entries = entries.len();
@ -62,7 +62,7 @@ impl Broadcast {
num_entries = 0;
ventries.clear();
bank = same_bank.clone();
max_tick_height = (bank.slot() + 1) * bank.ticks_per_slot() - 1;
max_tick_height = bank.max_tick_height();
}
num_entries += entries.len();
last_tick = entries.last().map(|v| v.1).unwrap_or(0);

View File

@ -136,6 +136,9 @@ pub struct Bank {
/// Bank tick height
tick_height: AtomicUsize, // TODO: Use AtomicU64 if/when available
// Bank max_tick_height
max_tick_height: u64,
/// The number of ticks in each slot.
ticks_per_slot: u64,
@ -209,6 +212,8 @@ impl Bank {
bank.epoch_schedule = parent.epoch_schedule;
bank.slot = slot;
bank.max_tick_height = (bank.slot + 1) * bank.ticks_per_slot - 1;
bank.parent = RwLock::new(Some(parent.clone()));
bank.parent_hash = parent.hash();
bank.collector_id = *collector_id;
@ -345,6 +350,7 @@ impl Bank {
.genesis_hash(&genesis_block.hash());
self.ticks_per_slot = genesis_block.ticks_per_slot;
self.max_tick_height = (self.slot + 1) * self.ticks_per_slot - 1;
// make bank 0 votable
self.is_delta.store(true, Ordering::Relaxed);
@ -928,6 +934,11 @@ impl Bank {
self.tick_height.load(Ordering::SeqCst) as u64
}
/// Return this bank's max_tick_height
pub fn max_tick_height(&self) -> u64 {
self.max_tick_height
}
/// Return the number of slots per epoch for the given epoch
pub fn get_slots_in_epoch(&self, epoch: u64) -> u64 {
self.epoch_schedule.get_slots_in_epoch(epoch)