Skip to content

Commit

Permalink
fix: add busy handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Aug 25, 2023
1 parent 5dd300f commit d712e0d
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::{
collections::{BTreeMap, HashMap, VecDeque},
hash::BuildHasherDefault,
sync::Arc,
thread::sleep,
time::Duration,
};

use chainhook_sdk::{
Expand Down Expand Up @@ -35,6 +37,7 @@ use std::sync::mpsc::channel;
use crate::db::find_all_inscriptions_in_block;

use super::{
inscription_parsing::get_inscriptions_revealed_in_block,
inscription_tracking::augment_transaction_with_ordinals_transfers_data,
satoshi_numbering::compute_satoshi_number,
};
Expand Down Expand Up @@ -765,8 +768,23 @@ pub fn consolidate_block_with_pre_computed_ordinals_data(
let coinbase_subsidy = Height(block.block_identifier.index).subsidy();
let coinbase_txid = &block.transactions[0].transaction_identifier.clone();
let mut cumulated_fees = 0;
let mut inscriptions_data =
find_all_inscriptions_in_block(&block.block_identifier.index, inscriptions_db_tx, ctx);
let expected_inscriptions_count = get_inscriptions_revealed_in_block(&block).len();
let mut inscriptions_data = loop {
let results =
find_all_inscriptions_in_block(&block.block_identifier.index, inscriptions_db_tx, ctx);
if results.len() == expected_inscriptions_count {
break results;
}
// Handle race conditions: if the db is being updated, the number of expected entries could be un-met.
sleep(Duration::from_secs(3));
ctx.try_log(|logger| {
warn!(
logger,
"Database retuning {} results instead of the expected {expected_inscriptions_count}",
results.len()
);
});
};
for (tx_index, tx) in block.transactions.iter_mut().enumerate() {
// Add inscriptions data
consolidate_transaction_with_pre_computed_inscription_data(
Expand Down

0 comments on commit d712e0d

Please sign in to comment.