diff --git a/storage/blockchain/src/ops/block.rs b/storage/blockchain/src/ops/block.rs index d4ab1dd..191b49c 100644 --- a/storage/blockchain/src/ops/block.rs +++ b/storage/blockchain/src/ops/block.rs @@ -9,7 +9,7 @@ use monero_serai::{ }; use cuprate_database::{ - DbResult, RuntimeError, StorableVec, {DatabaseIter, DatabaseRo, DatabaseRw}, + DbResult, RuntimeError, StorableVec, {DatabaseRo, DatabaseRw}, }; use cuprate_helper::cast::usize_to_u64; use cuprate_helper::{ @@ -278,10 +278,12 @@ pub fn get_block_complete_entry_from_height( let first_tx_idx = miner_tx_idx + 1; - let tx_blobs = tables - .tx_blobs_iter() - .get_range(first_tx_idx..(usize_to_u64(numb_non_miner_txs) + first_tx_idx))? - .map(|tx_blob| Ok(Bytes::from(tx_blob?.0))) + let tx_blobs = (first_tx_idx..(usize_to_u64(numb_non_miner_txs) + first_tx_idx)) + .map(|idx| { + let tx_blob = tables.tx_blobs().get(&idx)?.0; + + Ok(Bytes::from(tx_blob)) + }) .collect::>()?; Ok(BlockCompleteEntry { diff --git a/storage/blockchain/src/service/read.rs b/storage/blockchain/src/service/read.rs index ca660bd..387e2e2 100644 --- a/storage/blockchain/src/service/read.rs +++ b/storage/blockchain/src/service/read.rs @@ -22,9 +22,7 @@ use rayon::{ }; use thread_local::ThreadLocal; -use cuprate_database::{ - ConcreteEnv, DatabaseIter, DatabaseRo, DbResult, Env, EnvInner, RuntimeError, -}; +use cuprate_database::{ConcreteEnv, DatabaseRo, DbResult, Env, EnvInner, RuntimeError}; use cuprate_database_service::{init_thread_pool, DatabaseReadService, ReaderThreads}; use cuprate_helper::map::combine_low_high_bits_to_u128; use cuprate_types::{ @@ -638,10 +636,9 @@ fn next_chain_entry( let chain_height = crate::ops::blockchain::chain_height(table_block_heights)?; let last_height_in_chain_entry = min(first_known_height + next_entry_size, chain_height); - let (block_ids, block_weights) = table_block_infos - .get_range(first_known_height..last_height_in_chain_entry)? - .map(|block_info| { - let block_info = block_info?; + let (block_ids, block_weights) = (first_known_height..last_height_in_chain_entry) + .map(|height| { + let block_info = table_block_infos.get(&height)?; Ok((block_info.block_hash, block_info.weight)) }) diff --git a/storage/database/src/backend/heed/database.rs b/storage/database/src/backend/heed/database.rs index 15f16b4..c17fddf 100644 --- a/storage/database/src/backend/heed/database.rs +++ b/storage/database/src/backend/heed/database.rs @@ -1,7 +1,7 @@ //! Implementation of `trait Database` for `heed`. //---------------------------------------------------------------------------------------------------- Import -use std::{cell::RefCell, ops::RangeBounds}; +use std::cell::RefCell; use crate::{ backend::heed::types::HeedDb, @@ -90,6 +90,7 @@ fn is_empty(db: &HeedDb, tx_ro: &heed::RoTxn<'_>) -> //---------------------------------------------------------------------------------------------------- DatabaseIter Impl impl DatabaseIter for HeedTableRo<'_, T> { + /* #[inline] fn get_range<'a, Range>( &'a self, @@ -101,6 +102,8 @@ impl DatabaseIter for HeedTableRo<'_, T> { Ok(self.db.range(self.tx_ro, &range)?.map(|res| Ok(res?.1))) } + */ + #[inline] fn iter(&self) -> DbResult> + '_> { Ok(self.db.iter(self.tx_ro)?.map(|res| Ok(res?))) diff --git a/storage/database/src/backend/redb/database.rs b/storage/database/src/backend/redb/database.rs index 0be58ef..84d7c75 100644 --- a/storage/database/src/backend/redb/database.rs +++ b/storage/database/src/backend/redb/database.rs @@ -65,6 +65,7 @@ fn is_empty( //---------------------------------------------------------------------------------------------------- DatabaseIter impl DatabaseIter for RedbTableRo { + /* #[inline] fn get_range<'a, Range>( &'a self, @@ -79,6 +80,8 @@ impl DatabaseIter for RedbTableRo { })) } + */ + #[inline] fn iter(&self) -> DbResult> + '_> { Ok(ReadableTable::iter(self)?.map(|result| { diff --git a/storage/database/src/backend/tests.rs b/storage/database/src/backend/tests.rs index 0c0fe05..93454bf 100644 --- a/storage/database/src/backend/tests.rs +++ b/storage/database/src/backend/tests.rs @@ -225,7 +225,7 @@ fn db_read_write() { // Assert the whole range is there. { - let range = table_ro.get_range(..).unwrap(); + let range = table_ro.values().unwrap(); let mut i = 0; for result in range { let value = result.unwrap(); @@ -235,20 +235,14 @@ fn db_read_write() { assert_eq!(i, N); } - // `get_range()` tests. - let mut key = KEY; - key += N; - let range = KEY..key; + // iter tests. // Assert count is correct. - assert_eq!( - N as usize, - table_ro.get_range(range.clone()).unwrap().count() - ); + assert_eq!(N as usize, table_ro.values().unwrap().count()); // Assert each returned value from the iterator is owned. { - let mut iter = table_ro.get_range(range.clone()).unwrap(); + let mut iter = table_ro.values().unwrap(); let value = iter.next().unwrap().unwrap(); // 1. take value out drop(iter); // 2. drop the `impl Iterator + 'a` assert_value(value); // 3. assert even without the iterator, the value is alive @@ -256,7 +250,7 @@ fn db_read_write() { // Assert each value is the same. { - let mut iter = table_ro.get_range(range).unwrap(); + let mut iter = table_ro.values().unwrap(); for _ in 0..N { let value = iter.next().unwrap().unwrap(); assert_value(value); diff --git a/storage/database/src/database.rs b/storage/database/src/database.rs index c019972..fcee041 100644 --- a/storage/database/src/database.rs +++ b/storage/database/src/database.rs @@ -1,8 +1,6 @@ //! Abstracted database table operations; `trait DatabaseRo` & `trait DatabaseRw`. //---------------------------------------------------------------------------------------------------- Import -use std::ops::RangeBounds; - use crate::{ error::{DbResult, RuntimeError}, table::Table, @@ -35,6 +33,9 @@ Each iteration of the iterator has the potential to error as well." /// - /// - pub trait DatabaseIter { + /* + FIXME: + /// Get an [`Iterator`] of value's corresponding to a range of keys. /// /// For example: @@ -55,6 +56,8 @@ pub trait DatabaseIter { where Range: RangeBounds + 'a; + */ + /// Get an [`Iterator`] that returns the `(key, value)` types for this database. #[doc = doc_iter!()] #[expect(clippy::iter_not_returning_iterator)]