pub struct ConcurrentMerkleTree<const MAX_DEPTH: usize, const MAX_BUFFER_SIZE: usize> {
    pub sequence_number: u64,
    pub active_index: u64,
    pub buffer_size: u64,
    pub change_logs: [ChangeLog<MAX_DEPTH>; MAX_BUFFER_SIZE],
    pub rightmost_proof: Path<MAX_DEPTH>,
}
Expand description

Conurrent Merkle Tree is a Merkle Tree that allows multiple tree operations targeted for the same tree root to succeed.

In a normal merkle tree, only the first tree operation will succeed because the following operations will have proofs for the unmodified tree state. ConcurrentMerkleTree avoids this by storing a buffer of modified nodes (change_logs) which allows it to implement fast-forwarding of concurrent merkle tree operations.

As long as the concurrent merkle tree operations have proofs that are valid for a previous state of the tree that can be found in the stored buffer, that tree operation’s proof can be fast-forwarded and the tree operation can be applied.

There are two primitive operations for Concurrent Merkle Trees: set_leaf and append. Setting a leaf value requires passing a proof to perform that tree operation, but appending does not require a proof.

An additional key property of ConcurrentMerkleTree is support for append operations, which do not require any proofs to be passed. This is accomplished by keeping track of the proof to the rightmost leaf in the tree (rightmost_proof).

Fields

sequence_number: u64active_index: u64

Index of most recent root & changes

buffer_size: u64

Number of active changes we are tracking

change_logs: [ChangeLog<MAX_DEPTH>; MAX_BUFFER_SIZE]

Proof for respective root

rightmost_proof: Path<MAX_DEPTH>

Implementations

This is the trustless initialization method that should be used in most cases.

This is a trustful initialization method that assumes the root contains the expected leaves.

At the time of this crate’s publishing, there is no supported way to efficiently verify a pre-initialized root on-chain. Using this method before having a method for on-chain verification will prevent other applications from indexing the leaf data stored in this tree.

Errors if one of the leaves of the current merkle tree is non-EMPTY

Returns the current root of the merkle tree

Returns the most recent changelog

This method will fail if the leaf cannot be proven to exist in the current tree root.

This method will attempts to prove the leaf first using the proof nodes provided. However if this fails, then a proof will be constructed by inferring a proof from the changelog buffer.

Note: this is not the same as verifying that a (proof, leaf) combination is valid for the given root. That functionality is provided by check_valid_proof.

Appending a non-empty Node will always succeed .

Convenience function for set_leaf

This method will set_leaf if the leaf at index is an empty node, otherwise it will append the new leaf.

This method will update the leaf at index.

However if the proof cannot be verified, this method will fail.

Checks that the proof provided is valid for the current root.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern. Read more
If this function returns true, then it must be valid to reinterpret bits as &Self. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.