|
@@ -2331,8 +2331,11 @@ fn idl_set_buffer(
|
|
|
let instructions = prepend_compute_unit_ix(vec![ix], &client, priority_fee)?;
|
|
|
|
|
|
// Send the transaction.
|
|
|
- for retry_transactions in 0..20 {
|
|
|
- let latest_hash = client.get_latest_blockhash()?;
|
|
|
+ let mut latest_hash = client.get_latest_blockhash()?;
|
|
|
+ for retries in 0..20 {
|
|
|
+ if !client.is_blockhash_valid(&latest_hash, client.commitment())? {
|
|
|
+ latest_hash = client.get_latest_blockhash()?;
|
|
|
+ }
|
|
|
let tx = Transaction::new_signed_with_payer(
|
|
|
&instructions,
|
|
|
Some(&keypair.pubkey()),
|
|
@@ -2343,7 +2346,7 @@ fn idl_set_buffer(
|
|
|
match client.send_and_confirm_transaction_with_spinner(&tx) {
|
|
|
Ok(_) => break,
|
|
|
Err(e) => {
|
|
|
- if retry_transactions == 19 {
|
|
|
+ if retries == 19 {
|
|
|
return Err(anyhow!("Error: {e}. Failed to send transaction."));
|
|
|
}
|
|
|
println!("Error: {e}. Retrying transaction.");
|
|
@@ -2591,8 +2594,11 @@ fn idl_write(
|
|
|
// Send transaction.
|
|
|
let instructions = prepend_compute_unit_ix(vec![ix], &client, priority_fee)?;
|
|
|
|
|
|
- for retry_transactions in 0..20 {
|
|
|
- let latest_hash = client.get_latest_blockhash()?;
|
|
|
+ let mut latest_hash = client.get_latest_blockhash()?;
|
|
|
+ for retries in 0..20 {
|
|
|
+ if !client.is_blockhash_valid(&latest_hash, client.commitment())? {
|
|
|
+ latest_hash = client.get_latest_blockhash()?;
|
|
|
+ }
|
|
|
let tx = Transaction::new_signed_with_payer(
|
|
|
&instructions,
|
|
|
Some(&keypair.pubkey()),
|
|
@@ -2603,7 +2609,7 @@ fn idl_write(
|
|
|
match client.send_and_confirm_transaction_with_spinner(&tx) {
|
|
|
Ok(_) => break,
|
|
|
Err(e) => {
|
|
|
- if retry_transactions == 19 {
|
|
|
+ if retries == 19 {
|
|
|
return Err(anyhow!("Error: {e}. Failed to send transaction."));
|
|
|
}
|
|
|
println!("Error: {e}. Retrying transaction.");
|
|
@@ -3779,16 +3785,31 @@ fn create_idl_account(
|
|
|
data,
|
|
|
});
|
|
|
}
|
|
|
- let latest_hash = client.get_latest_blockhash()?;
|
|
|
instructions = prepend_compute_unit_ix(instructions, &client, priority_fee)?;
|
|
|
|
|
|
- let tx = Transaction::new_signed_with_payer(
|
|
|
- &instructions,
|
|
|
- Some(&keypair.pubkey()),
|
|
|
- &[&keypair],
|
|
|
- latest_hash,
|
|
|
- );
|
|
|
- client.send_and_confirm_transaction_with_spinner(&tx)?;
|
|
|
+ let mut latest_hash = client.get_latest_blockhash()?;
|
|
|
+ for retries in 0..20 {
|
|
|
+ if !client.is_blockhash_valid(&latest_hash, client.commitment())? {
|
|
|
+ latest_hash = client.get_latest_blockhash()?;
|
|
|
+ }
|
|
|
+
|
|
|
+ let tx = Transaction::new_signed_with_payer(
|
|
|
+ &instructions,
|
|
|
+ Some(&keypair.pubkey()),
|
|
|
+ &[&keypair],
|
|
|
+ latest_hash,
|
|
|
+ );
|
|
|
+
|
|
|
+ match client.send_and_confirm_transaction_with_spinner(&tx) {
|
|
|
+ Ok(_) => break,
|
|
|
+ Err(err) => {
|
|
|
+ if retries == 19 {
|
|
|
+ return Err(anyhow!("Error creating IDL account: {}", err));
|
|
|
+ }
|
|
|
+ println!("Error creating IDL account: {}. Retrying...", err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Write directly to the IDL account buffer.
|
|
@@ -3851,8 +3872,11 @@ fn create_idl_buffer(
|
|
|
priority_fee,
|
|
|
)?;
|
|
|
|
|
|
- for retries in 0..5 {
|
|
|
- let latest_hash = client.get_latest_blockhash()?;
|
|
|
+ let mut latest_hash = client.get_latest_blockhash()?;
|
|
|
+ for retries in 0..20 {
|
|
|
+ if !client.is_blockhash_valid(&latest_hash, client.commitment())? {
|
|
|
+ latest_hash = client.get_latest_blockhash()?;
|
|
|
+ }
|
|
|
let tx = Transaction::new_signed_with_payer(
|
|
|
&instructions,
|
|
|
Some(&keypair.pubkey()),
|
|
@@ -3862,7 +3886,7 @@ fn create_idl_buffer(
|
|
|
match client.send_and_confirm_transaction_with_spinner(&tx) {
|
|
|
Ok(_) => break,
|
|
|
Err(err) => {
|
|
|
- if retries == 4 {
|
|
|
+ if retries == 19 {
|
|
|
return Err(anyhow!("Error creating buffer account: {}", err));
|
|
|
}
|
|
|
println!("Error creating buffer account: {}. Retrying...", err);
|
|
@@ -4517,7 +4541,8 @@ fn get_recommended_micro_lamport_fee(client: &RpcClient, priority_fee: Option<u6
|
|
|
|
|
|
Ok(median_priority_fee)
|
|
|
}
|
|
|
-
|
|
|
+/// Prepend a compute unit ix, if the priority fee is greater than 0.
|
|
|
+/// This helps to improve the chances that the transaction will land.
|
|
|
fn prepend_compute_unit_ix(
|
|
|
instructions: Vec<Instruction>,
|
|
|
client: &RpcClient,
|