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

[cli] idl_write to wait for buffer being finished #3020

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
22 changes: 20 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ use std::path::{Path, PathBuf};
use std::process::{Child, Stdio};
use std::str::FromStr;
use std::string::ToString;
use std::thread::sleep;
use std::time::Duration;
use tar::Archive;

mod checks;
Expand Down Expand Up @@ -2600,9 +2602,9 @@ fn idl_write(
while offset < idl_data.len() {
println!("Step {offset}/{} ", idl_data.len());
// Instruction data.
let end = std::cmp::min(offset + MAX_WRITE_SIZE, idl_data.len());
let data = {
let start = offset;
let end = std::cmp::min(offset + MAX_WRITE_SIZE, idl_data.len());
serialize_idl_ix(anchor_lang::idl::IdlInstruction::Write {
data: idl_data[start..end].to_vec(),
})?
Expand Down Expand Up @@ -2639,7 +2641,23 @@ fn idl_write(
if retries == 19 {
return Err(anyhow!("Error: {e}. Failed to send transaction."));
}
println!("Error: {e}. Retrying transaction.");
// maybe the transaction has been finalized, but we haven't seen it yet
let sleep_time = 16;
println!("Error: {e}, but let's wait for {sleep_time} seconds and see...");
sleep(Duration::from_secs(sleep_time));
let idl_account = get_idl_account(&client, &idl_address)?;
if idl_account.data_len.saturating_sub(1) >= end as u32 {
println!(
"IDL already written for step {}, end bytes: {}",
offset, end
);
break;
} else {
println!(
"Error: {:?}. Retrying transaction (step {}, end {}, data_len {})",
e, offset, end, idl_account.data_len
);
}
}
}
}
Expand Down
Loading