feat(storage): non-optional committed chain in CanonStateNotification (#7566)

This commit is contained in:
Alexey Shekhirin
2024-04-11 14:27:01 +01:00
committed by GitHub
parent 80f8707a1b
commit 681b1a598f
5 changed files with 35 additions and 44 deletions

View File

@ -194,23 +194,22 @@ where
}
fn on_new_state(&mut self, new_state: CanonStateNotification) {
if let Some(committed) = new_state.committed() {
let mut cached = CachedReads::default();
let mut cached = CachedReads::default();
// extract the state from the notification and put it into the cache
let new_state = committed.state();
for (addr, acc) in new_state.bundle_accounts_iter() {
if let Some(info) = acc.info.clone() {
// we want pre cache existing accounts and their storage
// this only includes changed accounts and storage but is better than nothing
let storage =
acc.storage.iter().map(|(key, slot)| (*key, slot.present_value)).collect();
cached.insert_account(addr, info, storage);
}
// extract the state from the notification and put it into the cache
let committed = new_state.committed();
let new_state = committed.state();
for (addr, acc) in new_state.bundle_accounts_iter() {
if let Some(info) = acc.info.clone() {
// we want pre cache existing accounts and their storage
// this only includes changed accounts and storage but is better than nothing
let storage =
acc.storage.iter().map(|(key, slot)| (*key, slot.present_value)).collect();
cached.insert_account(addr, info, storage);
}
self.pre_cached = Some(PrecachedState { block: committed.tip().hash(), cached });
}
self.pre_cached = Some(PrecachedState { block: committed.tip().hash(), cached });
}
}