From 3834032d8e7b6550e63244886224106143ef65e3 Mon Sep 17 00:00:00 2001 From: imabdulbasit Date: Wed, 18 Oct 2023 22:53:17 +0500 Subject: [PATCH 1/5] adjust retries for compression nonce --- consumer/src/solana.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/consumer/src/solana.rs b/consumer/src/solana.rs index 768085c..8479946 100644 --- a/consumer/src/solana.rs +++ b/consumer/src/solana.rs @@ -215,10 +215,21 @@ impl Solana { &self, signature: &Signature, ) -> Result { - let response = with_retry!( + let response = (|| async { self.rpc() .get_transaction(signature, UiTransactionEncoding::Json) + .await + }) + .retry( + &ExponentialBuilder::default() + .with_jitter() + .with_min_delay(Duration::from_millis(300)) + .with_max_delay(Duration::from_secs(2)) + .with_max_times(25), ) + .notify(|err: &ClientError, dur: Duration| { + error!("retrying error {:?} in {:?}", err, dur); + }) .await?; let meta = response From d0b440e5894e6fd55ddcb668d72c6b67546ee8ae Mon Sep 17 00:00:00 2001 From: imabdulbasit Date: Thu, 19 Oct 2023 00:43:04 +0500 Subject: [PATCH 2/5] adjust delay time for rpc call to extract nonce --- consumer/src/solana.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/consumer/src/solana.rs b/consumer/src/solana.rs index 8479946..4606830 100644 --- a/consumer/src/solana.rs +++ b/consumer/src/solana.rs @@ -223,9 +223,10 @@ impl Solana { .retry( &ExponentialBuilder::default() .with_jitter() - .with_min_delay(Duration::from_millis(300)) - .with_max_delay(Duration::from_secs(2)) - .with_max_times(25), + .with_factor(1.5) + .with_min_delay(Duration::from_millis(1500)) + .with_max_delay(Duration::from_secs(3)) + .with_max_times(20), ) .notify(|err: &ClientError, dur: Duration| { error!("retrying error {:?} in {:?}", err, dur); From f427683d2c471a5f008a9efed0c1dcd9662ed888 Mon Sep 17 00:00:00 2001 From: imabdulbasit Date: Thu, 19 Oct 2023 16:11:50 +0500 Subject: [PATCH 3/5] Change commitment level to finalized for is_blockhash_valid call --- consumer/src/solana.rs | 50 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/consumer/src/solana.rs b/consumer/src/solana.rs index 4606830..7e58faa 100644 --- a/consumer/src/solana.rs +++ b/consumer/src/solana.rs @@ -224,8 +224,8 @@ impl Solana { &ExponentialBuilder::default() .with_jitter() .with_factor(1.5) - .with_min_delay(Duration::from_millis(1500)) - .with_max_delay(Duration::from_secs(3)) + .with_min_delay(Duration::from_secs(2)) + .with_max_delay(Duration::from_secs(5)) .with_max_times(20), ) .notify(|err: &ClientError, dur: Duration| { @@ -293,21 +293,25 @@ impl Solana { message, }; - let signature = with_retry!(self.rpc().send_transaction_with_config(&transaction, RpcSendTransactionConfig { - skip_preflight: true, ..Default::default() - })) + let signature = with_retry!(self.rpc().send_transaction_with_config( + &transaction, + RpcSendTransactionConfig { + skip_preflight: true, + ..Default::default() + } + )) .when(|e| { - !matches!(e.kind, ClientErrorKind::TransactionError(_) | ClientErrorKind::SigningError(_)| ClientErrorKind::RpcError(RpcError::RpcResponseError { - data: solana_client::rpc_request::RpcResponseErrorData::SendTransactionPreflightFailure(_), - .. - })) + !matches!( + e.kind, + ClientErrorKind::TransactionError(_) | ClientErrorKind::SigningError(_) + ) }) - .await - .map_err(|e| { - let msg = format!("failed to send transaction: {e}"); - error!(msg); - anyhow!(msg) - })?; + .await + .map_err(|e| { + let msg = format!("failed to send transaction: {e}"); + error!(msg); + anyhow!(msg) + })?; let recent_blockhash = transaction.get_recent_blockhash(); @@ -319,7 +323,7 @@ impl Solana { None => { let valid_blockhash = self .rpc() - .is_blockhash_valid(recent_blockhash, CommitmentConfig::processed()) + .is_blockhash_valid(recent_blockhash, CommitmentConfig::finalized()) .await?; if valid_blockhash { @@ -854,7 +858,11 @@ impl<'a> MintBackend for E edition, )); - let blockhash = blockhash.unwrap_or(with_retry!(rpc.get_latest_blockhash()).await?); + let blockhash = if let Some(blockhash) = blockhash { + blockhash + } else { + with_retry!(rpc.get_latest_blockhash()).await? + }; let message = solana_program::message::Message::new_with_blockhash( &instructions, @@ -1143,8 +1151,12 @@ impl<'a> MintBackend Date: Thu, 19 Oct 2023 17:18:32 +0500 Subject: [PATCH 4/5] error log for send transaction failure when retrying --- consumer/src/solana.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/consumer/src/solana.rs b/consumer/src/solana.rs index 7e58faa..a1ecbee 100644 --- a/consumer/src/solana.rs +++ b/consumer/src/solana.rs @@ -306,6 +306,12 @@ impl Solana { ClientErrorKind::TransactionError(_) | ClientErrorKind::SigningError(_) ) }) + .notify(|err: &ClientError, dur: Duration| { + error!( + "failed to send transaction retrying error {:?} in {:?}", + err, dur + ); + }) .await .map_err(|e| { let msg = format!("failed to send transaction: {e}"); From 6208124511c0a30d04c8d8f9b79e1c4d34ac3f96 Mon Sep 17 00:00:00 2001 From: imabdulbasit Date: Tue, 24 Oct 2023 17:31:25 +0500 Subject: [PATCH 5/5] err log to output signature for failed get transaction call --- consumer/src/solana.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/consumer/src/solana.rs b/consumer/src/solana.rs index a1ecbee..69d2f06 100644 --- a/consumer/src/solana.rs +++ b/consumer/src/solana.rs @@ -231,7 +231,11 @@ impl Solana { .notify(|err: &ClientError, dur: Duration| { error!("retrying error {:?} in {:?}", err, dur); }) - .await?; + .await + .map_err(|e| { + error!("failed to get transaction for signature {:?}", signature); + e + })?; let meta = response .transaction @@ -335,11 +339,11 @@ impl Solana { if valid_blockhash { tokio::time::sleep(std::time::Duration::from_millis(250)).await; continue; - } else { - let msg = format!("blockhash is invalid: {recent_blockhash}"); - error!(msg); - bail!(msg) } + + let msg = format!("blockhash is invalid: {recent_blockhash}"); + error!(msg); + bail!(msg) }, Some(Err(e)) => { let msg = format!("failed to send transaction: {e}");