Skip to content

Commit

Permalink
Remove unnecessary input to transaction_accounts_lamports_sum (#4497)
Browse files Browse the repository at this point in the history
* remove unnecesary input to transaction_accounts_lamports_sum

* Add debug_assert
  • Loading branch information
LStan authored Jan 27, 2025
1 parent 912311d commit db80f89
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,16 +925,17 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
) -> ExecutedTransaction {
let transaction_accounts = std::mem::take(&mut loaded_transaction.accounts);

// Ensure the length of accounts matches the expected length from tx.account_keys().
// This is a sanity check in case that someone starts adding some additional accounts
// since this has been done before. See discussion in PR #4497 for details
debug_assert!(transaction_accounts.len() == tx.account_keys().len());

fn transaction_accounts_lamports_sum(
accounts: &[(Pubkey, AccountSharedData)],
message: &impl SVMMessage,
) -> Option<u128> {
let mut lamports_sum = 0u128;
for i in 0..message.account_keys().len() {
let (_, account) = accounts.get(i)?;
lamports_sum = lamports_sum.checked_add(u128::from(account.lamports()))?;
}
Some(lamports_sum)
accounts.iter().try_fold(0u128, |sum, (_, account)| {
sum.checked_add(u128::from(account.lamports()))
})
}

let default_rent_collector = RentCollector::default();
Expand All @@ -943,7 +944,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
.unwrap_or(&default_rent_collector);

let lamports_before_tx =
transaction_accounts_lamports_sum(&transaction_accounts, tx).unwrap_or(0);
transaction_accounts_lamports_sum(&transaction_accounts).unwrap_or(0);

let compute_budget = config
.compute_budget
Expand Down Expand Up @@ -1062,7 +1063,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
} = transaction_context.into();

if status.is_ok()
&& transaction_accounts_lamports_sum(&accounts, tx)
&& transaction_accounts_lamports_sum(&accounts)
.filter(|lamports_after_tx| lamports_before_tx == *lamports_after_tx)
.is_none()
{
Expand Down

0 comments on commit db80f89

Please sign in to comment.