From 1c4adb8765f9f14ed367772c424bfdc36dc94de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20Bezerra?= Date: Mon, 20 May 2024 01:41:09 -0300 Subject: [PATCH] chore: cleanup unused RocksDB functions --- .gitignore | 1 + src/eth/storage/rocks/rocks_db.rs | 13 ++--- src/eth/storage/rocks/rocks_permanent.rs | 4 +- src/eth/storage/rocks/rocks_state.rs | 72 ------------------------ 4 files changed, 6 insertions(+), 84 deletions(-) diff --git a/.gitignore b/.gitignore index e9635ea15..f48f821e7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ data/**/*.db data/**/*.json data/**/*.txt data/**/*.rocksdb +data/rocksdb/ # E2E (Stratus) e2e/artifacts diff --git a/src/eth/storage/rocks/rocks_db.rs b/src/eth/storage/rocks/rocks_db.rs index ef1e5c8af..731ce500b 100644 --- a/src/eth/storage/rocks/rocks_db.rs +++ b/src/eth/storage/rocks/rocks_db.rs @@ -10,7 +10,6 @@ use anyhow::anyhow; use anyhow::Result; use rocksdb::backup::BackupEngine; use rocksdb::backup::BackupEngineOptions; -use rocksdb::backup::RestoreOptions; #[cfg(feature = "metrics")] use rocksdb::statistics::Histogram; #[cfg(feature = "metrics")] @@ -57,8 +56,11 @@ pub struct RocksDb { impl Deserialize<'de> + std::hash::Hash + Eq, V: Serialize + for<'de> Deserialize<'de> + Clone> RocksDb { pub fn new(cf_name: &str, db: Arc, config: DbConfig) -> anyhow::Result> { - let opts = Self::get_options(config, cf_name == "accounts" || cf_name == "account_slots"); + let enable_cache = cf_name == "accounts" || cf_name == "account_slots"; + let opts = Self::get_options(config, enable_cache); + db.create_cf(cf_name, &opts)?; + Ok(Arc::new(Self { db, opts, @@ -233,13 +235,6 @@ impl Deserialize<'de> + std::hash::Hash + Eq, V: Seriali Ok(()) } - pub fn restore(&self) -> anyhow::Result<()> { - let mut backup_engine = self.backup_engine()?; - let restore_options = RestoreOptions::default(); - backup_engine.restore_from_latest_backup(self.db.path(), self.backup_path()?, &restore_options)?; - Ok(()) - } - // Clears the database pub fn clear(&self) -> Result<()> { let mut batch = WriteBatch::default(); diff --git a/src/eth/storage/rocks/rocks_permanent.rs b/src/eth/storage/rocks/rocks_permanent.rs index de892cc86..a71a4e37c 100644 --- a/src/eth/storage/rocks/rocks_permanent.rs +++ b/src/eth/storage/rocks/rocks_permanent.rs @@ -40,9 +40,7 @@ pub struct RocksPermanentStorage { impl RocksPermanentStorage { pub async fn new() -> anyhow::Result { tracing::info!("starting rocksdb storage"); - - let state = RocksStorageState::new("./data/rocks"); - //state.sync_data().await?; + let state = RocksStorageState::new("./data/rocksdb"); 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 4c0a22f1f..4095fddbb 100644 --- a/src/eth/storage/rocks/rocks_state.rs +++ b/src/eth/storage/rocks/rocks_state.rs @@ -13,7 +13,6 @@ use rocksdb::DB; use tokio::sync::mpsc; use tokio::task; use tracing::info; -use tracing::warn; use super::rocks_db::DbConfig; use super::rocks_db::RocksDb; @@ -115,77 +114,6 @@ impl RocksStorageState { Ok((account_block_number.to_u64().unwrap_or(0u64)).into()) } - pub async fn sync_data(&self) -> anyhow::Result<()> { - tracing::info!("starting sync_data"); - tracing::info!("account_block_number {:?}", self.accounts.get_current_block_number()); - tracing::info!("slots_block_number {:?}", self.account_slots.get_current_block_number()); - tracing::info!("slots_history_block_number {:?}", self.account_slots_history.get_index_block_number()); - tracing::info!("accounts_history_block_number {:?}", self.accounts_history.get_index_block_number()); - tracing::info!("logs_block_number {:?}", self.logs.get_index_block_number()); - tracing::info!("transactions_block_number {:?}", self.transactions.get_index_block_number()); - - if let Some((last_block_number, _)) = self.blocks_by_number.last() { - tracing::info!("last_block_number {:?}", last_block_number); - if self.accounts.get_current_block_number() != self.account_slots.get_current_block_number() { - warn!( - "block numbers are not in sync {:?} {:?} {:?} {:?} {:?} {:?}", - self.accounts.get_current_block_number(), - self.account_slots.get_current_block_number(), - self.account_slots_history.get_index_block_number(), - self.accounts_history.get_index_block_number(), - self.logs.get_index_block_number(), - self.transactions.get_index_block_number(), - ); - let mut min_block_number = std::cmp::min( - std::cmp::min( - std::cmp::min(self.accounts.get_current_block_number(), self.account_slots.get_current_block_number()), - std::cmp::min( - self.account_slots_history.get_index_block_number(), - self.accounts_history.get_index_block_number(), - ), - ), - std::cmp::min(self.logs.get_index_block_number(), self.transactions.get_index_block_number()), - ); - - let last_secure_block_number = last_block_number.inner_value().as_u64() - 5000; - if last_secure_block_number > min_block_number { - self.accounts.restore().unwrap(); - tracing::warn!("accounts restored"); - self.accounts_history.restore().unwrap(); - tracing::warn!("accounts_history restored"); - self.account_slots.restore().unwrap(); - tracing::warn!("account_slots restored"); - self.account_slots_history.restore().unwrap(); - tracing::warn!("account_slots_history restored"); - self.transactions.restore().unwrap(); - tracing::warn!("transactions restored"); - self.blocks_by_number.restore().unwrap(); - tracing::warn!("blocks_by_number restored"); - self.blocks_by_hash.restore().unwrap(); - tracing::warn!("blocks_by_hash restored"); - self.logs.restore().unwrap(); - tracing::warn!("logs restored"); - - min_block_number = std::cmp::min( - std::cmp::min( - std::cmp::min(self.accounts.get_current_block_number(), self.account_slots.get_current_block_number()), - std::cmp::min( - self.account_slots_history.get_index_block_number(), - self.accounts_history.get_index_block_number(), - ), - ), - std::cmp::min(self.logs.get_index_block_number(), self.transactions.get_index_block_number()), - ); - } - self.reset_at(BlockNumber::from(min_block_number)).await?; - } - } - - tracing::info!("data is in sync"); - - Ok(()) - } - pub async fn reset_at(&self, block_number: BlockNumber) -> anyhow::Result<()> { let tasks = vec![ {