From ca0f16ccc00493e1116a974bafe04a4f5ba6d3c0 Mon Sep 17 00:00:00 2001 From: Sathish Ambley Date: Tue, 26 Feb 2019 21:41:05 -0800 Subject: [PATCH] Fix test failure --- runtime/src/accounts.rs | 36 +++++++++++++++++++----------------- src/blocktree_processor.rs | 3 ++- src/fullnode.rs | 3 ++- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 554040a9de..22e4cf7bcc 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -686,19 +686,16 @@ impl AccountsDB { { if parent_fork != fork { self.insert_account_entry(fork, id, offset, &map); - if self.remove_account_entries(&parents, &map) { - keys.push(pubkey.clone()); - } - } - let account = self.get_account(id, offset); - if account.tokens == 0 { - if self.remove_account_entries(&[fork], &map) { - keys.push(pubkey.clone()); - } - if vote_program::check_id(&account.owner) { - self.index_info.vote_index.write().unwrap().remove(pubkey); - } } else { + let account = self.get_account(id, offset); + if account.tokens == 0 { + if self.remove_account_entries(&[fork], &map) { + keys.push(pubkey.clone()); + } + if vote_program::check_id(&account.owner) { + self.index_info.vote_index.write().unwrap().remove(pubkey); + } + } } } }); @@ -759,12 +756,16 @@ impl Accounts { /// Slow because lock is held for 1 operation insted of many pub fn load_slow(&self, fork: Fork, pubkey: &Pubkey) -> Option { - self.accounts_db.load(fork, pubkey, true).filter(|acc| acc.tokens != 0) + self.accounts_db + .load(fork, pubkey, true) + .filter(|acc| acc.tokens != 0) } /// Slow because lock is held for 1 operation insted of many pub fn load_slow_no_parent(&self, fork: Fork, pubkey: &Pubkey) -> Option { - self.accounts_db.load(fork, pubkey, false).filter(|acc| acc.tokens != 0) + self.accounts_db + .load(fork, pubkey, false) + .filter(|acc| acc.tokens != 0) } /// Slow because lock is held for 1 operation insted of many @@ -1346,11 +1347,12 @@ mod tests { assert_eq!(db.load(1, &key, true), None); for _ in 1..100 { let idx = thread_rng().gen_range(0, 99); - assert_eq!(db.load(0, &pubkeys[idx], true), None); - let account = db.load(1, &pubkeys[idx], true).unwrap(); + let account0 = db.load(0, &pubkeys[idx], true).unwrap(); + let account1 = db.load(1, &pubkeys[idx], true).unwrap(); let mut default_account = Account::default(); default_account.tokens = (idx + 1) as u64; - assert_eq!(compare_account(&default_account, &account), true); + assert_eq!(compare_account(&default_account, &account0), true); + assert_eq!(compare_account(&default_account, &account1), true); } cleanup_dirs(&paths); } diff --git a/src/blocktree_processor.rs b/src/blocktree_processor.rs index a8ef3c7ce0..b6594e8d99 100644 --- a/src/blocktree_processor.rs +++ b/src/blocktree_processor.rs @@ -475,7 +475,8 @@ mod tests { Blocktree::open(&ledger_path).expect("Expected to successfully open database ledger"); blocktree.write_entries(1, 0, 0, &entries).unwrap(); let entry_height = genesis_block.ticks_per_slot + entries.len() as u64; - let (bank_forks, bank_forks_info) = process_blocktree(&genesis_block, &blocktree, None).unwrap(); + let (bank_forks, bank_forks_info) = + process_blocktree(&genesis_block, &blocktree, None).unwrap(); assert_eq!(bank_forks_info.len(), 1); assert_eq!( diff --git a/src/fullnode.rs b/src/fullnode.rs index 18bbd7e6f3..88e54e010a 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -746,7 +746,8 @@ mod tests { // Close the validator so that rocksdb has locks available validator_exit(); - let (bank_forks, bank_forks_info, _, _) = new_banks_from_blocktree(&validator_ledger_path, None); + let (bank_forks, bank_forks_info, _, _) = + new_banks_from_blocktree(&validator_ledger_path, None); let bank = bank_forks.working_bank(); let entry_height = bank_forks_info[0].entry_height;