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

add config to simulate on top of working bank #211

Merged
merged 1 commit into from
Dec 6, 2022
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
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

does this simulate on top of current bank? maybe tweak comment to clarify

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it fetches the bank with the provided commitment level

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