client: Start resending sooner during `send_and_confirm_transactions_in_parallel` (#348)

client: Confirm sooner during send_and_confirm_in_parallel
This commit is contained in:
Jon C 2024-03-21 14:35:09 +01:00 committed by GitHub
parent 1e08e90498
commit b2f4fb306e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 57 additions and 51 deletions

View File

@ -5,7 +5,7 @@ use {
}, },
bincode::serialize, bincode::serialize,
dashmap::DashMap, dashmap::DashMap,
futures_util::future::{join_all, TryFutureExt}, futures_util::future::{join_all, FutureExt},
solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool}, solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool},
solana_rpc_client::spinner::{self, SendTransactionProgress}, solana_rpc_client::spinner::{self, SendTransactionProgress},
solana_rpc_client_api::{ solana_rpc_client_api::{
@ -188,9 +188,7 @@ async fn send_transaction_with_rpc_fallback(
serialized_transaction: Vec<u8>, serialized_transaction: Vec<u8>,
context: &SendingContext, context: &SendingContext,
index: usize, index: usize,
counter: usize,
) -> Result<()> { ) -> Result<()> {
tokio::time::sleep(SEND_INTERVAL.saturating_mul(counter as u32)).await;
let send_over_rpc = if let Some(tpu_client) = tpu_client { let send_over_rpc = if let Some(tpu_client) = tpu_client {
!tpu_client !tpu_client
.send_wire_transaction(serialized_transaction.clone()) .send_wire_transaction(serialized_transaction.clone())
@ -261,23 +259,14 @@ async fn sign_all_messages_and_send<T: Signers + ?Sized>(
.expect("Transaction should be signable"); .expect("Transaction should be signable");
let serialized_transaction = serialize(&transaction).expect("Transaction should serialize"); let serialized_transaction = serialize(&transaction).expect("Transaction should serialize");
let signature = transaction.signatures[0]; let signature = transaction.signatures[0];
futures.push( futures.push(async move {
send_transaction_with_rpc_fallback( tokio::time::sleep(SEND_INTERVAL.saturating_mul(counter as u32)).await;
rpc_client,
tpu_client,
transaction,
serialized_transaction.clone(),
context,
*index,
counter,
)
.and_then(move |_| async move {
// send to confirm the transaction // send to confirm the transaction
context.unconfirmed_transaction_map.insert( context.unconfirmed_transaction_map.insert(
signature, signature,
TransactionData { TransactionData {
index: *index, index: *index,
serialized_transaction, serialized_transaction: serialized_transaction.clone(),
last_valid_block_height: blockhashdata.last_valid_block_height, last_valid_block_height: blockhashdata.last_valid_block_height,
message: message.clone(), message: message.clone(),
}, },
@ -296,9 +285,16 @@ async fn sign_all_messages_and_send<T: Signers + ?Sized>(
), ),
); );
} }
Ok(()) send_transaction_with_rpc_fallback(
}), rpc_client,
); tpu_client,
transaction,
serialized_transaction,
context,
*index,
)
.await
});
} }
// collect to convert Vec<Result<_>> to Result<Vec<_>> // collect to convert Vec<Result<_>> to Result<Vec<_>>
join_all(futures).await.into_iter().collect::<Result<_>>()?; join_all(futures).await.into_iter().collect::<Result<_>>()?;
@ -477,6 +473,7 @@ pub async fn send_and_confirm_transactions_in_parallel<T: Signers + ?Sized>(
// clear the map so that we can start resending // clear the map so that we can start resending
unconfirmed_transasction_map.clear(); unconfirmed_transasction_map.clear();
let futures = [
sign_all_messages_and_send( sign_all_messages_and_send(
&progress_bar, &progress_bar,
&rpc_client, &rpc_client,
@ -485,15 +482,24 @@ pub async fn send_and_confirm_transactions_in_parallel<T: Signers + ?Sized>(
signers, signers,
&context, &context,
) )
.await?; .boxed_local(),
async {
// wait until all the transactions are confirmed or expired // Give the signing and sending a head start before trying to
// confirm and resend
tokio::time::sleep(TPU_RESEND_REFRESH_RATE).await;
confirm_transactions_till_block_height_and_resend_unexpired_transaction_over_tpu( confirm_transactions_till_block_height_and_resend_unexpired_transaction_over_tpu(
&progress_bar, &progress_bar,
&tpu_client, &tpu_client,
&context, &context,
) )
.await; .await;
// Infallible, but required to have the same return type as
// `sign_all_messages_and_send`
Ok(())
}
.boxed_local(),
];
join_all(futures).await.into_iter().collect::<Result<_>>()?;
if unconfirmed_transasction_map.is_empty() { if unconfirmed_transasction_map.is_empty() {
break; break;