diff --git a/components/chainhook-cli/Cargo.toml b/components/chainhook-cli/Cargo.toml index 06273f5e..d29ed21a 100644 --- a/components/chainhook-cli/Cargo.toml +++ b/components/chainhook-cli/Cargo.toml @@ -64,7 +64,6 @@ cli = ["clap", "clap_generate", "toml", "ctrlc"] debug = ["chainhook-sdk/debug"] release = ["chainhook-sdk/release"] redis_tests = [] -# stacks-signers = [] # [patch.crates-io] # raft-proto = { git = "https://github.com/tikv/raft-rs", rev="95c532612ee6a83591fce9a8b51d6afe87b58835"} diff --git a/components/chainhook-cli/src/cli/mod.rs b/components/chainhook-cli/src/cli/mod.rs index 1eeaaf7f..219950f3 100644 --- a/components/chainhook-cli/src/cli/mod.rs +++ b/components/chainhook-cli/src/cli/mod.rs @@ -11,8 +11,8 @@ use crate::storage::{ delete_confirmed_entry_from_stacks_blocks, delete_unconfirmed_entry_from_stacks_blocks, get_last_block_height_inserted, get_last_unconfirmed_block_height_inserted, get_stacks_block_at_block_height, insert_unconfirmed_entry_in_stacks_blocks, - is_stacks_block_present, open_readonly_db_conns, open_readonly_stacks_db_conn, - open_readwrite_stacks_db_conn, set_last_confirmed_insert_key, + is_stacks_block_present, open_readonly_stacks_db_conn, open_readwrite_stacks_db_conn, + set_last_confirmed_insert_key, StacksDbConnections, }; use chainhook_sdk::chainhooks::bitcoin::BitcoinChainhookSpecification; use chainhook_sdk::chainhooks::bitcoin::BitcoinChainhookSpecificationNetworkMap; @@ -547,8 +547,10 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> { ) .await; // Refresh DB connection so it picks up recent changes made by TSV consolidation. - let mut db_conns = - open_readonly_db_conns(&config.expected_cache_path(), &ctx)?; + let mut db_conns = StacksDbConnections::open_readonly( + &config.expected_cache_path(), + &ctx, + )?; scan_stacks_chainstate_via_rocksdb_using_predicate( &predicate_spec, None, diff --git a/components/chainhook-cli/src/service/runloops.rs b/components/chainhook-cli/src/service/runloops.rs index 8ce522b5..c177b563 100644 --- a/components/chainhook-cli/src/service/runloops.rs +++ b/components/chainhook-cli/src/service/runloops.rs @@ -19,8 +19,7 @@ use crate::{ bitcoin::scan_bitcoin_chainstate_via_rpc_using_predicate, common::PredicateScanResult, stacks::scan_stacks_chainstate_via_rocksdb_using_predicate, }, - service::{open_readwrite_predicates_db_conn_or_panic, set_predicate_interrupted_status}, - storage::open_readonly_db_conns, + service::{open_readwrite_predicates_db_conn_or_panic, set_predicate_interrupted_status}, storage::StacksDbConnections, }; use super::ScanningData; @@ -54,7 +53,7 @@ pub fn start_stacks_scan_runloop( let kill_signal = Arc::new(RwLock::new(false)); kill_signals.insert(predicate_spec.uuid.clone(), kill_signal.clone()); stacks_scan_pool.execute(move || { - let mut db_conns = match open_readonly_db_conns( + let mut db_conns = match StacksDbConnections::open_readonly( &moved_config.expected_cache_path(), &moved_ctx, ) { diff --git a/components/chainhook-cli/src/storage/mod.rs b/components/chainhook-cli/src/storage/mod.rs index 901eecb1..25a48e6a 100644 --- a/components/chainhook-cli/src/storage/mod.rs +++ b/components/chainhook-cli/src/storage/mod.rs @@ -16,6 +16,7 @@ const KEY_SUFFIX: &[u8; 2] = b":d"; const LAST_UNCONFIRMED_KEY_PREFIX: &[u8; 3] = b"m:~"; const LAST_CONFIRMED_KEY_PREFIX: &[u8; 3] = b"m:t"; +/// Keeps references to all databases used to monitor Stacks transactions and events. // TODO(rafaelcr): Expand this struct to be flexible enough to include Bitcoin DBs and/or turn some DBs on/off. pub struct StacksDbConnections { pub stacks_db: DB, @@ -23,11 +24,14 @@ pub struct StacksDbConnections { pub signers_db: Connection, } -pub fn open_readonly_db_conns(base_dir: &PathBuf, ctx: &Context) -> Result { - Ok(StacksDbConnections { - stacks_db: open_readonly_stacks_db_conn(base_dir, ctx)?, - signers_db: open_readonly_signers_db_conn(base_dir, ctx)?, - }) +impl StacksDbConnections { + /// Opens all connections in read-only mode. + pub fn open_readonly(base_dir: &PathBuf, ctx: &Context) -> Result { + Ok(StacksDbConnections { + stacks_db: open_readonly_stacks_db_conn(base_dir, ctx)?, + signers_db: open_readonly_signers_db_conn(base_dir, ctx)?, + }) + } } fn get_db_default_options() -> Options { diff --git a/components/chainhook-cli/src/storage/sqlite.rs b/components/chainhook-cli/src/storage/sqlite.rs index 16e05968..a31df002 100644 --- a/components/chainhook-cli/src/storage/sqlite.rs +++ b/components/chainhook-cli/src/storage/sqlite.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use chainhook_sdk::{try_error, utils::Context}; use rusqlite::{Connection, OpenFlags}; +/// Configures the SQLite connection with common settings. fn connection_with_defaults_pragma(conn: Connection) -> Result { conn.busy_timeout(std::time::Duration::from_secs(300)) .map_err(|e| format!("unable to set db timeout: {e}"))?; diff --git a/components/chainhook-sdk/src/chainhooks/stacks/mod.rs b/components/chainhook-sdk/src/chainhooks/stacks/mod.rs index a59344ea..36995f1a 100644 --- a/components/chainhook-sdk/src/chainhooks/stacks/mod.rs +++ b/components/chainhook-sdk/src/chainhooks/stacks/mod.rs @@ -873,10 +873,7 @@ pub fn evaluate_stacks_predicate_on_non_consensus_events<'a>( | StacksPredicate::NftEvent(_) | StacksPredicate::StxEvent(_) | StacksPredicate::PrintEvent(_) - | StacksPredicate::Txid(_) => { - // Ignore, possibly expected behavior? - // https://github.com/hirosystems/chainhook/pull/663#discussion_r1814995429 - }, + | StacksPredicate::Txid(_) => {}, }; } (occurrences, expired_predicates)