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

Backport #446 to v1.17 #448

Merged
merged 1 commit into from
Nov 12, 2023
Merged
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
1 change: 1 addition & 0 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3797,6 +3797,7 @@ pub mod rpc_full {
commitment: preflight_commitment,
min_context_slot,
})?;

let transaction = sanitize_transaction(unsanitized_tx, preflight_bank)?;
let signature = *transaction.signature();

Expand Down
64 changes: 33 additions & 31 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4404,13 +4404,14 @@ impl Bank {
transaction: SanitizedTransaction,
) -> TransactionSimulationResult {
let account_keys = transaction.message().account_keys();
let number_of_accounts = account_keys.len();
let account_overrides = self.get_account_overrides_for_simulation(&account_keys);
let batch = self.prepare_unlocked_batch_from_single_tx(&transaction);
let mut timings = ExecuteTimings::default();

let LoadAndExecuteTransactionsOutput {
loaded_transactions,
execution_results,
mut execution_results,
..
} = self.load_and_execute_transactions(
&batch,
Expand All @@ -4426,42 +4427,43 @@ impl Bank {
None,
);

Self::build_transaction_simulation_result(&loaded_transactions[0], &execution_results[0])
}
let post_simulation_accounts = loaded_transactions
.into_iter()
.next()
.unwrap()
.0
.ok()
.map(|loaded_transaction| {
loaded_transaction
.accounts
.into_iter()
.take(number_of_accounts)
.collect::<Vec<_>>()
})
.unwrap_or_default();

fn build_transaction_simulation_result(
loaded_transaction_result: &TransactionLoadResult,
execution_result: &TransactionExecutionResult,
) -> TransactionSimulationResult {
let (logs, return_data, units_consumed, result) = match execution_result {
TransactionExecutionResult::Executed { details, .. } => {
let log_messages = if let Some(ref log_messages) = details.log_messages {
log_messages.clone()
} else {
vec![]
};
let units_consumed = timings
.details
.per_program_timings
.iter()
.fold(0, |acc: u64, (_, program_timing)| {
acc.saturating_add(program_timing.accumulated_units)
});

(
log_messages,
details.return_data.as_ref().cloned(),
details.executed_units,
execution_result.flattened_result(),
)
}
TransactionExecutionResult::NotExecuted(_) => {
(vec![], None, 0, execution_result.flattened_result())
debug!("simulate_transaction: {:?}", timings);

let execution_result = execution_results.pop().unwrap();
let flattened_result = execution_result.flattened_result();
let (logs, return_data) = match execution_result {
TransactionExecutionResult::Executed { details, .. } => {
(details.log_messages, details.return_data)
}
TransactionExecutionResult::NotExecuted(_) => (None, None),
};

let post_simulation_accounts = loaded_transaction_result
.0
.as_ref()
.ok()
.map(|tx| tx.accounts.clone())
.unwrap_or_default();
let logs = logs.unwrap_or_default();

TransactionSimulationResult {
result,
result: flattened_result,
logs,
post_simulation_accounts,
units_consumed,
Expand Down