Skip to content

Commit 71c90d7

Browse files
author
Ludo Galabru
committed
feat: re-introduce ingestion
1 parent 278a655 commit 71c90d7

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

components/hord-cli/src/cli/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
749749
let mut hord_config = config.get_hord_config();
750750
hord_config.network_thread_max = cmd.network_threads;
751751

752-
let (tx, handle) = start_ordinals_number_processor(&config, ctx);
752+
let (tx, handle) = start_ordinals_number_processor(&config, ctx, None);
753753

754754
rebuild_rocks_db(
755755
&config,

components/hord-cli/src/db/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,7 @@ pub fn process_blocks(
22072207
inscription_height_hint: &mut InscriptionHeigthHint,
22082208
inscriptions_db_conn_rw: &mut Connection,
22092209
hord_config: &HordConfig,
2210+
post_processor: &Option<Sender<BitcoinBlockData>>,
22102211
ctx: &Context,
22112212
) {
22122213
let mut cache_l1 = HashMap::new();
@@ -2224,6 +2225,10 @@ pub fn process_blocks(
22242225
hord_config,
22252226
ctx,
22262227
);
2228+
2229+
if let Some(post_processor_tx) = post_processor {
2230+
let _ = post_processor_tx.send(block);
2231+
}
22272232
}
22282233
}
22292234

components/hord-cli/src/hord/ordinals.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{sync::Arc, thread::JoinHandle};
1+
use std::{
2+
sync::{mpsc::Sender, Arc},
3+
thread::JoinHandle,
4+
};
25

36
use chainhook_sdk::{types::BitcoinBlockData, utils::Context};
47

@@ -15,6 +18,7 @@ use super::new_traversals_lazy_cache;
1518
pub fn start_ordinals_number_processor(
1619
config: &Config,
1720
ctx: &Context,
21+
post_processor: Option<Sender<BitcoinBlockData>>,
1822
) -> (
1923
crossbeam_channel::Sender<Vec<(BitcoinBlockData, LazyBlock)>>,
2024
JoinHandle<()>,
@@ -97,6 +101,7 @@ pub fn start_ordinals_number_processor(
97101
&mut inscription_height_hint,
98102
&mut inscriptions_db_conn_rw,
99103
&hord_config,
104+
&post_processor,
100105
&ctx,
101106
);
102107

components/hord-cli/src/service/mod.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,40 @@ impl Service {
8989
// Catch-up with chain tip
9090
{
9191
// Start predicate processor
92-
let (tx, handle) = start_ordinals_number_processor(&self.config, &self.ctx);
92+
let (tx_replayer, rx_replayer) = channel();
93+
94+
let (tx, handle) =
95+
start_ordinals_number_processor(&self.config, &self.ctx, Some(tx_replayer));
96+
97+
let mut moved_event_observer_config = event_observer_config.clone();
98+
let moved_ctx = self.ctx.clone();
99+
100+
let _ = hiro_system_kit::thread_named("Initial predicate processing")
101+
.spawn(move || {
102+
if let Some(mut chainhook_config) =
103+
moved_event_observer_config.chainhook_config.take()
104+
{
105+
let mut bitcoin_predicates_ref: Vec<&BitcoinChainhookSpecification> =
106+
vec![];
107+
for bitcoin_predicate in chainhook_config.bitcoin_chainhooks.iter_mut() {
108+
bitcoin_predicate.enabled = false;
109+
bitcoin_predicates_ref.push(bitcoin_predicate);
110+
}
111+
while let Ok(block) = rx_replayer.recv() {
112+
let future = process_block_with_predicates(
113+
block,
114+
&bitcoin_predicates_ref,
115+
&moved_event_observer_config,
116+
&moved_ctx,
117+
);
118+
let res = hiro_system_kit::nestable_block_on(future);
119+
if let Err(_) = res {
120+
error!(moved_ctx.expect_logger(), "Initial ingestion failing");
121+
}
122+
}
123+
}
124+
})
125+
.expect("unable to spawn thread");
93126

94127
while let Some((start_block, end_block)) = should_sync_hord_db(&self.config, &self.ctx)?
95128
{

0 commit comments

Comments
 (0)