Skip to content

Commit

Permalink
add config to simulate on top of working bank (#211)
Browse files Browse the repository at this point in the history
rm frozen bank check
  • Loading branch information
segfaultdoc authored Dec 6, 2022
1 parent 7c81a47 commit b32dd6d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
6 changes: 6 additions & 0 deletions rpc-client-api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ pub struct RpcSimulateTransactionConfig {
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum SimulationSlotConfig {
/// Simulate on top of bank with the provided commitment.
Commitment(CommitmentConfig),

/// Simulate on the provided slot's bank.
Slot(Slot),

/// Simulates on top of the RPC's highest slot's bank i.e. the working bank.
Tip,
}

impl Default for SimulationSlotConfig {
Expand Down
1 change: 1 addition & 0 deletions rpc-client/src/nonblocking/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5446,6 +5446,7 @@ impl RpcClient {
T: serde::de::DeserializeOwned,
{
let response = self.sender.send_batch(requests_and_params).await?;
debug!("response: {:?}", response);

serde_json::from_value(response).map_err(|err| ClientError {
request: None,
Expand Down
1 change: 1 addition & 0 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4036,6 +4036,7 @@ pub mod rpc_full {
SimulationSlotConfig::Slot(slot) => meta.bank_from_slot(slot).ok_or_else(|| {
Error::invalid_params(format!("bank not found for the provided slot: {}", slot))
}),
SimulationSlotConfig::Tip => Ok(meta.bank_forks.read().unwrap().working_bank()),
}?;

// TODO: Come back to this and allow unfrozen bank as long as the parent is frozen.
Expand Down
23 changes: 0 additions & 23 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3851,24 +3851,9 @@ impl Bank {
pre_execution_accounts_requested: Vec<Option<Vec<Pubkey>>>,
post_execution_accounts_requested: Vec<Option<Vec<Pubkey>>>,
) -> result::Result<BundleSimulationResult, Box<dyn Error>> {
assert!(self.is_frozen(), "simulation bank must be frozen");
assert_eq!(pre_execution_accounts_requested.len(), bundle.len());
assert_eq!(post_execution_accounts_requested.len(), bundle.len());

self.simulate_bundle_unchecked(
bundle,
pre_execution_accounts_requested,
post_execution_accounts_requested,
)
}

/// Run transactions against a bank without committing the results; does not check if the bank is frozen.
fn simulate_bundle_unchecked(
&self,
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>> {
// Used to cache account data in between batch execution iterations
let mut account_overrides = AccountOverrides::default();

Expand Down Expand Up @@ -9020,14 +9005,6 @@ pub(crate) mod tests {
assert_eq!(account, bank.get_account(&pubkey).unwrap());
}

#[test]
#[should_panic]
fn test_simulate_bundle_unfrozen_bank() {
let (genesis_config, _mint_keypair) = create_genesis_config(1_000_000);
let bank = Bank::new_for_tests(&genesis_config);
let _ = bank.simulate_bundle(vec![], vec![], vec![]);
}

#[test]
#[should_panic]
fn test_simulate_bundle_mismatched_lengths() {
Expand Down

0 comments on commit b32dd6d

Please sign in to comment.