Skip to content

Commit 577f1c2

Browse files
author
Ludo Galabru
committed
fix: boot sequence
1 parent 30f299e commit 577f1c2

File tree

1 file changed

+33
-34
lines changed
  • components/hord-cli/src/service

1 file changed

+33
-34
lines changed

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

+33-34
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,38 @@ impl Service {
106106

107107
let hord_config = self.config.get_hord_config();
108108

109-
if let Some((start_block, end_block)) = should_sync_hord_db(&self.config, &self.ctx)? {
109+
let (tx, rx) = channel();
110+
111+
let mut moved_event_observer_config = event_observer_config.clone();
112+
let moved_ctx = self.ctx.clone();
113+
114+
let _ = hiro_system_kit::thread_named("Initial predicate processing")
115+
.spawn(move || {
116+
if let Some(mut chainhook_config) =
117+
moved_event_observer_config.chainhook_config.take()
118+
{
119+
let mut bitcoin_predicates_ref: Vec<&BitcoinChainhookSpecification> = vec![];
120+
for bitcoin_predicate in chainhook_config.bitcoin_chainhooks.iter_mut() {
121+
bitcoin_predicate.enabled = false;
122+
bitcoin_predicates_ref.push(bitcoin_predicate);
123+
}
124+
while let Ok(block) = rx.recv() {
125+
let future = process_block_with_predicates(
126+
block,
127+
&bitcoin_predicates_ref,
128+
&moved_event_observer_config,
129+
&moved_ctx,
130+
);
131+
let res = hiro_system_kit::nestable_block_on(future);
132+
if let Err(_) = res {
133+
error!(moved_ctx.expect_logger(), "Initial ingestion failing");
134+
}
135+
}
136+
}
137+
})
138+
.expect("unable to spawn thread");
139+
140+
while let Some((start_block, end_block)) = should_sync_hord_db(&self.config, &self.ctx)? {
110141
if start_block == 0 {
111142
info!(
112143
self.ctx.expect_logger(),
@@ -119,44 +150,12 @@ impl Service {
119150
);
120151
}
121152

122-
let (tx, rx) = channel();
123-
124-
let mut moved_event_observer_config = event_observer_config.clone();
125-
let moved_ctx = self.ctx.clone();
126-
127-
let _ = hiro_system_kit::thread_named("Initial predicate processing")
128-
.spawn(move || {
129-
if let Some(mut chainhook_config) =
130-
moved_event_observer_config.chainhook_config.take()
131-
{
132-
let mut bitcoin_predicates_ref: Vec<&BitcoinChainhookSpecification> =
133-
vec![];
134-
for bitcoin_predicate in chainhook_config.bitcoin_chainhooks.iter_mut() {
135-
bitcoin_predicate.enabled = false;
136-
bitcoin_predicates_ref.push(bitcoin_predicate);
137-
}
138-
while let Ok(block) = rx.recv() {
139-
let future = process_block_with_predicates(
140-
block,
141-
&bitcoin_predicates_ref,
142-
&moved_event_observer_config,
143-
&moved_ctx,
144-
);
145-
let res = hiro_system_kit::nestable_block_on(future);
146-
if let Err(_) = res {
147-
error!(moved_ctx.expect_logger(), "Initial ingestion failing");
148-
}
149-
}
150-
}
151-
})
152-
.expect("unable to spawn thread");
153-
154153
crate::hord::perform_hord_db_update(
155154
start_block,
156155
end_block,
157156
&self.config.get_hord_config(),
158157
&self.config,
159-
Some(tx),
158+
Some(tx.clone()),
160159
&self.ctx,
161160
)
162161
.await?;

0 commit comments

Comments
 (0)