Remove old function: account_balance_for_capitalization (#16383)
This function currently returns one of its' parameters and is thus useless.
This commit is contained in:
@ -587,15 +587,9 @@ impl Accounts {
|
|||||||
|total_capitalization: &mut u64, (_pubkey, loaded_account, _slot)| {
|
|total_capitalization: &mut u64, (_pubkey, loaded_account, _slot)| {
|
||||||
let lamports = loaded_account.lamports();
|
let lamports = loaded_account.lamports();
|
||||||
if Self::is_loadable(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 = AccountsDb::checked_iterative_sum_for_capitalization(
|
||||||
*total_capitalization,
|
*total_capitalization,
|
||||||
account_cap,
|
lamports,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -3617,15 +3617,6 @@ impl AccountsDb {
|
|||||||
AccountsHash::checked_cast_for_capitalization(balances.map(|b| b as u128).sum::<u128>())
|
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(
|
fn calculate_accounts_hash(
|
||||||
&self,
|
&self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
@ -3671,13 +3662,7 @@ impl AccountsDb {
|
|||||||
|loaded_account| {
|
|loaded_account| {
|
||||||
let loaded_hash = loaded_account
|
let loaded_hash = loaded_account
|
||||||
.loaded_hash(self.expected_cluster_type());
|
.loaded_hash(self.expected_cluster_type());
|
||||||
let balance =
|
let balance = account_info.lamports;
|
||||||
Self::account_balance_for_capitalization(
|
|
||||||
account_info.lamports,
|
|
||||||
loaded_account.owner(),
|
|
||||||
loaded_account.executable(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if check_hash {
|
if check_hash {
|
||||||
let computed_hash = loaded_account
|
let computed_hash = loaded_account
|
||||||
.compute_hash(
|
.compute_hash(
|
||||||
@ -3863,11 +3848,7 @@ impl AccountsDb {
|
|||||||
let balance = if zero_raw_lamports {
|
let balance = if zero_raw_lamports {
|
||||||
crate::accounts_hash::ZERO_RAW_LAMPORTS_SENTINEL
|
crate::accounts_hash::ZERO_RAW_LAMPORTS_SENTINEL
|
||||||
} else {
|
} else {
|
||||||
Self::account_balance_for_capitalization(
|
raw_lamports
|
||||||
raw_lamports,
|
|
||||||
loaded_account.owner(),
|
|
||||||
loaded_account.executable(),
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let source_item = CalculateHashIntermediate::new(
|
let source_item = CalculateHashIntermediate::new(
|
||||||
@ -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]
|
#[test]
|
||||||
fn test_account_balance_for_capitalization_sysvar() {
|
fn test_account_balance_for_capitalization_sysvar() {
|
||||||
let normal_sysvar = solana_sdk::account::create_account_for_test(
|
let normal_sysvar = solana_sdk::account::create_account_for_test(
|
||||||
&solana_sdk::slot_history::SlotHistory::default(),
|
&solana_sdk::slot_history::SlotHistory::default(),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(normal_sysvar.lamports, 1);
|
||||||
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]
|
#[test]
|
||||||
fn test_account_balance_for_capitalization_native_program() {
|
fn test_account_balance_for_capitalization_native_program() {
|
||||||
let normal_native_program =
|
let normal_native_program =
|
||||||
solana_sdk::native_loader::create_loadable_account_for_test("foo");
|
solana_sdk::native_loader::create_loadable_account_for_test("foo");
|
||||||
assert_eq!(
|
assert_eq!(normal_native_program.lamports, 1);
|
||||||
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]
|
#[test]
|
||||||
|
Reference in New Issue
Block a user