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

Backfill Release 10/29 #94

Merged
merged 11 commits into from
Oct 24, 2023
80 changes: 57 additions & 23 deletions consumer/src/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
nonblocking::rpc_client::RpcClient as SolanaRpcClient,
rpc_client::SerializableTransaction,
rpc_config::RpcSendTransactionConfig,
rpc_request::RpcError,

Check warning on line 33 in consumer/src/solana.rs

View workflow job for this annotation

GitHub Actions / Cargo Test

unused import: `rpc_request::RpcError`

Check warning on line 33 in consumer/src/solana.rs

View workflow job for this annotation

GitHub Actions / Cargo Test

unused import: `rpc_request::RpcError`

Check warning on line 33 in consumer/src/solana.rs

View workflow job for this annotation

GitHub Actions / clippy/check/doc

unused import: `rpc_request::RpcError`

Check warning on line 33 in consumer/src/solana.rs

View workflow job for this annotation

GitHub Actions / clippy/check/doc

unused import: `rpc_request::RpcError`
};
use solana_program::{
instruction::Instruction, program_pack::Pack, pubkey::Pubkey,
Expand Down Expand Up @@ -215,11 +215,27 @@
&self,
signature: &Signature,
) -> Result<u32, SolanaAssetIdError> {
let response = with_retry!(
let response = (|| async {
self.rpc()
.get_transaction(signature, UiTransactionEncoding::Json)
.await
})
.retry(
&ExponentialBuilder::default()
.with_jitter()
.with_factor(1.5)
.with_min_delay(Duration::from_secs(2))
.with_max_delay(Duration::from_secs(5))
.with_max_times(20),
)
.await?;
.notify(|err: &ClientError, dur: Duration| {
error!("retrying error {:?} in {:?}", err, dur);
})
.await
.map_err(|e| {
error!("failed to get transaction for signature {:?}", signature);
e
})?;

let meta = response
.transaction
Expand Down Expand Up @@ -281,21 +297,31 @@
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)
})?;
.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}");
error!(msg);
anyhow!(msg)
})?;

let recent_blockhash = transaction.get_recent_blockhash();

Expand All @@ -307,17 +333,17 @@
None => {
let valid_blockhash = self
.rpc()
.is_blockhash_valid(recent_blockhash, CommitmentConfig::processed())
.is_blockhash_valid(recent_blockhash, CommitmentConfig::finalized())
.await?;

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}");
Expand Down Expand Up @@ -433,7 +459,7 @@
true,
None,
None,
Some(mpl_token_metadata::state::CollectionDetails::V1 { size: 0 }),

Check warning on line 462 in consumer/src/solana.rs

View workflow job for this annotation

GitHub Actions / Cargo Test

use of deprecated variant `mpl_token_metadata::state::CollectionDetails::V1`: The collection size tracking feature is deprecated and will soon be removed.

Check warning on line 462 in consumer/src/solana.rs

View workflow job for this annotation

GitHub Actions / Cargo Test

use of deprecated variant `mpl_token_metadata::state::CollectionDetails::V1`: The collection size tracking feature is deprecated and will soon be removed.

Check warning on line 462 in consumer/src/solana.rs

View workflow job for this annotation

GitHub Actions / clippy/check/doc

use of deprecated variant `mpl_token_metadata::state::CollectionDetails::V1`: The collection size tracking feature is deprecated and will soon be removed.

Check warning on line 462 in consumer/src/solana.rs

View workflow job for this annotation

GitHub Actions / clippy/check/doc

use of deprecated variant `mpl_token_metadata::state::CollectionDetails::V1`: The collection size tracking feature is deprecated and will soon be removed.
);
let create_master_edition_ins = mpl_token_metadata::instruction::create_master_edition_v3(
mpl_token_metadata::ID,
Expand Down Expand Up @@ -842,7 +868,11 @@
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 @@ -1131,8 +1161,12 @@
.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
Loading