diff --git a/local-cluster/src/local_cluster.rs b/local-cluster/src/local_cluster.rs index d0cf25e98bb4cf..dbafe4792aec4c 100644 --- a/local-cluster/src/local_cluster.rs +++ b/local-cluster/src/local_cluster.rs @@ -63,7 +63,8 @@ use { net::{IpAddr, Ipv4Addr, UdpSocket}, path::{Path, PathBuf}, sync::{Arc, RwLock}, - time::Instant, + thread, + time::{Duration, Instant}, }, }; @@ -723,45 +724,51 @@ impl LocalCluster { .into()) } - pub fn send_transaction_and_confirm_with_retries( + pub fn send_transaction_confirm_success_with_retries( client: &QuicTpuClient, keypairs: &T, transaction: &mut Transaction, attempts: usize, ) -> std::result::Result { 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; } } @@ -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()) } @@ -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, @@ -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,