Skip to content

Commit d712e0d

Browse files
author
Ludo Galabru
committed
fix: add busy handler
1 parent 5dd300f commit d712e0d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

components/ordhook-core/src/core/protocol/inscription_sequencing.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::{
22
collections::{BTreeMap, HashMap, VecDeque},
33
hash::BuildHasherDefault,
44
sync::Arc,
5+
thread::sleep,
6+
time::Duration,
57
};
68

79
use chainhook_sdk::{
@@ -35,6 +37,7 @@ use std::sync::mpsc::channel;
3537
use crate::db::find_all_inscriptions_in_block;
3638

3739
use super::{
40+
inscription_parsing::get_inscriptions_revealed_in_block,
3841
inscription_tracking::augment_transaction_with_ordinals_transfers_data,
3942
satoshi_numbering::compute_satoshi_number,
4043
};
@@ -765,8 +768,23 @@ pub fn consolidate_block_with_pre_computed_ordinals_data(
765768
let coinbase_subsidy = Height(block.block_identifier.index).subsidy();
766769
let coinbase_txid = &block.transactions[0].transaction_identifier.clone();
767770
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+
};
770788
for (tx_index, tx) in block.transactions.iter_mut().enumerate() {
771789
// Add inscriptions data
772790
consolidate_transaction_with_pre_computed_inscription_data(

0 commit comments

Comments
 (0)