Skip to content

Commit

Permalink
share function to withdraw errored transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones committed Mar 15, 2024
1 parent ca0ae44 commit 0e45085
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4876,16 +4876,12 @@ impl Bank {
lamports_per_signature,
);

// In case of instruction error, even though no accounts
// were stored we still need to charge the payer the
// fee.
//
//...except nonce accounts, which already have their
// post-load, fee deducted, pre-execute account state
// stored
if execution_status.is_err() && !is_nonce {
self.withdraw(tx.message().fee_payer(), fee)?;
}
self.check_execution_status_and_charge_fee(
tx.message(),
execution_status,
is_nonce,
fee,
)?;

fees += fee;
Ok(())
Expand Down Expand Up @@ -4927,22 +4923,15 @@ impl Bank {
.is_active(&include_loaded_accounts_data_size_in_fee_calculation::id()),
);

// In case of instruction error, even though no accounts
// were stored we still need to charge the payer the
// fee.
//
//...except nonce accounts, which already have their
// post-load, fee deducted, pre-execute account state
// stored
if execution_status.is_err() && !is_nonce {
self.withdraw(
tx.message().fee_payer(),
fee_details.total_fee(
self.feature_set
.is_active(&remove_rounding_in_fee_calculation::id()),
),
)?;
}
self.check_execution_status_and_charge_fee(
message,
execution_status,
is_nonce,
fee_details.total_fee(
self.feature_set
.is_active(&remove_rounding_in_fee_calculation::id()),
),
)?;

accumulated_fee_details.accumulate(&fee_details);
Ok(())
Expand All @@ -4956,6 +4945,27 @@ impl Bank {
results
}

fn check_execution_status_and_charge_fee(
&self,
message: &SanitizedMessage,
execution_status: &transaction::Result<()>,
is_nonce: bool,
fee: u64,
) -> Result<()> {
// In case of instruction error, even though no accounts
// were stored we still need to charge the payer the
// fee.
//
//...except nonce accounts, which already have their
// post-load, fee deducted, pre-execute account state
// stored
if execution_status.is_err() && !is_nonce {
self.withdraw(message.fee_payer(), fee)?;
}

Ok(())
}

/// `committed_transactions_count` is the number of transactions out of `sanitized_txs`
/// that was executed. Of those, `committed_transactions_count`,
/// `committed_with_failure_result_count` is the number of executed transactions that returned
Expand Down

0 comments on commit 0e45085

Please sign in to comment.