Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bw-solana committed Nov 5, 2024
1 parent b53051a commit fb9849f
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions local-cluster/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ use {
net::{IpAddr, Ipv4Addr, UdpSocket},
path::{Path, PathBuf},
sync::{Arc, RwLock},
time::Instant,
thread,
time::{Duration, Instant},
},
};

Expand Down Expand Up @@ -723,45 +724,51 @@ impl LocalCluster {
.into())
}

pub fn send_transaction_and_confirm_with_retries<T: Signers + ?Sized>(
pub fn send_transaction_confirm_success_with_retries<T: Signers + ?Sized>(
client: &QuicTpuClient,
keypairs: &T,
transaction: &mut Transaction,
attempts: usize,
) -> std::result::Result<Signature, TransportError> {
for attempt in 0..attempts {
// Send the transaction to the upcoming leaders
// Send the transaction to the upcoming leaders.
client.send_transaction_to_upcoming_leaders(transaction)?;

// Check for signature confirmation
// Check for successful transaction confirmation.
let signature = &transaction.signatures[0];
let now = Instant::now();
loop {
// Get the transaction signature status.
let Ok(signature_status) = client.rpc_client().get_signature_status(signature)
else {
error!("failed to get tx signature status");
if now.elapsed().as_secs() > MAX_PROCESSING_AGE as u64 {
warn!("attempt {attempt} timed out waiting for tx signature");
break;
}
continue;
};

let tx_status = match signature_status {
Some(tx_status) => tx_status,
None => {
trace!("tx signature not found");
if now.elapsed().as_secs() > MAX_PROCESSING_AGE as u64 {
error!("attempt {attempt} timed out waiting for tx signature");
break;
}
continue;
// Check if transaction has landed in a block.
let Some(tx_status) = signature_status else {
trace!("tx signature not found");
if now.elapsed().as_secs() > MAX_PROCESSING_AGE as u64 {
warn!("attempt {attempt} timed out waiting for tx signature");
break;
}
// Wait a little to give the tx a chance to get included.
thread::sleep(Duration::from_millis(100));
continue;
};

// Check if the transaction was successful.
match tx_status {
Ok(_) => {
info!("tx signature confirmed");
return Ok(*signature);
}
Err(err) => {
error!("tx signature error: {err}");
error!("attempt {attempt} tx signature error: {err}");
break;
}
}
Expand All @@ -773,7 +780,7 @@ impl LocalCluster {
}
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"failed to confirm transaction".to_string(),
"failed to confirm transaction with success".to_string(),
)
.into())
}
Expand Down Expand Up @@ -857,7 +864,7 @@ impl LocalCluster {
.unwrap()
.0,
);
LocalCluster::send_transaction_and_confirm_with_retries(
LocalCluster::send_transaction_confirm_success_with_retries(
client,
&[from_account],
&mut transaction,
Expand Down Expand Up @@ -892,7 +899,7 @@ impl LocalCluster {
.0,
);

LocalCluster::send_transaction_and_confirm_with_retries(
LocalCluster::send_transaction_confirm_success_with_retries(
client,
&[from_account.as_ref(), &stake_account_keypair],
&mut transaction,
Expand Down

0 comments on commit fb9849f

Please sign in to comment.