diff --git a/components/hord-cli/src/config/file.rs b/components/hord-cli/src/config/file.rs index 3ad98315..798e8cd0 100644 --- a/components/hord-cli/src/config/file.rs +++ b/components/hord-cli/src/config/file.rs @@ -11,6 +11,7 @@ pub struct ConfigFile { #[derive(Deserialize, Debug, Clone)] pub struct LogConfigFile { pub ordinals_computation: Option, + pub chainhook: Option, } #[derive(Deserialize, Debug, Clone)] diff --git a/components/hord-cli/src/config/generator.rs b/components/hord-cli/src/config/generator.rs index 2c88a624..6fe050ff 100644 --- a/components/hord-cli/src/config/generator.rs +++ b/components/hord-cli/src/config/generator.rs @@ -33,6 +33,10 @@ max_number_of_concurrent_bitcoin_scans = 100 max_number_of_processing_threads = 16 max_number_of_networking_threads = 16 max_caching_memory_size_mb = 32000 + +[logs] +ordinals_computation = true +chainhook = true "#, network = network.to_lowercase(), ); diff --git a/components/hord-cli/src/config/mod.rs b/components/hord-cli/src/config/mod.rs index 226a8725..4aa2b6e6 100644 --- a/components/hord-cli/src/config/mod.rs +++ b/components/hord-cli/src/config/mod.rs @@ -36,6 +36,7 @@ pub struct Config { #[derive(Clone, Debug)] pub struct LogConfig { pub ordinals_computation: bool, + pub chainhook: bool, } #[derive(Clone, Debug)] @@ -233,9 +234,14 @@ impl Config { }, logs: LogConfig { ordinals_computation: config_file - .logs + .logs.as_ref() .and_then(|l| l.ordinals_computation) .unwrap_or(true), + chainhook: config_file + .logs.as_ref() + .and_then(|l| l.chainhook) + .unwrap_or(true), + }, }; Ok(config) @@ -366,6 +372,7 @@ impl Config { }, logs: LogConfig { ordinals_computation: true, + chainhook: false, }, } } @@ -398,6 +405,7 @@ impl Config { }, logs: LogConfig { ordinals_computation: true, + chainhook: false, }, } } @@ -431,7 +439,8 @@ impl Config { bitcoin_network: BitcoinNetwork::Mainnet, }, logs: LogConfig { - ordinals_computation: false, + ordinals_computation: true, + chainhook: false, }, } } diff --git a/components/hord-cli/src/core/pipeline/mod.rs b/components/hord-cli/src/core/pipeline/mod.rs index 296ce02c..a3bf8b41 100644 --- a/components/hord-cli/src/core/pipeline/mod.rs +++ b/components/hord-cli/src/core/pipeline/mod.rs @@ -209,7 +209,7 @@ pub async fn download_and_pipeline_blocks( thread_index = (thread_index + 1) % hord_config.ingestion_thread_max; } - ctx.try_log(|logger| info!(logger, "Gargbage collecting will start")); + ctx.try_log(|logger| info!(logger, "Pipeline successfully fed with sequence of blocks ({} to {})", start_block, end_block)); for tx in tx_thread_pool.iter() { let _ = tx.send(None); @@ -230,7 +230,7 @@ pub async fn download_and_pipeline_blocks( let _ = storage_thread.join(); let _ = set.shutdown(); - ctx.try_log(|logger| info!(logger, "Gargbage collecting did finish")); + ctx.try_log(|logger| info!(logger, "Pipeline successfully processed sequence of blocks ({} to {})", start_block, end_block)); // match guard.report().build() { // Ok(report) => { diff --git a/components/hord-cli/src/service/http_api.rs b/components/hord-cli/src/service/http_api.rs index 12dd74a1..2e6939f2 100644 --- a/components/hord-cli/src/service/http_api.rs +++ b/components/hord-cli/src/service/http_api.rs @@ -9,7 +9,6 @@ use chainhook_sdk::{ observer::ObserverCommand, utils::Context, }; -use hiro_system_kit::slog; use redis::{Commands, Connection}; use rocket::config::{self, Config, LogLevel}; use rocket::serde::json::{json, Json, Value as JsonValue}; @@ -72,7 +71,7 @@ pub async fn start_predicate_api_server( #[get("/ping")] fn handle_ping(ctx: &State) -> Json { - ctx.try_log(|logger| slog::info!(logger, "Handling HTTP GET /ping")); + ctx.try_log(|logger| info!(logger, "Handling HTTP GET /ping")); Json(json!({ "status": 200, "result": "chainhook service up and running", @@ -84,13 +83,13 @@ fn handle_get_predicates( api_config: &State, ctx: &State, ) -> Json { - ctx.try_log(|logger| slog::info!(logger, "Handling HTTP GET /v1/observers")); + ctx.try_log(|logger| info!(logger, "Handling HTTP GET /v1/observers")); match open_readwrite_predicates_db_conn(api_config) { Ok(mut predicates_db_conn) => { let predicates = match get_entries_from_predicates_db(&mut predicates_db_conn, &ctx) { Ok(predicates) => predicates, Err(e) => { - ctx.try_log(|logger| slog::warn!(logger, "unable to retrieve predicates: {e}")); + ctx.try_log(|logger| warn!(logger, "unable to retrieve predicates: {e}")); return Json(json!({ "status": 500, "message": "unable to retrieve predicates", @@ -122,7 +121,7 @@ fn handle_create_predicate( background_job_tx: &State>>>, ctx: &State, ) -> Json { - ctx.try_log(|logger| slog::info!(logger, "Handling HTTP POST /v1/observers")); + ctx.try_log(|logger| info!(logger, "Handling HTTP POST /v1/observers")); let predicate = predicate.into_inner(); if let Err(e) = predicate.validate() { return Json(json!({ @@ -169,7 +168,7 @@ fn handle_get_predicate( api_config: &State, ctx: &State, ) -> Json { - ctx.try_log(|logger| slog::info!(logger, "Handling HTTP GET /v1/observers/{}", predicate_uuid)); + ctx.try_log(|logger| info!(logger, "Handling HTTP GET /v1/observers/{}", predicate_uuid)); match open_readwrite_predicates_db_conn(api_config) { Ok(mut predicates_db_conn) => { @@ -219,7 +218,7 @@ fn handle_delete_bitcoin_predicate( ctx: &State, ) -> Json { ctx.try_log(|logger| { - slog::info!( + info!( logger, "Handling HTTP DELETE /v1/observers/{}", predicate_uuid diff --git a/components/hord-cli/src/service/mod.rs b/components/hord-cli/src/service/mod.rs index df04e15c..7730a946 100644 --- a/components/hord-cli/src/service/mod.rs +++ b/components/hord-cli/src/service/mod.rs @@ -3,7 +3,7 @@ mod runloops; use crate::cli::fetch_and_standardize_block; use crate::config::{Config, PredicatesApi, PredicatesApiConfig}; -use crate::core::pipeline::download_and_pipeline_blocks; +use crate::core::pipeline::{download_and_pipeline_blocks, PostProcessorCommand}; use crate::core::pipeline::processors::start_inscription_indexing_processor; use crate::core::protocol::sequencing::{ update_hord_db_and_augment_bitcoin_block_v3, @@ -37,7 +37,6 @@ use chainhook_sdk::types::{ OrdinalOperation, }; use chainhook_sdk::utils::Context; -use hiro_system_kit::slog; use redis::{Commands, Connection}; use std::collections::{BTreeMap, HashMap}; @@ -128,7 +127,6 @@ impl Service { while let Some((start_block, end_block)) = should_sync_hord_db(&self.config, &self.ctx)? { - // let end_block = end_block.min(start_block + 256); info!( self.ctx.expect_logger(), "Indexing inscriptions from block #{start_block} to block #{end_block}" @@ -146,6 +144,8 @@ impl Service { ) .await?; } + + let _ = blocks_post_processor.commands_tx.send(PostProcessorCommand::Terminate); } // Bitcoin scan operation threadpool @@ -184,12 +184,23 @@ impl Service { let (observer_event_tx, observer_event_rx) = crossbeam_channel::unbounded(); let traversals_cache = Arc::new(new_traversals_lazy_cache(hord_config.cache_size)); + let inner_ctx = if hord_config.logs.chainhook { + self.ctx.clone() + } else { + Context::empty() + }; + + info!( + self.ctx.expect_logger(), + "Database successfully updated, service will start streaming blocks" + ); + let _ = start_event_observer( event_observer_config.clone(), observer_command_tx, observer_command_rx, Some(observer_event_tx), - self.ctx.clone(), + inner_ctx, ); loop { @@ -305,7 +316,7 @@ impl Service { Ok(dbs) => dbs, Err(e) => { self.ctx.try_log(|logger| { - slog::error!(logger, "Unable to open readwtite connection: {e}",) + error!(logger, "Unable to open readwtite connection: {e}",) }); continue; } @@ -315,6 +326,11 @@ impl Service { match chain_update { BitcoinChainEvent::ChainUpdatedWithBlocks(ref mut data) => { for block in data.new_blocks.iter_mut() { + info!( + self.ctx.expect_logger(), + "Block #{} received, starting processing", block.block_identifier.index + ); + let mut cache_l1 = HashMap::new(); let mut hint = InscriptionHeigthHint::new(); if let Err(e) = update_hord_db_and_augment_bitcoin_block_v3( @@ -328,7 +344,7 @@ impl Service { &self.ctx, ) { self.ctx.try_log(|logger| { - slog::error!( + error!( logger, "Unable to insert bitcoin block {} in hord_db: {e}", block.block_identifier.index @@ -338,6 +354,11 @@ impl Service { } } BitcoinChainEvent::ChainUpdatedWithReorg(ref mut data) => { + info!( + self.ctx.expect_logger(), + "Re-org detected" + ); + for block in data.blocks_to_rollback.iter() { if let Err(e) = revert_hord_db_with_augmented_bitcoin_block( block, @@ -346,7 +367,7 @@ impl Service { &self.ctx, ) { self.ctx.try_log(|logger| { - slog::error!( + error!( logger, "Unable to rollback bitcoin block {}: {e}", block.block_identifier @@ -369,7 +390,7 @@ impl Service { &self.ctx, ) { self.ctx.try_log(|logger| { - slog::error!( + error!( logger, "Unable to apply bitcoin block {} with hord_db: {e}", block.block_identifier.index @@ -380,7 +401,7 @@ impl Service { } }; self.ctx.try_log(|logger| { - slog::info!( + info!( logger, "Flushing traversals_cache ({} entries)", traversals_cache.len()