diff --git a/crates/rooch-config/src/store_config.rs b/crates/rooch-config/src/store_config.rs index 601e1aff88..1380b6bcb3 100644 --- a/crates/rooch-config/src/store_config.rs +++ b/crates/rooch-config/src/store_config.rs @@ -15,8 +15,7 @@ use std::str::FromStr; use std::sync::Arc; pub const DEFAULT_DB_DIR: &str = "roochdb"; -pub const DEFAULT_DB_ROOCH_SUBDIR: &str = "rooch_store"; -pub const DEFAULT_DB_MOVEOS_SUBDIR: &str = "moveos_store"; +pub const DEFAULT_DB_STORE_SUBDIR: &str = "store"; pub const DEFAULT_DB_INDEXER_SUBDIR: &str = "indexer"; // for Rooch DB instance, doesn't need too much row cache: @@ -94,14 +93,10 @@ pub struct StoreConfig { impl StoreConfig { pub(crate) fn init(&mut self, base: Arc) -> Result<()> { self.base = Some(base); - let rooch_store_dir = self.get_rooch_store_dir(); - let moveos_store_dir = self.get_moveos_store_dir(); - let indexer_store_dir = self.get_indexer_store_dir(); - if !rooch_store_dir.exists() { - std::fs::create_dir_all(rooch_store_dir.clone())?; - } - if !moveos_store_dir.exists() { - std::fs::create_dir_all(moveos_store_dir.clone())?; + let store_dir = self.get_store_dir(); + let indexer_store_dir = self.get_indexer_dir(); + if !store_dir.exists() { + std::fs::create_dir_all(store_dir.clone())?; } if !indexer_store_dir.exists() { std::fs::create_dir_all(indexer_store_dir.clone())?; @@ -121,26 +116,18 @@ impl StoreConfig { self.data_dir().join(DEFAULT_DB_DIR) } - pub fn get_moveos_store_dir(&self) -> PathBuf { - self.get_rooch_db_dir().join(DEFAULT_DB_MOVEOS_SUBDIR) - } - - pub fn get_rooch_store_dir(&self) -> PathBuf { - self.get_rooch_db_dir().join(DEFAULT_DB_ROOCH_SUBDIR) + pub fn get_store_dir(&self) -> PathBuf { + self.get_rooch_db_dir().join(DEFAULT_DB_STORE_SUBDIR) } - pub fn get_indexer_store_dir(&self) -> PathBuf { + pub fn get_indexer_dir(&self) -> PathBuf { self.get_rooch_db_dir().join(DEFAULT_DB_INDEXER_SUBDIR) } - pub fn rocksdb_config(&self, is_moveos_db: bool) -> RocksdbConfig { + pub fn rocksdb_config(&self) -> RocksdbConfig { let default = RocksdbConfig::default(); - let mut block_cache_size = default.block_cache_size; - let mut row_cache_size = default.row_cache_size; - if !is_moveos_db { - block_cache_size = DEFAULT_ROCKSDB_BLOCK_CACHE_SIZE; - row_cache_size = DEFAULT_ROCKSDB_ROW_CACHE_SIZE; - } + let block_cache_size = default.block_cache_size; + let row_cache_size = default.row_cache_size; RocksdbConfig { max_open_files: self.max_open_files.unwrap_or(default.max_open_files), @@ -163,18 +150,11 @@ impl StoreConfig { } } - pub fn get_mock_moveos_store_dir(data_dir: &DataDirPath) -> PathBuf { - data_dir - .path() - .join(DEFAULT_DB_DIR) - .join(DEFAULT_DB_MOVEOS_SUBDIR) - } - - pub fn get_mock_rooch_store_dir(data_dir: &DataDirPath) -> PathBuf { + pub fn get_mock_store_dir(data_dir: &DataDirPath) -> PathBuf { data_dir .path() .join(DEFAULT_DB_DIR) - .join(DEFAULT_DB_ROOCH_SUBDIR) + .join(DEFAULT_DB_STORE_SUBDIR) } } diff --git a/crates/rooch-db/src/lib.rs b/crates/rooch-db/src/lib.rs index c907d662d2..0b220dd399 100644 --- a/crates/rooch-db/src/lib.rs +++ b/crates/rooch-db/src/lib.rs @@ -1,6 +1,8 @@ // Copyright (c) RoochNetwork // SPDX-License-Identifier: Apache-2.0 +use std::collections::HashSet; + use anyhow::Result; use moveos_store::MoveOSStore; use moveos_types::moveos_std::object::RootObjectEntity; @@ -19,31 +21,34 @@ pub struct RoochDB { impl RoochDB { pub fn init(config: &StoreConfig) -> Result { - let (rooch_store_dir, moveos_store_dir, indexer_store_dir) = ( - config.get_rooch_store_dir(), - config.get_moveos_store_dir(), - config.get_indexer_store_dir(), - ); - - //TODO should we merge the moveos_store with rooch_store use one StoreInstance. - let moveos_store = - MoveOSStore::new_with_instance(StoreInstance::new_db_instance(RocksDB::new( - moveos_store_dir, - moveos_store::StoreMeta::get_column_family_names().to_vec(), - config.rocksdb_config(true), - None, - )?))?; - - let rooch_store = - RoochStore::new_with_instance(StoreInstance::new_db_instance(RocksDB::new( - rooch_store_dir, - rooch_store::StoreMeta::get_column_family_names().to_vec(), - config.rocksdb_config(false), - None, - )?))?; - - let indexer_store = IndexerStore::new(indexer_store_dir.clone())?; - let indexer_reader = IndexerReader::new(indexer_store_dir)?; + let (store_dir, indexer_dir) = (config.get_store_dir(), config.get_indexer_dir()); + + let mut column_families = moveos_store::StoreMeta::get_column_family_names().to_vec(); + column_families.append(&mut rooch_store::StoreMeta::get_column_family_names().to_vec()); + //ensure no duplicate column families + { + let mut set = HashSet::new(); + column_families.iter().for_each(|cf| { + if !set.insert(cf) { + panic!("Duplicate column family: {}", cf); + } + }); + } + + let instance = StoreInstance::new_db_instance(RocksDB::new( + store_dir, + column_families, + config.rocksdb_config(), + //TODO collect metrics + None, + )?); + + let moveos_store = MoveOSStore::new_with_instance(instance.clone())?; + + let rooch_store = RoochStore::new_with_instance(instance)?; + + let indexer_store = IndexerStore::new(indexer_dir.clone())?; + let indexer_reader = IndexerReader::new(indexer_dir)?; Ok(Self { moveos_store, diff --git a/crates/rooch/src/commands/indexer/commands/mod.rs b/crates/rooch/src/commands/indexer/commands/mod.rs index 7c0b963db0..381e1e7b6c 100644 --- a/crates/rooch/src/commands/indexer/commands/mod.rs +++ b/crates/rooch/src/commands/indexer/commands/mod.rs @@ -20,7 +20,7 @@ fn init_indexer( let store_config = opt.store_config(); - let indexer_db_path = store_config.get_indexer_store_dir(); + let indexer_db_path = store_config.get_indexer_dir(); let indexer_store = IndexerStore::new(indexer_db_path.clone())?; let indexer_reader = IndexerReader::new(indexer_db_path)?; diff --git a/moveos/moveos-store/src/lib.rs b/moveos/moveos-store/src/lib.rs index 69baf1c593..31e20a7ffa 100644 --- a/moveos/moveos-store/src/lib.rs +++ b/moveos/moveos-store/src/lib.rs @@ -39,7 +39,7 @@ pub mod transaction_store; // pub const DEFAULT_PREFIX_NAME: ColumnFamilyName = "default"; pub const STATE_NODE_PREFIX_NAME: ColumnFamilyName = "state_node"; -pub const TRANSACTION_PREFIX_NAME: ColumnFamilyName = "transaction"; +pub const TRANSACTION_EXECUTION_INFO_PREFIX_NAME: ColumnFamilyName = "transaction_execution_info"; pub const EVENT_PREFIX_NAME: ColumnFamilyName = "event"; pub const EVENT_HANDLE_PREFIX_NAME: ColumnFamilyName = "event_handle"; pub const CONFIG_STARTUP_INFO_PREFIX_NAME: ColumnFamilyName = "config_startup_info"; @@ -50,7 +50,7 @@ pub const CONFIG_GENESIS_PREFIX_NAME: ColumnFamilyName = "config_genesis"; static VEC_PREFIX_NAME: Lazy> = Lazy::new(|| { vec![ STATE_NODE_PREFIX_NAME, - TRANSACTION_PREFIX_NAME, + TRANSACTION_EXECUTION_INFO_PREFIX_NAME, EVENT_PREFIX_NAME, EVENT_HANDLE_PREFIX_NAME, CONFIG_STARTUP_INFO_PREFIX_NAME, diff --git a/moveos/moveos-store/src/transaction_store/mod.rs b/moveos/moveos-store/src/transaction_store/mod.rs index 2a0382d401..fc5bba1d37 100644 --- a/moveos/moveos-store/src/transaction_store/mod.rs +++ b/moveos/moveos-store/src/transaction_store/mod.rs @@ -6,14 +6,14 @@ use moveos_types::h256::H256; use moveos_types::transaction::TransactionExecutionInfo; use raw_store::CodecKVStore; -use crate::TRANSACTION_PREFIX_NAME; +use crate::TRANSACTION_EXECUTION_INFO_PREFIX_NAME; use raw_store::derive_store; derive_store!( TransactionDBStore, H256, TransactionExecutionInfo, - TRANSACTION_PREFIX_NAME + TRANSACTION_EXECUTION_INFO_PREFIX_NAME ); pub trait TransactionStore {