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

fix: shut down observer on bitcoin block download failure #573

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion components/chainhook-sdk/src/indexer/bitcoin/mod.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading