Struct jmt::JellyfishMerkleTree

source ·
pub struct JellyfishMerkleTree<'a, R, H: SimpleHasher> { /* private fields */ }
Expand description

A Jellyfish Merkle tree data structure, parameterized by a TreeReader R and a SimpleHasher H. See crate for description.

Implementations§

source§

impl<'a, R, H> JellyfishMerkleTree<'a, R, H>
where R: 'a + TreeReader + HasPreimage, H: SimpleHasher,

source

pub fn get_with_ics23_proof( &self, key: Vec<u8>, version: Version ) -> Result<(Option<OwnedValue>, CommitmentProof)>

Returns the value corresponding to the specified key (if there is a value associated with it) along with an [ics23::CommitmentProof] proving either the presence of the value at that key, or the absence of any value at that key, depending on which is the case.

source§

impl<'a, R, H> JellyfishMerkleTree<'a, R, H>
where R: 'a + TreeReader, H: SimpleHasher,

source

pub fn new(reader: &'a R) -> Self

Creates a JellyfishMerkleTree backed by the given TreeReader.

source

pub fn batch_put_value_sets( &self, value_sets: Vec<Vec<(KeyHash, OwnedValue)>>, node_hashes: Option<Vec<&HashMap<NibblePath, [u8; 32]>>>, first_version: Version ) -> Result<(Vec<RootHash>, TreeUpdateBatch)>

The batch version of put_value_sets.

source

pub fn put_value_set( &self, value_set: impl IntoIterator<Item = (KeyHash, Option<OwnedValue>)>, version: Version ) -> Result<(RootHash, TreeUpdateBatch)>

This is a convenient function that calls put_value_sets with a single keyed_value_set.

source

pub fn put_value_set_with_proof( &self, value_set: impl IntoIterator<Item = (KeyHash, Option<OwnedValue>)>, version: Version ) -> Result<(RootHash, UpdateMerkleProof<H>, TreeUpdateBatch)>

This is a convenient function that calls put_value_sets_with_proof with a single keyed_value_set.

source

pub fn put_value_sets( &self, value_sets: impl IntoIterator<Item = impl IntoIterator<Item = (KeyHash, Option<OwnedValue>)>>, first_version: Version ) -> Result<(Vec<RootHash>, TreeUpdateBatch)>

Returns the new nodes and values in a batch after applying value_set. For example, if after transaction T_i the committed state of tree in the persistent storage looks like the following structure:

             S_i
            /   \
           .     .
          .       .
         /         \
        o           x
       / \
      A   B
       storage (disk)

where A and B denote the states of two adjacent accounts, and x is a sibling subtree of the path from root to A and B in the tree. Then a value_set produced by the next transaction T_{i+1} modifies other accounts C and D exist in the subtree under x, a new partial tree will be constructed in memory and the structure will be:

                S_i      |      S_{i+1}
               /   \     |     /       \
              .     .    |    .         .
             .       .   |   .           .
            /         \  |  /             \
           /           x | /               x'
          o<-------------+-               / \
         / \             |               C   D
        A   B            |
          storage (disk) |    cache (memory)

With this design, we are able to query the global state in persistent storage and generate the proposed tree delta based on a specific root hash and value_set. For example, if we want to execute another transaction T_{i+1}', we can use the tree S_i in storage and apply the value_set of transaction T_{i+1}. Then if the storage commits the returned batch, the state S_{i+1} is ready to be read from the tree by calling get_with_proof. Anything inside the batch is not reachable from public interfaces before being committed.

source

pub fn append_value_set( &self, value_set: impl IntoIterator<Item = (KeyHash, Option<OwnedValue>)>, latest_version: Version ) -> Result<(RootHash, TreeUpdateBatch)>

Append value sets to the latest version of the tree, without incrementing its version.

source

pub fn put_value_sets_with_proof( &self, value_sets: impl IntoIterator<Item = impl IntoIterator<Item = (KeyHash, Option<OwnedValue>)>>, first_version: Version ) -> Result<(Vec<(RootHash, UpdateMerkleProof<H>)>, TreeUpdateBatch)>

Same as [put_value_sets], this method returns a Merkle proof for every update of the Merkle tree. The proofs can be verified using the [verify_update] method, which requires the old root_hash, the merkle_proof and the new root_hash The first argument contains all the root hashes that were stored in the tree cache so far. The last one is the new root hash of the tree.

source

pub fn get_with_proof( &self, key: KeyHash, version: Version ) -> Result<(Option<OwnedValue>, SparseMerkleProof<H>)>

Returns the value (if applicable) and the corresponding merkle proof.

source

pub fn get_with_exclusion_proof( &self, key_hash: KeyHash, version: Version ) -> Result<Result<(OwnedValue, SparseMerkleProof<H>), ExclusionProof<H>>>

Returns the value (if applicable) and the corresponding merkle proof.

source

pub fn get_range_proof( &self, rightmost_key_to_prove: KeyHash, version: Version ) -> Result<SparseMerkleRangeProof<H>>

Gets the proof that shows a list of keys up to rightmost_key_to_prove exist at version.

source

pub fn get(&self, key: KeyHash, version: Version) -> Result<Option<OwnedValue>>

Returns the value (if applicable), without any proof.

Equivalent to get_with_proof and dropping the proof, but more efficient.

source

pub fn get_root_hash(&self, version: Version) -> Result<RootHash>

source

pub fn get_root_hash_option(&self, version: Version) -> Result<Option<RootHash>>

source

pub fn get_leaf_count(&self, version: Version) -> Result<usize>

Auto Trait Implementations§

§

impl<'a, R, H> Freeze for JellyfishMerkleTree<'a, R, H>

§

impl<'a, R, H> RefUnwindSafe for JellyfishMerkleTree<'a, R, H>

§

impl<'a, R, H> Send for JellyfishMerkleTree<'a, R, H>
where R: Sync, H: Send,

§

impl<'a, R, H> Sync for JellyfishMerkleTree<'a, R, H>
where R: Sync, H: Sync,

§

impl<'a, R, H> Unpin for JellyfishMerkleTree<'a, R, H>
where H: Unpin,

§

impl<'a, R, H> UnwindSafe for JellyfishMerkleTree<'a, R, H>

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.

§

impl<T> Instrument for T

§

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

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

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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