Skip to content

Commit f614727

Browse files
mergify[bot]joncinque
authored andcommitted
v1.18: client: Timeout resends during send_and_confirm_in_parallel (backport of #358) (#384)
client: Timeout resends during `send_and_confirm_in_parallel` (#358) * client: Timeout resends during `send_and_confirm_in_parallel` * Clarify constant (cherry picked from commit 36c66f5) Co-authored-by: Jon C <me@jonc.dev>
1 parent a164b70 commit f614727

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

client/src/send_and_confirm_transactions_in_parallel.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use {
3131
tokio::{sync::RwLock, task::JoinHandle, time::Instant},
3232
};
3333

34-
const BLOCKHASH_REFRESH_RATE: Duration = Duration::from_secs(10);
34+
const BLOCKHASH_REFRESH_RATE: Duration = Duration::from_secs(5);
3535
const TPU_RESEND_REFRESH_RATE: Duration = Duration::from_secs(2);
3636
const SEND_INTERVAL: Duration = Duration::from_millis(10);
3737
type QuicTpuClient = TpuClient<QuicPool, QuicConnectionManager, QuicConfig>;
@@ -326,21 +326,20 @@ async fn confirm_transactions_till_block_height_and_resend_unexpired_transaction
326326
);
327327
}
328328

329+
if let Some(progress_bar) = progress_bar {
330+
let progress = progress_from_context_and_block_height(context, max_valid_block_height);
331+
progress.set_message_for_confirmed_transactions(
332+
progress_bar,
333+
"Checking transaction status...",
334+
);
335+
}
336+
329337
// wait till all transactions are confirmed or we have surpassed max processing age for the last sent transaction
330338
while !unconfirmed_transaction_map.is_empty()
331339
&& current_block_height.load(Ordering::Relaxed) <= max_valid_block_height
332340
{
333341
let block_height = current_block_height.load(Ordering::Relaxed);
334342

335-
if let Some(progress_bar) = progress_bar {
336-
let progress =
337-
progress_from_context_and_block_height(context, max_valid_block_height);
338-
progress.set_message_for_confirmed_transactions(
339-
progress_bar,
340-
"Checking transaction status...",
341-
);
342-
}
343-
344343
if let Some(tpu_client) = tpu_client {
345344
let instant = Instant::now();
346345
// retry sending transaction only over TPU port
@@ -349,10 +348,29 @@ async fn confirm_transactions_till_block_height_and_resend_unexpired_transaction
349348
.iter()
350349
.filter(|x| block_height < x.last_valid_block_height)
351350
.map(|x| x.serialized_transaction.clone())
352-
.collect();
353-
let _ = tpu_client
354-
.try_send_wire_transaction_batch(txs_to_resend_over_tpu)
355-
.await;
351+
.collect::<Vec<_>>();
352+
let num_txs_to_resend = txs_to_resend_over_tpu.len();
353+
// This is a "reasonable" constant for how long it should
354+
// take to fan the transactions out, taken from
355+
// `solana_tpu_client::nonblocking::tpu_client::send_wire_transaction_futures`
356+
const SEND_TIMEOUT_INTERVAL: Duration = Duration::from_secs(5);
357+
let message = if tokio::time::timeout(
358+
SEND_TIMEOUT_INTERVAL,
359+
tpu_client.try_send_wire_transaction_batch(txs_to_resend_over_tpu),
360+
)
361+
.await
362+
.is_err()
363+
{
364+
format!("Timed out resending {num_txs_to_resend} transactions...")
365+
} else {
366+
format!("Resent {num_txs_to_resend} transactions...")
367+
};
368+
369+
if let Some(progress_bar) = progress_bar {
370+
let progress =
371+
progress_from_context_and_block_height(context, max_valid_block_height);
372+
progress.set_message_for_confirmed_transactions(progress_bar, &message);
373+
}
356374

357375
let elapsed = instant.elapsed();
358376
if elapsed < TPU_RESEND_REFRESH_RATE {
@@ -370,14 +388,6 @@ async fn confirm_transactions_till_block_height_and_resend_unexpired_transaction
370388
max_valid_block_height = max_valid_block_height_in_remaining_transaction;
371389
}
372390
}
373-
374-
if let Some(progress_bar) = progress_bar {
375-
let progress = progress_from_context_and_block_height(context, max_valid_block_height);
376-
progress.set_message_for_confirmed_transactions(
377-
progress_bar,
378-
"Checking transaction status...",
379-
);
380-
}
381391
}
382392
}
383393

0 commit comments

Comments
 (0)