Skip to content

Commit 39671f4

Browse files
author
Ludo Galabru
committed
fix: re-initiate inscriptions connection every 250 blocks
1 parent 58cd9e1 commit 39671f4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

components/hord-cli/src/scan/bitcoin.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate(
7575
BlockHeights::BlockRange(start_block, end_block).get_sorted_entries()
7676
};
7777

78-
// Are we dealing with an ordinals-based predicate?
79-
// If so, we could use the ordinal storage to provide a set of hints.
8078
let mut inscriptions_db_conn = open_readonly_hord_db_conn(&config.expected_cache_path(), ctx)?;
8179

8280
info!(
@@ -96,6 +94,14 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate(
9694
while let Some(current_block_height) = block_heights_to_scan.pop_front() {
9795
number_of_blocks_scanned += 1;
9896

97+
// Re-initiate connection every 250 blocks (pessimistic) to avoid stale connections
98+
let conn_updated = if number_of_blocks_scanned % 250 == 0 {
99+
inscriptions_db_conn = open_readonly_hord_db_conn(&config.expected_cache_path(), ctx)?;
100+
true
101+
} else {
102+
false
103+
};
104+
99105
if !get_any_entry_in_ordinal_activities(&current_block_height, &inscriptions_db_conn, &ctx)
100106
{
101107
continue;
@@ -143,7 +149,7 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate(
143149

144150
info!(
145151
ctx.expect_logger(),
146-
"Processing block #{current_block_height} through {} predicate (inscriptions revealed: [{}])",
152+
"Processing block #{current_block_height} through {} predicate (inscriptions revealed: [{}], db_conn updated: {conn_updated})",
147153
predicate_spec.uuid,
148154
inscriptions_revealed.join(", ")
149155
);

0 commit comments

Comments
 (0)