mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-22 19:49:28 +00:00
Merge branch 'get-range-fix' into init
This commit is contained in:
commit
108e58a9d1
7 changed files with 518 additions and 395 deletions
859
Cargo.lock
generated
859
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -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::{
|
||||
|
@ -268,10 +268,12 @@ pub fn get_block_complete_entry(
|
|||
|
||||
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::<Result<_, RuntimeError>>()?;
|
||||
|
||||
Ok(BlockCompleteEntry {
|
||||
|
|
|
@ -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::{
|
||||
|
@ -616,10 +614,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))
|
||||
})
|
||||
|
|
|
@ -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<T: Table>(db: &HeedDb<T::Key, T::Value>, tx_ro: &heed::RoTxn<'_>) ->
|
|||
|
||||
//---------------------------------------------------------------------------------------------------- DatabaseIter Impl
|
||||
impl<T: Table> DatabaseIter<T> for HeedTableRo<'_, T> {
|
||||
/*
|
||||
#[inline]
|
||||
fn get_range<'a, Range>(
|
||||
&'a self,
|
||||
|
@ -101,6 +102,8 @@ impl<T: Table> DatabaseIter<T> for HeedTableRo<'_, T> {
|
|||
Ok(self.db.range(self.tx_ro, &range)?.map(|res| Ok(res?.1)))
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
#[inline]
|
||||
fn iter(&self) -> DbResult<impl Iterator<Item = DbResult<(T::Key, T::Value)>> + '_> {
|
||||
Ok(self.db.iter(self.tx_ro)?.map(|res| Ok(res?)))
|
||||
|
|
|
@ -65,6 +65,7 @@ fn is_empty<T: Table>(
|
|||
|
||||
//---------------------------------------------------------------------------------------------------- DatabaseIter
|
||||
impl<T: Table + 'static> DatabaseIter<T> for RedbTableRo<T::Key, T::Value> {
|
||||
/*
|
||||
#[inline]
|
||||
fn get_range<'a, Range>(
|
||||
&'a self,
|
||||
|
@ -79,6 +80,8 @@ impl<T: Table + 'static> DatabaseIter<T> for RedbTableRo<T::Key, T::Value> {
|
|||
}))
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
#[inline]
|
||||
fn iter(&self) -> DbResult<impl Iterator<Item = DbResult<(T::Key, T::Value)>> + '_> {
|
||||
Ok(ReadableTable::iter(self)?.map(|result| {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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."
|
|||
/// - <https://github.com/Cuprate/cuprate/pull/102#discussion_r1548695610>
|
||||
/// - <https://github.com/Cuprate/cuprate/pull/104>
|
||||
pub trait DatabaseIter<T: Table> {
|
||||
/*
|
||||
FIXME: <https://github.com/Cuprate/cuprate/issues/348>
|
||||
|
||||
/// Get an [`Iterator`] of value's corresponding to a range of keys.
|
||||
///
|
||||
/// For example:
|
||||
|
@ -55,6 +56,8 @@ pub trait DatabaseIter<T: Table> {
|
|||
where
|
||||
Range: RangeBounds<T::Key> + 'a;
|
||||
|
||||
*/
|
||||
|
||||
/// Get an [`Iterator`] that returns the `(key, value)` types for this database.
|
||||
#[doc = doc_iter!()]
|
||||
#[expect(clippy::iter_not_returning_iterator)]
|
||||
|
|
Loading…
Reference in a new issue