Skip to content

Commit bad1ee6

Browse files
author
Ludo Galabru
committed
fix: move parsing back to network thread
1 parent d80b1af commit bad1ee6

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

Cargo.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/chainhook-cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tar = "0.4.38"
3535
flume = "0.10.14"
3636
ansi_term = "0.12.1"
3737
atty = "0.2.14"
38-
crossbeam-channel = "0.5.6"
38+
crossbeam-channel = "0.5.8"
3939
uuid = { version = "1.3.0", features = ["v4", "fast-rng"] }
4040
threadpool = "1.8.1"
4141

components/chainhook-event-observer/src/hord/db/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use threadpool::ThreadPool;
1414

1515
use crate::{
1616
indexer::bitcoin::{
17-
download_block_with_retry, parse_downloaded_block, retrieve_block_hash_with_retry,
17+
download_block_with_retry, retrieve_block_hash_with_retry,
1818
standardize_bitcoin_block, BitcoinBlockFullBreakdown,
1919
},
2020
observer::BitcoinConfig,
@@ -786,7 +786,7 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
786786
let future =
787787
download_block_with_retry(&block_hash, &moved_bitcoin_config, &moved_ctx);
788788
let block_data = hiro_system_kit::nestable_block_on(future).unwrap();
789-
let _ = block_data_tx.send(Some(block_data));
789+
let _ = block_data_tx.send(Some((block_height, block_hash, block_data)));
790790
});
791791
}
792792
let res = retrieve_block_data_pool.join();
@@ -796,10 +796,9 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
796796

797797
let _ = hiro_system_kit::thread_named("Block data compression")
798798
.spawn(move || {
799-
while let Ok(Some(downloaded_block)) = block_data_rx.recv() {
799+
while let Ok(Some((_, _, block_data))) = block_data_rx.recv() {
800800
let block_compressed_tx_moved = block_compressed_tx.clone();
801801
compress_block_data_pool.execute(move || {
802-
let block_data = parse_downloaded_block(downloaded_block).unwrap();
803802
let compressed_block = CompactedBlock::from_full_block(&block_data);
804803
let block_index = block_data.height as u32;
805804
let _ = block_compressed_tx_moved.send(Some((

components/chainhook-event-observer/src/indexer/bitcoin/mod.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,21 @@ pub async fn download_block_with_retry(
174174
block_hash: &str,
175175
bitcoin_config: &BitcoinConfig,
176176
ctx: &Context,
177-
) -> Result<Vec<u8>, String> {
177+
) -> Result<BitcoinBlockFullBreakdown, String> {
178178
let mut errors_count = 0;
179179
let block = loop {
180180
match download_block(block_hash, bitcoin_config, ctx).await {
181-
Ok(result) => break result,
181+
Ok(result) => match parse_downloaded_block(result) {
182+
Ok(result) => break result,
183+
Err(e) => {
184+
errors_count += 1;
185+
error!(
186+
"unable to retrieve block #{block_hash} (attempt #{errors_count}): {}",
187+
e.to_string()
188+
);
189+
std::thread::sleep(std::time::Duration::from_millis(500));
190+
}
191+
},
182192
Err(e) => {
183193
errors_count += 1;
184194
error!(

0 commit comments

Comments
 (0)