serde-snapshot uses methods to access AccountsDb::bank_hashes (#29989)
This commit is contained in:
parent
8f8c0a4818
commit
005dc96bc5
|
@ -7568,6 +7568,28 @@ impl AccountsDb {
|
||||||
self.bank_hashes.read().unwrap().get(&slot).cloned()
|
self.bank_hashes.read().unwrap().get(&slot).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// When reconstructing AccountsDb from a snapshot, insert the `bank_hash_info` into the
|
||||||
|
/// internal bank hashses map.
|
||||||
|
///
|
||||||
|
/// This fn is only called when loading from a snapshot, which means AccountsDb is new and its
|
||||||
|
/// bank hashes is unpopulated. Therefore, a bank hash must not already exist at `slot` [^1].
|
||||||
|
///
|
||||||
|
/// [^1] Slot 0 is a special case, however. When a new AccountsDb is created--like when
|
||||||
|
/// loading from a snapshot--the bank hashes map is populated with a default entry at slot 0.
|
||||||
|
/// It is valid to have a snapshot at slot 0, so it must be handled accordingly.
|
||||||
|
pub fn set_bank_hash_info_from_snapshot(&self, slot: Slot, bank_hash_info: BankHashInfo) {
|
||||||
|
let old_bank_hash_info = self
|
||||||
|
.bank_hashes
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.insert(slot, bank_hash_info);
|
||||||
|
assert!(
|
||||||
|
old_bank_hash_info.is_none()
|
||||||
|
|| (slot == 0 && old_bank_hash_info == Some(BankHashInfo::default())),
|
||||||
|
"There should not already be a BankHashInfo at slot {slot}: {old_bank_hash_info:?}",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn update_index<'a, T: ReadableAccount + Sync>(
|
fn update_index<'a, T: ReadableAccount + Sync>(
|
||||||
&self,
|
&self,
|
||||||
infos: Vec<AccountInfo>,
|
infos: Vec<AccountInfo>,
|
||||||
|
|
|
@ -718,11 +718,7 @@ where
|
||||||
);
|
);
|
||||||
|
|
||||||
// Process deserialized data, set necessary fields in self
|
// Process deserialized data, set necessary fields in self
|
||||||
accounts_db
|
accounts_db.set_bank_hash_info_from_snapshot(snapshot_slot, snapshot_bank_hash_info);
|
||||||
.bank_hashes
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.insert(snapshot_slot, snapshot_bank_hash_info);
|
|
||||||
accounts_db.storage.initialize(storage);
|
accounts_db.storage.initialize(storage);
|
||||||
accounts_db
|
accounts_db
|
||||||
.next_id
|
.next_id
|
||||||
|
|
|
@ -270,14 +270,10 @@ impl<'a> TypeContext<'a> for Context {
|
||||||
)
|
)
|
||||||
}));
|
}));
|
||||||
let slot = serializable_db.slot;
|
let slot = serializable_db.slot;
|
||||||
let bank_hash_info: BankHashInfo = serializable_db
|
let bank_hash_info = serializable_db
|
||||||
.accounts_db
|
.accounts_db
|
||||||
.bank_hashes
|
.get_bank_hash_info(serializable_db.slot)
|
||||||
.read()
|
.unwrap_or_else(|| panic!("No bank_hashes entry for slot {}", serializable_db.slot));
|
||||||
.unwrap()
|
|
||||||
.get(&serializable_db.slot)
|
|
||||||
.unwrap_or_else(|| panic!("No bank_hashes entry for slot {}", serializable_db.slot))
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
let historical_roots = serializable_db
|
let historical_roots = serializable_db
|
||||||
.accounts_db
|
.accounts_db
|
||||||
|
|
Loading…
Reference in New Issue