diff --git a/src/eth/storage/rocks/rocks_cf.rs b/src/eth/storage/rocks/rocks_cf.rs index b752b49f1..a96e84528 100644 --- a/src/eth/storage/rocks/rocks_cf.rs +++ b/src/eth/storage/rocks/rocks_cf.rs @@ -117,7 +117,7 @@ where self.db.put_cf(&cf, serialized_key, serialized_value).unwrap(); } - pub fn prepare_batch_insertion(&self, changes: Vec<(K, V)>, current_block: Option, batch: &mut WriteBatch) { + pub fn prepare_batch_insertion(&self, changes: Vec<(K, V)>, batch: &mut WriteBatch) { let cf = self.db.cf_handle(&self.column_family).unwrap(); for (key, value) in changes { @@ -126,34 +126,6 @@ where // Add each serialized key-value pair to the batch batch.put_cf(&cf, serialized_key, serialized_value); } - - if let Some(current_block) = current_block { - let serialized_block_key = bincode::serialize(&"current_block").unwrap(); - let serialized_block_value = bincode::serialize(¤t_block).unwrap(); - batch.put_cf(&cf, serialized_block_key, serialized_block_value); - } - } - - /// inserts data but keep a block as key pointing to the keys inserted in a given block - /// this makes for faster search based on block_number, ergo index - pub fn prepare_batch_insertion_indexed(&self, changes: Vec<(K, V)>, current_block: u64, batch: &mut WriteBatch) { - let cf = self.db.cf_handle(&self.column_family).unwrap(); - - let mut keys = vec![]; - - for (key, value) in changes { - let serialized_key = bincode::serialize(&key).unwrap(); - let serialized_value = bincode::serialize(&value).unwrap(); - - keys.push(key); - - // Add each serialized key-value pair to the batch - batch.put_cf(&cf, serialized_key, serialized_value); - } - - let serialized_block_value = bincode::serialize(¤t_block).unwrap(); - let serialized_keys = bincode::serialize(&keys).unwrap(); - batch.put_cf(&cf, serialized_block_value, serialized_keys); } // Deletes an entry from the database by key diff --git a/src/eth/storage/rocks/rocks_permanent.rs b/src/eth/storage/rocks/rocks_permanent.rs index 424a3942d..e17e6fd3a 100644 --- a/src/eth/storage/rocks/rocks_permanent.rs +++ b/src/eth/storage/rocks/rocks_permanent.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use std::sync::atomic::AtomicU64; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -use std::sync::Arc; use async_trait::async_trait; use rocksdb::WriteBatch; @@ -157,9 +156,8 @@ impl PermanentStorage for RocksPermanentStorage { let txs_rocks = self.state.transactions.clone(); let logs_rocks = self.state.logs.clone(); - txs_rocks.prepare_batch_insertion_indexed(txs_batch, number.as_u64(), &mut batch); - - logs_rocks.prepare_batch_insertion_indexed(logs_batch, number.as_u64(), &mut batch); + txs_rocks.prepare_batch_insertion(txs_batch, &mut batch); + logs_rocks.prepare_batch_insertion(logs_batch, &mut batch); let hash = *block.hash(); @@ -171,9 +169,9 @@ impl PermanentStorage for RocksPermanentStorage { transaction.execution.changes.retain(|_, change| change.bytecode.clone().is_modified()); } let hash_clone = hash; - blocks_by_number.prepare_batch_insertion(vec![(number.into(), block_without_changes.into())], Some(number.as_u64()), &mut batch); + blocks_by_number.prepare_batch_insertion(vec![(number.into(), block_without_changes.into())], &mut batch); - blocks_by_hash.prepare_batch_insertion_indexed(vec![(hash_clone.into(), number.into())], number.as_u64(), &mut batch); + blocks_by_hash.prepare_batch_insertion(vec![(hash_clone.into(), number.into())], &mut batch); self.state.update_state_with_execution_changes(&account_changes, number, &mut batch); diff --git a/src/eth/storage/rocks/rocks_state.rs b/src/eth/storage/rocks/rocks_state.rs index 1e6fc42cc..99fe3c5d5 100644 --- a/src/eth/storage/rocks/rocks_state.rs +++ b/src/eth/storage/rocks/rocks_state.rs @@ -304,7 +304,7 @@ impl RocksStorageState { .collect::>(); let mut batch = WriteBatch::default(); - self_accounts_clone.prepare_batch_insertion(accounts_temp_vec, Some(block_number.into()), &mut batch); + self_accounts_clone.prepare_batch_insertion(accounts_temp_vec, &mut batch); self_accounts_clone.db.write(batch).unwrap(); info!("Accounts updated up to block number {}", block_number); @@ -335,7 +335,7 @@ impl RocksStorageState { .collect::>(); let mut batch = WriteBatch::default(); - self_account_slots_clone.prepare_batch_insertion(slots_temp_vec, Some(block_number.into()), &mut batch); + self_account_slots_clone.prepare_batch_insertion(slots_temp_vec, &mut batch); self_account_slots_clone.db.write(batch).unwrap(); } }); @@ -380,8 +380,8 @@ impl RocksStorageState { } } - accounts.prepare_batch_insertion(account_changes, Some(block_number.into()), batch); - accounts_history.prepare_batch_insertion_indexed(account_history_changes, block_number.into(), batch); + accounts.prepare_batch_insertion(account_changes, batch); + accounts_history.prepare_batch_insertion(account_history_changes, batch); let mut slot_changes = Vec::new(); let mut slot_history_changes = Vec::new(); @@ -396,8 +396,8 @@ impl RocksStorageState { } } } - account_slots.prepare_batch_insertion(slot_changes, Some(block_number.into()), batch); - account_slots_history.prepare_batch_insertion_indexed(slot_history_changes, block_number.into(), batch); + account_slots.prepare_batch_insertion(slot_changes, batch); + account_slots_history.prepare_batch_insertion(slot_history_changes, batch); } pub fn read_transaction(&self, tx_hash: &Hash) -> anyhow::Result> { @@ -546,7 +546,7 @@ impl RocksStorageState { .collect_vec(); let mut batch = WriteBatch::default(); - self.account_slots.prepare_batch_insertion(slot_batch, Some(block_number.into()), &mut batch); + self.account_slots.prepare_batch_insertion(slots, &mut batch); self.account_slots.db.write(batch).unwrap(); }