Remove leader_schedule_offset public method
Also, * Rename the private variable to include units. * Better doc
This commit is contained in:
parent
32caa55d67
commit
f76ac94d70
|
@ -101,8 +101,9 @@ pub struct Bank {
|
||||||
/// The number of slots in each epoch.
|
/// The number of slots in each epoch.
|
||||||
slots_per_epoch: u64,
|
slots_per_epoch: u64,
|
||||||
|
|
||||||
// The number of slots until the next leader schedule activates.
|
// A number of slots before slot_index 0. Used to generate the current
|
||||||
leader_schedule_offset: u64,
|
// epoch's leader schedule.
|
||||||
|
leader_schedule_slot_offset: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Bank {
|
impl Default for Bank {
|
||||||
|
@ -115,7 +116,7 @@ impl Default for Bank {
|
||||||
hash: RwLock::<Hash>::default(),
|
hash: RwLock::<Hash>::default(),
|
||||||
ticks_per_slot: DEFAULT_TICKS_PER_SLOT,
|
ticks_per_slot: DEFAULT_TICKS_PER_SLOT,
|
||||||
slots_per_epoch: DEFAULT_SLOTS_PER_EPOCH,
|
slots_per_epoch: DEFAULT_SLOTS_PER_EPOCH,
|
||||||
leader_schedule_offset: DEFAULT_SLOTS_PER_EPOCH,
|
leader_schedule_slot_offset: DEFAULT_SLOTS_PER_EPOCH,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +135,7 @@ impl Bank {
|
||||||
bank.last_id_queue = RwLock::new(parent.last_id_queue.read().unwrap().clone());
|
bank.last_id_queue = RwLock::new(parent.last_id_queue.read().unwrap().clone());
|
||||||
bank.ticks_per_slot = parent.ticks_per_slot;
|
bank.ticks_per_slot = parent.ticks_per_slot;
|
||||||
bank.slots_per_epoch = parent.slots_per_epoch;
|
bank.slots_per_epoch = parent.slots_per_epoch;
|
||||||
bank.leader_schedule_offset = parent.leader_schedule_offset;
|
bank.leader_schedule_slot_offset = parent.leader_schedule_slot_offset;
|
||||||
|
|
||||||
bank.parent = Some(parent.clone());
|
bank.parent = Some(parent.clone());
|
||||||
if *parent.hash.read().unwrap() == Hash::default() {
|
if *parent.hash.read().unwrap() == Hash::default() {
|
||||||
|
@ -673,16 +674,11 @@ impl Bank {
|
||||||
self.slots_per_epoch
|
self.slots_per_epoch
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the number of slots until the next leader schedule activates.
|
|
||||||
pub fn leader_schedule_offset(&self) -> u64 {
|
|
||||||
self.leader_schedule_offset
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the checkpointed bank that should be used to generate a leader schedule.
|
/// Return the checkpointed bank that should be used to generate a leader schedule.
|
||||||
/// Return None if a sufficiently old bank checkpoint doesn't exist.
|
/// Return None if a sufficiently old bank checkpoint doesn't exist.
|
||||||
pub fn leader_schedule_bank(&self) -> Option<Arc<Bank>> {
|
pub fn leader_schedule_bank(&self) -> Option<Arc<Bank>> {
|
||||||
let epoch_slot_height = self.slot_height() - self.slot_index();
|
let epoch_slot_height = self.slot_height() - self.slot_index();
|
||||||
let expected = epoch_slot_height.saturating_sub(self.leader_schedule_offset);
|
let expected = epoch_slot_height.saturating_sub(self.leader_schedule_slot_offset);
|
||||||
self.parents()
|
self.parents()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|bank| bank.slot_height() <= expected)
|
.find(|bank| bank.slot_height() <= expected)
|
||||||
|
@ -1027,11 +1023,11 @@ mod tests {
|
||||||
assert!(bank.leader_schedule_bank().is_none());
|
assert!(bank.leader_schedule_bank().is_none());
|
||||||
|
|
||||||
let bank = Bank::new_from_parent(&Arc::new(bank));
|
let bank = Bank::new_from_parent(&Arc::new(bank));
|
||||||
let ticks_per_offset = bank.leader_schedule_offset() * bank.ticks_per_slot();
|
let ticks_per_offset = bank.leader_schedule_slot_offset * bank.ticks_per_slot();
|
||||||
register_ticks(&bank, ticks_per_offset);
|
register_ticks(&bank, ticks_per_offset);
|
||||||
assert_eq!(bank.slot_height(), bank.leader_schedule_offset());
|
assert_eq!(bank.slot_height(), bank.leader_schedule_slot_offset);
|
||||||
|
|
||||||
let slot_height = bank.slots_per_epoch() - bank.leader_schedule_offset();
|
let slot_height = bank.slots_per_epoch() - bank.leader_schedule_slot_offset;
|
||||||
let bank = Bank::new_from_parent(&Arc::new(bank));
|
let bank = Bank::new_from_parent(&Arc::new(bank));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.leader_schedule_bank().unwrap().slot_height(),
|
bank.leader_schedule_bank().unwrap().slot_height(),
|
||||||
|
|
Loading…
Reference in New Issue