Skip to content

Commit 2b51dca

Browse files
author
Ludo Galabru
committed
fix: track interrupted scans
1 parent 87c409e commit 2b51dca

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

components/chainhook-cli/src/service/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ impl Service {
337337
pub enum PredicateStatus {
338338
Scanning(ScanningData),
339339
Streaming(StreamingData),
340+
Interrupted(String),
340341
Disabled,
341342
}
342343

components/chainhook-cli/src/service/runloops.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use chainhook_event_observer::{
1010
use threadpool::ThreadPool;
1111

1212
use crate::{
13-
config::Config,
13+
config::{Config, PredicatesApi},
1414
scan::{
1515
bitcoin::scan_bitcoin_chainstate_via_rpc_using_predicate,
1616
stacks::scan_stacks_chainstate_via_rocksdb_using_predicate,
1717
},
18-
storage::open_readonly_stacks_db_conn,
18+
storage::open_readonly_stacks_db_conn, service::{PredicateStatus, update_predicate_status, open_readwrite_predicates_db_conn_or_panic},
1919
};
2020

2121
pub fn start_stacks_scan_runloop(
@@ -50,13 +50,22 @@ pub fn start_stacks_scan_runloop(
5050
&moved_config,
5151
&moved_ctx,
5252
);
53-
let last_block_scanned = match hiro_system_kit::nestable_block_on(op) {
53+
let res = hiro_system_kit::nestable_block_on(op);
54+
let last_block_scanned = match res {
5455
Ok(last_block_scanned) => last_block_scanned,
5556
Err(e) => {
5657
error!(
5758
moved_ctx.expect_logger(),
5859
"Unable to evaluate predicate on Stacks chainstate: {e}",
5960
);
61+
62+
// Update predicate status in redis
63+
if let PredicatesApi::On(ref api_config) = moved_config.http_api {
64+
let status = PredicateStatus::Interrupted("Unable to evaluate predicate on Stacks chainstate: {e}".to_string());
65+
let mut predicates_db_conn = open_readwrite_predicates_db_conn_or_panic(api_config, &moved_ctx);
66+
update_predicate_status(&predicate_spec.key(), status, &mut predicates_db_conn, &moved_ctx);
67+
}
68+
6069
return;
6170
}
6271
};

0 commit comments

Comments
 (0)