Skip to content

Commit

Permalink
Remove old function: account_balance_for_capitalization (#16383)
Browse files Browse the repository at this point in the history
This function currently returns one of its' parameters and is thus useless.
  • Loading branch information
steviez authored Apr 8, 2021
1 parent 878e52f commit e69f37a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 78 deletions.
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
75 changes: 4 additions & 71 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,67 +8227,19 @@ 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
);
assert_eq!(normal_sysvar.lamports, 1);
}

#[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
);
assert_eq!(normal_native_program.lamports, 1);
}

#[test]
Expand Down

0 comments on commit e69f37a

Please sign in to comment.