Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/starknet_patricia_storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ serde_json.workspace = true
starknet-types-core.workspace = true
starknet_api.workspace = true
thiserror.workspace = true
tokio.workspace = true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant tokio dev-dependency after promoting to dependency

Low Severity

tokio.workspace = true now appears in both [dependencies] (line 34, newly added) and [dev-dependencies] (line 41, pre-existing). Since both use workspace = true with no additional features, the dev-dependency entry is now redundant — regular dependencies are automatically available in tests and benchmarks.

Additional Locations (1)

Fix in Cursor Fix in Web

validator = { workspace = true, features = ["derive"] }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_patricia_storage/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ pub enum DeserializationError {
// TODO(Ariel): This is only used for EdgeNode construction failures (path length etc.), add
// error types here and use them instead of the general ValueError.
#[error("Invalid value for deserialization: {0}.")]
ValueError(Box<dyn std::error::Error>),
ValueError(Box<dyn std::error::Error + Send>),
}
24 changes: 15 additions & 9 deletions crates/starknet_patricia_storage/src/rocksdb_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rust_rocksdb::{
DB,
};
use serde::{Deserialize, Serialize};
use tokio::task::spawn_blocking;
use validator::Validate;

use crate::storage_trait::{
Expand Down Expand Up @@ -278,22 +279,27 @@ impl Storage for RocksDbStorage {
type Config = RocksDbStorageConfig;

async fn get(&self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
Ok(self.db.get(&key.0)?.map(DbValue))
// TODO(Nimrod): Config should indicate whether to spawn a task or not.
let db = self.db.clone();
let key = key.clone();
Ok(spawn_blocking(move || db.get(&key.0).map(|opt| opt.map(DbValue))).await??)
}

async fn set(&mut self, key: DbKey, value: DbValue) -> PatriciaStorageResult<()> {
Ok(self.db.put_opt(&key.0, &value.0, &self.options.write_options)?)
}

async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
let raw_keys = keys.iter().map(|k| &k.0);
let res = self
.db
.multi_get(raw_keys)
.into_iter()
.map(|r| r.map(|opt| opt.map(DbValue)))
.collect::<Result<_, _>>()?;
Ok(res)
// TODO(Nimrod): Config should indicate whether to spawn a task or not.
let db = self.db.clone();
let keys: Vec<Vec<u8>> = keys.iter().map(|k| k.0.clone()).collect();
spawn_blocking(move || {
db.multi_get(keys)
.into_iter()
.map(|r| Ok(r?.map(DbValue)))
.collect::<PatriciaStorageResult<_>>()
})
.await?
}

async fn mset(&mut self, key_to_value: DbHashMap) -> PatriciaStorageResult<()> {
Expand Down
3 changes: 3 additions & 0 deletions crates/starknet_patricia_storage/src/storage_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use apollo_config::dumping::SerializeConfig;
use apollo_config::{ParamPath, SerializedParam};
use serde::{Deserialize, Serialize, Serializer};
use starknet_types_core::felt::Felt;
use tokio::task::JoinError;
use validator::Validate;

use crate::errors::DeserializationError;
Expand Down Expand Up @@ -37,6 +38,8 @@ pub enum PatriciaStorageError {
AerospikeStorage(#[from] crate::aerospike_storage::AerospikeStorageError),
#[error(transparent)]
Deserialization(#[from] DeserializationError),
#[error(transparent)]
Join(#[from] JoinError),
#[cfg(any(test, feature = "mdbx_storage"))]
#[error(transparent)]
Mdbx(#[from] libmdbx::Error),
Expand Down
Loading