rename bank_id to bank_slot

This commit is contained in:
Rob Walker
2019-03-04 16:40:28 -08:00
committed by Grimes
parent 4f6d7702c5
commit 6d82123125
7 changed files with 34 additions and 34 deletions

View File

@ -12,16 +12,16 @@ pub struct BankForks {
impl Index<u64> for BankForks { impl Index<u64> for BankForks {
type Output = Arc<Bank>; type Output = Arc<Bank>;
fn index(&self, bank_id: u64) -> &Arc<Bank> { fn index(&self, bank_slot: u64) -> &Arc<Bank> {
&self.banks[&bank_id] &self.banks[&bank_slot]
} }
} }
impl BankForks { impl BankForks {
pub fn new(bank_id: u64, bank: Bank) -> Self { pub fn new(bank_slot: u64, bank: Bank) -> Self {
let mut banks = HashMap::new(); let mut banks = HashMap::new();
let working_bank = Arc::new(bank); let working_bank = Arc::new(bank);
banks.insert(bank_id, working_bank.clone()); banks.insert(bank_slot, working_bank.clone());
Self { Self {
banks, banks,
working_bank, working_bank,
@ -45,8 +45,8 @@ impl BankForks {
.map(|(k, _v)| *k) .map(|(k, _v)| *k)
.collect() .collect()
} }
pub fn get(&self, bank_id: u64) -> Option<&Arc<Bank>> { pub fn get(&self, bank_slot: u64) -> Option<&Arc<Bank>> {
self.banks.get(&bank_id) self.banks.get(&bank_slot)
} }
pub fn new_from_banks(initial_banks: &[Arc<Bank>]) -> Self { pub fn new_from_banks(initial_banks: &[Arc<Bank>]) -> Self {
@ -62,13 +62,13 @@ impl BankForks {
} }
// TODO: use the bank's own ID instead of receiving a parameter? // TODO: use the bank's own ID instead of receiving a parameter?
pub fn insert(&mut self, bank_id: u64, bank: Bank) { pub fn insert(&mut self, bank_slot: u64, bank: Bank) {
let mut bank = Arc::new(bank); let mut bank = Arc::new(bank);
assert_eq!(bank_id, bank.slot()); assert_eq!(bank_slot, bank.slot());
let prev = self.banks.insert(bank_id, bank.clone()); let prev = self.banks.insert(bank_slot, bank.clone());
assert!(prev.is_none()); assert!(prev.is_none());
if bank_id > self.working_bank.slot() { if bank_slot > self.working_bank.slot() {
self.working_bank = bank.clone() self.working_bank = bank.clone()
} }

View File

@ -98,7 +98,7 @@ fn process_block(bank: &Bank, entries: &[Entry]) -> Result<()> {
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct BankForksInfo { pub struct BankForksInfo {
pub bank_id: u64, pub bank_slot: u64,
pub entry_height: u64, pub entry_height: u64,
} }
@ -190,7 +190,7 @@ pub fn process_blocktree(
})?; })?;
let bfi = BankForksInfo { let bfi = BankForksInfo {
bank_id: slot, bank_slot: slot,
entry_height: starting_entry_height, entry_height: starting_entry_height,
}; };
fork_info.push((starting_bank, bfi)); fork_info.push((starting_bank, bfi));
@ -204,7 +204,7 @@ pub fn process_blocktree(
// Reached the end of this fork. Record the final entry height and last entry.hash // Reached the end of this fork. Record the final entry height and last entry.hash
let bfi = BankForksInfo { let bfi = BankForksInfo {
bank_id: slot, bank_slot: slot,
entry_height, entry_height,
}; };
fork_info.push((bank, bfi)); fork_info.push((bank, bfi));
@ -316,7 +316,7 @@ mod tests {
assert_eq!( assert_eq!(
bank_forks_info[0], bank_forks_info[0],
BankForksInfo { BankForksInfo {
bank_id: 1, // never finished first slot bank_slot: 1, // never finished first slot
entry_height: ticks_per_slot, entry_height: ticks_per_slot,
} }
); );
@ -373,21 +373,21 @@ mod tests {
assert_eq!( assert_eq!(
bank_forks_info[0], bank_forks_info[0],
BankForksInfo { BankForksInfo {
bank_id: 3, // Fork 1's head is slot 3 bank_slot: 3, // Fork 1's head is slot 3
entry_height: ticks_per_slot * 4, entry_height: ticks_per_slot * 4,
} }
); );
assert_eq!( assert_eq!(
bank_forks_info[1], bank_forks_info[1],
BankForksInfo { BankForksInfo {
bank_id: 4, // Fork 2's head is slot 4 bank_slot: 4, // Fork 2's head is slot 4
entry_height: ticks_per_slot * 3, entry_height: ticks_per_slot * 3,
} }
); );
// Ensure bank_forks holds the right banks // Ensure bank_forks holds the right banks
for info in bank_forks_info { for info in bank_forks_info {
assert_eq!(bank_forks[info.bank_id].slot(), info.bank_id); assert_eq!(bank_forks[info.bank_slot].slot(), info.bank_slot);
} }
} }
@ -493,7 +493,7 @@ mod tests {
assert_eq!( assert_eq!(
bank_forks_info[0], bank_forks_info[0],
BankForksInfo { BankForksInfo {
bank_id: 1, bank_slot: 1,
entry_height, entry_height,
} }
); );
@ -518,7 +518,7 @@ mod tests {
assert_eq!( assert_eq!(
bank_forks_info[0], bank_forks_info[0],
BankForksInfo { BankForksInfo {
bank_id: 0, bank_slot: 0,
entry_height: 1, entry_height: 1,
} }
); );

View File

@ -120,7 +120,7 @@ impl Fullnode {
let exit = Arc::new(AtomicBool::new(false)); let exit = Arc::new(AtomicBool::new(false));
let bank_info = &bank_forks_info[0]; let bank_info = &bank_forks_info[0];
let bank = bank_forks[bank_info.bank_id].clone(); let bank = bank_forks[bank_info.bank_slot].clone();
info!( info!(
"starting PoH... {} {}", "starting PoH... {} {}",

View File

@ -126,7 +126,7 @@ impl PohRecorder {
.count(); .count();
let e = if cnt > 0 { let e = if cnt > 0 {
debug!( debug!(
"flush_cache: bank_id: {} tick_height: {} max: {} sending: {}", "flush_cache: bank_slot: {} tick_height: {} max: {} sending: {}",
working_bank.bank.slot(), working_bank.bank.slot(),
working_bank.bank.tick_height(), working_bank.bank.tick_height(),
working_bank.max_tick_height, working_bank.max_tick_height,

View File

@ -95,8 +95,8 @@ impl ReplayStage {
let active_banks = bank_forks.read().unwrap().active_banks(); let active_banks = bank_forks.read().unwrap().active_banks();
trace!("active banks {:?}", active_banks); trace!("active banks {:?}", active_banks);
let mut votable: Vec<u64> = vec![]; let mut votable: Vec<u64> = vec![];
for bank_id in &active_banks { for bank_slot in &active_banks {
let bank = bank_forks.read().unwrap().get(*bank_id).unwrap().clone(); let bank = bank_forks.read().unwrap().get(*bank_slot).unwrap().clone();
if !Self::is_tpu(&bank, my_id) { if !Self::is_tpu(&bank, my_id) {
Self::replay_blocktree_into_bank( Self::replay_blocktree_into_bank(
&bank, &bank,
@ -105,12 +105,12 @@ impl ReplayStage {
&forward_entry_sender, &forward_entry_sender,
)?; )?;
} }
let max_tick_height = (*bank_id + 1) * bank.ticks_per_slot() - 1; let max_tick_height = (*bank_slot + 1) * bank.ticks_per_slot() - 1;
if bank.tick_height() == max_tick_height { if bank.tick_height() == max_tick_height {
bank.freeze(); bank.freeze();
info!("bank frozen {}", bank.slot()); info!("bank frozen {}", bank.slot());
votable.push(*bank_id); votable.push(*bank_slot);
progress.remove(bank_id); progress.remove(bank_slot);
let id = leader_schedule_utils::slot_leader_at(bank.slot(), &bank); let id = leader_schedule_utils::slot_leader_at(bank.slot(), &bank);
if let Err(e) = slot_full_sender.send((bank.slot(), id)) { if let Err(e) = slot_full_sender.send((bank.slot(), id)) {
info!("{} slot_full alert failed: {:?}", my_id, e); info!("{} slot_full alert failed: {:?}", my_id, e);
@ -228,11 +228,11 @@ impl ReplayStage {
blocktree: &Blocktree, blocktree: &Blocktree,
progress: &mut HashMap<u64, (Hash, usize)>, progress: &mut HashMap<u64, (Hash, usize)>,
) -> result::Result<(Vec<Entry>, usize)> { ) -> result::Result<(Vec<Entry>, usize)> {
let bank_id = bank.slot(); let bank_slot = bank.slot();
let bank_progress = &mut progress let bank_progress = &mut progress
.entry(bank_id) .entry(bank_slot)
.or_insert((bank.last_blockhash(), 0)); .or_insert((bank.last_blockhash(), 0));
blocktree.get_slot_entries_with_blob_count(bank_id, bank_progress.1 as u64, None) blocktree.get_slot_entries_with_blob_count(bank_slot, bank_progress.1 as u64, None)
} }
pub fn replay_entries_into_bank( pub fn replay_entries_into_bank(
@ -292,10 +292,10 @@ impl ReplayStage {
fn generate_new_bank_forks(blocktree: &Blocktree, forks: &mut BankForks) { fn generate_new_bank_forks(blocktree: &Blocktree, forks: &mut BankForks) {
// Find the next slot that chains to the old slot // Find the next slot that chains to the old slot
let frozen_banks = forks.frozen_banks(); let frozen_banks = forks.frozen_banks();
let frozen_bank_ids: Vec<u64> = frozen_banks.keys().cloned().collect(); let frozen_bank_slots: Vec<u64> = frozen_banks.keys().cloned().collect();
trace!("frozen_banks {:?}", frozen_bank_ids); trace!("frozen_banks {:?}", frozen_bank_slots);
let next_slots = blocktree let next_slots = blocktree
.get_slots_since(&frozen_bank_ids) .get_slots_since(&frozen_bank_slots)
.expect("Db error"); .expect("Db error");
trace!("generate new forks {:?}", next_slots); trace!("generate new forks {:?}", next_slots);
for (parent_id, children) in next_slots { for (parent_id, children) in next_slots {

View File

@ -206,7 +206,7 @@ pub mod tests {
let bank_forks = BankForks::new(0, Bank::new(&genesis_block)); let bank_forks = BankForks::new(0, Bank::new(&genesis_block));
let bank_forks_info = vec![BankForksInfo { let bank_forks_info = vec![BankForksInfo {
bank_id: 0, bank_slot: 0,
entry_height: 0, entry_height: 0,
}]; }];

View File

@ -90,7 +90,7 @@ fn test_replay() {
let blockhash = bank.last_blockhash(); let blockhash = bank.last_blockhash();
let bank_forks = BankForks::new(0, bank); let bank_forks = BankForks::new(0, bank);
let bank_forks_info = vec![BankForksInfo { let bank_forks_info = vec![BankForksInfo {
bank_id: 0, bank_slot: 0,
entry_height: 0, entry_height: 0,
}]; }];