From 6cdf0a3ea633e9ce7ef05d26f06077e2a0456081 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 28 Feb 2023 23:45:04 +0800 Subject: [PATCH] fix: `seek_by_key_subkey` usage on `HistoricalStateProvider` (#1584) --- crates/storage/db/src/abstraction/cursor.rs | 2 +- crates/storage/provider/src/providers/state/historical.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/storage/db/src/abstraction/cursor.rs b/crates/storage/db/src/abstraction/cursor.rs index c5d1703b22a..3e28b78c14a 100644 --- a/crates/storage/db/src/abstraction/cursor.rs +++ b/crates/storage/db/src/abstraction/cursor.rs @@ -73,7 +73,7 @@ pub trait DbDupCursorRO<'tx, T: DupSort> { /// Returns the next `value` of a duplicate `key`. fn next_dup_val(&mut self) -> ValueOnlyResult; - /// Seek by key and subkey + /// Seek by key and subkey. Make sure that the returned value subkey matches the queried one. fn seek_by_key_subkey(&mut self, key: T::Key, subkey: T::SubKey) -> ValueOnlyResult; /// Returns an iterator starting at a key greater or equal than `start_key` of a DupSort diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index cd7ce2c8e77..b5339469128 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -56,6 +56,7 @@ impl<'a, 'b, TX: DbTx<'a>> AccountProvider for HistoricalStateProviderRef<'a, 'b .tx .cursor_dup_read::()? .seek_by_key_subkey(changeset_transition_id, address)? + .filter(|acc| acc.address == address) .ok_or(ProviderError::AccountChangeset { transition_id: changeset_transition_id, address, @@ -95,6 +96,7 @@ impl<'a, 'b, TX: DbTx<'a>> StateProvider for HistoricalStateProviderRef<'a, 'b, .tx .cursor_dup_read::()? .seek_by_key_subkey((changeset_transition_id, address).into(), storage_key)? + .filter(|entry| entry.key == storage_key) .ok_or(ProviderError::StorageChangeset { transition_id: changeset_transition_id, address, @@ -107,8 +109,9 @@ impl<'a, 'b, TX: DbTx<'a>> StateProvider for HistoricalStateProviderRef<'a, 'b, Ok(self .tx .cursor_dup_read::()? - .seek_by_key_subkey(address, storage_key) - .map(|r| r.map(|entry| entry.value))?) + .seek_by_key_subkey(address, storage_key)? + .filter(|entry| entry.key == storage_key) + .map(|entry| entry.value)) } }