Skip to content

Commit

Permalink
style nits
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Oct 25, 2024
1 parent 553cf23 commit 38a3d5a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
1 change: 0 additions & 1 deletion components/chainhook-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
10 changes: 6 additions & 4 deletions components/chainhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions components/chainhook-cli/src/service/runloops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
) {
Expand Down
14 changes: 9 additions & 5 deletions components/chainhook-cli/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ 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,
// TODO(rafaelcr): Make this optional if we're not interested in signer data.
pub signers_db: Connection,
}

pub fn open_readonly_db_conns(base_dir: &PathBuf, ctx: &Context) -> Result<StacksDbConnections, String> {
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<Self, String> {
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 {
Expand Down
1 change: 1 addition & 0 deletions components/chainhook-cli/src/storage/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection, String> {
conn.busy_timeout(std::time::Duration::from_secs(300))
.map_err(|e| format!("unable to set db timeout: {e}"))?;
Expand Down
5 changes: 1 addition & 4 deletions components/chainhook-sdk/src/chainhooks/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 38a3d5a

Please sign in to comment.