From 4b0d4e9834c74b1d5eb496c310f8fc02f8a2a245 Mon Sep 17 00:00:00 2001 From: sakridge Date: Wed, 25 Mar 2020 10:59:52 -0700 Subject: [PATCH] Remove accounts unwrap (#9063) automerge --- runtime/src/accounts_db.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 60e15a1394..07e9384aa1 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -1376,9 +1376,11 @@ impl AccountsDB { let index = self.accounts_index.read().unwrap(); let storage = self.storage.read().unwrap(); for slot in dead_slots.iter() { - for store in storage.0.get(slot).unwrap().values() { - for account in store.accounts.accounts(0) { - index.unref_from_storage(&account.meta.pubkey); + if let Some(slot_storage) = storage.0.get(slot) { + for store in slot_storage.values() { + for account in store.accounts.accounts(0) { + index.unref_from_storage(&account.meta.pubkey); + } } } } @@ -3373,4 +3375,12 @@ pub mod tests { assert_load_account(&accounts, current_slot, pubkey2, old_lamport); assert_load_account(&accounts, current_slot, dummy_pubkey, dummy_lamport); } + + #[test] + fn clean_dead_slots_empty() { + let accounts = AccountsDB::new_single(); + let mut dead_slots = HashSet::new(); + dead_slots.insert(10); + accounts.clean_dead_slots(&mut dead_slots); + } }