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>
impl<'a, R, H> JellyfishMerkleTree<'a, R, H>
Sourcepub fn get_with_ics23_proof(
&self,
key: Vec<u8>,
version: Version,
) -> Result<(Option<OwnedValue>, CommitmentProof)>
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,
impl<'a, R, H> JellyfishMerkleTree<'a, R, H>where
R: 'a + TreeReader,
H: SimpleHasher,
Sourcepub fn new(reader: &'a R) -> Self
pub fn new(reader: &'a R) -> Self
Creates a JellyfishMerkleTree
backed by the given TreeReader
.
Sourcepub 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)>
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
.
Sourcepub fn put_value_set(
&self,
value_set: impl IntoIterator<Item = (KeyHash, Option<OwnedValue>)>,
version: Version,
) -> Result<(RootHash, TreeUpdateBatch)>
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
.
Sourcepub fn put_value_set_with_proof(
&self,
value_set: impl IntoIterator<Item = (KeyHash, Option<OwnedValue>)>,
version: Version,
) -> Result<(RootHash, UpdateMerkleProof<H>, TreeUpdateBatch)>
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
.
Sourcepub fn put_value_sets(
&self,
value_sets: impl IntoIterator<Item = impl IntoIterator<Item = (KeyHash, Option<OwnedValue>)>>,
first_version: Version,
) -> Result<(Vec<RootHash>, TreeUpdateBatch)>
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.
Sourcepub fn append_value_set(
&self,
value_set: impl IntoIterator<Item = (KeyHash, Option<OwnedValue>)>,
latest_version: Version,
) -> Result<(RootHash, TreeUpdateBatch)>
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.
Sourcepub 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)>
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.
Sourcepub fn get_with_proof(
&self,
key: KeyHash,
version: Version,
) -> Result<(Option<OwnedValue>, SparseMerkleProof<H>)>
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.
Sourcepub fn get_with_exclusion_proof(
&self,
key_hash: KeyHash,
version: Version,
) -> Result<Result<(OwnedValue, SparseMerkleProof<H>), ExclusionProof<H>>>
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.
Sourcepub fn get_range_proof(
&self,
rightmost_key_to_prove: KeyHash,
version: Version,
) -> Result<SparseMerkleRangeProof<H>>
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
.
Sourcepub fn get(&self, key: KeyHash, version: Version) -> Result<Option<OwnedValue>>
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.
pub fn get_root_hash(&self, version: Version) -> Result<RootHash>
pub fn get_root_hash_option(&self, version: Version) -> Result<Option<RootHash>>
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>where
R: RefUnwindSafe,
H: RefUnwindSafe,
impl<'a, R, H> Send for JellyfishMerkleTree<'a, R, H>
impl<'a, R, H> Sync for JellyfishMerkleTree<'a, R, H>
impl<'a, R, H> Unpin for JellyfishMerkleTree<'a, R, H>where
H: Unpin,
impl<'a, R, H> UnwindSafe for JellyfishMerkleTree<'a, R, H>where
R: RefUnwindSafe,
H: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more