From 9073f42285605ed7625039b3aae2316949dfc127 Mon Sep 17 00:00:00 2001 From: Micaiah Reid Date: Mon, 18 Mar 2024 11:14:31 -0400 Subject: [PATCH] fix: update scan status for non-triggering predicates (#511) ### Description Previously, we would only update the scanning status every 10 blocks _if_ the block we just scanned had a trigger. This leads to users not getting status updates on the predicates that don't trigger often. Now, we update status every 10 blocks that we scan. This could lead to some noisy logs, so it should possibly be shipped with #498 --- components/chainhook-cli/src/scan/bitcoin.rs | 28 ++++++++++---------- components/chainhook-cli/src/scan/stacks.rs | 28 ++++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) 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(),