From 5351b5d52daa70aa11fa1865933e36f01fb401f3 Mon Sep 17 00:00:00 2001 From: gabriel-aranha-cw Date: Fri, 7 Jun 2024 14:23:26 -0300 Subject: [PATCH] path override --- src/config.rs | 7 +++++- src/eth/consensus/mod.rs | 2 +- src/eth/storage/rocks/rocks_permanent.rs | 4 ++-- src/eth/storage/rocks/rocks_state.rs | 29 ++++++++++-------------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/config.rs b/src/config.rs index ef28cd27d..a3c3d624d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -836,6 +836,11 @@ pub struct PermanentStorageConfig { /// Permamenent storage timeout when opening a connection (in millis). #[arg(long = "perm-storage-timeout", value_parser=parse_duration, env = "PERM_STORAGE_TIMEOUT")] pub perm_storage_timeout: Duration, + + #[cfg(feature = "rocks")] + /// RocksDB storage path prefix to execute multiple local Stratus instances. + #[arg(long = "rocks-path-prefix", env = "ROCKS_PATH_PREFIX", default_value = "")] + pub rocks_path_prefix: Option, } #[derive(DebugAsJson, Clone, serde::Serialize)] @@ -856,7 +861,7 @@ impl PermanentStorageConfig { let perm: Arc = match self.perm_storage_kind { PermanentStorageKind::InMemory => Arc::new(InMemoryPermanentStorage::default()), #[cfg(feature = "rocks")] - PermanentStorageKind::Rocks => Arc::new(RocksPermanentStorage::new().await?), + PermanentStorageKind::Rocks => Arc::new(RocksPermanentStorage::new(self.rocks_path_prefix.clone()).await?), PermanentStorageKind::Postgres { ref url } => { let config = PostgresPermanentStorageConfig { url: url.to_owned(), diff --git a/src/eth/consensus/mod.rs b/src/eth/consensus/mod.rs index 0b306c4ba..cc2c285bc 100644 --- a/src/eth/consensus/mod.rs +++ b/src/eth/consensus/mod.rs @@ -207,7 +207,7 @@ impl Consensus { socket.connect("8.8.8.8:80").ok().unwrap(); let my_ip = socket.local_addr().ok().map(|addr| addr.ip().to_string()).unwrap(); - PeerAddress::new(format!("http://{}", my_ip), jsonrpc_port, grpc_port) //FIXME TODO pick ports from config + PeerAddress::new(format!("http://{}", my_ip), jsonrpc_port, grpc_port) } /// Initializes the heartbeat and election timers. diff --git a/src/eth/storage/rocks/rocks_permanent.rs b/src/eth/storage/rocks/rocks_permanent.rs index 74dc152d3..bdbefc483 100644 --- a/src/eth/storage/rocks/rocks_permanent.rs +++ b/src/eth/storage/rocks/rocks_permanent.rs @@ -41,10 +41,10 @@ pub struct RocksPermanentStorage { } impl RocksPermanentStorage { - pub async fn new() -> anyhow::Result { + pub async fn new(rocks_path_prefix: Option) -> anyhow::Result { tracing::info!("creating rocksdb storage"); - let state = RocksStorageState::new(); + let state = RocksStorageState::new(rocks_path_prefix); state.sync_data().await?; let block_number = state.preload_block_number()?; Ok(Self { state, block_number }) diff --git a/src/eth/storage/rocks/rocks_state.rs b/src/eth/storage/rocks/rocks_state.rs index b7cf34a44..f592f694a 100644 --- a/src/eth/storage/rocks/rocks_state.rs +++ b/src/eth/storage/rocks/rocks_state.rs @@ -53,20 +53,21 @@ pub struct RocksStorageState { pub backup_trigger: Arc>, } -impl Default for RocksStorageState { - fn default() -> Self { +impl RocksStorageState { + pub fn new(rocks_path_prefix: Option) -> Self { let (tx, rx) = mpsc::channel::<()>(1); - //XXX TODO while repair/restore from backup, make sure to sync online and only when its in sync with other nodes, receive requests + let path_prefix = rocks_path_prefix.unwrap_or_else(|| "".to_string()); + let state = Self { - accounts: RocksDb::new("./data/accounts.rocksdb", DbConfig::Default).unwrap(), - accounts_history: RocksDb::new("./data/accounts_history.rocksdb", DbConfig::FastWriteSST).unwrap(), - account_slots: RocksDb::new("./data/account_slots.rocksdb", DbConfig::Default).unwrap(), - account_slots_history: RocksDb::new("./data/account_slots_history.rocksdb", DbConfig::FastWriteSST).unwrap(), - transactions: RocksDb::new("./data/transactions.rocksdb", DbConfig::LargeSSTFiles).unwrap(), - blocks_by_number: RocksDb::new("./data/blocks_by_number.rocksdb", DbConfig::LargeSSTFiles).unwrap(), - blocks_by_hash: RocksDb::new("./data/blocks_by_hash.rocksdb", DbConfig::LargeSSTFiles).unwrap(), //XXX this is not needed we can afford to have blocks_by_hash pointing into blocks_by_number - logs: RocksDb::new("./data/logs.rocksdb", DbConfig::LargeSSTFiles).unwrap(), + accounts: RocksDb::new(&format!("{}./data/accounts.rocksdb", path_prefix), DbConfig::Default).unwrap(), + accounts_history: RocksDb::new(&format!("{}./data/accounts_history.rocksdb", path_prefix), DbConfig::FastWriteSST).unwrap(), + account_slots: RocksDb::new(&format!("{}./data/account_slots.rocksdb", path_prefix), DbConfig::Default).unwrap(), + account_slots_history: RocksDb::new(&format!("{}./data/account_slots_history.rocksdb", path_prefix), DbConfig::FastWriteSST).unwrap(), + transactions: RocksDb::new(&format!("{}./data/transactions.rocksdb", path_prefix), DbConfig::LargeSSTFiles).unwrap(), + blocks_by_number: RocksDb::new(&format!("{}./data/blocks_by_number.rocksdb", path_prefix), DbConfig::LargeSSTFiles).unwrap(), + blocks_by_hash: RocksDb::new(&format!("{}./data/blocks_by_hash.rocksdb", path_prefix), DbConfig::LargeSSTFiles).unwrap(), + logs: RocksDb::new(&format!("{}./data/logs.rocksdb", path_prefix), DbConfig::LargeSSTFiles).unwrap(), backup_trigger: Arc::new(tx), }; @@ -74,12 +75,6 @@ impl Default for RocksStorageState { state } -} - -impl RocksStorageState { - pub fn new() -> Self { - Self::default() - } pub fn listen_for_backup_trigger(&self, mut rx: mpsc::Receiver<()>) -> anyhow::Result<()> { tracing::info!("creating backup trigger listener");