diff --git a/base_layer/core/src/chain_storage/lmdb_db/key_prefix_cursor.rs b/base_layer/core/src/chain_storage/lmdb_db/key_prefix_cursor.rs index a0401b4771..30dc674658 100644 --- a/base_layer/core/src/chain_storage/lmdb_db/key_prefix_cursor.rs +++ b/base_layer/core/src/chain_storage/lmdb_db/key_prefix_cursor.rs @@ -62,26 +62,6 @@ where V: DeserializeOwned } } - /// Returns the item on or before the given seek key, progressing backwards until the key prefix no longer matches - #[allow(dead_code)] - pub fn prev(&mut self) -> Result, V)>, ChainStorageError> { - if !self.has_seeked { - let prefix_key = self.prefix_key; - if let Some((k, val)) = self.seek_gte(prefix_key)? { - // seek_range_k returns the greater key, so we only want to return the current value that was seeked to - // if it exactly matches the prefix_key - if k == prefix_key { - return Ok(Some((k, val))); - } - } - } - - match self.cursor.prev(&self.access).to_opt()? { - Some((k, v)) => Self::deserialize_if_matches(self.prefix_key, k, v), - None => Ok(None), - } - } - // This function could be used later in cases where multiple seeks are required. #[cfg(test)] pub fn reset_to(&mut self, prefix_key: &'a [u8]) { diff --git a/base_layer/core/src/chain_storage/lmdb_db/lmdb.rs b/base_layer/core/src/chain_storage/lmdb_db/lmdb.rs index defd4a0af8..75e238b088 100644 --- a/base_layer/core/src/chain_storage/lmdb_db/lmdb.rs +++ b/base_layer/core/src/chain_storage/lmdb_db/lmdb.rs @@ -445,52 +445,3 @@ pub fn lmdb_clear(txn: &WriteTransaction<'_>, db: &Database) -> Result( - txn: &WriteTransaction<'_>, - db: &Database, - f: F, -) -> Result<(), ChainStorageError> -where - F: Fn(V) -> Option, - V: DeserializeOwned, - R: Serialize, -{ - let mut access = txn.access(); - let mut cursor = txn.cursor(db).map_err(|e| { - error!(target: LOG_TARGET, "Could not get read cursor from lmdb: {:?}", e); - ChainStorageError::AccessError(e.to_string()) - })?; - let iter = CursorIter::new( - MaybeOwned::Borrowed(&mut cursor), - &access, - |c, a| c.first(a), - Cursor::next::<[u8], [u8]>, - )?; - let items = iter - .map(|r| r.map(|(k, v)| (k.to_vec(), v.to_vec()))) - .collect::, _>>()?; - - for (key, val) in items { - // let (key, val) = row?; - let val = deserialize::(&val)?; - if let Some(ret) = f(val) { - let ret_bytes = serialize(&ret)?; - access.put(db, &key, &ret_bytes, put::Flags::empty()).map_err(|e| { - if let lmdb_zero::Error::Code(code) = &e { - if *code == lmdb_zero::error::MAP_FULL { - return ChainStorageError::DbResizeRequired; - } - } - error!( - target: LOG_TARGET, - "Could not replace value in lmdb transaction: {:?}", e - ); - ChainStorageError::AccessError(e.to_string()) - })?; - } - } - Ok(()) -}