Skip to content

Commit

Permalink
fix: boot sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Jul 7, 2023
1 parent 30f299e commit 577f1c2
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions components/hord-cli/src/service/mod.rs
Expand Up @@ -106,7 +106,38 @@ impl Service {

let hord_config = self.config.get_hord_config();

if let Some((start_block, end_block)) = should_sync_hord_db(&self.config, &self.ctx)? {
let (tx, rx) = channel();

let mut moved_event_observer_config = event_observer_config.clone();
let moved_ctx = self.ctx.clone();

let _ = hiro_system_kit::thread_named("Initial predicate processing")
.spawn(move || {
if let Some(mut chainhook_config) =
moved_event_observer_config.chainhook_config.take()
{
let mut bitcoin_predicates_ref: Vec<&BitcoinChainhookSpecification> = vec![];
for bitcoin_predicate in chainhook_config.bitcoin_chainhooks.iter_mut() {
bitcoin_predicate.enabled = false;
bitcoin_predicates_ref.push(bitcoin_predicate);
}
while let Ok(block) = rx.recv() {
let future = process_block_with_predicates(
block,
&bitcoin_predicates_ref,
&moved_event_observer_config,
&moved_ctx,
);
let res = hiro_system_kit::nestable_block_on(future);
if let Err(_) = res {
error!(moved_ctx.expect_logger(), "Initial ingestion failing");
}
}
}
})
.expect("unable to spawn thread");

while let Some((start_block, end_block)) = should_sync_hord_db(&self.config, &self.ctx)? {
if start_block == 0 {
info!(
self.ctx.expect_logger(),
Expand All @@ -119,44 +150,12 @@ impl Service {
);
}

let (tx, rx) = channel();

let mut moved_event_observer_config = event_observer_config.clone();
let moved_ctx = self.ctx.clone();

let _ = hiro_system_kit::thread_named("Initial predicate processing")
.spawn(move || {
if let Some(mut chainhook_config) =
moved_event_observer_config.chainhook_config.take()
{
let mut bitcoin_predicates_ref: Vec<&BitcoinChainhookSpecification> =
vec![];
for bitcoin_predicate in chainhook_config.bitcoin_chainhooks.iter_mut() {
bitcoin_predicate.enabled = false;
bitcoin_predicates_ref.push(bitcoin_predicate);
}
while let Ok(block) = rx.recv() {
let future = process_block_with_predicates(
block,
&bitcoin_predicates_ref,
&moved_event_observer_config,
&moved_ctx,
);
let res = hiro_system_kit::nestable_block_on(future);
if let Err(_) = res {
error!(moved_ctx.expect_logger(), "Initial ingestion failing");
}
}
}
})
.expect("unable to spawn thread");

crate::hord::perform_hord_db_update(
start_block,
end_block,
&self.config.get_hord_config(),
&self.config,
Some(tx),
Some(tx.clone()),
&self.ctx,
)
.await?;
Expand Down

0 comments on commit 577f1c2

Please sign in to comment.