Skip to content

Commit

Permalink
fix: update scan status for non-triggering predicates (#511)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
MicaiahReid committed Mar 27, 2024
1 parent 485394e commit 9073f42
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
28 changes: 14 additions & 14 deletions components/chainhook-cli/src/scan/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!(
Expand Down
28 changes: 14 additions & 14 deletions components/chainhook-cli/src/scan/stacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 9073f42

Please sign in to comment.