Skip to content

Commit

Permalink
fix simulate_bundle client and better error handling (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
segfaultdoc committed Feb 28, 2023
1 parent 383b788 commit c51e137
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions client/src/nonblocking/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,8 @@ impl RpcClient {
bundle,
RpcSimulateBundleConfig {
simulation_bank: Some(SimulationSlotConfig::Commitment(self.commitment())),
pre_execution_accounts_configs: vec![None; bundle.transactions.len()],
post_execution_accounts_configs: vec![None; bundle.transactions.len()],
..RpcSimulateBundleConfig::default()
},
)
Expand Down
14 changes: 10 additions & 4 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3438,6 +3438,7 @@ pub mod rpc_full {
super::*,
crate::rpc::utils::{build_simulate_bundle_params, rpc_bundle_result_from_bank_result},
itertools::izip,
solana_runtime::bank::SimulateBundleError,
solana_sdk::message::{SanitizedVersionedMessage, VersionedMessage},
};

Expand Down Expand Up @@ -3603,6 +3604,14 @@ pub mod rpc_full {
) -> Result<Vec<RpcPrioritizationFee>>;
}

fn jsonrpc_error_from_simulate_bundle_error(e: SimulateBundleError) -> Error {
match e {
SimulateBundleError::AccountNotFoundInBank(pubkey) => {
Error::invalid_params(format!("account {:?} not found in bank", pubkey))
}
}
}

pub struct FullImpl;
impl Full for FullImpl {
type Metadata = JsonRpcRequestProcessor;
Expand Down Expand Up @@ -4083,10 +4092,7 @@ pub mod rpc_full {

let bank_result = bank
.simulate_bundle(sanitized_txs, pre_execution_pks, post_execution_pks)
.map_err(|e| {
error!("bank error {}", e);
Error::internal_error()
})?;
.map_err(jsonrpc_error_from_simulate_bundle_error)?;

let rpc_bundle_result = rpc_bundle_result_from_bank_result(bank_result, config)?;

Expand Down
13 changes: 9 additions & 4 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ use {
cmp::min,
collections::{HashMap, HashSet},
convert::{TryFrom, TryInto},
error::Error,
fmt, mem,
ops::{Deref, RangeInclusive},
path::PathBuf,
Expand All @@ -171,6 +170,7 @@ use {
thread::Builder,
time::{Duration, Instant},
},
thiserror::Error,
};

/// params to `verify_bank_hash`
Expand Down Expand Up @@ -521,6 +521,12 @@ pub struct BundleSimulationResult {
pub transaction_results: Vec<BundleTransactionSimulationResult>,
}

#[derive(Error, Debug)]
pub enum SimulateBundleError {
#[error("account missing from bank: {0}")]
AccountNotFoundInBank(Pubkey),
}

#[derive(Clone)]
pub struct BundleTransactionSimulationResult {
pub result: Result<()>,
Expand Down Expand Up @@ -3848,7 +3854,7 @@ impl Bank {
bundle: Vec<SanitizedTransaction>,
pre_execution_accounts_requested: Vec<Option<Vec<Pubkey>>>,
post_execution_accounts_requested: Vec<Option<Vec<Pubkey>>>,
) -> result::Result<BundleSimulationResult, Box<dyn Error>> {
) -> result::Result<BundleSimulationResult, SimulateBundleError> {
assert_eq!(pre_execution_accounts_requested.len(), bundle.len());
assert_eq!(post_execution_accounts_requested.len(), bundle.len());

Expand Down Expand Up @@ -3918,8 +3924,7 @@ impl Bank {
Ok(data)
} else {
self.get_account(pubkey)
// TODO(seg): let's use a concrete error type
.ok_or(format!("pubkey {} does not exist", pubkey))
.ok_or(SimulateBundleError::AccountNotFoundInBank(*pubkey))
}?;
pre_accounts.push(AccountData {
pubkey: *pubkey,
Expand Down

0 comments on commit c51e137

Please sign in to comment.