Skip to content

Commit

Permalink
rpc: simulate tx: add jsonParsed support for inner instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Dec 15, 2023
1 parent bba1335 commit ad2e601
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
6 changes: 3 additions & 3 deletions rpc-client-api/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -423,7 +423,7 @@ pub struct RpcSimulateTransactionResult {
pub accounts: Option<Vec<Option<UiAccount>>>,
pub units_consumed: Option<u64>,
pub return_data: Option<UiTransactionReturnData>,
pub inner_instructions: Option<Vec<InnerInstructions>>,
pub inner_instructions: Option<Vec<UiInnerInstructions>>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
Expand Down
10 changes: 7 additions & 3 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3266,6 +3266,7 @@ pub mod rpc_full {
use {
super::*,
solana_sdk::message::{SanitizedVersionedMessage, VersionedMessage},
solana_transaction_status::UiInnerInstructions,
};
#[rpc]
pub trait Full {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -3822,6 +3825,7 @@ pub mod rpc_full {
.collect(),
})
.filter(|i| !i.instructions.is_empty())
.map(|converted| UiInnerInstructions::parse(converted, &account_keys))
.collect()
});

Expand Down
6 changes: 3 additions & 3 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion transaction-status/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad2e601

Please sign in to comment.