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

getblocks retry 5 times on "Block not found on disk" before giving up #118

Closed
wants to merge 2 commits into from
Closed
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
29 changes: 26 additions & 3 deletions src/new_index/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bitcoin::consensus::encode::{deserialize, Decodable};
#[cfg(feature = "liquid")]
use elements::encode::{deserialize, Decodable};

use core::panic;
use std::collections::HashMap;
use std::fs;
use std::io::Cursor;
Expand Down Expand Up @@ -82,9 +83,31 @@ fn bitcoind_fetcher(
spawn_thread("bitcoind_fetcher", move || {
for entries in new_headers.chunks(100) {
let blockhashes: Vec<BlockHash> = entries.iter().map(|e| *e.hash()).collect();
let blocks = daemon
.getblocks(&blockhashes)
.expect("failed to get blocks from bitcoind");

let mut attempts = 5;
let blocks = loop {
attempts -= 1;

match daemon.getblocks(&blockhashes) {
Ok(blocks) => break blocks,
Err(e) => {
let err_msg = format!("{e:?}");
if err_msg.contains("Block not found on disk") {
// There is a small chance the node returns the header but didn't finish to index the block
log::warn!(
"getblocks failing with: {e:?} trying {attempts} more time"
)
} else {
panic!("failed to get blocks from bitcoind: {}", err_msg);
}
}
}
if attempts == 0 {
panic!("failed to get blocks from bitcoind")
}
thread::sleep(std::time::Duration::from_secs(1));
};

assert_eq!(blocks.len(), entries.len());
let block_entries: Vec<BlockEntry> = blocks
.into_iter()
Expand Down
Loading