Skip to content

Commit 676aac1

Browse files
author
Ludo Galabru
committed
fix: async/await regression
1 parent 1f45ec2 commit 676aac1

File tree

8 files changed

+81
-261
lines changed

8 files changed

+81
-261
lines changed

components/chainhook-cli/src/scan/bitcoin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub async fn scan_bitcoin_chain_with_predicate(
158158
};
159159

160160
let ordinal_index = initialize_ordinal_index(&event_observer_config).unwrap();
161-
match OrdinalIndexUpdater::update(&ordinal_index) {
161+
match OrdinalIndexUpdater::update(&ordinal_index).await {
162162
Ok(_r) => {}
163163
Err(e) => {}
164164
}
@@ -171,7 +171,7 @@ pub async fn scan_bitcoin_chain_with_predicate(
171171
raw_block,
172172
&mut bitcoin_context,
173173
ctx,
174-
)?;
174+
).await?;
175175

176176
let mut hits = vec![];
177177
for tx in block.transactions.iter() {

components/chainhook-event-observer/src/indexer/bitcoin/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub async fn retrieve_full_block(
106106
Ok((block_height, block))
107107
}
108108

109-
pub fn standardize_bitcoin_block(
109+
pub async fn standardize_bitcoin_block(
110110
indexer_config: &IndexerConfig,
111111
block_height: u64,
112112
block: Block,
@@ -115,7 +115,7 @@ pub fn standardize_bitcoin_block(
115115
) -> Result<BitcoinBlockData, String> {
116116
let mut transactions = vec![];
117117

118-
match OrdinalIndexUpdater::update(&mut bitcoin_context.ordinal_index) {
118+
match OrdinalIndexUpdater::update(&mut bitcoin_context.ordinal_index).await {
119119
Ok(_) => {
120120
ctx.try_log(|logger| {
121121
slog::info!(

components/chainhook-event-observer/src/indexer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ impl Indexer {
8585
block: Block,
8686
ctx: &Context,
8787
) -> Result<Option<BitcoinChainEvent>, String> {
88-
let block = bitcoin::standardize_bitcoin_block(
88+
let block = hiro_system_kit::nestable_block_on(bitcoin::standardize_bitcoin_block(
8989
&self.config,
9090
block_height,
9191
block,
9292
&mut self.bitcoin_context,
9393
ctx,
94-
)?;
94+
))?;
9595
let event = self.bitcoin_blocks_pool.process_block(block, ctx);
9696
event
9797
}

components/chainhook-event-observer/src/indexer/ordinals/indexing/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ impl OrdinalIndex {
367367
Ok(info)
368368
}
369369

370-
pub fn update(&self) -> Result {
371-
OrdinalIndexUpdater::update(self)
370+
pub async fn update(&self) -> Result {
371+
OrdinalIndexUpdater::update(self).await
372372
}
373373

374374
pub fn is_reorged(&self) -> bool {

components/chainhook-event-observer/src/indexer/ordinals/indexing/updater.rs

+70-70
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct OrdinalIndexUpdater {
5050
}
5151

5252
impl OrdinalIndexUpdater {
53-
pub fn update(index: &OrdinalIndex) -> Result {
53+
pub async fn update(index: &OrdinalIndex) -> Result {
5454
let wtx = index.begin_write()?;
5555

5656
let height = wtx
@@ -80,10 +80,10 @@ impl OrdinalIndexUpdater {
8080
outputs_traversed: 0,
8181
};
8282

83-
updater.update_index(index, wtx)
83+
updater.update_index(index, wtx).await
8484
}
8585

86-
fn update_index<'index>(
86+
async fn update_index<'index>(
8787
&mut self,
8888
index: &'index OrdinalIndex,
8989
mut wtx: WriteTransaction<'index>,
@@ -109,7 +109,7 @@ impl OrdinalIndexUpdater {
109109
&mut wtx,
110110
block,
111111
&mut value_cache,
112-
)?;
112+
).await?;
113113

114114
uncommitted += 1;
115115

@@ -305,12 +305,12 @@ impl OrdinalIndexUpdater {
305305
Ok((outpoint_sender, value_receiver))
306306
}
307307

308-
fn index_block(
308+
async fn index_block(
309309
&mut self,
310310
index: &OrdinalIndex,
311311
outpoint_sender: &mut Sender<OutPoint>,
312312
value_receiver: &mut Receiver<u64>,
313-
wtx: &mut WriteTransaction,
313+
wtx: &mut WriteTransaction<'_>,
314314
block: BlockData,
315315
value_cache: &mut HashMap<OutPoint, u64>,
316316
) -> Result<()> {
@@ -351,7 +351,7 @@ impl OrdinalIndexUpdater {
351351
continue;
352352
}
353353
// We don't know the value of this tx input. Send this outpoint to background thread to be fetched
354-
outpoint_sender.blocking_send(prev_output)?;
354+
let _ = outpoint_sender.send(prev_output).await?;
355355
}
356356
}
357357
}
@@ -409,7 +409,7 @@ impl OrdinalIndexUpdater {
409409
)?;
410410

411411
for (tx, txid) in block.txdata.iter().skip(1).chain(block.txdata.first()) {
412-
lost_sats += inscription_updater.index_transaction_inscriptions(tx, *txid, None)?;
412+
lost_sats += inscription_updater.index_transaction_inscriptions(tx, *txid, None).await?;
413413
}
414414

415415
statistic_to_count.insert(&Statistic::LostSats.key(), &lost_sats)?;
@@ -427,68 +427,68 @@ impl OrdinalIndexUpdater {
427427
Ok(())
428428
}
429429

430-
fn index_transaction_sats(
431-
&mut self,
432-
tx: &Transaction,
433-
txid: Txid,
434-
sat_to_satpoint: &mut Table<u64, &SatPointValue>,
435-
input_sat_ranges: &mut VecDeque<(u64, u64)>,
436-
sat_ranges_written: &mut u64,
437-
outputs_traversed: &mut u64,
438-
inscription_updater: &mut InscriptionUpdater,
439-
) -> Result {
440-
inscription_updater.index_transaction_inscriptions(tx, txid, Some(input_sat_ranges))?;
441-
442-
for (vout, output) in tx.output.iter().enumerate() {
443-
let outpoint = OutPoint {
444-
vout: vout.try_into().unwrap(),
445-
txid,
446-
};
447-
let mut sats = Vec::new();
448-
449-
let mut remaining = output.value;
450-
while remaining > 0 {
451-
let range = input_sat_ranges.pop_front().ok_or_else(|| {
452-
anyhow::anyhow!("insufficient inputs for transaction outputs")
453-
})?;
454-
455-
if !Sat(range.0).is_common() {
456-
sat_to_satpoint.insert(
457-
&range.0,
458-
&SatPoint {
459-
outpoint,
460-
offset: output.value - remaining,
461-
}
462-
.store(),
463-
)?;
464-
}
465-
466-
let count = range.1 - range.0;
467-
468-
let assigned = if count > remaining {
469-
self.sat_ranges_since_flush += 1;
470-
let middle = range.0 + remaining;
471-
input_sat_ranges.push_front((middle, range.1));
472-
(range.0, middle)
473-
} else {
474-
range
475-
};
476-
477-
sats.extend_from_slice(&assigned.store());
478-
479-
remaining -= assigned.1 - assigned.0;
480-
481-
*sat_ranges_written += 1;
482-
}
483-
484-
*outputs_traversed += 1;
485-
486-
self.range_cache.insert(outpoint.store(), sats);
487-
self.outputs_inserted_since_flush += 1;
488-
}
489-
490-
Ok(())
491-
}
430+
// fn index_transaction_sats(
431+
// &mut self,
432+
// tx: &Transaction,
433+
// txid: Txid,
434+
// sat_to_satpoint: &mut Table<u64, &SatPointValue>,
435+
// input_sat_ranges: &mut VecDeque<(u64, u64)>,
436+
// sat_ranges_written: &mut u64,
437+
// outputs_traversed: &mut u64,
438+
// inscription_updater: &mut InscriptionUpdater,
439+
// ) -> Result {
440+
// inscription_updater.index_transaction_inscriptions(tx, txid, Some(input_sat_ranges))?;
441+
442+
// for (vout, output) in tx.output.iter().enumerate() {
443+
// let outpoint = OutPoint {
444+
// vout: vout.try_into().unwrap(),
445+
// txid,
446+
// };
447+
// let mut sats = Vec::new();
448+
449+
// let mut remaining = output.value;
450+
// while remaining > 0 {
451+
// let range = input_sat_ranges.pop_front().ok_or_else(|| {
452+
// anyhow::anyhow!("insufficient inputs for transaction outputs")
453+
// })?;
454+
455+
// if !Sat(range.0).is_common() {
456+
// sat_to_satpoint.insert(
457+
// &range.0,
458+
// &SatPoint {
459+
// outpoint,
460+
// offset: output.value - remaining,
461+
// }
462+
// .store(),
463+
// )?;
464+
// }
465+
466+
// let count = range.1 - range.0;
467+
468+
// let assigned = if count > remaining {
469+
// self.sat_ranges_since_flush += 1;
470+
// let middle = range.0 + remaining;
471+
// input_sat_ranges.push_front((middle, range.1));
472+
// (range.0, middle)
473+
// } else {
474+
// range
475+
// };
476+
477+
// sats.extend_from_slice(&assigned.store());
478+
479+
// remaining -= assigned.1 - assigned.0;
480+
481+
// *sat_ranges_written += 1;
482+
// }
483+
484+
// *outputs_traversed += 1;
485+
486+
// self.range_cache.insert(outpoint.store(), sats);
487+
// self.outputs_inserted_since_flush += 1;
488+
// }
489+
490+
// Ok(())
491+
// }
492492

493493
fn commit(&mut self, wtx: WriteTransaction, value_cache: HashMap<OutPoint, u64>) -> Result {
494494
println!(

components/chainhook-event-observer/src/indexer/ordinals/indexing/updater/inscription_updater.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
8181
})
8282
}
8383

84-
pub(super) fn index_transaction_inscriptions(
84+
pub(super) async fn index_transaction_inscriptions(
8585
&mut self,
8686
tx: &Transaction,
8787
txid: Txid,
@@ -114,7 +114,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
114114
{
115115
value.value()
116116
} else {
117-
self.value_receiver.blocking_recv().ok_or_else(|| {
117+
self.value_receiver.recv().await.ok_or_else(|| {
118118
anyhow::anyhow!(
119119
"failed to get transaction for {}",
120120
tx_in.previous_output.txid

0 commit comments

Comments
 (0)