pub struct JellyfishMerkleTree<'a, R, V> { /* private fields */ }
Expand description

The Jellyfish Merkle tree data structure. See crate for description.

Implementations§

source§

impl<'a, R, V> JellyfishMerkleTree<'a, R, V>where R: 'a + TreeReader<V>, V: Value,

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<(HashValue, V)>>, node_hashes: Option<Vec<&HashMap<NibblePath, HashValue>>>, first_version: Version ) -> Result<(Vec<HashValue>, TreeUpdateBatch<V>)>

The batch version of put_value_sets.

source

pub fn put_value_set( &self, value_set: Vec<(HashValue, V)>, version: Version ) -> Result<(HashValue, TreeUpdateBatch<V>)>

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

source

pub fn put_value_sets( &self, value_sets: Vec<Vec<(HashValue, V)>>, first_version: Version ) -> Result<(Vec<HashValue>, TreeUpdateBatch<V>)>

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 get_with_proof( &self, key: HashValue, version: Version ) -> Result<(Option<V>, SparseMerkleProof<V>)>

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

source

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

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

source

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

source

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

Auto Trait Implementations§

§

impl<'a, R, V> RefUnwindSafe for JellyfishMerkleTree<'a, R, V>where R: RefUnwindSafe, V: RefUnwindSafe,

§

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

§

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

§

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

§

impl<'a, R, V> UnwindSafe for JellyfishMerkleTree<'a, R, V>where R: RefUnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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