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

[executor] sequence may skip errors #5

Merged
merged 1 commit into from
Sep 19, 2024
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
15 changes: 14 additions & 1 deletion libs/solana-transaction-builder-executor/src/builder_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ async fn get_latest_blockhash(url: String) -> anyhow::Result<Hash> {
pub async fn execute_transactions_in_sequence(
transaction_executor: Arc<TransactionExecutor>,
execution_data: Vec<TransactionBuilderExecutionData>,
fail_on_first_error: bool,
) -> anyhow::Result<()> {
let sequence_length = execution_data.len();
let mut errors: Vec<String> = Vec::new();

for (index, async_transaction_builder) in execution_data.into_iter().enumerate() {
let human_index = index + 1;
let tx_uuid = &async_transaction_builder.tx_uuid;
Expand All @@ -88,11 +91,21 @@ pub async fn execute_transactions_in_sequence(
info!("Transaction {sig} {human_index}/{tx_uuid} executed successfully");
}
Err(err) => {
anyhow::bail!("Transaction {human_index}/{tx_uuid} failed: {:?}", err);
let error_msg = format!("Transaction {human_index}/{tx_uuid} failed: {:?}", err);
if fail_on_first_error {
return Err(anyhow!(error_msg));
} else {
error!("{}", error_msg);
errors.push(error_msg);
}
}
};
}

if !errors.is_empty() {
return Err(anyhow!(errors.join("\n")));
}

Ok(())
}

Expand Down
Loading