Skip to content

Commit

Permalink
fix simulate_bundle client and better error handling (#267) (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
segfaultdoc authored Feb 28, 2023
1 parent e5e34ea commit 9c7999a
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 @@ -1455,6 +1455,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 @@ -3397,6 +3397,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,
};

#[rpc]
Expand Down Expand Up @@ -3547,6 +3548,14 @@ pub mod rpc_full {
) -> Result<RpcResponse<Option<u64>>>;
}

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 @@ -4028,10 +4037,7 @@ pub mod rpc_full {
// TODO (LB): fix simulate_bundle
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 @@ -151,7 +151,6 @@ use {
cmp::min,
collections::{HashMap, HashSet},
convert::{TryFrom, TryInto},
error::Error,
fmt, mem,
ops::{Div, RangeInclusive},
path::PathBuf,
Expand All @@ -167,6 +166,7 @@ use {
},
time::{Duration, Instant},
},
thiserror::Error,
};

#[derive(Debug, Default)]
Expand Down Expand Up @@ -756,6 +756,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 @@ -3702,7 +3708,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 @@ -3771,8 +3777,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((*pubkey, data));
}
Expand Down

0 comments on commit 9c7999a

Please sign in to comment.