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

Seg/fix sim #267

Merged
merged 2 commits into from
Feb 28, 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
2 changes: 2 additions & 0 deletions rpc-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 @@ -3441,6 +3441,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 @@ -3606,6 +3607,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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can inline pubkey into the template

}
}
}

pub struct FullImpl;
impl Full for FullImpl {
type Metadata = JsonRpcRequestProcessor;
Expand Down Expand Up @@ -4084,10 +4093,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 @@ -158,7 +158,6 @@ use {
cmp::min,
collections::{HashMap, HashSet},
convert::{TryFrom, TryInto},
error::Error,
fmt, mem,
ops::{Deref, RangeInclusive},
path::PathBuf,
Expand All @@ -174,6 +173,7 @@ use {
thread::Builder,
time::{Duration, Instant},
},
thiserror::Error,
};

/// params to `verify_bank_hash`
Expand Down Expand Up @@ -523,6 +523,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 @@ -3850,7 +3856,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 @@ -3920,8 +3926,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