Clean up accounts hash internal state api (#7090)

This commit is contained in:
Sagar Dhawan 2019-11-22 08:56:00 -08:00 committed by GitHub
parent 68bad56e7d
commit 4485b978c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -458,9 +458,11 @@ impl Accounts {
} }
} }
pub fn hash_internal_state(&self, slot_id: Slot) -> Option<BankHash> { pub fn hash_internal_state(&self, slot_id: Slot) -> BankHash {
let slot_hashes = self.accounts_db.slot_hashes.read().unwrap(); 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 /// This function will prevent multiple threads from modifying the same account state at the
@ -1093,11 +1095,18 @@ mod tests {
} }
#[test] #[test]
#[should_panic]
fn test_accounts_empty_hash_internal_state() { fn test_accounts_empty_hash_internal_state() {
let accounts = Accounts::new(None); 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())); 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<Pubkey>, num: usize) { fn check_accounts(accounts: &Accounts, pubkeys: &Vec<Pubkey>, num: usize) {

View File

@ -1413,11 +1413,7 @@ impl Bank {
/// of the delta of the ledger since the last vote and up to now /// of the delta of the ledger since the last vote and up to now
fn hash_internal_state(&self) -> Hash { fn hash_internal_state(&self) -> Hash {
// If there are no accounts, return the hash of the previous state and the latest blockhash // If there are no accounts, return the hash of the previous state and the latest blockhash
let accounts_delta_hash = self let accounts_delta_hash = self.rc.accounts.hash_internal_state(self.slot());
.rc
.accounts
.hash_internal_state(self.slot())
.expect("No accounts delta was found for this bank, that should not be possible");
let mut signature_count_buf = [0u8; 8]; let mut signature_count_buf = [0u8; 8];
LittleEndian::write_u64(&mut signature_count_buf[..], self.signature_count() as u64); LittleEndian::write_u64(&mut signature_count_buf[..], self.signature_count() as u64);
hashv(&[ hashv(&[