-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wip] Add failing test case to spot an accountsDb corruption bug #7143
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1735,6 +1735,86 @@ pub mod tests { | |
assert!(check_storage(&daccounts, 2, 31)); | ||
} | ||
|
||
fn assert_load_account( | ||
accounts: &AccountsDB, | ||
slot: Slot, | ||
pubkey: Pubkey, | ||
expected_lamports: u64, | ||
) { | ||
let ancestors = vec![(slot, 0)].into_iter().collect(); | ||
let (account, slot) = accounts.load_slow(&ancestors, &pubkey).unwrap(); | ||
assert_eq!((account.lamports, slot), (expected_lamports, slot)); | ||
} | ||
|
||
fn reconstruct_accounts_db_via_serialization(accounts: AccountsDB, slot: Slot) -> AccountsDB { | ||
let mut writer = Cursor::new(vec![]); | ||
serialize_into(&mut writer, &AccountsDBSerialize::new(&accounts, slot)).unwrap(); | ||
|
||
let buf = writer.into_inner(); | ||
let mut reader = BufReader::new(&buf[..]); | ||
let daccounts = AccountsDB::new(None); | ||
|
||
let local_paths = { | ||
let paths = daccounts.paths.read().unwrap(); | ||
AccountsDB::format_paths(paths.to_vec()) | ||
}; | ||
|
||
let copied_accounts = TempDir::new().unwrap(); | ||
// Simulate obtaining a copy of the AppendVecs from a tarball | ||
copy_append_vecs(&accounts, copied_accounts.path()).unwrap(); | ||
daccounts | ||
.accounts_from_stream(&mut reader, local_paths, copied_accounts.path()) | ||
.unwrap(); | ||
|
||
print_count_and_status("daccounts", &daccounts); | ||
|
||
daccounts | ||
} | ||
|
||
fn purge_zero_lamport_accounts(accounts: &AccountsDB, slot: Slot) { | ||
let ancestors = vec![(slot as Slot, 0)].into_iter().collect(); | ||
accounts.purge_zero_lamport_accounts(&ancestors); | ||
} | ||
|
||
#[test] | ||
fn test_accounts_db_serialize_zero_and_free() { | ||
solana_logger::setup(); | ||
|
||
let some_lamport = 223; | ||
let zero_lamport = 0; | ||
let no_data = 0; | ||
let owner = Account::default().owner; | ||
|
||
let account = Account::new(some_lamport, no_data, &owner); | ||
let pubkey = Pubkey::new_rand(); | ||
let zero_lamport_account = Account::new(zero_lamport, no_data, &owner); | ||
|
||
let filler_account = Account::new(some_lamport, no_data, &owner); | ||
let filler_account_pubkey = Pubkey::new_rand(); | ||
|
||
let accounts = AccountsDB::new_single(); | ||
|
||
let mut current_slot = 1; | ||
accounts.store(current_slot, &[(&pubkey, &account)]); | ||
accounts.add_root(current_slot); | ||
|
||
current_slot += 1; | ||
accounts.store(current_slot, &[(&pubkey, &zero_lamport_account)]); | ||
for _ in 0..33000 { | ||
accounts.store(current_slot, &[(&filler_account_pubkey, &filler_account)]); | ||
} | ||
accounts.add_root(current_slot); | ||
|
||
error!("doesn't fail:"); | ||
assert_load_account(&accounts, current_slot, pubkey, zero_lamport); | ||
|
||
purge_zero_lamport_accounts(&accounts, current_slot); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remove this line, this test passes. |
||
let accounts = reconstruct_accounts_db_via_serialization(accounts, current_slot); | ||
|
||
error!("does fail due to a reconstruction bug:"); | ||
assert_load_account(&accounts, current_slot, pubkey, zero_lamport); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should behave exactly same as this identical assertion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails like this. |
||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn test_store_account_stress() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I reduce this number, this test passes...