Skip to content

Commit

Permalink
fix: shut down observer on bitcoin block download failure (#573)
Browse files Browse the repository at this point in the history
Fixes #572
  • Loading branch information
MicaiahReid committed May 8, 2024
1 parent 5f20a86 commit f3530b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/chainhook-sdk/src/indexer/bitcoin/mod.rs
Expand Up @@ -153,7 +153,7 @@ pub async fn download_and_parse_block_with_retry(
ctx: &Context,
) -> Result<BitcoinBlockFullBreakdown, String> {
let mut errors_count = 0;
let max_retries = 10;
let max_retries = 20;
let block = loop {
match download_and_parse_block(http_client, block_hash, bitcoin_config, ctx).await {
Ok(result) => break result,
Expand Down
31 changes: 26 additions & 5 deletions components/chainhook-sdk/src/observer/http.rs
Expand Up @@ -58,7 +58,7 @@ pub async fn handle_new_bitcoin_block(
match download_and_parse_block_with_retry(&http_client, block_hash, bitcoin_config, ctx)
.await
{
Ok(block) => block,
Ok(block) => Some(block),
Err(e) => {
ctx.try_log(|logger| {
slog::warn!(
Expand All @@ -67,12 +67,33 @@ pub async fn handle_new_bitcoin_block(
e.to_string()
)
});
return Json(json!({
"status": 500,
"result": "unable to retrieve_full_block",
}));
None
}
};
let Some(block) = block else {
ctx.try_log(|logger| {
slog::crit!(
logger,
"Could not download bitcoin block after receiving new_burn_block. Exiting Chainhook observer."
)
});
match background_job_tx.lock() {
Ok(tx) => {
let _ = tx.send(ObserverCommand::Terminate);
}
Err(e) => {
ctx.try_log(|logger| {
slog::crit!(logger, "Could not shut down event observer: {e}")
});
std::process::exit(1)
}
}

return Json(json!({
"status": 500,
"result": "unable to retrieve_full_block",
}));
};

let header = block.get_block_header();
let block_height = header.block_identifier.index;
Expand Down

0 comments on commit f3530b7

Please sign in to comment.