Skip to content

Commit

Permalink
log and return error for retrieve block hash
Browse files Browse the repository at this point in the history
  • Loading branch information
MicaiahReid committed Mar 14, 2024
1 parent 7753e0e commit 86a03ad
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/chainhook-sdk/src/indexer/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,21 @@ pub async fn retrieve_block_hash_with_retry(
ctx: &Context,
) -> Result<String, String> {
let mut errors_count = 0;
let max_retries = 10;
let block_hash = loop {
match retrieve_block_hash(http_client, block_height, bitcoin_config, ctx).await {
Ok(result) => break result,
Err(_e) => {
Err(e) => {
errors_count += 1;
if errors_count > 3 {
if errors_count > 3 && errors_count < max_retries {
ctx.try_log(|logger| {
slog::warn!(
logger,
"unable to retrieve block hash #{block_height}: will retry in a few seconds (attempt #{errors_count}).",
"unable to retrieve block hash #{block_height}: will retry in a few seconds (attempt #{errors_count}). Error: {e}",
)
});
} else if errors_count == max_retries {
return Err(format!("unable to retrieve block hash #{block_height} after {errors_count} attempts. Error: {e}"));
}
std::thread::sleep(std::time::Duration::from_secs(2));
}
Expand Down

0 comments on commit 86a03ad

Please sign in to comment.