diff --git a/components/chainhook-cli/src/scan/bitcoin.rs b/components/chainhook-cli/src/scan/bitcoin.rs index 84a92ced1..41ae6e365 100644 --- a/components/chainhook-cli/src/scan/bitcoin.rs +++ b/components/chainhook-cli/src/scan/bitcoin.rs @@ -98,6 +98,20 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate( let http_client = build_http_client(); while let Some(current_block_height) = block_heights_to_scan.pop_front() { + if let Some(ref mut predicates_db_conn) = predicates_db_conn { + if number_of_blocks_scanned % 10 == 0 || number_of_blocks_scanned == 0 { + set_predicate_scanning_status( + &predicate_spec.key(), + number_of_blocks_to_scan, + number_of_blocks_scanned, + number_of_times_triggered, + current_block_height, + predicates_db_conn, + ctx, + ); + } + } + if current_block_height > chain_tip { let prev_chain_tip = chain_tip; // we've scanned up to the chain tip as of the start of this scan @@ -182,20 +196,6 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate( return Err(format!("Scan aborted (consecutive action errors >= 3)")); } } - - if let Some(ref mut predicates_db_conn) = predicates_db_conn { - if number_of_blocks_scanned % 10 == 0 || number_of_blocks_scanned == 1 { - set_predicate_scanning_status( - &predicate_spec.key(), - number_of_blocks_to_scan, - number_of_blocks_scanned, - number_of_times_triggered, - current_block_height, - predicates_db_conn, - ctx, - ); - } - } } info!( diff --git a/components/chainhook-cli/src/scan/stacks.rs b/components/chainhook-cli/src/scan/stacks.rs index 583b89a32..eee8162a3 100644 --- a/components/chainhook-cli/src/scan/stacks.rs +++ b/components/chainhook-cli/src/scan/stacks.rs @@ -221,6 +221,19 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate( }; while let Some(current_block_height) = block_heights_to_scan.pop_front() { + if let Some(ref mut predicates_db_conn) = predicates_db_conn { + if number_of_blocks_scanned % 10 == 0 || number_of_blocks_scanned == 0 { + set_predicate_scanning_status( + &predicate_spec.key(), + number_of_blocks_to_scan, + number_of_blocks_scanned, + number_of_times_triggered, + current_block_height, + predicates_db_conn, + ctx, + ); + } + } if current_block_height > chain_tip { let prev_chain_tip = chain_tip; // we've scanned up to the chain tip as of the start of this scan @@ -279,6 +292,7 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate( let (hits_per_blocks, _predicates_expired) = evaluate_stacks_chainhook_on_blocks(blocks, &predicate_spec, ctx); + if hits_per_blocks.is_empty() { continue; } @@ -325,20 +339,6 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate( return Err(format!("Scan aborted (consecutive action errors >= 3)")); } } - - if let Some(ref mut predicates_db_conn) = predicates_db_conn { - if number_of_blocks_scanned % 10 == 0 || number_of_blocks_scanned == 1 { - set_predicate_scanning_status( - &predicate_spec.key(), - number_of_blocks_to_scan, - number_of_blocks_scanned, - number_of_times_triggered, - current_block_height, - predicates_db_conn, - ctx, - ); - } - } } info!( ctx.expect_logger(),