Skip to content

Commit

Permalink
Skip transaction simulation on retries
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Jun 4, 2024
1 parent f9f33f9 commit 550adc2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/bin/sys-lend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,10 +1002,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
&vec![signer],
)?
};
let simulation_result = send_rpc_client.simulate_transaction(&transaction)?.value;
if simulation_result.err.is_some() {
return Err(format!("Simulation failure: {simulation_result:?}").into());
}

/*
println!(
Expand All @@ -1016,7 +1012,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
*/

let signature = transaction.signatures[0];

let msg = match cmd {
Command::Deposit => format!(
"Depositing {} from {} into {} via {}",
Expand All @@ -1040,6 +1035,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
),
};

let simulation_result = send_rpc_client.simulate_transaction(&transaction)?.value;
if simulation_result.err.is_some() {
return Err(format!("Simulation failure: {simulation_result:?}").into());
}

if !send_transaction_until_expired(
&send_rpc_client,
&transaction,
Expand Down
17 changes: 13 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@ pub fn app_version() -> String {
})
}

// Assumes `transaction` has already been signed and simulated...
pub fn send_transaction_until_expired(
rpc_client: &RpcClient,
transaction: &impl SerializableTransaction,
last_valid_block_height: u64,
) -> bool {
use std::{
thread::sleep,
time::{Duration, Instant},
use {
solana_client::rpc_config::RpcSendTransactionConfig,
std::{
thread::sleep,
time::{Duration, Instant},
},
};

let mut last_send_attempt = None;

let config = RpcSendTransactionConfig {
skip_preflight: true,
..RpcSendTransactionConfig::default()
};

loop {
if last_send_attempt.is_none()
|| Instant::now()
Expand All @@ -61,7 +70,7 @@ pub fn send_transaction_until_expired(
"Sending transaction {} [{valid_msg}]",
transaction.get_signature()
);
if let Err(err) = rpc_client.send_transaction(transaction) {
if let Err(err) = rpc_client.send_transaction_with_config(transaction, config) {
println!("Transaction failed to send: {err:?}");
}
last_send_attempt = Some(Instant::now());
Expand Down

0 comments on commit 550adc2

Please sign in to comment.