diff --git a/crates/storage/db/src/tables/models/sharded_key.rs b/crates/storage/db/src/tables/models/sharded_key.rs index eefc175e3e..71985f1f8e 100644 --- a/crates/storage/db/src/tables/models/sharded_key.rs +++ b/crates/storage/db/src/tables/models/sharded_key.rs @@ -29,6 +29,12 @@ impl ShardedKey { pub fn new(key: T, highest_block_number: BlockNumber) -> Self { ShardedKey { key, highest_block_number } } + + /// Creates a new key with the highest block number set to maximum. + /// This is useful when we want to search the last value for a given key. + pub fn last(key: T) -> Self { + Self { key, highest_block_number: u64::MAX } + } } impl Encode for ShardedKey diff --git a/crates/storage/db/src/tables/models/storage_sharded_key.rs b/crates/storage/db/src/tables/models/storage_sharded_key.rs index e8f3d55a41..2b8025a8f3 100644 --- a/crates/storage/db/src/tables/models/storage_sharded_key.rs +++ b/crates/storage/db/src/tables/models/storage_sharded_key.rs @@ -1,4 +1,4 @@ -//! Sharded key +//! Storage sharded key use crate::{ table::{Decode, Encode}, @@ -32,6 +32,15 @@ impl StorageShardedKey { pub fn new(address: H160, storage_key: H256, highest_block_number: BlockNumber) -> Self { Self { address, sharded_key: ShardedKey { key: storage_key, highest_block_number } } } + + /// Creates a new key with the highest block number set to maximum. + /// This is useful when we want to search the last value for a given key. + pub fn last(address: H160, storage_key: H256) -> Self { + Self { + address, + sharded_key: ShardedKey { key: storage_key, highest_block_number: u64::MAX }, + } + } } impl Encode for StorageShardedKey {