Skip to content

Commit

Permalink
fix: safer db open, dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Apr 7, 2023
1 parent 7751ba0 commit 43d37d7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
12 changes: 9 additions & 3 deletions components/chainhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,15 @@ pub fn should_sync_hord_db(config: &Config, ctx: &Context) -> Result<Option<(u64
}
};

let start_block = {
let blocks_db = open_readonly_hord_db_conn_rocks_db(&config.expected_cache_path(), &ctx)?;
find_last_block_inserted(&blocks_db) as u64
let start_block = match open_readonly_hord_db_conn_rocks_db(&config.expected_cache_path(), &ctx) {
Ok(blocks_db) => find_last_block_inserted(&blocks_db) as u64,
Err(err) => {
warn!(
ctx.expect_logger(),
"{}", err
);
0
}
};

if start_block == 0 {
Expand Down
5 changes: 3 additions & 2 deletions components/chainhook-event-observer/src/hord/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,10 @@ pub fn open_readonly_hord_db_conn_rocks_db(
) -> Result<DB, String> {
let path = get_default_hord_db_file_path_rocks_db(&base_dir);
let mut opts = rocksdb::Options::default();
opts.create_if_missing(true);
opts.set_compression_type(rocksdb::DBCompressionType::Lz4);
opts.set_max_open_files(1000);
let db = DB::open_for_read_only(&opts, path, false).unwrap();
let db = DB::open_for_read_only(&opts, path, false).map_err(|e| format!("unable to open blocks_db: {}", e.to_string()))?;
Ok(db)
}

Expand All @@ -359,7 +360,7 @@ pub fn open_readwrite_hord_db_conn_rocks_db(
opts.create_if_missing(true);
opts.set_compression_type(rocksdb::DBCompressionType::Lz4);
opts.set_max_open_files(1000);
let db = DB::open(&opts, path).unwrap();
let db = DB::open(&opts, path).map_err(|e| format!("unable to open blocks_db: {}", e.to_string()))?;
Ok(db)
}

Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/components/chainhook-node.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM rust:bullseye as build

WORKDIR /src

RUN apt update && apt install -y ca-certificates pkg-config libssl-dev
RUN apt update && apt install -y ca-certificates pkg-config libssl-dev libclang-11-dev

RUN rustup update 1.67.0 && rustup default 1.67.0

Expand Down

0 comments on commit 43d37d7

Please sign in to comment.