@@ -3,15 +3,19 @@ use std::collections::{HashMap, VecDeque};
3
3
use crate :: {
4
4
archive:: download_stacks_dataset_if_required,
5
5
block:: { Record , RecordKind } ,
6
- config:: Config ,
6
+ config:: { Config , PredicatesApi , PredicatesApiConfig } ,
7
+ service:: {
8
+ open_readwrite_predicates_db_conn_or_panic, update_predicate_status, PredicateStatus ,
9
+ ScanningData ,
10
+ } ,
7
11
storage:: {
8
12
get_last_block_height_inserted, get_last_unconfirmed_block_height_inserted,
9
13
get_stacks_block_at_block_height, insert_entry_in_stacks_blocks, is_stacks_block_present,
10
14
open_readwrite_stacks_db_conn,
11
15
} ,
12
16
} ;
13
17
use chainhook_event_observer:: {
14
- chainhooks:: stacks:: evaluate_stacks_chainhook_on_blocks,
18
+ chainhooks:: { stacks:: evaluate_stacks_chainhook_on_blocks, types :: ChainhookSpecification } ,
15
19
indexer:: { self , stacks:: standardize_stacks_serialized_block_header, Indexer } ,
16
20
rocksdb:: DB ,
17
21
utils:: Context ,
@@ -140,9 +144,15 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate(
140
144
} ,
141
145
} ;
142
146
143
- let proofs = HashMap :: new ( ) ;
147
+ let mut predicates_db_conn = match config. http_api {
148
+ PredicatesApi :: On ( ref api_config) => {
149
+ Some ( open_readwrite_predicates_db_conn_or_panic ( api_config, ctx) )
150
+ }
151
+ PredicatesApi :: Off => None ,
152
+ } ;
144
153
145
- let mut actions_triggered = 0 ;
154
+ let proofs = HashMap :: new ( ) ;
155
+ let mut occurrences_found = 0 ;
146
156
let mut blocks_scanned = 0 ;
147
157
info ! (
148
158
ctx. expect_logger( ) ,
@@ -182,7 +192,7 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate(
182
192
error ! ( ctx. expect_logger( ) , "unable to handle action {}" , e) ;
183
193
}
184
194
Ok ( action) => {
185
- actions_triggered += 1 ;
195
+ occurrences_found += 1 ;
186
196
let res = match action {
187
197
StacksChainhookOccurrence :: Http ( request) => {
188
198
send_request ( request, 3 , 1 , & ctx) . await
@@ -202,6 +212,18 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate(
202
212
return Err ( format ! ( "Scan aborted (consecutive action errors >= 3)" ) ) ;
203
213
}
204
214
215
+ if let Some ( ref mut predicates_db_conn) = predicates_db_conn {
216
+ if blocks_scanned % 5000 == 0 {
217
+ let status = PredicateStatus :: Scanning ( ScanningData {
218
+ start_block,
219
+ end_block,
220
+ cursor,
221
+ occurrences_found,
222
+ } ) ;
223
+ update_predicate_status ( & predicate_spec. key ( ) , status, predicates_db_conn)
224
+ }
225
+ }
226
+
205
227
cursor += 1 ;
206
228
// Update end_block, in case a new block was discovered during the scan
207
229
if cursor == end_block {
@@ -224,9 +246,17 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate(
224
246
}
225
247
info ! (
226
248
ctx. expect_logger( ) ,
227
- "{blocks_scanned} blocks scanned, {actions_triggered} actions triggered "
249
+ "{blocks_scanned} blocks scanned, {occurrences_found} occurrences found "
228
250
) ;
229
-
251
+ let status = PredicateStatus :: Scanning ( ScanningData {
252
+ start_block,
253
+ end_block,
254
+ cursor,
255
+ occurrences_found,
256
+ } ) ;
257
+ if let Some ( ref mut predicates_db_conn) = predicates_db_conn {
258
+ update_predicate_status ( & predicate_spec. key ( ) , status, predicates_db_conn)
259
+ }
230
260
Ok ( last_block_scanned)
231
261
}
232
262
@@ -253,7 +283,7 @@ pub async fn scan_stacks_chainstate_via_csv_using_predicate(
253
283
254
284
let proofs = HashMap :: new ( ) ;
255
285
256
- let mut actions_triggered = 0 ;
286
+ let mut occurrences_found = 0 ;
257
287
let mut blocks_scanned = 0 ;
258
288
info ! (
259
289
ctx. expect_logger( ) ,
@@ -294,7 +324,7 @@ pub async fn scan_stacks_chainstate_via_csv_using_predicate(
294
324
error ! ( ctx. expect_logger( ) , "unable to handle action {}" , e) ;
295
325
}
296
326
Ok ( action) => {
297
- actions_triggered += 1 ;
327
+ occurrences_found += 1 ;
298
328
let res = match action {
299
329
StacksChainhookOccurrence :: Http ( request) => {
300
330
send_request ( request, 3 , 1 , & ctx) . await
@@ -316,7 +346,7 @@ pub async fn scan_stacks_chainstate_via_csv_using_predicate(
316
346
}
317
347
info ! (
318
348
ctx. expect_logger( ) ,
319
- "{blocks_scanned} blocks scanned, {actions_triggered} actions triggered "
349
+ "{blocks_scanned} blocks scanned, {occurrences_found} occurrences found "
320
350
) ;
321
351
322
352
Ok ( last_block_scanned)
0 commit comments