@@ -2,6 +2,8 @@ use std::{
2
2
collections:: { BTreeMap , HashMap , VecDeque } ,
3
3
hash:: BuildHasherDefault ,
4
4
sync:: Arc ,
5
+ thread:: sleep,
6
+ time:: Duration ,
5
7
} ;
6
8
7
9
use chainhook_sdk:: {
@@ -35,6 +37,7 @@ use std::sync::mpsc::channel;
35
37
use crate :: db:: find_all_inscriptions_in_block;
36
38
37
39
use super :: {
40
+ inscription_parsing:: get_inscriptions_revealed_in_block,
38
41
inscription_tracking:: augment_transaction_with_ordinals_transfers_data,
39
42
satoshi_numbering:: compute_satoshi_number,
40
43
} ;
@@ -765,8 +768,23 @@ pub fn consolidate_block_with_pre_computed_ordinals_data(
765
768
let coinbase_subsidy = Height ( block. block_identifier . index ) . subsidy ( ) ;
766
769
let coinbase_txid = & block. transactions [ 0 ] . transaction_identifier . clone ( ) ;
767
770
let mut cumulated_fees = 0 ;
768
- let mut inscriptions_data =
769
- find_all_inscriptions_in_block ( & block. block_identifier . index , inscriptions_db_tx, ctx) ;
771
+ let expected_inscriptions_count = get_inscriptions_revealed_in_block ( & block) . len ( ) ;
772
+ let mut inscriptions_data = loop {
773
+ let results =
774
+ find_all_inscriptions_in_block ( & block. block_identifier . index , inscriptions_db_tx, ctx) ;
775
+ if results. len ( ) == expected_inscriptions_count {
776
+ break results;
777
+ }
778
+ // Handle race conditions: if the db is being updated, the number of expected entries could be un-met.
779
+ sleep ( Duration :: from_secs ( 3 ) ) ;
780
+ ctx. try_log ( |logger| {
781
+ warn ! (
782
+ logger,
783
+ "Database retuning {} results instead of the expected {expected_inscriptions_count}" ,
784
+ results. len( )
785
+ ) ;
786
+ } ) ;
787
+ } ;
770
788
for ( tx_index, tx) in block. transactions . iter_mut ( ) . enumerate ( ) {
771
789
// Add inscriptions data
772
790
consolidate_transaction_with_pre_computed_inscription_data (
0 commit comments