| Crates.io | bitcoinleveldb-cfg |
| lib.rs | bitcoinleveldb-cfg |
| version | 0.1.19 |
| created_at | 2023-01-18 17:18:54.912351+00 |
| updated_at | 2025-12-01 16:58:14.070809+00 |
| description | Typed configuration layer for LevelDB-backed Bitcoin data stores, defining network-aware paths, logical database roles, and LevelDB tuning parameters for use within the bitcoin-rs ecosystem. |
| homepage | |
| repository | https://github.com/klebs6/bitcoin-rs |
| max_upload_size | |
| id | 761846 |
| size | 186,392 |
Configuration primitives for running LevelDB-backed Bitcoin data stores in Rust.
This crate provides a small, opinionated configuration layer that standardizes how LevelDB databases are named, located, and parameterized within the broader bitcoin-rs workspace. It focuses exclusively on the configuration surface (paths, logical database roles, and tunable parameters), keeping I/O and schema logic in adjacent crates.
bitcoinleveldb-cfg aims to:
It does not implement a database driver. Instead it is designed to be consumed by a LevelDB wrapper (e.g., bitcoinleveldb or a raw leveldb-sys binding) to open and manage the actual database instances.
The crate typically centers around a small number of core types (exact names may differ slightly in the actual code):
Network / Chain enum — identifies which Bitcoin network the configuration targets (e.g., Mainnet, Testnet, Regtest, possibly Signet or custom chains).DbRole / LogicalDb enum — enumerates logical database roles such as headers, blocks, UTXO set, and additional indexes. These roles determine the on-disk subdirectory or file names.LevelDbTuning / LevelDbOptionsCfg — collects tunable parameters such as cache size, block size, write buffer size, and bloom filter options.BitcoinLevelDbCfg / DbCfg — the primary configuration object that binds network, base data directory, logical database role, and tuning parameters into a ready-to-use configuration that a LevelDB wrapper can consume.In a typical architecture, the configuration object is pure data: it does not open files or sockets; it simply describes what should be opened and with which parameters.
Below is a representative example for how a consumer crate might use bitcoinleveldb-cfg. Names are indicative, not guaranteed; consult the actual API in this crate for precise signatures.
use bitcoinleveldb_cfg::{
BitcoinLevelDbCfg, // primary configuration type
Network, // network/chain enumeration
DbRole, // logical database role
LevelDbTuning, // low-level tuning parameters
};
fn main() -> anyhow::Result<()> {
// Decide which chain and data directory to use.
let network = Network::Mainnet;
let datadir = "/var/lib/bitcoin-rs";
// Configure base tuning parameters; these will be translated into
// concrete LevelDB options by your LevelDB wrapper crate.
let tuning = LevelDbTuning {
block_cache_bytes: 512 * 1024 * 1024, // 512 MiB
write_buffer_bytes: 128 * 1024 * 1024,
max_open_files: 2048,
use_compression: true,
..LevelDbTuning::default()
};
// Describe a specific logical database: e.g., the block index.
let cfg = BitcoinLevelDbCfg::new(datadir, network, DbRole::BlockIndex, tuning)?;
// Turn this into actual LevelDB options in your driver crate.
// (The below call is conceptual; adapt to your driver.)
let options = cfg.to_leveldb_options();
let path = cfg.path();
// Example integration with a hypothetical `bitcoinleveldb` crate:
// let db = bitcoinleveldb::open(path, &options)?;
Ok(())
}
A crate that integrates with bitcoinleveldb-cfg usually:
Network and base data directory.DbRole values per logical database.BitcoinLevelDbCfg for each role.The crate typically enforces a consistent directory structure such as:
<datadir>/
mainnet/
blocks/
chainstate/
index/
...
testnet/
...
regtest/
...
The exact layout is encoded in the config types, so all collaborating components agree on the set of LevelDB instances and their on-disk locations. This is particularly important for:
bitcoin-rs workspace.Bitcoin-scale data volumes make LevelDB tuning nontrivial. bitcoinleveldb-cfg centralizes the parameters that control:
By encoding these parameters in a structured configuration type, you can:
bitcoin-rsWithin the https://github.com/klebs6/bitcoin-rs repository, this crate is expected to be consumed by:
For consumers outside the workspace, the crate can be used as a configuration boundary so you can:
bitcoin-rs tools.If this crate defines Cargo features, they are typically used to:
Regtest or experimental networks).heavy-load, low-mem).Check Cargo.toml in the repository for the precise set of available features.
Configuration constructors usually validate:
These validations typically return structured errors (e.g., an enum implementing std::error::Error) suitable for integration with error stacks (e.g., anyhow, eyre) in consumer crates.
Use bitcoinleveldb-cfg if you:
bitcoin-rs workspace.If you only need a raw LevelDB binding with no Bitcoin-specific semantics, a general LevelDB crate may be sufficient.
This crate is distributed under the MIT license.
Source code and issue tracking are hosted in the bitcoin-rs repository:
Contributions, bug reports, and improvement suggestions are welcome through that repository.