Move the RocksDB column family list into finalized_state
The list was previously split between config and finalized_state.
This commit is contained in:
parent
4109534c9b
commit
44f2326672
|
@ -52,27 +52,13 @@ fn gen_temp_path(prefix: &str) -> PathBuf {
|
|||
}
|
||||
|
||||
impl Config {
|
||||
pub(crate) fn open_db(&self, network: Network) -> rocksdb::DB {
|
||||
/// Returns the path and database options for the finalized state database
|
||||
pub(crate) fn db_config(&self, network: Network) -> (PathBuf, rocksdb::Options) {
|
||||
let net_dir = match network {
|
||||
Network::Mainnet => "mainnet",
|
||||
Network::Testnet => "testnet",
|
||||
};
|
||||
|
||||
let mut opts = rocksdb::Options::default();
|
||||
|
||||
let cfs = vec![
|
||||
rocksdb::ColumnFamilyDescriptor::new("hash_by_height", opts.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("height_by_hash", opts.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("block_by_height", opts.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("tx_by_hash", opts.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("utxo_by_outpoint", opts.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("sprout_nullifiers", opts.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("sapling_nullifiers", opts.clone()),
|
||||
];
|
||||
|
||||
opts.create_if_missing(true);
|
||||
opts.create_missing_column_families(true);
|
||||
|
||||
let path = if self.ephemeral {
|
||||
gen_temp_path(&format!(
|
||||
"zebra-state-v{}-{}",
|
||||
|
@ -86,7 +72,12 @@ impl Config {
|
|||
.join(net_dir)
|
||||
};
|
||||
|
||||
rocksdb::DB::open_cf_descriptors(&opts, path, cfs).unwrap()
|
||||
let mut opts = rocksdb::Options::default();
|
||||
|
||||
opts.create_if_missing(true);
|
||||
opts.create_missing_column_families(true);
|
||||
|
||||
(path, opts)
|
||||
}
|
||||
|
||||
/// Construct a config for an ephemeral in memory database
|
||||
|
|
|
@ -31,7 +31,18 @@ pub struct FinalizedState {
|
|||
|
||||
impl FinalizedState {
|
||||
pub fn new(config: &Config, network: Network) -> Self {
|
||||
let db = config.open_db(network);
|
||||
let (path, db_options) = config.db_config(network);
|
||||
let column_families = vec![
|
||||
rocksdb::ColumnFamilyDescriptor::new("hash_by_height", db_options.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("height_by_hash", db_options.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("block_by_height", db_options.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("tx_by_hash", db_options.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("utxo_by_outpoint", db_options.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("sprout_nullifiers", db_options.clone()),
|
||||
rocksdb::ColumnFamilyDescriptor::new("sapling_nullifiers", db_options.clone()),
|
||||
];
|
||||
let db = rocksdb::DB::open_cf_descriptors(&db_options, path, column_families)
|
||||
.expect("database path and options are valid");
|
||||
|
||||
let new_state = Self {
|
||||
queued_by_prev_hash: HashMap::new(),
|
||||
|
|
Loading…
Reference in New Issue