Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4139,9 +4139,16 @@ impl Bank {
};

self.store_account(pubkey, new_account);

// If the new account has zero lamports, that means it is being closed.
let new_account_data_size = if new_account.lamports() == 0 {
0
} else {
new_account.data().len()
};
self.calculate_and_update_accounts_data_size_delta_off_chain(
old_account_data_size,
new_account.data().len(),
new_account_data_size,
);
}

Expand Down
41 changes: 41 additions & 0 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,47 @@ fn test_store_account_and_update_capitalization_unchanged() {
assert_eq!(account, bank.get_account(&pubkey).unwrap());
}

/// Ensure that store_account_and_update_capitalization() correctly updates accounts_data_size
#[test]
fn test_store_account_and_update_capitalization_accounts_data_size() {
let (genesis_config, _mint_keypair) = create_genesis_config(100 * LAMPORTS_PER_SOL);
let bank = Bank::new_for_tests(&genesis_config);

let data_size = 123;
let mut account = AccountSharedData::new(LAMPORTS_PER_SOL, data_size, &system_program::id());
let address = Pubkey::new_unique();

// test 1: store a new account
let accounts_data_size_pre = bank.load_accounts_data_size();
bank.store_account_and_update_capitalization(&address, &account);
let accounts_data_size_post = bank.load_accounts_data_size();
assert_eq!(
accounts_data_size_pre + data_size as u64,
accounts_data_size_post,
);

// test 2: change the account's data
let data_size_delta = 42;
account.set_data(vec![0; data_size + data_size_delta]);
let accounts_data_size_pre = bank.load_accounts_data_size();
bank.store_account_and_update_capitalization(&address, &account);
let accounts_data_size_post = bank.load_accounts_data_size();
assert_eq!(
accounts_data_size_pre + data_size_delta as u64,
accounts_data_size_post,
);

// test 3: close the account
account.set_lamports(0);
let accounts_data_size_pre = bank.load_accounts_data_size();
bank.store_account_and_update_capitalization(&address, &account);
let accounts_data_size_post = bank.load_accounts_data_size();
assert_eq!(
accounts_data_size_pre - (data_size + data_size_delta) as u64,
accounts_data_size_post,
);
}

pub(in crate::bank) fn new_from_parent_next_epoch(
parent: Arc<Bank>,
bank_forks: &RwLock<BankForks>,
Expand Down
Loading