bug(db): move seek fn from DubTable to Table (#1031)

This commit is contained in:
rakita
2023-01-26 17:39:28 +01:00
committed by GitHub
parent 6dcced0cfb
commit a9c75d2fc7
4 changed files with 18 additions and 20 deletions

View File

@@ -14,6 +14,9 @@ pub trait DbCursorRO<'tx, T: Table> {
/// Seeks for the exact `(key, value)` pair with `key`.
fn seek_exact(&mut self, key: T::Key) -> PairResult<T>;
/// Seeks for a `(key, value)` pair greater or equal than `key`.
fn seek(&mut self, key: T::Key) -> PairResult<T>;
/// Returns the next `(key, value)` pair.
#[allow(clippy::should_implement_trait)]
fn next(&mut self) -> PairResult<T>;
@@ -48,9 +51,6 @@ pub trait DbCursorRO<'tx, T: Table> {
/// Read only cursor over DupSort table.
pub trait DbDupCursorRO<'tx, T: DupSort> {
/// Seeks for a `(key, value)` pair greater or equal than `key`.
fn seek(&mut self, key: T::SubKey) -> PairResult<T>;
/// Returns the next `(key, value)` pair of a DupSort table.
fn next_dup(&mut self) -> PairResult<T>;

View File

@@ -109,6 +109,10 @@ impl<'tx, T: Table> DbCursorRO<'tx, T> for CursorMock {
todo!()
}
fn seek(&mut self, _key: T::Key) -> PairResult<T> {
todo!()
}
fn next(&mut self) -> PairResult<T> {
todo!()
}
@@ -151,10 +155,6 @@ impl<'tx, T: DupSort> DbDupCursorRO<'tx, T> for CursorMock {
todo!()
}
fn seek(&mut self, _key: T::SubKey) -> PairResult<T> {
todo!()
}
fn next_no_dup(&mut self) -> PairResult<T> {
todo!()
}

View File

@@ -52,6 +52,10 @@ impl<'tx, K: TransactionKind, T: Table> DbCursorRO<'tx, T> for Cursor<'tx, K, T>
decode!(self.inner.set_key(key.encode().as_ref()))
}
fn seek(&mut self, key: <T as Table>::Key) -> PairResult<T> {
decode!(self.inner.set_range(key.encode().as_ref()))
}
fn next(&mut self) -> PairResult<T> {
decode!(self.inner.next())
}
@@ -107,10 +111,6 @@ impl<'tx, K: TransactionKind, T: Table> DbCursorRO<'tx, T> for Cursor<'tx, K, T>
}
impl<'tx, K: TransactionKind, T: DupSort> DbDupCursorRO<'tx, T> for Cursor<'tx, K, T> {
fn seek(&mut self, key: <T as DupSort>::SubKey) -> PairResult<T> {
decode!(self.inner.set_range(key.encode().as_ref()))
}
/// Returns the next `(key, value)` pair of a DUPSORT table.
fn next_dup(&mut self) -> PairResult<T> {
decode!(self.inner.next_dup())

View File

@@ -1,9 +1,6 @@
use crate::{AccountProvider, BlockHashProvider, StateProvider};
use reth_db::{
cursor::{DbCursorRO, DbDupCursorRO},
models::storage_sharded_key::StorageShardedKey,
tables,
transaction::DbTx,
cursor::DbCursorRO, models::storage_sharded_key::StorageShardedKey, tables, transaction::DbTx,
};
use reth_interfaces::Result;
use reth_primitives::{
@@ -71,11 +68,12 @@ impl<'a, 'b, TX: DbTx<'a>> StateProvider for HistoricalStateProviderRef<'a, 'b,
return Ok(Some(entry.value))
}
if let Some((_, entry)) = cursor.seek(storage_key)? {
if entry.key == storage_key {
return Ok(Some(entry.value))
}
}
// TODO(rakita) this will be reworked shortly in StorageHistory PR.
// if let Some((_, entry)) = cursor.seek(storage_key)? {
// if entry.key == storage_key {
// return Ok(Some(entry.value))
// }
// }
}
Ok(None)
}