Skip to content

Commit 46be0ab

Browse files
author
Ludo Galabru
committed
feat: improve repair command conveniency
1 parent 561e51e commit 46be0ab

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
650650
let mut hord_config = config.get_hord_config();
651651
hord_config.network_thread_max = cmd.network_threads;
652652

653-
let block_ingestion_processor = start_block_archiving_processor(&config, ctx, None);
653+
let block_ingestion_processor =
654+
start_block_archiving_processor(&config, ctx, false, None);
654655

655656
download_and_pipeline_blocks(
656657
&config,

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::{
1717
pub fn start_block_archiving_processor(
1818
config: &Config,
1919
ctx: &Context,
20+
update_tip: bool,
2021
_post_processor: Option<Sender<BitcoinBlockData>>,
2122
) -> PostProcessorController {
2223
let (commands_tx, commands_rx) = crossbeam_channel::bounded::<PostProcessorCommand>(2);
@@ -66,7 +67,7 @@ pub fn start_block_archiving_processor(
6667
}
6768
},
6869
};
69-
store_compacted_blocks(compacted_blocks, &blocks_db_rw, &ctx);
70+
store_compacted_blocks(compacted_blocks, update_tip, &blocks_db_rw, &ctx);
7071
}
7172

7273
if let Err(e) = blocks_db_rw.flush() {
@@ -86,13 +87,20 @@ pub fn start_block_archiving_processor(
8687

8788
pub fn store_compacted_blocks(
8889
mut compacted_blocks: Vec<(u64, LazyBlock)>,
90+
update_tip: bool,
8991
blocks_db_rw: &DB,
9092
ctx: &Context,
9193
) {
9294
compacted_blocks.sort_by(|(a, _), (b, _)| a.cmp(b));
9395

9496
for (block_height, compacted_block) in compacted_blocks.into_iter() {
95-
insert_entry_in_blocks(block_height as u32, &compacted_block, &blocks_db_rw, &ctx);
97+
insert_entry_in_blocks(
98+
block_height as u32,
99+
&compacted_block,
100+
update_tip,
101+
&blocks_db_rw,
102+
&ctx,
103+
);
96104
ctx.try_log(|logger| {
97105
info!(logger, "Block #{block_height} saved to disk");
98106
});

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn start_inscription_indexing_processor(
7373

7474
if let Ok(PostProcessorCommand::Start) = commands_rx.recv() {
7575
let _ = events_tx.send(PostProcessorEvent::Started);
76-
info!(ctx.expect_logger(), "Start inscription indexing runloop");
76+
debug!(ctx.expect_logger(), "Start inscription indexing runloop");
7777
}
7878

7979
loop {
@@ -107,10 +107,15 @@ pub fn start_inscription_indexing_processor(
107107

108108
// Early return
109109
if blocks.is_empty() {
110-
store_compacted_blocks(compacted_blocks, &blocks_db_rw, &ctx);
110+
store_compacted_blocks(compacted_blocks, true, &blocks_db_rw, &ctx);
111111
continue;
112112
} else {
113-
store_compacted_blocks(compacted_blocks, &blocks_db_rw, &Context::empty());
113+
store_compacted_blocks(
114+
compacted_blocks,
115+
true,
116+
&blocks_db_rw,
117+
&Context::empty(),
118+
);
114119
}
115120

116121
info!(ctx.expect_logger(), "Processing {} blocks", blocks.len());

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn start_transfers_recomputing_processor(
3939

4040
if let Ok(PostProcessorCommand::Start) = commands_rx.recv() {
4141
let _ = events_tx.send(PostProcessorEvent::Started);
42-
info!(ctx.expect_logger(), "Start inscription indexing runloop");
42+
debug!(ctx.expect_logger(), "Start inscription indexing runloop");
4343
}
4444

4545
loop {

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,19 @@ pub fn open_readwrite_hord_db_conn_rocks_db(
267267
pub fn insert_entry_in_blocks(
268268
block_height: u32,
269269
lazy_block: &LazyBlock,
270+
update_tip: bool,
270271
blocks_db_rw: &DB,
271272
_ctx: &Context,
272273
) {
273274
let block_height_bytes = block_height.to_be_bytes();
274275
blocks_db_rw
275276
.put(&block_height_bytes, &lazy_block.bytes)
276277
.expect("unable to insert blocks");
277-
blocks_db_rw
278-
.put(b"metadata::last_insert", block_height_bytes)
279-
.expect("unable to insert metadata");
278+
if update_tip {
279+
blocks_db_rw
280+
.put(b"metadata::last_insert", block_height_bytes)
281+
.expect("unable to insert metadata");
282+
}
280283
}
281284

282285
pub fn find_last_block_inserted(blocks_db: &DB) -> u32 {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ mod http_api;
22
mod runloops;
33

44
use crate::config::{Config, PredicatesApi, PredicatesApiConfig};
5+
use crate::core::pipeline::download_and_pipeline_blocks;
56
use crate::core::pipeline::processors::inscription_indexing::process_blocks;
67
use crate::core::pipeline::processors::start_inscription_indexing_processor;
78
use crate::core::pipeline::processors::transfers_recomputing::start_transfers_recomputing_processor;
8-
use crate::core::pipeline::download_and_pipeline_blocks;
99
use crate::core::protocol::inscription_parsing::parse_inscriptions_in_standardized_block;
1010
use crate::core::protocol::inscription_sequencing::SequenceCursor;
1111
use crate::core::{
@@ -252,6 +252,7 @@ impl Service {
252252
insert_entry_in_blocks(
253253
block.block_identifier.index as u32,
254254
&compressed_block,
255+
true,
255256
&blocks_db_rw,
256257
&ctx,
257258
);

0 commit comments

Comments
 (0)