Skip to content
This repository was archived by the owner on Aug 7, 2026. It is now read-only.

feat(smt): Fjall storage backend for RocksDbStorage - #1101

Open
battlmonstr wants to merge 45 commits into
0xMiden:nextfrom
battlmonstr:smt-bench-fjall
Open

feat(smt): Fjall storage backend for RocksDbStorage#1101
battlmonstr wants to merge 45 commits into
0xMiden:nextfrom
battlmonstr:smt-bench-fjall

Conversation

@battlmonstr

@battlmonstr battlmonstr commented Jul 21, 2026

Copy link
Copy Markdown

Overview

The goal is to implement alternative storage backends for merkle::smt::large::storage and compare them against each other. A Fjall database was chosen as a promising candidate alternative. A couple of others backends are tested but not included here.

RocksDbStorage (rocksdb.rs) used to have business logic to store a large SMT. That business logic was wired to RocksDB but in theory could be applied to any key-value storage mechanism.

Instead of copy-pasting RocksDbStorage for each backend an approach was chosen to refactor the RocksDbStorage to work with a new set of abstract KVDB traits. These traits can be implemented for multiple alternative backends. It saves time because instead of testing, updating and reviewing the whole 1700 SLOC per backend the new code has about 400 SLOC per backend.

Contents

The PR commits are organized in this sequence:

  1. Preparational commits and refactorings.
  2. RocksDbStorage refactoring onto KVDB traits: the traits and RocksKVDB implementation are introduced, then RocksDbStorage is ported method by method, and finalized with a code cleanup.
  3. Generalizing RocksDbStorage to KVDBSmtStorage and introducing an smt-kvdb-rocks feature flag to prepare for alternative backends. Renamings after generalization.
  4. Fjall KVDB implementation with smt-kvdb-fjall feature flag.

Each intermediate commit produces a valid state in which tests and benchmarks pass.
It is recommended to do code review sequentially commit by commit.

Tests

make test-large-smt
make test-large-smt-no-forest
make test-large-smt-fjall

Benchmarks

macOS 26, Mac Mini M4 Pro 10+4 cores

test RocksDB Fjall
test-large-smt-no-forest 0.4 sec 0.6 sec
bench-large-smt-rocksdb 11 sec 11.2 sec
bench-large-smt-rocksdb-open 3.5 sec 4 sec
bench-large-smt-codspeed-rocksdb - -46%..-5%
bench-large-smt-criterion-rocksdb - -34%..+22%

Fjall patch

Original Fjall runs criterion benchmarks and rocksdb_large_smt integration test much slower than RocksDB because it calls fsync() multiple times during normal operation while RocksDB doesn't. fjall library and its dependency lsm-tree are patched to disable this behavior and speed up the tests.

@battlmonstr
battlmonstr force-pushed the smt-bench-fjall branch 8 times, most recently from 46ea10b to ae1f4d3 Compare July 24, 2026 19:40
to support RustRover IDE
Without --reset it is not possible to run the command twice in a row.
It fails with an error when running on an existing db.
The existing target runs both smt::large and smt::large_forest unit tests.
Running only smt::large is useful until the large_forest module is refactored.
The Makefile declares bench-large-smt-* targets to run benchmarks in the miden-crypto binary (main.rs).

There are 2 more related benchmarks:
* "criterion" - miden-crypto/benches/large_smt.rs
* "codspeed" - benches/smt-codspeed/benches/smt_codspeed.rs

It is useful to be able to run them in isolation for alternative backends comparison.
This is needed to make RocksDbConfig backend-agnostic.
write_buffer_manager creation relies on rocksdb library.
for reuse across alternative backends
The constants are shared among alternative backends.
@battlmonstr
battlmonstr marked this pull request as ready for review July 25, 2026 07:25
@github-actions

Copy link
Copy Markdown

Automated check (CONTRIBUTING.md)

Findings:

Recommendations:

  • Consider adding a Test plan or clear review steps.

Next steps:

@battlmonstr

Copy link
Copy Markdown
Author

/quality-review

@battlmonstr

Copy link
Copy Markdown
Author

@sergerad, @krushimir, @huitseeker this is ready for review, please approve the CI workflows 🙏

@battlmonstr
battlmonstr force-pushed the smt-bench-fjall branch 3 times, most recently from 2ac8eb6 to 4e5d071 Compare July 28, 2026 10:01
Before RocksDbStorage implementation was tied to RocksKVDB backend.
Now the implementation is renamed to KVDBSmtStorage<KVDB>.
RocksDbStorage is an alias to KVDBSmtStorage<RocksKVDB>.
Before "rocksdb" feature enabled both persistence and RocksDB backend.
This adds a new feature "smt-kvdb" for persistence (backend agnostic).
A new feature set "smt-kvdb-*" to enable persistence with a particular backend.
"rocksdb" is alias of "smt-kvdb-rocks".

smt-kvdb-default feature is needed for --all-features builds.
In such build smt-kvdb-default is enabled, and it effectively disables non-default backends.
change RocksDb prefix to PersistentSmtStorage on all related config types
because this config is reused between different backends.
and RocksDbSnapshotStorage to PersistentSmtStorageSnapshot
because this class can be backed by alternative backends.
After generic KVDBSmtStorage refactoring this implementation is not tied to RocksDB,
so the comments need to be updated.
After generic KVDBSmtStorage refactoring this file is not tied to RocksDB.
KVDB traits implementation using Fjall database.
This backend can be selected by smt-kvdb-fjall feature flag.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant