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,
impl<'a, R, V> JellyfishMerkleTree<'a, R, V>where R: 'a + TreeReader<V>, V: Value,
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<(HashValue, V)>>,
node_hashes: Option<Vec<&HashMap<NibblePath, HashValue>>>,
first_version: Version
) -> Result<(Vec<HashValue>, TreeUpdateBatch<V>)>
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
.
sourcepub fn put_value_set(
&self,
value_set: Vec<(HashValue, V)>,
version: Version
) -> Result<(HashValue, TreeUpdateBatch<V>)>
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
.
sourcepub fn put_value_sets(
&self,
value_sets: Vec<Vec<(HashValue, V)>>,
first_version: Version
) -> Result<(Vec<HashValue>, TreeUpdateBatch<V>)>
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.
sourcepub fn get_with_proof(
&self,
key: HashValue,
version: Version
) -> Result<(Option<V>, SparseMerkleProof<V>)>
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.
sourcepub fn get_range_proof(
&self,
rightmost_key_to_prove: HashValue,
version: Version
) -> Result<SparseMerkleRangeProof>
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
.