Skip to content

Commit d4128aa

Browse files
author
Ludo Galabru
committed
fix: off-by-one error in backward traversal
1 parent 27f6838 commit d4128aa

File tree

1 file changed

+6
-3
lines changed
  • components/chainhook-event-observer/src/hord/db

1 file changed

+6
-3
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ pub fn find_inscriptions_at_wached_outpoint(
426426
.prepare("SELECT inscription_id, inscription_number, ordinal_number, offset FROM inscriptions WHERE outpoint_to_watch = ? ORDER BY offset ASC")
427427
.map_err(|e| format!("unable to query inscriptions table: {}", e.to_string()))?;
428428
let mut results = vec![];
429-
let mut rows = stmt.query(args)
429+
let mut rows = stmt
430+
.query(args)
430431
.map_err(|e| format!("unable to query inscriptions table: {}", e.to_string()))?;
431432
while let Ok(Some(row)) = rows.next() {
432433
let inscription_id: String = row.get(0).unwrap();
@@ -537,6 +538,7 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
537538
let compress_block_data_pool = ThreadPool::new(16);
538539
let (block_compressed_tx, block_compressed_rx) = crossbeam_channel::bounded(32);
539540

541+
// Thread pool #1: given a block height, retrieve the block hash
540542
for block_cursor in start_block..=end_block {
541543
let block_height = block_cursor.clone();
542544
let block_hash_tx = block_hash_tx.clone();
@@ -549,6 +551,7 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
549551
})
550552
}
551553

554+
// Thread pool #2: given a block hash, retrieve the full block (verbosity max, including prevout)
552555
let bitcoin_network = bitcoin_config.network.clone();
553556
let bitcoin_config = bitcoin_config.clone();
554557
let moved_ctx = ctx.clone();
@@ -597,7 +600,7 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
597600
.expect("unable to spawn thread");
598601

599602
let mut blocks_stored = 0;
600-
let mut cursor = 1 + find_latest_compacted_block_known(&rw_hord_db_conn) as usize;
603+
let mut cursor = 1 + start_block as usize;
601604
let mut inbox = HashMap::new();
602605

603606
while let Ok(Some((block_height, compacted_block, raw_block))) = block_compressed_rx.recv() {
@@ -816,7 +819,7 @@ pub fn retrieve_satoshi_point_using_local_storage(
816819
// )
817820
// });
818821

819-
if sats_in >= sats_out {
822+
if sats_out < sats_in {
820823
ordinal_offset = sats_out - (sats_in - txin_value);
821824
ordinal_block_number = block_height;
822825

0 commit comments

Comments
 (0)