From a9c75d2fc76d11a9d2071bd9c976cf33213ce51c Mon Sep 17 00:00:00 2001 From: rakita Date: Thu, 26 Jan 2023 17:39:28 +0100 Subject: [PATCH] bug(db): move seek fn from DubTable to Table (#1031) --- crates/storage/db/src/abstraction/cursor.rs | 6 +++--- crates/storage/db/src/abstraction/mock.rs | 8 ++++---- .../storage/db/src/implementation/mdbx/cursor.rs | 8 ++++---- .../storage/provider/src/providers/historical.rs | 16 +++++++--------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/crates/storage/db/src/abstraction/cursor.rs b/crates/storage/db/src/abstraction/cursor.rs index 4e4c9d058b..f99027f27d 100644 --- a/crates/storage/db/src/abstraction/cursor.rs +++ b/crates/storage/db/src/abstraction/cursor.rs @@ -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; + /// Seeks for a `(key, value)` pair greater or equal than `key`. + fn seek(&mut self, key: T::Key) -> PairResult; + /// Returns the next `(key, value)` pair. #[allow(clippy::should_implement_trait)] fn next(&mut self) -> PairResult; @@ -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; - /// Returns the next `(key, value)` pair of a DupSort table. fn next_dup(&mut self) -> PairResult; diff --git a/crates/storage/db/src/abstraction/mock.rs b/crates/storage/db/src/abstraction/mock.rs index fd30354063..f6db059d89 100644 --- a/crates/storage/db/src/abstraction/mock.rs +++ b/crates/storage/db/src/abstraction/mock.rs @@ -109,6 +109,10 @@ impl<'tx, T: Table> DbCursorRO<'tx, T> for CursorMock { todo!() } + fn seek(&mut self, _key: T::Key) -> PairResult { + todo!() + } + fn next(&mut self) -> PairResult { todo!() } @@ -151,10 +155,6 @@ impl<'tx, T: DupSort> DbDupCursorRO<'tx, T> for CursorMock { todo!() } - fn seek(&mut self, _key: T::SubKey) -> PairResult { - todo!() - } - fn next_no_dup(&mut self) -> PairResult { todo!() } diff --git a/crates/storage/db/src/implementation/mdbx/cursor.rs b/crates/storage/db/src/implementation/mdbx/cursor.rs index 9225ecc713..f14a922700 100644 --- a/crates/storage/db/src/implementation/mdbx/cursor.rs +++ b/crates/storage/db/src/implementation/mdbx/cursor.rs @@ -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: ::Key) -> PairResult { + decode!(self.inner.set_range(key.encode().as_ref())) + } + fn next(&mut self) -> PairResult { 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: ::SubKey) -> PairResult { - 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 { decode!(self.inner.next_dup()) diff --git a/crates/storage/provider/src/providers/historical.rs b/crates/storage/provider/src/providers/historical.rs index 6e140cfcf6..11bbee3800 100644 --- a/crates/storage/provider/src/providers/historical.rs +++ b/crates/storage/provider/src/providers/historical.rs @@ -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) }