Skip to content

starknet_patricia_storage: spawn blocking tasks for rocksDB reads#12168

Open
nimrod-starkware wants to merge 1 commit intographite-base/12168from
nimrod/parallel-reads/spawn-blocking-reads
Open

starknet_patricia_storage: spawn blocking tasks for rocksDB reads#12168
nimrod-starkware wants to merge 1 commit intographite-base/12168from
nimrod/parallel-reads/spawn-blocking-reads

Conversation

@nimrod-starkware
Copy link
Contributor

@nimrod-starkware nimrod-starkware commented Feb 1, 2026

Note

Medium Risk
Changes the execution model and error surface of RocksDB reads; while localized, it can impact performance and failure modes (e.g., task join/cancellation errors) under load.

Overview
RocksDB read operations in RocksDbStorage (get/mget) are now executed via tokio::task::spawn_blocking to avoid blocking async executors, with results/errors propagated back through the async Storage API.

To support this, the crate adds a tokio dependency and extends PatriciaStorageError with a JoinError variant; DeserializationError::ValueError is tightened to require Send so it can cross task boundaries.

Written by Cursor Bugbot for commit 9fd588f. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

nimrod-starkware commented Feb 1, 2026

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@nimrod-starkware nimrod-starkware changed the title starknet_particia_storage: spawn blocking tasks for rocksDB reads starknet_patricia_storage: spawn blocking tasks for rocksDB reads Feb 1, 2026
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/spawn-blocking-reads branch from d0eb009 to f0d1e7b Compare February 1, 2026 10:41
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/unordered-futures branch from 25d8851 to c241a58 Compare February 1, 2026 11:19
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/spawn-blocking-reads branch from f0d1e7b to a92bc6a Compare February 1, 2026 11:19
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/unordered-futures branch from c241a58 to 94e1db2 Compare February 2, 2026 08:36
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/spawn-blocking-reads branch from a92bc6a to 115e961 Compare February 2, 2026 08:36
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/unordered-futures branch from 94e1db2 to a72e9b6 Compare February 3, 2026 13:08
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/spawn-blocking-reads branch from 115e961 to 81de56c Compare February 3, 2026 13:08
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/unordered-futures branch from a72e9b6 to 89917c9 Compare February 3, 2026 14:59
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/spawn-blocking-reads branch from 81de56c to 1e672eb Compare February 3, 2026 14:59
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

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

Copy link
Contributor

@ArielElp ArielElp left a comment

Choose a reason for hiding this comment

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

@ArielElp reviewed 4 files and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @nimrod-starkware).


crates/starknet_patricia_storage/src/rocksdb_storage.rs line 297 at r1 (raw file):

        let keys: Vec<Vec<u8>> = keys.iter().map(|k| k.0.clone()).collect();
        spawn_blocking(move || {
            let raw_keys = keys.iter().map(|k| k.as_slice());

why is this needed? can't multi_get just get keys?


crates/starknet_patricia_storage/src/rocksdb_storage.rs line 303 at r1 (raw file):

                .collect::<Result<Vec<_>, PatriciaStorageError>>()
        })
        .await?

why not use the old structure? hopefuly this avoids map_err and type annotations for the compiler in collect

        spawn_blocking(move || {
            let res = db
                .multi_get(keys)
                .into_iter()
                .map(|r| r.map(|opt| opt.map(DbValue)))
                .collect::<Result<_, _>>()?;

            Ok(res)
        })
        .await?

Copy link
Contributor

@ArielElp ArielElp left a comment

Choose a reason for hiding this comment

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

@ArielElp made 1 comment.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @nimrod-starkware).


crates/starknet_patricia_storage/src/storage_trait.rs line 41 at r1 (raw file):

    #[error(transparent)]
    Deserialization(#[from] DeserializationError),
    #[error(transparent)]

Why the new error, possible from awaiting spawn_blocking?

@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/unordered-futures branch from 8c2f0f1 to f55e97b Compare February 17, 2026 07:13
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/spawn-blocking-reads branch from d9b393f to a39458d Compare February 17, 2026 07:13
Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

@nimrod-starkware made 2 comments.
Reviewable status: 2 of 4 files reviewed, 4 unresolved discussions (waiting on ArielElp).


crates/starknet_patricia_storage/src/rocksdb_storage.rs line 297 at r1 (raw file):

Previously, ArielElp wrote…

why is this needed? can't multi_get just get keys?

When you call spawn_blocking, you can't pass references unless they have 'static lifetime. (this is why i need to clone)


crates/starknet_patricia_storage/src/storage_trait.rs line 41 at r1 (raw file):

Previously, ArielElp wrote…

Why the new error, possible from awaiting spawn_blocking?

exactly

@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/unordered-futures branch from f55e97b to be9859b Compare February 19, 2026 09:21
@nimrod-starkware nimrod-starkware force-pushed the nimrod/parallel-reads/spawn-blocking-reads branch from a39458d to 9fd588f Compare February 19, 2026 09:21
@nimrod-starkware nimrod-starkware changed the base branch from nimrod/parallel-reads/unordered-futures to graphite-base/12168 February 19, 2026 10:30
Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

@nimrod-starkware made 1 comment.
Reviewable status: 2 of 4 files reviewed, 4 unresolved discussions (waiting on ArielElp).


crates/starknet_patricia_storage/src/rocksdb_storage.rs line 303 at r1 (raw file):

Previously, ArielElp wrote…

why not use the old structure? hopefuly this avoids map_err and type annotations for the compiler in collect

        spawn_blocking(move || {
            let res = db
                .multi_get(keys)
                .into_iter()
                .map(|r| r.map(|opt| opt.map(DbValue)))
                .collect::<Result<_, _>>()?;

            Ok(res)
        })
        .await?

This is because the new error variant that can happen as result of joining

Copy link
Contributor

@ArielElp ArielElp left a comment

Choose a reason for hiding this comment

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

@ArielElp reviewed 2 files and all commit messages, made 1 comment, and resolved 2 discussions.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on nimrod-starkware).


crates/starknet_patricia_storage/src/rocksdb_storage.rs line 303 at r1 (raw file):

Previously, nimrod-starkware wrote…

This is because the new error variant that can happen as result of joining

But PatriciaStorageError has two transparent variants, one for Rocks errors and one for join errors, so shouldn't ? work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments