@@ -35,6 +35,7 @@ use crate::db::{drop_block_data_from_all_dbs, open_all_dbs_rw};
35
35
use crate :: scan:: bitcoin:: process_block_with_predicates;
36
36
use crate :: service:: observers:: create_and_consolidate_chainhook_config_with_predicates;
37
37
use crate :: service:: runloops:: start_bitcoin_scan_runloop;
38
+ use crate :: utils:: bitcoind:: bitcoind_wait_for_chain_tip;
38
39
use crate :: utils:: monitoring:: { start_serving_prometheus_metrics, PrometheusMonitoring } ;
39
40
use crate :: { try_debug, try_error, try_info} ;
40
41
use chainhook_sdk:: chainhooks:: bitcoin:: BitcoinChainhookOccurrencePayload ;
@@ -404,6 +405,7 @@ impl Service {
404
405
}
405
406
406
407
pub async fn check_blocks_db_integrity ( & mut self ) -> Result < ( ) , String > {
408
+ bitcoind_wait_for_chain_tip ( & self . config , & self . ctx ) ;
407
409
let ( tip, missing_blocks) = {
408
410
let blocks_db = open_blocks_db_with_retry ( false , & self . config , & self . ctx ) ;
409
411
@@ -446,7 +448,10 @@ impl Service {
446
448
& self ,
447
449
block_post_processor : Option < crossbeam_channel:: Sender < BitcoinBlockData > > ,
448
450
) -> Result < ( ) , String > {
449
- // 1: Catch up blocks DB so it is at the same height as the ordinals DB.
451
+ // 0: Make sure bitcoind is synchronized.
452
+ bitcoind_wait_for_chain_tip ( & self . config , & self . ctx ) ;
453
+
454
+ // 1: Catch up blocks DB so it is at least at the same height as the ordinals DB.
450
455
if let Some ( ( start_block, end_block) ) = should_sync_rocks_db ( & self . config , & self . ctx ) ? {
451
456
let blocks_post_processor = start_block_archiving_processor (
452
457
& self . config ,
@@ -472,7 +477,8 @@ impl Service {
472
477
. await ?;
473
478
}
474
479
475
- // 2: Catch up ordinals DB until it reaches bitcoind block height. This will also advance blocks DB.
480
+ // 2: Catch up ordinals DB until it reaches bitcoind block height. This will also advance blocks DB and BRC-20 DB if
481
+ // enabled.
476
482
let mut last_block_processed = 0 ;
477
483
while let Some ( ( start_block, end_block, speed) ) =
478
484
should_sync_ordhook_db ( & self . config , & self . ctx ) ?
@@ -502,7 +508,6 @@ impl Service {
502
508
& self . ctx ,
503
509
)
504
510
. await ?;
505
-
506
511
last_block_processed = end_block;
507
512
}
508
513
0 commit comments