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

Separate send and confirm rpc calls into their own retry blocks #61

Merged
merged 2 commits into from
Sep 22, 2023
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
52 changes: 41 additions & 11 deletions consumer/src/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
},
state::{Creator, DataV2, EDITION, PREFIX},
};
use solana_client::rpc_client::RpcClient as SolanaRpcClient;
use solana_client::{
client_error::{ClientError, ClientErrorKind},
rpc_client::RpcClient as SolanaRpcClient,
};
use solana_program::{
instruction::Instruction, program_pack::Pack, pubkey::Pubkey,
system_instruction::create_account, system_program,
};
use solana_sdk::{
signature::Signature,
signer::{keypair::Keypair, Signer},
transaction::Transaction,
transaction::{Transaction, TransactionError},
};
use solana_transaction_status::{UiInnerInstructions, UiInstruction, UiTransactionEncoding};
use spl_account_compression::{
Expand Down Expand Up @@ -68,6 +71,9 @@
.with_min_delay(Duration::from_millis(30))
.with_max_times(10),
)
.notify(|err: &ClientError, dur: Duration| {
error!("retrying error {:?} in {:?}", err, dur);
})
.call()
}};
}
Expand Down Expand Up @@ -247,10 +253,7 @@
let signatures = transaction
.signed_message_signatures
.iter()
.map(|s| {
Signature::from_str(s)
.map_err(|e| anyhow!(format!("failed to parse signature: {e}")))
})
.map(|s| Signature::from_str(s).context("failed to parse signature"))
.collect::<Result<Vec<Signature>>>()?;

let message = bincode::deserialize(
Expand All @@ -265,13 +268,40 @@
message,
};

call_with_retry!(self.rpc().send_and_confirm_transaction(&transaction))
.map(|s| s.to_string())
.map_err(|e| {
let msg = format!("failed to submit transaction: {e}");
let signature =
call_with_retry!(self.rpc().send_transaction(&transaction)).map_err(|e| {
let msg = format!("failed to send transaction: {e}");
error!(msg);
anyhow!(msg)
})
})?;

(|| {
let status = self
.rpc()
.get_signature_status(&signature)
.map_err(|e| e.kind)?;

match status {
Some(result) => result.map_err(ClientErrorKind::TransactionError),
None => Err(TransactionError::BlockhashNotFound.into()),
}
})
.retry(
&ExponentialBuilder::default()
.with_jitter()
.with_min_delay(Duration::from_millis(10))
.with_max_times(15),
)
.when(|e| {
e.get_transaction_error() == Some(TransactionError::BlockhashNotFound)
|| e.get_transaction_error().is_none()
})
.notify(|err: &ClientErrorKind, dur: Duration| {
error!("retrying error {:?} in {:?}", err, dur);
})
.call()?;

Ok(signature.to_string())
}
}

Expand Down Expand Up @@ -376,7 +406,7 @@
true,
None,
None,
Some(mpl_token_metadata::state::CollectionDetails::V1 { size: 0 }),

Check warning on line 409 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 409 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.
);
let create_master_edition_ins = mpl_token_metadata::instruction::create_master_edition_v3(
mpl_token_metadata::ID,
Expand Down
Loading