From 272c86835a3be1dd6af3289c5a69dc4f9a920bd2 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Wed, 25 Sep 2024 14:24:46 +0200 Subject: [PATCH] getblocks retry 5 times before giving up --- src/new_index/fetch.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/new_index/fetch.rs b/src/new_index/fetch.rs index d7637ee5..f0516045 100644 --- a/src/new_index/fetch.rs +++ b/src/new_index/fetch.rs @@ -82,9 +82,24 @@ fn bitcoind_fetcher( spawn_thread("bitcoind_fetcher", move || { for entries in new_headers.chunks(100) { let blockhashes: Vec = 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) => { + // 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") + } + } + 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 = blocks .into_iter()