Promote dangerous cond. from just warning to panic (#8439)
This commit is contained in:
parent
fef913085e
commit
0b48c8eb35
|
@ -280,7 +280,7 @@ impl AccountStorageEntry {
|
||||||
|
|
||||||
fn remove_account(&self) -> usize {
|
fn remove_account(&self) -> usize {
|
||||||
let mut count_and_status = self.count_and_status.write().unwrap();
|
let mut count_and_status = self.count_and_status.write().unwrap();
|
||||||
let (count, mut status) = *count_and_status;
|
let (mut count, mut status) = *count_and_status;
|
||||||
|
|
||||||
if count == 1 && status == AccountStorageStatus::Full {
|
if count == 1 && status == AccountStorageStatus::Full {
|
||||||
// this case arises when we remove the last account from the
|
// this case arises when we remove the last account from the
|
||||||
|
@ -298,12 +298,18 @@ impl AccountStorageEntry {
|
||||||
status = AccountStorageStatus::Available;
|
status = AccountStorageStatus::Available;
|
||||||
}
|
}
|
||||||
|
|
||||||
if count > 0 {
|
// Some code path is removing accounts too many; this may result in an
|
||||||
*count_and_status = (count - 1, status);
|
// unintended reveal of old state for unrelated accounts.
|
||||||
} else {
|
assert!(
|
||||||
warn!("count value 0 for slot {}", self.slot_id);
|
count > 0,
|
||||||
}
|
"double remove of account in slot: {}/store: {}!!",
|
||||||
count_and_status.0
|
self.slot_id,
|
||||||
|
self.id
|
||||||
|
);
|
||||||
|
|
||||||
|
count -= 1;
|
||||||
|
*count_and_status = (count, status);
|
||||||
|
count
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_file<P: AsRef<Path>>(&mut self, path: P) -> IOResult<()> {
|
pub fn set_file<P: AsRef<Path>>(&mut self, path: P) -> IOResult<()> {
|
||||||
|
@ -2705,4 +2711,17 @@ pub mod tests {
|
||||||
db.add_root(base_slot);
|
db.add_root(base_slot);
|
||||||
assert_eq!(1, db.get_snapshot_storages(after_slot).len());
|
assert_eq!(1, db.get_snapshot_storages(after_slot).len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic(expected = "double remove of account in slot: 0/store: 0!!")]
|
||||||
|
fn test_storage_remove_account_double_remove() {
|
||||||
|
let accounts = AccountsDB::new(Vec::new());
|
||||||
|
let pubkey = Pubkey::new_rand();
|
||||||
|
let account = Account::new(1, 0, &Account::default().owner);
|
||||||
|
accounts.store(0, &[(&pubkey, &account)]);
|
||||||
|
let storage = accounts.storage.read().unwrap();
|
||||||
|
let storage_entry = storage.0[&0].values().next().unwrap();
|
||||||
|
storage_entry.remove_account();
|
||||||
|
storage_entry.remove_account();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue