Skip to content

Commit

Permalink
feat: improve repair command conveniency
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Aug 13, 2023
1 parent 561e51e commit 46be0ab
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
3 changes: 2 additions & 1 deletion components/hord-cli/src/cli/mod.rs
Expand Up @@ -650,7 +650,8 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
let mut hord_config = config.get_hord_config();
hord_config.network_thread_max = cmd.network_threads;

let block_ingestion_processor = start_block_archiving_processor(&config, ctx, None);
let block_ingestion_processor =
start_block_archiving_processor(&config, ctx, false, None);

download_and_pipeline_blocks(
&config,
Expand Down
Expand Up @@ -17,6 +17,7 @@ use crate::{
pub fn start_block_archiving_processor(
config: &Config,
ctx: &Context,
update_tip: bool,
_post_processor: Option<Sender<BitcoinBlockData>>,
) -> PostProcessorController {
let (commands_tx, commands_rx) = crossbeam_channel::bounded::<PostProcessorCommand>(2);
Expand Down Expand Up @@ -66,7 +67,7 @@ pub fn start_block_archiving_processor(
}
},
};
store_compacted_blocks(compacted_blocks, &blocks_db_rw, &ctx);
store_compacted_blocks(compacted_blocks, update_tip, &blocks_db_rw, &ctx);
}

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

pub fn store_compacted_blocks(
mut compacted_blocks: Vec<(u64, LazyBlock)>,
update_tip: bool,
blocks_db_rw: &DB,
ctx: &Context,
) {
compacted_blocks.sort_by(|(a, _), (b, _)| a.cmp(b));

for (block_height, compacted_block) in compacted_blocks.into_iter() {
insert_entry_in_blocks(block_height as u32, &compacted_block, &blocks_db_rw, &ctx);
insert_entry_in_blocks(
block_height as u32,
&compacted_block,
update_tip,
&blocks_db_rw,
&ctx,
);
ctx.try_log(|logger| {
info!(logger, "Block #{block_height} saved to disk");
});
Expand Down
Expand Up @@ -73,7 +73,7 @@ pub fn start_inscription_indexing_processor(

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

loop {
Expand Down Expand Up @@ -107,10 +107,15 @@ pub fn start_inscription_indexing_processor(

// Early return
if blocks.is_empty() {
store_compacted_blocks(compacted_blocks, &blocks_db_rw, &ctx);
store_compacted_blocks(compacted_blocks, true, &blocks_db_rw, &ctx);
continue;
} else {
store_compacted_blocks(compacted_blocks, &blocks_db_rw, &Context::empty());
store_compacted_blocks(
compacted_blocks,
true,
&blocks_db_rw,
&Context::empty(),
);
}

info!(ctx.expect_logger(), "Processing {} blocks", blocks.len());
Expand Down
Expand Up @@ -39,7 +39,7 @@ pub fn start_transfers_recomputing_processor(

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

loop {
Expand Down
9 changes: 6 additions & 3 deletions components/hord-cli/src/db/mod.rs
Expand Up @@ -267,16 +267,19 @@ pub fn open_readwrite_hord_db_conn_rocks_db(
pub fn insert_entry_in_blocks(
block_height: u32,
lazy_block: &LazyBlock,
update_tip: bool,
blocks_db_rw: &DB,
_ctx: &Context,
) {
let block_height_bytes = block_height.to_be_bytes();
blocks_db_rw
.put(&block_height_bytes, &lazy_block.bytes)
.expect("unable to insert blocks");
blocks_db_rw
.put(b"metadata::last_insert", block_height_bytes)
.expect("unable to insert metadata");
if update_tip {
blocks_db_rw
.put(b"metadata::last_insert", block_height_bytes)
.expect("unable to insert metadata");
}
}

pub fn find_last_block_inserted(blocks_db: &DB) -> u32 {
Expand Down
3 changes: 2 additions & 1 deletion components/hord-cli/src/service/mod.rs
Expand Up @@ -2,10 +2,10 @@ mod http_api;
mod runloops;

use crate::config::{Config, PredicatesApi, PredicatesApiConfig};
use crate::core::pipeline::download_and_pipeline_blocks;
use crate::core::pipeline::processors::inscription_indexing::process_blocks;
use crate::core::pipeline::processors::start_inscription_indexing_processor;
use crate::core::pipeline::processors::transfers_recomputing::start_transfers_recomputing_processor;
use crate::core::pipeline::download_and_pipeline_blocks;
use crate::core::protocol::inscription_parsing::parse_inscriptions_in_standardized_block;
use crate::core::protocol::inscription_sequencing::SequenceCursor;
use crate::core::{
Expand Down Expand Up @@ -252,6 +252,7 @@ impl Service {
insert_entry_in_blocks(
block.block_identifier.index as u32,
&compressed_block,
true,
&blocks_db_rw,
&ctx,
);
Expand Down

0 comments on commit 46be0ab

Please sign in to comment.