Skip to content

Commit 33224fc

Browse files
committed
Fixes accounts_data_size update in replace_program_account()
1 parent 7fa607c commit 33224fc

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

runtime/src/bank.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5725,9 +5725,11 @@ impl Bank {
57255725
.unwrap()
57265726
.remove_programs([*old_address].into_iter());
57275727

5728+
// The new account's data wasn't changed, just moved to a new address.
5729+
// The old account's data was effectively removed.
57285730
self.calculate_and_update_accounts_data_size_delta_off_chain(
57295731
old_account.data().len(),
5730-
new_account.data().len(),
5732+
0,
57315733
);
57325734
}
57335735
}

runtime/src/bank/tests.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7037,25 +7037,24 @@ fn test_program_replacement() {
70377037

70387038
// Setup original program account
70397039
let old_address = Pubkey::new_unique();
7040-
let new_address = Pubkey::new_unique();
7041-
bank.store_account_and_update_capitalization(
7042-
&old_address,
7043-
&AccountSharedData::from(Account {
7044-
lamports: 100,
7045-
..Account::default()
7046-
}),
7047-
);
7048-
assert_eq!(bank.get_balance(&old_address), 100);
7040+
let old_lamports = 100;
7041+
let old_data_size = 1_111;
7042+
let old_program_account =
7043+
AccountSharedData::new(old_lamports, old_data_size, &Pubkey::new_unique());
7044+
bank.store_account_and_update_capitalization(&old_address, &old_program_account);
7045+
assert_eq!(bank.get_balance(&old_address), old_lamports);
70497046

70507047
// Setup new program account
7051-
let new_program_account = AccountSharedData::from(Account {
7052-
lamports: 123,
7053-
..Account::default()
7054-
});
7048+
let new_address = Pubkey::new_unique();
7049+
let new_lamports = old_lamports + 23;
7050+
let new_data_size = old_data_size + 444;
7051+
let new_program_account =
7052+
AccountSharedData::new(new_lamports, new_data_size, &Pubkey::new_unique());
70557053
bank.store_account_and_update_capitalization(&new_address, &new_program_account);
7056-
assert_eq!(bank.get_balance(&new_address), 123);
7054+
assert_eq!(bank.get_balance(&new_address), new_lamports);
70577055

70587056
let original_capitalization = bank.capitalization();
7057+
let original_accounts_data_size = bank.load_accounts_data_size();
70597058

70607059
bank.replace_program_account(&old_address, &new_address, "bank-apply_program_replacement");
70617060

@@ -7066,7 +7065,16 @@ fn test_program_replacement() {
70667065
assert_eq!(bank.get_account(&old_address), Some(new_program_account));
70677066

70687067
// Lamports in the old token account were burnt
7069-
assert_eq!(bank.capitalization(), original_capitalization - 100);
7068+
assert_eq!(
7069+
bank.capitalization(),
7070+
original_capitalization - old_lamports
7071+
);
7072+
7073+
// Old program account was removed from accounts data size
7074+
assert_eq!(
7075+
bank.load_accounts_data_size(),
7076+
original_accounts_data_size - old_data_size as u64,
7077+
);
70707078
}
70717079

70727080
fn min_rent_exempt_balance_for_sysvars(bank: &Bank, sysvar_ids: &[Pubkey]) -> u64 {

0 commit comments

Comments
 (0)