@@ -11067,52 +11067,86 @@ pub mod tests {
11067
11067
#[test]
11068
11068
fn test_shrink_zero_lamport_single_ref_account() {
11069
11069
solana_logger::setup();
11070
+ // note that 'None' checks the case based on the default value of `latest_full_snapshot_slot` in `AccountsDb`
11071
+ for latest_full_snapshot_slot in [None, Some(0), Some(1), Some(2)] {
11072
+ // store a zero and non-zero lamport account
11073
+ // make sure clean marks the ref_count=1, zero lamport account dead and removes pubkey from index completely
11074
+ let accounts = AccountsDb::new_single_for_tests();
11075
+ let pubkey_zero = Pubkey::from([1; 32]);
11076
+ let pubkey2 = Pubkey::from([2; 32]);
11077
+ let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
11078
+ let zero_lamport_account =
11079
+ AccountSharedData::new(0, 0, AccountSharedData::default().owner());
11080
+ let slot = 1;
11081
+ // Store a zero-lamport account and a non-zero lamport account
11082
+ accounts.store_for_tests(
11083
+ slot,
11084
+ &[(&pubkey_zero, &zero_lamport_account), (&pubkey2, &account)],
11085
+ );
11070
11086
11071
- // store a zero and non-zero lamport account
11072
- // make sure clean marks the ref_count=1, zero lamport account dead and removes pubkey from index completely
11073
- let accounts = AccountsDb::new_single_for_tests();
11074
- let pubkey_zero = Pubkey::from([1; 32]);
11075
- let pubkey2 = Pubkey::from([2; 32]);
11076
- let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner());
11077
- let zero_lamport_account =
11078
- AccountSharedData::new(0, 0, AccountSharedData::default().owner());
11087
+ // Simulate rooting the zero-lamport account, should be a
11088
+ // candidate for cleaning
11089
+ accounts.calculate_accounts_delta_hash(slot);
11090
+ accounts.add_root_and_flush_write_cache(slot);
11079
11091
11080
- // Store a zero-lamport account and a non-zero lamport account
11081
- accounts.store_for_tests(
11082
- 1,
11083
- &[(&pubkey_zero, &zero_lamport_account), (&pubkey2, &account)],
11084
- );
11092
+ // for testing, we need to cause shrink to think this will be productive.
11093
+ // The zero lamport account isn't dead, but it can become dead inside shrink.
11094
+ accounts
11095
+ .storage
11096
+ .get_slot_storage_entry(slot)
11097
+ .unwrap()
11098
+ .alive_bytes
11099
+ .fetch_sub(aligned_stored_size(0), Ordering::Relaxed);
11085
11100
11086
- // Simulate rooting the zero-lamport account, should be a
11087
- // candidate for cleaning
11088
- accounts.calculate_accounts_delta_hash(1);
11089
- accounts.add_root_and_flush_write_cache(1);
11101
+ if let Some(latest_full_snapshot_slot) = latest_full_snapshot_slot {
11102
+ accounts.set_latest_full_snapshot_slot(latest_full_snapshot_slot);
11103
+ }
11090
11104
11091
- // for testing, we need to cause shrink to think this will be productive.
11092
- // The zero lamport account isn't dead, but it can become dead inside shrink.
11093
- accounts
11094
- .storage
11095
- .get_slot_storage_entry(1)
11096
- .unwrap()
11097
- .alive_bytes
11098
- .fetch_sub(aligned_stored_size(0), Ordering::Relaxed);
11105
+ // Shrink the slot. The behavior on the zero lamport account will depend on `latest_full_snapshot_slot`.
11106
+ accounts.shrink_slot_forced(slot);
11099
11107
11100
- // Slot 1 should be cleaned, but
11101
- // zero-lamport account should not be cleaned since last full snapshot root is before slot 1
11102
- accounts.shrink_slot_forced(1);
11108
+ assert!(
11109
+ accounts.storage.get_slot_storage_entry(1).is_some(),
11110
+ "{latest_full_snapshot_slot:?}"
11111
+ );
11103
11112
11104
- assert!(accounts.storage.get_slot_storage_entry(1).is_some());
11113
+ let expected_alive_count = if latest_full_snapshot_slot.unwrap_or(Slot::MAX) < slot {
11114
+ // zero lamport account should NOT be dead in the index
11115
+ assert!(
11116
+ accounts
11117
+ .accounts_index
11118
+ .contains_with(&pubkey_zero, None, None),
11119
+ "{latest_full_snapshot_slot:?}"
11120
+ );
11121
+ 2
11122
+ } else {
11123
+ // zero lamport account should be dead in the index
11124
+ assert!(
11125
+ !accounts
11126
+ .accounts_index
11127
+ .contains_with(&pubkey_zero, None, None),
11128
+ "{latest_full_snapshot_slot:?}"
11129
+ );
11130
+ // the zero lamport account should be marked as dead
11131
+ 1
11132
+ };
11105
11133
11106
- // the zero lamport account should be marked as dead
11107
- assert_eq!(accounts.alive_account_count_in_slot(1), 1);
11134
+ assert_eq!(
11135
+ accounts.alive_account_count_in_slot(slot),
11136
+ expected_alive_count,
11137
+ "{latest_full_snapshot_slot:?}"
11138
+ );
11108
11139
11109
- // zero lamport account should be dead in the index
11110
- assert!(!accounts
11111
- .accounts_index
11112
- .contains_with(&pubkey_zero, None, None));
11113
- // other account should still be alive
11114
- assert!(accounts.accounts_index.contains_with(&pubkey2, None, None));
11115
- assert!(accounts.storage.get_slot_storage_entry(1).is_some());
11140
+ // other account should still be alive
11141
+ assert!(
11142
+ accounts.accounts_index.contains_with(&pubkey2, None, None),
11143
+ "{latest_full_snapshot_slot:?}"
11144
+ );
11145
+ assert!(
11146
+ accounts.storage.get_slot_storage_entry(slot).is_some(),
11147
+ "{latest_full_snapshot_slot:?}"
11148
+ );
11149
+ }
11116
11150
}
11117
11151
11118
11152
#[test]
0 commit comments