Skip to content
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

Remove old function: account_balance_for_capitalization #16380

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 1 addition & 7 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,15 +587,9 @@ impl Accounts {
|total_capitalization: &mut u64, (_pubkey, loaded_account, _slot)| {
let lamports = loaded_account.lamports();
if Self::is_loadable(lamports) {
let account_cap = AccountsDb::account_balance_for_capitalization(
lamports,
&loaded_account.owner(),
loaded_account.executable(),
);

*total_capitalization = AccountsDb::checked_iterative_sum_for_capitalization(
*total_capitalization,
account_cap,
lamports,
);
}
},
Expand Down
86 changes: 2 additions & 84 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3617,15 +3617,6 @@ impl AccountsDb {
AccountsHash::checked_cast_for_capitalization(balances.map(|b| b as u128).sum::<u128>())
}

// remove this by inlining and remove extra unused params upto all callchain
pub fn account_balance_for_capitalization(
lamports: u64,
_owner: &Pubkey,
_executable: bool,
) -> u64 {
lamports
}

fn calculate_accounts_hash(
&self,
slot: Slot,
Expand Down Expand Up @@ -3671,13 +3662,7 @@ impl AccountsDb {
|loaded_account| {
let loaded_hash = loaded_account
.loaded_hash(self.expected_cluster_type());
let balance =
Self::account_balance_for_capitalization(
account_info.lamports,
loaded_account.owner(),
loaded_account.executable(),
);

let balance = account_info.lamports;
if check_hash {
let computed_hash = loaded_account
.compute_hash(
Expand Down Expand Up @@ -3863,11 +3848,7 @@ impl AccountsDb {
let balance = if zero_raw_lamports {
crate::accounts_hash::ZERO_RAW_LAMPORTS_SENTINEL
} else {
Self::account_balance_for_capitalization(
raw_lamports,
loaded_account.owner(),
loaded_account.executable(),
)
raw_lamports
};

let source_item = CalculateHashIntermediate::new(
Expand Down Expand Up @@ -8246,69 +8227,6 @@ pub mod tests {
}
}

#[test]
fn test_account_balance_for_capitalization_normal() {
// system accounts
assert_eq!(
AccountsDb::account_balance_for_capitalization(10, &Pubkey::default(), false),
10
);
// any random program data accounts
assert_eq!(
AccountsDb::account_balance_for_capitalization(
10,
&solana_sdk::pubkey::new_rand(),
false,
),
10
);
}

#[test]
fn test_account_balance_for_capitalization_sysvar() {
let normal_sysvar = solana_sdk::account::create_account_for_test(
&solana_sdk::slot_history::SlotHistory::default(),
);
assert_eq!(
AccountsDb::account_balance_for_capitalization(
normal_sysvar.lamports,
&normal_sysvar.owner,
normal_sysvar.executable,
),
1
);

// transactions can send any lamports to sysvars although this is not sensible.
assert_eq!(
AccountsDb::account_balance_for_capitalization(10, &solana_sdk::sysvar::id(), false),
10
);
}

#[test]
fn test_account_balance_for_capitalization_native_program() {
let normal_native_program =
solana_sdk::native_loader::create_loadable_account_for_test("foo");
assert_eq!(
AccountsDb::account_balance_for_capitalization(
normal_native_program.lamports,
&normal_native_program.owner,
normal_native_program.executable,
),
1
);

// test maliciously assigned bogus native loader account
assert_eq!(
AccountsDb::account_balance_for_capitalization(
1,
&solana_sdk::native_loader::id(),
false,
),
1
);
}

#[test]
fn test_checked_sum_for_capitalization_normal() {
assert_eq!(
Expand Down