Skip to content

Commit 0e3faf9

Browse files
author
Ludo Galabru
committed
fix: patch boot latency
1 parent 108117b commit 0e3faf9

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use chainhook_sdk::indexer::bitcoin::{
1919
use super::parse_ordinals_and_standardize_block;
2020

2121
pub enum PostProcessorCommand {
22+
Start,
2223
ProcessBlocks(Vec<(u64, LazyBlock)>, Vec<BitcoinBlockData>),
2324
Terminate,
2425
}
@@ -150,6 +151,8 @@ pub async fn download_and_pipeline_blocks(
150151
let mut inbox = HashMap::new();
151152
let mut inbox_cursor = start_sequencing_blocks_at_height.max(start_block);
152153
let mut blocks_processed = 0;
154+
let mut pre_seq_processor_started = false;
155+
let mut post_seq_processor_started = false;
153156

154157
loop {
155158
// Dequeue all the blocks available
@@ -173,6 +176,11 @@ pub async fn download_and_pipeline_blocks(
173176

174177
if !ooo_compacted_blocks.is_empty() {
175178
if let Some(ref blocks_tx) = blocks_post_processor_pre_sequence_commands_tx {
179+
if !pre_seq_processor_started {
180+
pre_seq_processor_started = true;
181+
let _ = blocks_tx.send(PostProcessorCommand::Start);
182+
}
183+
176184
let _ = blocks_tx.send(PostProcessorCommand::ProcessBlocks(ooo_compacted_blocks, vec![]));
177185
}
178186
}
@@ -194,6 +202,10 @@ pub async fn download_and_pipeline_blocks(
194202
}
195203
if !blocks.is_empty() {
196204
if let Some(ref blocks_tx) = blocks_post_processor_post_sequence_commands_tx {
205+
if !post_seq_processor_started {
206+
post_seq_processor_started = true;
207+
let _ = blocks_tx.send(PostProcessorCommand::Start);
208+
}
197209
let _ = blocks_tx.send(PostProcessorCommand::ProcessBlocks(compacted_blocks, blocks));
198210
}
199211
} else {

components/hord-cli/src/core/pipeline/processors/block_ingestion.rs

+5
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ pub fn start_block_ingestion_processor(
3232

3333
let mut empty_cycles = 0;
3434

35+
if let Ok(PostProcessorCommand::Start) = commands_rx.recv() {
36+
info!(ctx.expect_logger(), "Start block indexing runloop");
37+
}
38+
3539
loop {
3640
let (compacted_blocks, _) = match commands_rx.try_recv() {
3741
Ok(PostProcessorCommand::ProcessBlocks(compacted_blocks, blocks)) => {
3842
(compacted_blocks, blocks)
3943
}
4044
Ok(PostProcessorCommand::Terminate) => break,
45+
Ok(PostProcessorCommand::Start) => continue,
4146
Err(e) => match e {
4247
TryRecvError::Empty => {
4348
empty_cycles += 1;

components/hord-cli/src/core/pipeline/processors/inscription_indexing.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn start_inscription_indexing_processor(
4949

5050
let config = config.clone();
5151
let ctx = ctx.clone();
52-
let handle: JoinHandle<()> = hiro_system_kit::thread_named("Batch receiver")
52+
let handle: JoinHandle<()> = hiro_system_kit::thread_named("Inscription indexing runloop")
5353
.spawn(move || {
5454
let cache_l2 = Arc::new(new_traversals_lazy_cache(1024));
5555
let garbage_collect_every_n_blocks = 100;
@@ -66,23 +66,26 @@ pub fn start_inscription_indexing_processor(
6666
let mut inscription_height_hint = InscriptionHeigthHint::new();
6767
let mut empty_cycles = 0;
6868

69+
if let Ok(PostProcessorCommand::Start) = commands_rx.recv() {
70+
info!(ctx.expect_logger(), "Start inscription indexing runloop");
71+
}
72+
6973
loop {
7074
let (compacted_blocks, mut blocks) = match commands_rx.try_recv() {
7175
Ok(PostProcessorCommand::ProcessBlocks(compacted_blocks, blocks)) => {
76+
empty_cycles = 0;
7277
(compacted_blocks, blocks)
7378
}
7479
Ok(PostProcessorCommand::Terminate) => break,
80+
Ok(PostProcessorCommand::Start) => continue,
7581
Err(e) => match e {
7682
TryRecvError::Empty => {
7783
empty_cycles += 1;
78-
79-
if empty_cycles == 30 {
84+
if empty_cycles == 10 {
85+
empty_cycles = 0;
8086
let _ = events_tx.send(PostProcessorEvent::EmptyQueue);
8187
}
8288
sleep(Duration::from_secs(1));
83-
if empty_cycles > 120 {
84-
break;
85-
}
8689
continue;
8790
}
8891
_ => {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Service {
139139
start_block,
140140
end_block,
141141
hord_config.first_inscription_height,
142-
Some(&blocks_post_processor),
142+
None,
143143
Some(&blocks_post_processor),
144144
speed,
145145
&self.ctx,

0 commit comments

Comments
 (0)