From 4485b978c1ea827a9ef467d26ba23f00a956749f Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Fri, 22 Nov 2019 08:56:00 -0800 Subject: [PATCH] Clean up accounts hash internal state api (#7090) --- runtime/src/accounts.rs | 17 +++++++++++++---- runtime/src/bank.rs | 6 +----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index c19c4f49f9..40c462ed44 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -458,9 +458,11 @@ impl Accounts { } } - pub fn hash_internal_state(&self, slot_id: Slot) -> Option { + pub fn hash_internal_state(&self, slot_id: Slot) -> BankHash { let slot_hashes = self.accounts_db.slot_hashes.read().unwrap(); - slot_hashes.get(&slot_id).cloned() + *slot_hashes + .get(&slot_id) + .expect("No accounts hash was found for this bank, that should not be possible") } /// This function will prevent multiple threads from modifying the same account state at the @@ -1093,11 +1095,18 @@ mod tests { } #[test] + #[should_panic] fn test_accounts_empty_hash_internal_state() { let accounts = Accounts::new(None); - assert_eq!(accounts.hash_internal_state(0), None); + accounts.hash_internal_state(0); + } + + #[test] + #[should_panic] + fn test_accounts_empty_account_hash_internal_state() { + let accounts = Accounts::new(None); accounts.store_slow(0, &Pubkey::default(), &Account::new(1, 0, &sysvar::id())); - assert_eq!(accounts.hash_internal_state(0), None); + accounts.hash_internal_state(0); } fn check_accounts(accounts: &Accounts, pubkeys: &Vec, num: usize) { diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 8463b53a73..3937bfe94d 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -1413,11 +1413,7 @@ impl Bank { /// of the delta of the ledger since the last vote and up to now fn hash_internal_state(&self) -> Hash { // If there are no accounts, return the hash of the previous state and the latest blockhash - let accounts_delta_hash = self - .rc - .accounts - .hash_internal_state(self.slot()) - .expect("No accounts delta was found for this bank, that should not be possible"); + let accounts_delta_hash = self.rc.accounts.hash_internal_state(self.slot()); let mut signature_count_buf = [0u8; 8]; LittleEndian::write_u64(&mut signature_count_buf[..], self.signature_count() as u64); hashv(&[