diff --git a/components/chainhook-sdk/src/indexer/bitcoin/mod.rs b/components/chainhook-sdk/src/indexer/bitcoin/mod.rs index 7cf6a8d..7a54f6a 100644 --- a/components/chainhook-sdk/src/indexer/bitcoin/mod.rs +++ b/components/chainhook-sdk/src/indexer/bitcoin/mod.rs @@ -9,8 +9,9 @@ use bitcoincore_rpc::jsonrpc::error::RpcError; use bitcoincore_rpc_json::GetRawTransactionResultVoutScriptPubKey; use chainhook_types::bitcoin::{OutPoint, TxIn, TxOut}; use chainhook_types::{ - BitcoinBlockData, BitcoinBlockMetadata, BitcoinNetwork, BitcoinTransactionData, - BitcoinTransactionMetadata, BlockHeader, BlockIdentifier, TransactionIdentifier, + BitcoinBlockData, BitcoinBlockMetadata, BitcoinBlockSignaling, BitcoinNetwork, + BitcoinTransactionData,BitcoinTransactionMetadata, BlockHeader, BlockIdentifier, + TransactionIdentifier, }; use hiro_system_kit::slog; use reqwest::Client as HttpClient; diff --git a/components/chainhook-sdk/src/indexer/mod.rs b/components/chainhook-sdk/src/indexer/mod.rs index df21b35..55133bf 100644 --- a/components/chainhook-sdk/src/indexer/mod.rs +++ b/components/chainhook-sdk/src/indexer/mod.rs @@ -39,6 +39,7 @@ pub struct IndexerConfig { pub bitcoind_rpc_username: String, pub bitcoind_rpc_password: String, pub bitcoin_block_signaling: BitcoinBlockSignaling, + pub prometheus_monitoring_port: Option, } pub struct Indexer { diff --git a/components/ordhook-core/src/utils/bitcoind.rs b/components/chainhook-sdk/src/utils/bitcoind.rs similarity index 79% rename from components/ordhook-core/src/utils/bitcoind.rs rename to components/chainhook-sdk/src/utils/bitcoind.rs index 8313f57..b45eb22 100644 --- a/components/ordhook-core/src/utils/bitcoind.rs +++ b/components/chainhook-sdk/src/utils/bitcoind.rs @@ -1,19 +1,19 @@ use std::{thread::sleep, time::Duration}; -use chainhook_sdk::{ - bitcoincore_rpc::{Auth, Client, RpcApi}, - utils::Context, -}; +use bitcoincore_rpc::{Auth, Client, RpcApi}; +use hiro_system_kit::slog; +use crate::utils::Context; +use crate::indexer::IndexerConfig; -use crate::{config::Config, try_error, try_info}; +use crate::{try_error, try_info}; -fn bitcoind_get_client(config: &Config, ctx: &Context) -> Client { +fn bitcoind_get_client(config: &IndexerConfig, ctx: &Context) -> Client { loop { let auth = Auth::UserPass( - config.network.bitcoind_rpc_username.clone(), - config.network.bitcoind_rpc_password.clone(), + config.bitcoind_rpc_username.clone(), + config.bitcoind_rpc_password.clone(), ); - match Client::new(&config.network.bitcoind_rpc_url, auth) { + match Client::new(&config.bitcoind_rpc_url, auth) { Ok(con) => { return con; } @@ -26,7 +26,7 @@ fn bitcoind_get_client(config: &Config, ctx: &Context) -> Client { } /// Retrieves the block height from bitcoind. -pub fn bitcoind_get_block_height(config: &Config, ctx: &Context) -> u64 { +pub fn bitcoind_get_block_height(config: &IndexerConfig, ctx: &Context) -> u64 { let bitcoin_rpc = bitcoind_get_client(config, ctx); loop { match bitcoin_rpc.get_blockchain_info() { @@ -46,7 +46,7 @@ pub fn bitcoind_get_block_height(config: &Config, ctx: &Context) -> u64 { } /// Checks if bitcoind is still synchronizing blocks and waits until it's finished if that is the case. -pub fn bitcoind_wait_for_chain_tip(config: &Config, ctx: &Context) { +pub fn bitcoind_wait_for_chain_tip(config: &IndexerConfig, ctx: &Context) { let bitcoin_rpc = bitcoind_get_client(config, ctx); let mut confirmations = 0; loop { diff --git a/components/chainhook-sdk/src/utils/mod.rs b/components/chainhook-sdk/src/utils/mod.rs index 8c5bdeb..b3bfa6f 100644 --- a/components/chainhook-sdk/src/utils/mod.rs +++ b/components/chainhook-sdk/src/utils/mod.rs @@ -1,3 +1,5 @@ +pub mod bitcoind; + use std::{ collections::{BTreeSet, VecDeque}, fs::{self, OpenOptions}, diff --git a/components/ordhook-cli/src/config/file.rs b/components/ordhook-cli/src/config/file.rs index fbcbae5..e39b6b7 100644 --- a/components/ordhook-cli/src/config/file.rs +++ b/components/ordhook-cli/src/config/file.rs @@ -1,6 +1,7 @@ use chainhook_types::{BitcoinBlockSignaling, BitcoinNetwork}; +use chainhook_sdk::indexer::IndexerConfig; use ordhook::config::{ - Config, IndexerConfig, LogConfig, MetaProtocolsConfig, ResourcesConfig, SnapshotConfig, + Config, LogConfig, MetaProtocolsConfig, ResourcesConfig, SnapshotConfig, SnapshotConfigDownloadUrls, StorageConfig, DEFAULT_BITCOIND_RPC_THREADS, DEFAULT_BITCOIND_RPC_TIMEOUT, DEFAULT_BRC20_LRU_CACHE_SIZE, DEFAULT_MEMORY_AVAILABLE, DEFAULT_ULIMIT, diff --git a/components/ordhook-core/src/config/mod.rs b/components/ordhook-core/src/config/mod.rs index 06fc688..745abd5 100644 --- a/components/ordhook-core/src/config/mod.rs +++ b/components/ordhook-core/src/config/mod.rs @@ -1,5 +1,5 @@ pub use chainhook_postgres::PgConnectionConfig; -use chainhook_sdk::observer::EventObserverConfig; +use chainhook_sdk::{indexer::IndexerConfig, observer::EventObserverConfig}; use chainhook_types::{BitcoinBlockSignaling, BitcoinNetwork}; use std::path::PathBuf; @@ -66,16 +66,6 @@ pub struct UrlConfig { pub file_url: String, } -#[derive(Debug, Clone)] -pub struct IndexerConfig { - pub bitcoin_network: BitcoinNetwork, - pub bitcoind_rpc_url: String, - pub bitcoind_rpc_username: String, - pub bitcoind_rpc_password: String, - pub bitcoin_block_signaling: BitcoinBlockSignaling, - pub prometheus_monitoring_port: Option, -} - #[derive(Deserialize, Debug, Clone)] pub struct ResourcesConfig { pub ulimit: usize, diff --git a/components/ordhook-core/src/core/mod.rs b/components/ordhook-core/src/core/mod.rs index 3e501bc..6486bea 100644 --- a/components/ordhook-core/src/core/mod.rs +++ b/components/ordhook-core/src/core/mod.rs @@ -23,9 +23,9 @@ use crate::{ cursor::TransactionBytesCursor, ordinals_pg, }, - service::PgConnectionPools, - utils::bitcoind::bitcoind_get_block_height, + service::PgConnectionPools }; +use chainhook_sdk::utils::bitcoind::bitcoind_get_block_height; pub fn first_inscription_height(config: &Config) -> u64 { match config.network.bitcoin_network { @@ -164,7 +164,7 @@ pub async fn should_sync_ordinals_db( }; // TODO: Gracefully handle Regtest, Testnet and Signet - let end_block = bitcoind_get_block_height(config, ctx); + let end_block = bitcoind_get_block_height(&config.network, ctx); let (mut end_block, speed) = if start_block < 200_000 { (end_block.min(200_000), 10_000) } else if start_block < 550_000 { diff --git a/components/ordhook-core/src/service/mod.rs b/components/ordhook-core/src/service/mod.rs index ca1fcf9..6981768 100644 --- a/components/ordhook-core/src/service/mod.rs +++ b/components/ordhook-core/src/service/mod.rs @@ -15,13 +15,13 @@ use crate::db::blocks::{ }; use crate::db::cursor::{BlockBytesCursor, TransactionBytesCursor}; use crate::db::ordinals_pg; -use crate::utils::bitcoind::bitcoind_wait_for_chain_tip; use crate::utils::monitoring::{start_serving_prometheus_metrics, PrometheusMonitoring}; use crate::{try_crit, try_error, try_info}; use chainhook_postgres::{pg_begin, pg_pool, pg_pool_client}; use chainhook_sdk::observer::{ start_event_observer, BitcoinBlockDataCached, ObserverEvent, ObserverSidecar, }; +use chainhook_sdk::utils::bitcoind::bitcoind_wait_for_chain_tip; use chainhook_sdk::utils::{BlockHeights, Context}; use chainhook_types::BlockIdentifier; use crossbeam_channel::select; @@ -224,7 +224,7 @@ impl Service { } pub async fn check_blocks_db_integrity(&mut self) -> Result<(), String> { - bitcoind_wait_for_chain_tip(&self.config, &self.ctx); + bitcoind_wait_for_chain_tip(&self.config.network, &self.ctx); let (tip, missing_blocks) = { let blocks_db = open_blocks_db_with_retry(false, &self.config, &self.ctx); let ord_client = pg_pool_client(&self.pg_pools.ordinals).await?; @@ -263,7 +263,7 @@ impl Service { /// Synchronizes and indexes all databases until their block height matches bitcoind's block height. pub async fn catch_up_to_bitcoin_chain_tip(&self) -> Result<(), String> { // 0: Make sure bitcoind is synchronized. - bitcoind_wait_for_chain_tip(&self.config, &self.ctx); + bitcoind_wait_for_chain_tip(&self.config.network, &self.ctx); // 1: Catch up blocks DB so it is at least at the same height as the ordinals DB. if let Some((start_block, end_block)) = diff --git a/components/ordhook-core/src/utils/mod.rs b/components/ordhook-core/src/utils/mod.rs index 48d625f..c8b1cdb 100644 --- a/components/ordhook-core/src/utils/mod.rs +++ b/components/ordhook-core/src/utils/mod.rs @@ -1,4 +1,3 @@ -pub mod bitcoind; pub mod logger; pub mod monitoring;