Skip to main content

VerMapWithProof

Struct VerMapWithProof 

Source
pub struct VerMapWithProof<K, V, T: TrieCalc> { /* private fields */ }
Expand description

A versioned key-value map with Merkle root hash computation.

Wraps a VerMap<K, V> and a TrieCalc back-end T to provide a merkle_root method that lazily computes the 32-byte Merkle root hash for any branch or commit.

§Incremental updates

The internal trie tracks a sync point — the commit it was last synchronized to. When merkle_root is called:

  1. If the trie is already synced to the target → return cached hash.
  2. If the target is reachable via diff from the sync point → apply diff incrementally.
  3. Otherwise → full rebuild from the store’s iterator.

§Automatic cache lifecycle

The in-memory trie is transparently cached to disk so that process restarts only require an incremental diff rather than a full rebuild.

  • Auto-load — when created via new or from_map, the constructor silently attempts to restore a previous cache file. On miss or corruption it falls back to a full rebuild on the next merkle_root call.
  • Auto-save — the committed trie state is persisted eagerly inside merkle_root (specifically, after sync_to_commit completes). Errors are silently ignored because the cache is disposable: the authoritative data lives in the underlying VerMap.

No manual save_cache / load_cache calls are needed.

Implementations§

Source§

impl<K, V, T> VerMapWithProof<K, V, T>

Source

pub fn new() -> Self

Creates a new VerMapWithProof with a fresh VerMap.

Source

pub fn from_map(map: VerMap<K, V>) -> Self

Wraps an existing VerMap.

Runs gc for crash recovery (if needed) and B+ tree cleanup, then attempts to restore the trie cache.

Source

pub fn map(&self) -> &VerMap<K, V>

Returns a reference to the underlying VerMap.

Source

pub fn map_mut(&mut self) -> &mut VerMap<K, V>

Returns a mutable reference to the underlying VerMap.

Mutations through this reference will not automatically update the trie — call merkle_root to resynchronize.

Source

pub fn merkle_root(&mut self, branch: BranchId) -> Result<Vec<u8>>

Computes the Merkle root hash for the current state of branch.

Includes uncommitted changes. Performs an incremental diff update when possible, falling back to a full rebuild otherwise.

Source

pub fn merkle_root_at_commit(&mut self, commit: CommitId) -> Result<Vec<u8>>

Computes the Merkle root hash for a specific historical commit.

Source§

impl<K, V> VerMapWithProof<K, V, SmtCalc>

Source

pub fn prove(&self, key: &[u8]) -> Result<SmtProof>

Generates a Merkle proof for the given key.

The trie must be synced (call merkle_root first) for proof generation to work.

Source

pub fn verify_proof( root_hash: &[u8; 32], expected_key: &[u8], proof: &SmtProof, ) -> Result<bool>

Verifies a proof against a root hash and expected key.

Source§

impl<K, V> VerMapWithProof<K, V, MptCalc>

Source

pub fn prove_mpt(&self, key: &K) -> Result<MptProof>

Generates a Merkle proof for the given key.

The trie must be synced (call merkle_root first) for proof generation to work.

Source

pub fn verify_mpt_proof( root_hash: &[u8; 32], expected_key: &[u8], proof: &MptProof, ) -> Result<bool>

Verifies an MPT proof against a root hash for a specific key.

expected_key is the raw-byte key the caller expects this proof to cover.

Trait Implementations§

Source§

impl<K, V, T> Default for VerMapWithProof<K, V, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K, V, T: TrieCalc> Drop for VerMapWithProof<K, V, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<K, V, T> !Freeze for VerMapWithProof<K, V, T>

§

impl<K, V, T> RefUnwindSafe for VerMapWithProof<K, V, T>

§

impl<K, V, T> Send for VerMapWithProof<K, V, T>
where T: Send, K: Send, V: Send,

§

impl<K, V, T> Sync for VerMapWithProof<K, V, T>
where T: Sync, K: Sync, V: Sync,

§

impl<K, V, T> Unpin for VerMapWithProof<K, V, T>
where T: Unpin, K: Unpin, V: Unpin,

§

impl<K, V, T> UnsafeUnpin for VerMapWithProof<K, V, T>
where T: UnsafeUnpin,

§

impl<K, V, T> UnwindSafe for VerMapWithProof<K, V, T>
where T: UnwindSafe, K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more