diff --git a/components/chainhook-sdk/src/indexer/bitcoin/mod.rs b/components/chainhook-sdk/src/indexer/bitcoin/mod.rs index 0ff4c393..69c88e42 100644 --- a/components/chainhook-sdk/src/indexer/bitcoin/mod.rs +++ b/components/chainhook-sdk/src/indexer/bitcoin/mod.rs @@ -153,7 +153,7 @@ pub async fn download_and_parse_block_with_retry( ctx: &Context, ) -> Result { 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, diff --git a/components/chainhook-sdk/src/observer/http.rs b/components/chainhook-sdk/src/observer/http.rs index 4687ddd0..e32cb039 100644 --- a/components/chainhook-sdk/src/observer/http.rs +++ b/components/chainhook-sdk/src/observer/http.rs @@ -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!( @@ -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;