Barretenberg
The ZK-SNARK library at the core of Aztec
|
Implements a simple append-only merkle tree All methods are asynchronous unless specified as otherwise Accepts template arguments of the type of store backing the tree and the hashing policy Accepts the store as an argument on construction as well as a thread pool instance Asynchronous methods are exeucted on the provided thread pool. More...
#include <content_addressed_append_only_tree.hpp>
Public Member Functions | |
ContentAddressedAppendOnlyTree (std::unique_ptr< Store > store, std::shared_ptr< ThreadPool > workers, const std::vector< fr > &initial_values={}, bool commit_genesis_state=true) | |
ContentAddressedAppendOnlyTree (ContentAddressedAppendOnlyTree const &other)=delete | |
ContentAddressedAppendOnlyTree (ContentAddressedAppendOnlyTree &&other)=delete | |
ContentAddressedAppendOnlyTree & | operator= (ContentAddressedAppendOnlyTree const &other)=delete |
ContentAddressedAppendOnlyTree & | operator= (ContentAddressedAppendOnlyTree const &&other)=delete |
virtual | ~ContentAddressedAppendOnlyTree ()=default |
virtual void | add_value (const fr &value, const AppendCompletionCallback &on_completion) |
Adds a single value to the end of the tree. | |
virtual void | add_values (const std::vector< fr > &values, const AppendCompletionCallback &on_completion) |
Adds the given set of values to the end of the tree. | |
void | get_sibling_path (const index_t &index, const HashPathCallback &on_completion, bool includeUncommitted) const |
Returns the sibling path from the leaf at the given index to the root. | |
void | get_sibling_path (const index_t &index, const block_number_t &blockNumber, const HashPathCallback &on_completion, bool includeUncommitted) const |
Returns the sibling path from the leaf at the given index to the root. | |
void | get_subtree_sibling_path (uint32_t subtree_depth, const HashPathCallback &on_completion, bool includeUncommitted) const |
Get the subtree sibling path object. | |
void | get_subtree_sibling_path (const index_t &leaf_index, uint32_t subtree_depth, const HashPathCallback &on_completion, bool includeUncommitted) const |
Get the subtree sibling path object to a leaf. | |
void | get_meta_data (bool includeUncommitted, const MetaDataCallback &on_completion) const |
Returns the tree meta data. | |
void | get_meta_data (const block_number_t &blockNumber, bool includeUncommitted, const MetaDataCallback &on_completion) const |
Returns the tree meta data. | |
void | get_leaf (const index_t &index, bool includeUncommitted, const GetLeafCallback &completion) const |
Returns the leaf value at the provided index. | |
void | get_leaf (const index_t &index, const block_number_t &blockNumber, bool includeUncommitted, const GetLeafCallback &completion) const |
Returns the leaf value at the provided index. | |
void | find_leaf_indices (const std::vector< typename Store::LeafType > &leaves, bool includeUncommitted, const FindLeafCallback &on_completion) const |
Returns the index of the provided leaf in the tree. | |
void | find_leaf_indices (const std::vector< typename Store::LeafType > &leaves, const block_number_t &blockNumber, bool includeUncommitted, const FindLeafCallback &on_completion) const |
Returns the index of the provided leaf in the tree. | |
void | find_leaf_sibling_paths (const std::vector< typename Store::LeafType > &leaves, bool includeUncommitted, const FindSiblingPathCallback &on_completion) const |
Returns the sibling paths for the provided leaves in the tree. | |
void | find_leaf_sibling_paths (const std::vector< typename Store::LeafType > &leaves, const block_number_t &block_number, bool includeUncommitted, const FindSiblingPathCallback &on_completion) const |
Returns the sibling paths for the provided leaves in the tree. | |
void | find_leaf_indices_from (const std::vector< typename Store::LeafType > &leaves, const index_t &start_index, bool includeUncommitted, const FindLeafCallback &on_completion) const |
Returns the index of the provided leaf in the tree only if it exists after the index value provided. | |
void | find_leaf_indices_from (const std::vector< typename Store::LeafType > &leaves, const index_t &start_index, const block_number_t &blockNumber, bool includeUncommitted, const FindLeafCallback &on_completion) const |
Returns the index of the provided leaf in the tree only if it exists after the index value provided. | |
void | find_block_numbers (const std::vector< index_t > &indices, const GetBlockForIndexCallback &on_completion) const |
Returns the block numbers that correspond to the given indices values. | |
void | find_block_numbers (const std::vector< index_t > &indices, const block_number_t &blockNumber, const GetBlockForIndexCallback &on_completion) const |
Returns the block numbers that correspond to the given indices values, from the perspective of a historical block number. | |
void | commit (const CommitCallback &on_completion) |
Commit the tree to the backing store. | |
void | rollback (const RollbackCallback &on_completion) |
Rollback the uncommitted changes. | |
uint32_t | depth () const |
Synchronous method to retrieve the depth of the tree. | |
void | remove_historic_block (const block_number_t &blockNumber, const RemoveHistoricBlockCallback &on_completion) |
void | unwind_block (const block_number_t &blockNumber, const UnwindBlockCallback &on_completion) |
void | finalize_block (const block_number_t &blockNumber, const FinalizeBlockCallback &on_completion) |
void | checkpoint (const CheckpointCallback &on_completion) |
void | commit_checkpoint (const CheckpointCommitCallback &on_completion) |
void | revert_checkpoint (const CheckpointRevertCallback &on_completion) |
void | commit_all_checkpoints (const CheckpointCommitCallback &on_completion) |
void | revert_all_checkpoints (const CheckpointRevertCallback &on_completion) |
Protected Types | |
using | ReadTransaction = typename Store::ReadTransaction |
using | ReadTransactionPtr = typename Store::ReadTransactionPtr |
using | OptionalSiblingPath = std::vector< std::optional< fr > > |
Protected Member Functions | |
fr_sibling_path | optional_sibling_path_to_full_sibling_path (const OptionalSiblingPath &optionalPath) const |
void | add_values_internal (std::shared_ptr< std::vector< fr > > values, fr &new_root, index_t &new_size, bool update_index) |
void | add_values_internal (const std::vector< fr > &values, const AppendCompletionCallback &on_completion, bool update_index) |
OptionalSiblingPath | get_subtree_sibling_path_internal (const index_t &leaf_index, uint32_t subtree_depth, const RequestContext &requestContext, ReadTransaction &tx) const |
std::optional< fr > | find_leaf_hash (const index_t &leaf_index, const RequestContext &requestContext, ReadTransaction &tx, bool updateNodesByIndexCache=false) const |
index_t | get_batch_insertion_size (const index_t &treeSize, const index_t &remainingAppendSize) |
void | add_batch_internal (std::vector< fr > &values, fr &new_root, index_t &new_size, bool update_index, ReadTransaction &tx) |
Protected Attributes | |
std::unique_ptr< Store > | store_ |
uint32_t | depth_ |
uint64_t | max_size_ |
std::vector< fr > | zero_hashes_ |
std::shared_ptr< ThreadPool > | workers_ |
Implements a simple append-only merkle tree All methods are asynchronous unless specified as otherwise Accepts template arguments of the type of store backing the tree and the hashing policy Accepts the store as an argument on construction as well as a thread pool instance Asynchronous methods are exeucted on the provided thread pool.
Definition at line 45 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::AppendCompletionCallback = std::function<void(TypedResponse<AddDataResponse>&)> |
Definition at line 51 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::CheckpointCallback = EmptyResponseCallback |
Definition at line 63 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::CheckpointCommitCallback = EmptyResponseCallback |
Definition at line 64 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::CheckpointRevertCallback = EmptyResponseCallback |
Definition at line 65 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::CommitCallback = std::function<void(TypedResponse<CommitResponse>&)> |
Definition at line 57 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::EmptyResponseCallback = std::function<void(Response&)> |
Definition at line 50 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::FinalizeBlockCallback = EmptyResponseCallback |
Definition at line 61 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::FindLeafCallback = std::function<void(TypedResponse<FindLeafIndexResponse>&)> |
Definition at line 54 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::FindSiblingPathCallback = std::function<void(TypedResponse<FindLeafPathResponse>&)> |
Definition at line 55 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::GetBlockForIndexCallback = std::function<void(TypedResponse<BlockForIndexResponse>&)> |
Definition at line 62 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::GetLeafCallback = std::function<void(TypedResponse<GetLeafResponse>&)> |
Definition at line 56 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::HashPathCallback = std::function<void(TypedResponse<GetSiblingPathResponse>&)> |
Definition at line 53 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::MetaDataCallback = std::function<void(TypedResponse<TreeMetaResponse>&)> |
Definition at line 52 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 264 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 261 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 262 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::RemoveHistoricBlockCallback = std::function<void(TypedResponse<RemoveHistoricResponse>&)> |
Definition at line 59 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::RollbackCallback = EmptyResponseCallback |
Definition at line 58 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::StoreType = Store |
Definition at line 47 of file content_addressed_append_only_tree.hpp.
using bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::UnwindBlockCallback = std::function<void(TypedResponse<UnwindResponse>&)> |
Definition at line 60 of file content_addressed_append_only_tree.hpp.
bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::ContentAddressedAppendOnlyTree | ( | std::unique_ptr< Store > | store, |
std::shared_ptr< ThreadPool > | workers, | ||
const std::vector< fr > & | initial_values = {} , |
||
bool | commit_genesis_state = true |
||
) |
Definition at line 300 of file content_addressed_append_only_tree.hpp.
|
delete |
|
delete |
|
virtualdefault |
|
protected |
Definition at line 1100 of file content_addressed_append_only_tree.hpp.
|
virtual |
Adds a single value to the end of the tree.
value | The value to be added |
on_completion | Callback to be called on completion |
Definition at line 913 of file content_addressed_append_only_tree.hpp.
|
virtual |
Adds the given set of values to the end of the tree.
values | The values to be added |
on_completion | Callback to be called on completion |
Definition at line 920 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 927 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 1077 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::checkpoint | ( | const CheckpointCallback & | on_completion | ) |
Definition at line 967 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::commit | ( | const CommitCallback & | on_completion | ) |
Commit the tree to the backing store.
Definition at line 942 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::commit_all_checkpoints | ( | const CheckpointCommitCallback & | on_completion | ) |
Definition at line 990 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::commit_checkpoint | ( | const CheckpointCommitCallback & | on_completion | ) |
Definition at line 974 of file content_addressed_append_only_tree.hpp.
|
inline |
Synchronous method to retrieve the depth of the tree.
Definition at line 246 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::finalize_block | ( | const block_number_t & | blockNumber, |
const FinalizeBlockCallback & | on_completion | ||
) |
Definition at line 1040 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::find_block_numbers | ( | const std::vector< index_t > & | indices, |
const block_number_t & | blockNumber, | ||
const GetBlockForIndexCallback & | on_completion | ||
) | const |
Returns the block numbers that correspond to the given indices values, from the perspective of a historical block number.
Definition at line 461 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::find_block_numbers | ( | const std::vector< index_t > & | indices, |
const GetBlockForIndexCallback & | on_completion | ||
) | const |
Returns the block numbers that correspond to the given indices values.
Definition at line 442 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 554 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::find_leaf_indices | ( | const std::vector< typename Store::LeafType > & | leaves, |
bool | includeUncommitted, | ||
const FindLeafCallback & | on_completion | ||
) | const |
Returns the index of the provided leaf in the tree.
Definition at line 745 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::find_leaf_indices | ( | const std::vector< typename Store::LeafType > & | leaves, |
const block_number_t & | blockNumber, | ||
bool | includeUncommitted, | ||
const FindLeafCallback & | on_completion | ||
) | const |
Returns the index of the provided leaf in the tree.
Definition at line 754 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::find_leaf_indices_from | ( | const std::vector< typename Store::LeafType > & | leaves, |
const index_t & | start_index, | ||
bool | includeUncommitted, | ||
const FindLeafCallback & | on_completion | ||
) | const |
Returns the index of the provided leaf in the tree only if it exists after the index value provided.
Definition at line 764 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::find_leaf_indices_from | ( | const std::vector< typename Store::LeafType > & | leaves, |
const index_t & | start_index, | ||
const block_number_t & | blockNumber, | ||
bool | includeUncommitted, | ||
const FindLeafCallback & | on_completion | ||
) | const |
Returns the index of the provided leaf in the tree only if it exists after the index value provided.
Definition at line 791 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::find_leaf_sibling_paths | ( | const std::vector< typename Store::LeafType > & | leaves, |
bool | includeUncommitted, | ||
const FindSiblingPathCallback & | on_completion | ||
) | const |
Returns the sibling paths for the provided leaves in the tree.
Definition at line 832 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::find_leaf_sibling_paths | ( | const std::vector< typename Store::LeafType > & | leaves, |
const block_number_t & | block_number, | ||
bool | includeUncommitted, | ||
const FindSiblingPathCallback & | on_completion | ||
) | const |
Returns the sibling paths for the provided leaves in the tree.
Definition at line 867 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 1057 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::get_leaf | ( | const index_t & | index, |
bool | includeUncommitted, | ||
const GetLeafCallback & | completion | ||
) | const |
Returns the leaf value at the provided index.
index | The index of the leaf to be retrieved |
includeUncommitted | Whether to include uncommitted changes |
on_completion | Callback to be called on completion |
Definition at line 672 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::get_leaf | ( | const index_t & | index, |
const block_number_t & | blockNumber, | ||
bool | includeUncommitted, | ||
const GetLeafCallback & | completion | ||
) | const |
Returns the leaf value at the provided index.
index | The index of the leaf to be retrieved |
blockNumber | The block number of the tree to use as a reference |
includeUncommitted | Whether to include uncommitted changes |
on_completion | Callback to be called on completion |
Definition at line 697 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::get_meta_data | ( | bool | includeUncommitted, |
const MetaDataCallback & | on_completion | ||
) | const |
Returns the tree meta data.
includeUncommitted | Whether to include uncommitted changes |
on_completion | Callback to be called on completion |
Definition at line 359 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::get_meta_data | ( | const block_number_t & | blockNumber, |
bool | includeUncommitted, | ||
const MetaDataCallback & | on_completion | ||
) | const |
Returns the tree meta data.
blockNumber | The block number of the tree to use as a reference |
includeUncommitted | Whether to include uncommitted changes |
on_completion | Callback to be called on completion |
Definition at line 374 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::get_sibling_path | ( | const index_t & | index, |
const block_number_t & | blockNumber, | ||
const HashPathCallback & | on_completion, | ||
bool | includeUncommitted | ||
) | const |
Returns the sibling path from the leaf at the given index to the root.
index | The index at which to read the sibling path |
blockNumber | The block number of the tree to use as a reference |
on_completion | Callback to be called on completion |
includeUncommitted | Whether to include uncommitted changes |
Definition at line 408 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::get_sibling_path | ( | const index_t & | index, |
const HashPathCallback & | on_completion, | ||
bool | includeUncommitted | ||
) | const |
Returns the sibling path from the leaf at the given index to the root.
index | The index at which to read the sibling path |
on_completion | Callback to be called on completion |
includeUncommitted | Whether to include uncommitted changes |
Definition at line 400 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::get_subtree_sibling_path | ( | const index_t & | leaf_index, |
uint32_t | subtree_depth, | ||
const HashPathCallback & | on_completion, | ||
bool | includeUncommitted | ||
) | const |
Get the subtree sibling path object to a leaf.
leaf_index | The depth of the subtree |
subtree_depth | The depth of the subtree |
on_completion | Callback to be called on completion |
includeUncommitted | Whether to include uncommitted changes |
Definition at line 513 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::get_subtree_sibling_path | ( | uint32_t | subtree_depth, |
const HashPathCallback & | on_completion, | ||
bool | includeUncommitted | ||
) | const |
Get the subtree sibling path object.
subtree_depth | The depth of the subtree |
on_completion | Callback to be called on completion |
includeUncommitted | Whether to include uncommitted changes |
Definition at line 491 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 627 of file content_addressed_append_only_tree.hpp.
|
delete |
|
delete |
|
protected |
Definition at line 537 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::remove_historic_block | ( | const block_number_t & | blockNumber, |
const RemoveHistoricBlockCallback & | on_completion | ||
) |
Definition at line 1006 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::revert_all_checkpoints | ( | const CheckpointRevertCallback & | on_completion | ) |
Definition at line 998 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::revert_checkpoint | ( | const CheckpointRevertCallback & | on_completion | ) |
Definition at line 982 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::rollback | ( | const RollbackCallback & | on_completion | ) |
Rollback the uncommitted changes.
Definition at line 955 of file content_addressed_append_only_tree.hpp.
void bb::crypto::merkle_tree::ContentAddressedAppendOnlyTree< Store, HashingPolicy >::unwind_block | ( | const block_number_t & | blockNumber, |
const UnwindBlockCallback & | on_completion | ||
) |
Definition at line 1023 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 293 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 294 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 292 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 296 of file content_addressed_append_only_tree.hpp.
|
protected |
Definition at line 295 of file content_addressed_append_only_tree.hpp.