From ad2e60120efc1d6f01a460a01d5e50c3470366a4 Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 5 Dec 2023 08:52:29 -0600 Subject: [PATCH] rpc: simulate tx: add `jsonParsed` support for inner instructions --- banks-server/src/banks_server.rs | 3 ++- programs/sbf/tests/programs.rs | 2 +- rpc-client-api/src/response.rs | 6 +++--- rpc/src/rpc.rs | 10 +++++++--- runtime/src/bank.rs | 6 +++--- runtime/src/bank/tests.rs | 2 +- transaction-status/src/lib.rs | 2 +- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/banks-server/src/banks_server.rs b/banks-server/src/banks_server.rs index fc4fca0bc75716..1fcdce1ad436c5 100644 --- a/banks-server/src/banks_server.rs +++ b/banks-server/src/banks_server.rs @@ -195,7 +195,8 @@ fn simulate_transaction( units_consumed, return_data, inner_instructions, - } = bank.simulate_transaction_unchecked(sanitized_transaction, false); + } = bank.simulate_transaction_unchecked(&sanitized_transaction, false); + let simulation_details = TransactionSimulationDetails { logs, units_consumed, diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index 932cf678d072d2..32d3a2a6790e4d 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -766,7 +766,7 @@ fn test_return_data_and_log_data_syscall() { let transaction = Transaction::new(&[&mint_keypair], message, blockhash); let sanitized_tx = SanitizedTransaction::from_transaction_for_tests(transaction); - let result = bank.simulate_transaction(sanitized_tx, false); + let result = bank.simulate_transaction(&sanitized_tx, false); assert!(result.result.is_ok()); diff --git a/rpc-client-api/src/response.rs b/rpc-client-api/src/response.rs index 96f021750462fb..fa70e89b6b88ee 100644 --- a/rpc-client-api/src/response.rs +++ b/rpc-client-api/src/response.rs @@ -10,8 +10,8 @@ use { transaction::{Result, TransactionError}, }, solana_transaction_status::{ - ConfirmedTransactionStatusWithSignature, InnerInstructions, TransactionConfirmationStatus, - UiConfirmedBlock, UiTransactionReturnData, + ConfirmedTransactionStatusWithSignature, TransactionConfirmationStatus, UiConfirmedBlock, + UiInnerInstructions, UiTransactionReturnData, }, std::{collections::HashMap, fmt, net::SocketAddr, str::FromStr}, thiserror::Error, @@ -423,7 +423,7 @@ pub struct RpcSimulateTransactionResult { pub accounts: Option>>, pub units_consumed: Option, pub return_data: Option, - pub inner_instructions: Option>, + pub inner_instructions: Option>, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index eff7e5916a6c3c..146b0c0a7d5b46 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -3266,6 +3266,7 @@ pub mod rpc_full { use { super::*, solana_sdk::message::{SanitizedVersionedMessage, VersionedMessage}, + solana_transaction_status::UiInnerInstructions, }; #[rpc] pub trait Full { @@ -3677,7 +3678,7 @@ pub mod rpc_full { units_consumed, return_data, inner_instructions: _, // Always `None` due to `enable_cpi_recording = false` - } = preflight_bank.simulate_transaction(transaction, false) + } = preflight_bank.simulate_transaction(&transaction, false) { match err { TransactionError::BlockhashNotFound => { @@ -3756,7 +3757,6 @@ pub mod rpc_full { if sig_verify { verify_transaction(&transaction, &bank.feature_set)?; } - let number_of_accounts = transaction.message().account_keys().len(); let TransactionSimulationResult { result, @@ -3765,7 +3765,10 @@ pub mod rpc_full { units_consumed, return_data, inner_instructions, - } = bank.simulate_transaction(transaction, enable_cpi_recording); + } = bank.simulate_transaction(&transaction, enable_cpi_recording); + + let account_keys = transaction.message().account_keys(); + let number_of_accounts = account_keys.len(); let accounts = if let Some(config_accounts) = config_accounts { let accounts_encoding = config_accounts @@ -3822,6 +3825,7 @@ pub mod rpc_full { .collect(), }) .filter(|i| !i.instructions.is_empty()) + .map(|converted| UiInnerInstructions::parse(converted, &account_keys)) .collect() }); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index c24b80a7c27cd2..7bcf301c95c536 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -4313,7 +4313,7 @@ impl Bank { /// Run transactions against a frozen bank without committing the results pub fn simulate_transaction( &self, - transaction: SanitizedTransaction, + transaction: &SanitizedTransaction, enable_cpi_recording: bool, ) -> TransactionSimulationResult { assert!(self.is_frozen(), "simulation bank must be frozen"); @@ -4325,13 +4325,13 @@ impl Bank { /// is frozen, enabling use in single-Bank test frameworks pub fn simulate_transaction_unchecked( &self, - transaction: SanitizedTransaction, + transaction: &SanitizedTransaction, enable_cpi_recording: bool, ) -> 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 batch = self.prepare_unlocked_batch_from_single_tx(transaction); let mut timings = ExecuteTimings::default(); let LoadAndExecuteTransactionsOutput { diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 3f780a9d184ca0..c9c216ead2be6e 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -14137,6 +14137,6 @@ fn test_failed_simulation_compute_units() { bank.freeze(); let sanitized = SanitizedTransaction::from_transaction_for_tests(transaction); - let simulation = bank.simulate_transaction(sanitized, false); + let simulation = bank.simulate_transaction(&sanitized, false); assert_eq!(TEST_UNITS, simulation.units_consumed); } diff --git a/transaction-status/src/lib.rs b/transaction-status/src/lib.rs index fac20d9859cdbd..7231f95678e479 100644 --- a/transaction-status/src/lib.rs +++ b/transaction-status/src/lib.rs @@ -240,7 +240,7 @@ pub struct UiInnerInstructions { } impl UiInnerInstructions { - fn parse(inner_instructions: InnerInstructions, account_keys: &AccountKeys) -> Self { + pub fn parse(inner_instructions: InnerInstructions, account_keys: &AccountKeys) -> Self { Self { index: inner_instructions.index, instructions: inner_instructions