Skip to content

Commit

Permalink
Merge pull request #92 from holaplex/abdul/finalized-commitment
Browse files Browse the repository at this point in the history
Set commitment level to finalized for is_valid_blockhash rpc call
  • Loading branch information
imabdulbasit authored Oct 19, 2023
2 parents aeab2f7 + f427683 commit 3d8e4dc
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions consumer/src/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -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();

Expand All @@ -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 {
Expand Down Expand Up @@ -854,7 +858,11 @@ impl<'a> MintBackend<MintMetaplexEditionTransaction, MintEditionAddresses> 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,
Expand Down Expand Up @@ -1143,8 +1151,12 @@ impl<'a> MintBackend<MintMetaplexMetadataTransaction, MintCompressedMintV1Addres
.data(),
}];

let blockhash =
blockhash.unwrap_or(with_retry!(self.0.rpc_client.get_latest_blockhash()).await?);
let blockhash = if let Some(blockhash) = blockhash {
blockhash
} else {
with_retry!(self.0.rpc().get_latest_blockhash()).await?
};

let serialized_message = solana_program::message::Message::new_with_blockhash(
&instructions,
Some(&payer),
Expand Down

0 comments on commit 3d8e4dc

Please sign in to comment.