Skip to content

feat: SmtStorageReader trait#958

Closed
sergerad wants to merge 8 commits intonextfrom
sergerad-clone
Closed

feat: SmtStorageReader trait#958
sergerad wants to merge 8 commits intonextfrom
sergerad-clone

Conversation

@sergerad
Copy link
Copy Markdown
Contributor

@sergerad sergerad commented Apr 12, 2026

Description

Extract a new SmtStorageReader trait from SmtStorage, enabling LargeSmt<S> to work with read-only storage for read operations, and only require SmtStorage for mutations.

Motivation

Previously, LargeSmt<S: SmtStorage> required full read+write storage for all operations, including purely read-only ones like get_leaf, get_value, open, and tree loading. This made it impossible to use LargeSmt with a read-only storage backend.

In miden-node (PR), we are working towards removing synchronization mechanisms by providing read-only types which can be cloned.

Changes

Trait hierarchy (storage/mod.rs):

  • SmtStorageReader&self methods (leaf/subtree reads, iterators, get_depth24)
  • SmtStorage: SmtStorageReader&mut self methods (inserts, removes, apply)

LargeSmt<S> struct bound relaxed (large/mod.rs):

  • Struct bound changed from S: SmtStorage to S: SmtStorageReader
  • Impl blocks split by required capability:
    • impl<S: SmtStorageReader> — accessors (root, get_leaf, get_value, open, is_empty), iterators, construction from existing storage (new, load, load_with_root)
    • impl<S: SmtStorage>insert, with_entries, batch construction methods

Other files updated:

  • smt_trait.rsSparseMerkleTree impl bounded by SmtStorage
  • batch_ops.rs — bounded by SmtStorage
  • construction.rs — split into Reader (load from storage) and Storage (build with entries) blocks
  • iter.rs — bounded by SmtStorageReader
  • memory.rs, rocksdb.rs — split impl SmtStorage into impl SmtStorageReader + impl SmtStorage
  • smt/mod.rs — re-exports SmtStorageReader

Backwards compatibility

SmtStorage retains all original methods (read + write) via its supertrait SmtStorageReader, so existing code using S: SmtStorage continues to compile unchanged.

@sergerad sergerad changed the title feat: SmtStorageReader and SmtStorageWriter traits feat: SmtStorageReader trait Apr 12, 2026
@iamrecursion
Copy link
Copy Markdown
Collaborator

I have not read the code as it is still a draft, but please make sure that this does not incur any performance regressions for LargeSmt.

@sergerad
Copy link
Copy Markdown
Contributor Author

Closing in favour of #967 which points at main for v0.23.1

@sergerad sergerad closed this Apr 14, 2026
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.

2 participants