Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: Start resending sooner during send_and_confirm_transactions_in_parallel #348

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 57 additions & 51 deletions client/src/send_and_confirm_transactions_in_parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
},
bincode::serialize,
dashmap::DashMap,
futures_util::future::{join_all, TryFutureExt},
futures_util::future::{join_all, FutureExt},
solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool},
solana_rpc_client::spinner::{self, SendTransactionProgress},
solana_rpc_client_api::{
Expand Down Expand Up @@ -188,9 +188,7 @@ async fn send_transaction_with_rpc_fallback(
serialized_transaction: Vec<u8>,
context: &SendingContext,
index: usize,
counter: usize,
) -> Result<()> {
tokio::time::sleep(SEND_INTERVAL.saturating_mul(counter as u32)).await;
let send_over_rpc = if let Some(tpu_client) = tpu_client {
!tpu_client
.send_wire_transaction(serialized_transaction.clone())
Expand Down Expand Up @@ -261,44 +259,42 @@ async fn sign_all_messages_and_send<T: Signers + ?Sized>(
.expect("Transaction should be signable");
let serialized_transaction = serialize(&transaction).expect("Transaction should serialize");
let signature = transaction.signatures[0];
futures.push(
futures.push(async move {
tokio::time::sleep(SEND_INTERVAL.saturating_mul(counter as u32)).await;
// send to confirm the transaction
context.unconfirmed_transaction_map.insert(
signature,
TransactionData {
index: *index,
serialized_transaction: serialized_transaction.clone(),
last_valid_block_height: blockhashdata.last_valid_block_height,
message: message.clone(),
},
);
if let Some(progress_bar) = progress_bar {
let progress = progress_from_context_and_block_height(
context,
blockhashdata.last_valid_block_height,
);
progress.set_message_for_confirmed_transactions(
progress_bar,
&format!(
"Sending {}/{} transactions",
counter + 1,
current_transaction_count,
),
);
}
send_transaction_with_rpc_fallback(
rpc_client,
tpu_client,
transaction,
serialized_transaction.clone(),
serialized_transaction,
context,
*index,
counter,
)
.and_then(move |_| async move {
// send to confirm the transaction
context.unconfirmed_transaction_map.insert(
signature,
TransactionData {
index: *index,
serialized_transaction,
last_valid_block_height: blockhashdata.last_valid_block_height,
message: message.clone(),
},
);
if let Some(progress_bar) = progress_bar {
let progress = progress_from_context_and_block_height(
context,
blockhashdata.last_valid_block_height,
);
progress.set_message_for_confirmed_transactions(
progress_bar,
&format!(
"Sending {}/{} transactions",
counter + 1,
current_transaction_count,
),
);
}
Ok(())
}),
);
.await
});
}
// collect to convert Vec<Result<_>> to Result<Vec<_>>
join_all(futures).await.into_iter().collect::<Result<_>>()?;
Expand Down Expand Up @@ -477,23 +473,33 @@ pub async fn send_and_confirm_transactions_in_parallel<T: Signers + ?Sized>(
// clear the map so that we can start resending
unconfirmed_transasction_map.clear();

sign_all_messages_and_send(
&progress_bar,
&rpc_client,
&tpu_client,
messages_with_index,
signers,
&context,
)
.await?;

// wait until all the transactions are confirmed or expired
confirm_transactions_till_block_height_and_resend_unexpired_transaction_over_tpu(
&progress_bar,
&tpu_client,
&context,
)
.await;
let futures = [
sign_all_messages_and_send(
&progress_bar,
&rpc_client,
&tpu_client,
messages_with_index,
signers,
&context,
)
.boxed_local(),
async {
// 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(
&progress_bar,
&tpu_client,
&context,
)
.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<_>>()?;
Copy link

@godmodegalactus godmodegalactus Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great, could you add some timeouts on join_all for 2 minutes = 150 blockhashes please. Sometimes CLI gets stuck.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that sometimes... do you have any idea what causes it? In my experience, I don't see the block height updating, which makes me think that something in confirm_transactions_till_block_height_... is hanging.

I'd prefer that we only abort when we know that the block height has been passed, rather than hardcoding 2 minutes. We can detach the future with tokio::spawn, loop checking is_finished() on it, and abort it if the blockhash is expired. What do you think?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good idea a Notify channel and here we break if the blockheight exceeds the last transaction blockheight or something. This should be done for all join and/or awaits.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, do you mind if I include it in a separate PR? It isn't directly related to the changes here and can be done independently

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah not at all


if unconfirmed_transasction_map.is_empty() {
break;
Expand Down
Loading