diff --git a/runtime/src/bank_forks.rs b/runtime/src/bank_forks.rs index 2e42ea82c..65ecbb85b 100644 --- a/runtime/src/bank_forks.rs +++ b/runtime/src/bank_forks.rs @@ -50,7 +50,6 @@ type Result = std::result::Result; pub struct BankForks { pub banks: HashMap>, - working_bank: Arc, root: Slot, pub snapshot_config: Option, last_snapshot_slot: Slot, @@ -61,7 +60,7 @@ pub struct BankForks { impl Index for BankForks { type Output = Arc; - fn index(&self, bank_slot: Slot) -> &Arc { + fn index(&self, bank_slot: Slot) -> &Self::Output { &self.banks[&bank_slot] } } @@ -128,19 +127,12 @@ impl BankForks { } pub fn root_bank(&self) -> &Arc { - self.banks.get(&self.root()).expect("Root bank must exist") + &self[self.root()] } pub fn new_from_banks(initial_forks: &[Arc], root: Slot) -> Self { let mut banks = HashMap::new(); - // Set working bank to the highest available bank - let working_bank = initial_forks - .iter() - .max_by(|a, b| a.slot().cmp(&b.slot())) - .expect("working bank") - .clone(); - // Iterate through the heads of all the different forks for bank in initial_forks { banks.insert(bank.slot(), bank.clone()); @@ -157,7 +149,6 @@ impl BankForks { Self { root, banks, - working_bank, snapshot_config: None, last_snapshot_slot: root, accounts_hash_interval_slots: std::u64::MAX, @@ -169,8 +160,6 @@ impl BankForks { let bank = Arc::new(bank); let prev = self.banks.insert(bank.slot(), bank.clone()); assert!(prev.is_none()); - - self.working_bank = bank.clone(); bank } @@ -178,8 +167,12 @@ impl BankForks { self.banks.remove(&slot) } + pub fn highest_slot(&self) -> Slot { + self.banks.values().map(|bank| bank.slot()).max().unwrap() + } + pub fn working_bank(&self) -> Arc { - self.working_bank.clone() + self[self.highest_slot()].clone() } pub fn set_root(