Derive the working bank (#10670)
This commit is contained in:
@ -50,7 +50,6 @@ type Result<T> = std::result::Result<T, BankForksError>;
|
|||||||
|
|
||||||
pub struct BankForks {
|
pub struct BankForks {
|
||||||
pub banks: HashMap<Slot, Arc<Bank>>,
|
pub banks: HashMap<Slot, Arc<Bank>>,
|
||||||
working_bank: Arc<Bank>,
|
|
||||||
root: Slot,
|
root: Slot,
|
||||||
pub snapshot_config: Option<SnapshotConfig>,
|
pub snapshot_config: Option<SnapshotConfig>,
|
||||||
last_snapshot_slot: Slot,
|
last_snapshot_slot: Slot,
|
||||||
@ -61,7 +60,7 @@ 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_slot: Slot) -> &Arc<Bank> {
|
fn index(&self, bank_slot: Slot) -> &Self::Output {
|
||||||
&self.banks[&bank_slot]
|
&self.banks[&bank_slot]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,19 +127,12 @@ impl BankForks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn root_bank(&self) -> &Arc<Bank> {
|
pub fn root_bank(&self) -> &Arc<Bank> {
|
||||||
self.banks.get(&self.root()).expect("Root bank must exist")
|
&self[self.root()]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_banks(initial_forks: &[Arc<Bank>], root: Slot) -> Self {
|
pub fn new_from_banks(initial_forks: &[Arc<Bank>], root: Slot) -> Self {
|
||||||
let mut banks = HashMap::new();
|
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
|
// Iterate through the heads of all the different forks
|
||||||
for bank in initial_forks {
|
for bank in initial_forks {
|
||||||
banks.insert(bank.slot(), bank.clone());
|
banks.insert(bank.slot(), bank.clone());
|
||||||
@ -157,7 +149,6 @@ impl BankForks {
|
|||||||
Self {
|
Self {
|
||||||
root,
|
root,
|
||||||
banks,
|
banks,
|
||||||
working_bank,
|
|
||||||
snapshot_config: None,
|
snapshot_config: None,
|
||||||
last_snapshot_slot: root,
|
last_snapshot_slot: root,
|
||||||
accounts_hash_interval_slots: std::u64::MAX,
|
accounts_hash_interval_slots: std::u64::MAX,
|
||||||
@ -169,8 +160,6 @@ impl BankForks {
|
|||||||
let bank = Arc::new(bank);
|
let bank = Arc::new(bank);
|
||||||
let prev = self.banks.insert(bank.slot(), bank.clone());
|
let prev = self.banks.insert(bank.slot(), bank.clone());
|
||||||
assert!(prev.is_none());
|
assert!(prev.is_none());
|
||||||
|
|
||||||
self.working_bank = bank.clone();
|
|
||||||
bank
|
bank
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,8 +167,12 @@ impl BankForks {
|
|||||||
self.banks.remove(&slot)
|
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<Bank> {
|
pub fn working_bank(&self) -> Arc<Bank> {
|
||||||
self.working_bank.clone()
|
self[self.highest_slot()].clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_root(
|
pub fn set_root(
|
||||||
|
Reference in New Issue
Block a user