Barretenberg
The ZK-SNARK library at the core of Aztec
|
Holds the Merkle trees responsible for storing the state of the Aztec protocol. More...
#include <world_state.hpp>
Public Member Functions | |
WorldState (uint64_t thread_pool_size, const std::string &data_dir, uint64_t map_size, const std::unordered_map< MerkleTreeId, uint32_t > &tree_heights, const std::unordered_map< MerkleTreeId, index_t > &tree_prefill, uint32_t initial_header_generator_point) | |
WorldState (uint64_t thread_pool_size, const std::string &data_dir, const std::unordered_map< MerkleTreeId, uint64_t > &map_size, const std::unordered_map< MerkleTreeId, uint32_t > &tree_heights, const std::unordered_map< MerkleTreeId, index_t > &tree_prefill, uint32_t initial_header_generator_point) | |
WorldState (uint64_t thread_pool_size, const std::string &data_dir, uint64_t map_size, const std::unordered_map< MerkleTreeId, uint32_t > &tree_heights, const std::unordered_map< MerkleTreeId, index_t > &tree_prefill, const std::vector< PublicDataLeafValue > &prefilled_public_data, uint32_t initial_header_generator_point) | |
WorldState (uint64_t thread_pool_size, const std::string &data_dir, const std::unordered_map< MerkleTreeId, uint64_t > &map_size, const std::unordered_map< MerkleTreeId, uint32_t > &tree_heights, const std::unordered_map< MerkleTreeId, index_t > &tree_prefill, const std::vector< PublicDataLeafValue > &prefilled_public_data, uint32_t initial_header_generator_point) | |
void | copy_stores (const std::string &dstPath, bool compact) const |
Copies all underlying LMDB stores to the target directory while acquiring a write lock. | |
crypto::merkle_tree::TreeMetaResponse | get_tree_info (const WorldStateRevision &revision, MerkleTreeId tree_id) const |
Get tree metadata for a particular tree. | |
StateReference | get_state_reference (const WorldStateRevision &revision) const |
Gets the state reference for all the trees in the world state. | |
StateReference | get_initial_state_reference () const |
Gets the initial state reference for all the trees in the world state. | |
crypto::merkle_tree::fr_sibling_path | get_sibling_path (const WorldStateRevision &revision, MerkleTreeId tree_id, index_t leaf_index) const |
Get the sibling path object for a leaf in a tree. | |
void | get_block_numbers_for_leaf_indices (const WorldStateRevision &revision, MerkleTreeId tree_id, const std::vector< index_t > &leafIndices, std::vector< std::optional< block_number_t > > &blockNumbers) const |
template<typename T > | |
std::optional< crypto::merkle_tree::IndexedLeaf< T > > | get_indexed_leaf (const WorldStateRevision &revision, MerkleTreeId tree_id, index_t leaf_index) const |
Get the leaf preimage object. | |
template<typename T > | |
std::optional< T > | get_leaf (const WorldStateRevision &revision, MerkleTreeId tree_id, index_t leaf_index) const |
Gets the value of a leaf in a tree. | |
crypto::merkle_tree::GetLowIndexedLeafResponse | find_low_leaf_index (const WorldStateRevision &revision, MerkleTreeId tree_id, const bb::fr &leaf_key) const |
Finds the leaf that would have its nextIdx/nextValue fields modified if the target leaf were to be inserted into the tree. If the value already exists in the tree, the leaf with the same value is returned. | |
template<typename T > | |
void | find_leaf_indices (const WorldStateRevision &revision, MerkleTreeId tree_id, const std::vector< T > &leaves, std::vector< std::optional< index_t > > &indices, index_t start_index=0) const |
Finds the index of a leaf in a tree. | |
template<typename T > | |
void | find_sibling_paths (const WorldStateRevision &revision, MerkleTreeId tree_id, const std::vector< T > &leaves, std::vector< std::optional< SiblingPathAndIndex > > &paths) const |
Finds the sibling paths of leaves in a tree. | |
template<typename T > | |
void | append_leaves (MerkleTreeId tree_id, const std::vector< T > &leaves, Fork::Id fork_id=CANONICAL_FORK_ID) |
Appends a set of leaves to an existing Merkle Tree. | |
template<typename T > | |
BatchInsertionResult< T > | batch_insert_indexed_leaves (MerkleTreeId tree_id, const std::vector< T > &leaves, uint32_t subtree_depth, Fork::Id fork_id=CANONICAL_FORK_ID) |
Batch inserts a set of leaves into an indexed Merkle Tree. | |
template<typename T > | |
SequentialInsertionResult< T > | insert_indexed_leaves (MerkleTreeId tree_id, const std::vector< T > &leaves, Fork::Id fork_id=CANONICAL_FORK_ID) |
Inserts a set of leaves sequentially into an indexed Merkle Tree. | |
void | update_public_data (const crypto::merkle_tree::PublicDataLeafValue &new_value, Fork::Id fork_id=CANONICAL_FORK_ID) |
Updates a leaf in an existing Merkle Tree. | |
void | update_archive (const StateReference &block_state_ref, const bb::fr &block_header_hash, Fork::Id fork_id=CANONICAL_FORK_ID) |
Updates the archive tree with a new block. | |
std::pair< bool, std::string > | commit (WorldStateStatusFull &status) |
Commits the current state of the world state. | |
void | rollback () |
Rolls back any uncommitted changes made to the world state. | |
uint64_t | create_fork (const std::optional< block_number_t > &blockNumber) |
void | delete_fork (const uint64_t &forkId) |
WorldStateStatusSummary | set_finalized_blocks (const block_number_t &toBlockNumber) |
WorldStateStatusFull | unwind_blocks (const block_number_t &toBlockNumber) |
WorldStateStatusFull | remove_historical_blocks (const block_number_t &toBlockNumber) |
void | get_status_summary (WorldStateStatusSummary &status) const |
WorldStateStatusFull | sync_block (const StateReference &block_state_ref, const bb::fr &block_header_hash, const std::vector< bb::fr > ¬es, const std::vector< bb::fr > &l1_to_l2_messages, const std::vector< crypto::merkle_tree::NullifierLeafValue > &nullifiers, const std::vector< crypto::merkle_tree::PublicDataLeafValue > &public_writes) |
void | checkpoint (const uint64_t &forkId) |
void | commit_checkpoint (const uint64_t &forkId) |
void | revert_checkpoint (const uint64_t &forkId) |
void | commit_all_checkpoints (const uint64_t &forkId) |
void | revert_all_checkpoints (const uint64_t &forkId) |
Private Member Functions | |
TreeStateReference | get_tree_snapshot (MerkleTreeId id) |
void | create_canonical_fork (const std::string &dataDir, const std::unordered_map< MerkleTreeId, uint64_t > &dbSize, const std::vector< PublicDataLeafValue > &prefilled_public_data, uint64_t maxReaders) |
Fork::SharedPtr | retrieve_fork (const uint64_t &forkId) const |
Fork::SharedPtr | create_new_fork (const block_number_t &blockNumber) |
void | remove_forks_for_block (const block_number_t &blockNumber) |
bool | unwind_block (const block_number_t &blockNumber, WorldStateStatusFull &status) |
bool | remove_historical_block (const block_number_t &blockNumber, WorldStateStatusFull &status) |
bool | set_finalized_block (const block_number_t &blockNumber) |
void | get_all_tree_info (const WorldStateRevision &revision, std::array< TreeMeta, NUM_TREES > &responses) const |
void | validate_trees_are_equally_synched () |
WorldStateStatusFull | attempt_tree_resync () |
bool | is_archive_tip (const WorldStateRevision &revision, const bb::fr &block_header_hash) const |
bool | is_same_state_reference (const WorldStateRevision &revision, const StateReference &state_ref) const |
template<typename TreeType > | |
void | commit_tree (TreeDBStats &dbStats, Signal &signal, TreeType &tree, std::atomic_bool &success, std::string &message, TreeMeta &meta) |
template<typename TreeType > | |
void | unwind_tree (TreeDBStats &dbStats, Signal &signal, TreeType &tree, std::atomic_bool &success, std::string &message, TreeMeta &meta, const block_number_t &blockNumber) |
template<typename TreeType > | |
void | remove_historic_block_for_tree (TreeDBStats &dbStats, Signal &signal, TreeType &tree, std::atomic_bool &success, std::string &message, TreeMeta &meta, const block_number_t &blockNumber) |
Static Private Member Functions | |
static bool | block_state_matches_world_state (const StateReference &block_state_ref, const StateReference &tree_state_ref) |
static bb::fr | compute_initial_block_header_hash (const StateReference &initial_state_ref, uint32_t generator_point) |
static StateReference | get_state_reference (const WorldStateRevision &revision, Fork::SharedPtr fork, bool initial_state=false) |
static bool | determine_if_synched (std::array< TreeMeta, NUM_TREES > &metaResponses) |
static void | get_status_summary_from_meta_responses (WorldStateStatusSummary &status, std::array< TreeMeta, NUM_TREES > &metaResponses) |
static void | populate_status_summary (WorldStateStatusFull &status) |
Private Attributes | |
std::shared_ptr< bb::ThreadPool > | _workers |
WorldStateStores::Ptr | _persistentStores |
std::unordered_map< MerkleTreeId, uint32_t > | _tree_heights |
std::unordered_map< MerkleTreeId, index_t > | _initial_tree_size |
std::mutex | mtx |
std::unordered_map< uint64_t, Fork::SharedPtr > | _forks |
uint64_t | _forkId = 0 |
uint32_t | _initial_header_generator_point |
Holds the Merkle trees responsible for storing the state of the Aztec protocol.
Definition at line 59 of file world_state.hpp.
bb::world_state::WorldState::WorldState | ( | uint64_t | thread_pool_size, |
const std::string & | data_dir, | ||
uint64_t | map_size, | ||
const std::unordered_map< MerkleTreeId, uint32_t > & | tree_heights, | ||
const std::unordered_map< MerkleTreeId, index_t > & | tree_prefill, | ||
uint32_t | initial_header_generator_point | ||
) |
Definition at line 96 of file world_state.cpp.
bb::world_state::WorldState::WorldState | ( | uint64_t | thread_pool_size, |
const std::string & | data_dir, | ||
const std::unordered_map< MerkleTreeId, uint64_t > & | map_size, | ||
const std::unordered_map< MerkleTreeId, uint32_t > & | tree_heights, | ||
const std::unordered_map< MerkleTreeId, index_t > & | tree_prefill, | ||
uint32_t | initial_header_generator_point | ||
) |
Definition at line 59 of file world_state.cpp.
bb::world_state::WorldState::WorldState | ( | uint64_t | thread_pool_size, |
const std::string & | data_dir, | ||
uint64_t | map_size, | ||
const std::unordered_map< MerkleTreeId, uint32_t > & | tree_heights, | ||
const std::unordered_map< MerkleTreeId, index_t > & | tree_prefill, | ||
const std::vector< PublicDataLeafValue > & | prefilled_public_data, | ||
uint32_t | initial_header_generator_point | ||
) |
Definition at line 74 of file world_state.cpp.
bb::world_state::WorldState::WorldState | ( | uint64_t | thread_pool_size, |
const std::string & | data_dir, | ||
const std::unordered_map< MerkleTreeId, uint64_t > & | map_size, | ||
const std::unordered_map< MerkleTreeId, uint32_t > & | tree_heights, | ||
const std::unordered_map< MerkleTreeId, index_t > & | tree_prefill, | ||
const std::vector< PublicDataLeafValue > & | prefilled_public_data, | ||
uint32_t | initial_header_generator_point | ||
) |
Definition at line 36 of file world_state.cpp.
void bb::world_state::WorldState::append_leaves | ( | MerkleTreeId | tree_id, |
const std::vector< T > & | leaves, | ||
Fork::Id | fork_id = CANONICAL_FORK_ID |
||
) |
Appends a set of leaves to an existing Merkle Tree.
T | The type of the leaves. |
tree_id | The ID of the Merkle Tree. |
leaves | The leaves to append. |
Definition at line 619 of file world_state.hpp.
|
private |
Definition at line 1200 of file world_state.cpp.
BatchInsertionResult< T > bb::world_state::WorldState::batch_insert_indexed_leaves | ( | MerkleTreeId | tree_id, |
const std::vector< T > & | leaves, | ||
uint32_t | subtree_depth, | ||
Fork::Id | fork_id = CANONICAL_FORK_ID |
||
) |
Batch inserts a set of leaves into an indexed Merkle Tree.
T | The type of the leaves. |
tree_id | The ID of the Merkle Tree. |
leaves | The leaves to insert. |
Definition at line 662 of file world_state.hpp.
|
staticprivate |
void bb::world_state::WorldState::checkpoint | ( | const uint64_t & | forkId | ) |
Definition at line 1065 of file world_state.cpp.
std::pair< bool, std::string > bb::world_state::WorldState::commit | ( | WorldStateStatusFull & | status | ) |
Commits the current state of the world state.
Definition at line 522 of file world_state.cpp.
void bb::world_state::WorldState::commit_all_checkpoints | ( | const uint64_t & | forkId | ) |
Definition at line 1146 of file world_state.cpp.
void bb::world_state::WorldState::commit_checkpoint | ( | const uint64_t & | forkId | ) |
Definition at line 1092 of file world_state.cpp.
|
private |
Definition at line 374 of file world_state.hpp.
|
staticprivate |
Definition at line 950 of file world_state.cpp.
void bb::world_state::WorldState::copy_stores | ( | const std::string & | dstPath, |
bool | compact | ||
) | const |
Copies all underlying LMDB stores to the target directory while acquiring a write lock.
dstPath | Parent folder where trees will be copied |
compact | Whether to compact stores when copying |
Definition at line 174 of file world_state.cpp.
|
private |
Definition at line 111 of file world_state.cpp.
uint64_t bb::world_state::WorldState::create_fork | ( | const std::optional< block_number_t > & | blockNumber | ) |
Definition at line 195 of file world_state.cpp.
|
private |
Definition at line 246 of file world_state.cpp.
void bb::world_state::WorldState::delete_fork | ( | const uint64_t & | forkId | ) |
Definition at line 232 of file world_state.cpp.
|
staticprivate |
Definition at line 1050 of file world_state.cpp.
void bb::world_state::WorldState::find_leaf_indices | ( | const WorldStateRevision & | revision, |
MerkleTreeId | tree_id, | ||
const std::vector< T > & | leaves, | ||
std::vector< std::optional< index_t > > & | indices, | ||
index_t | start_index = 0 |
||
) | const |
Finds the index of a leaf in a tree.
revision | The revision to query |
tree_id | The ID of the tree |
leaves | The leaves to find |
indices | The indices to be updated |
start_index | The index to start searching from |
Definition at line 527 of file world_state.hpp.
GetLowIndexedLeafResponse bb::world_state::WorldState::find_low_leaf_index | ( | const WorldStateRevision & | revision, |
MerkleTreeId | tree_id, | ||
const bb::fr & | leaf_key | ||
) | const |
Finds the leaf that would have its nextIdx/nextValue fields modified if the target leaf were to be inserted into the tree. If the value already exists in the tree, the leaf with the same value is returned.
revision | The revision to query |
tree_id | The ID of the tree |
leaf_key | The leaf to find the predecessor of |
Definition at line 681 of file world_state.cpp.
void bb::world_state::WorldState::find_sibling_paths | ( | const WorldStateRevision & | revision, |
MerkleTreeId | tree_id, | ||
const std::vector< T > & | leaves, | ||
std::vector< std::optional< SiblingPathAndIndex > > & | paths | ||
) | const |
Finds the sibling paths of leaves in a tree.
revision | The revision to query |
tree_id | The ID of the tree |
leaves | The leaves to find paths for |
paths | The paths to be retrieved |
Definition at line 575 of file world_state.hpp.
|
private |
Definition at line 320 of file world_state.cpp.
void bb::world_state::WorldState::get_block_numbers_for_leaf_indices | ( | const WorldStateRevision & | revision, |
MerkleTreeId | tree_id, | ||
const std::vector< index_t > & | leafIndices, | ||
std::vector< std::optional< block_number_t > > & | blockNumbers | ||
) | const |
Definition at line 464 of file world_state.cpp.
std::optional< crypto::merkle_tree::IndexedLeaf< T > > bb::world_state::WorldState::get_indexed_leaf | ( | const WorldStateRevision & | revision, |
MerkleTreeId | tree_id, | ||
index_t | leaf_index | ||
) | const |
Get the leaf preimage object.
T | the type of the leaf. Either NullifierLeafValue, PublicDataLeafValue |
revision | The revision to query |
tree_id | The ID of the tree |
leaf_index | The index of the leaf |
Definition at line 433 of file world_state.hpp.
StateReference bb::world_state::WorldState::get_initial_state_reference | ( | ) | const |
Gets the initial state reference for all the trees in the world state.
Definition at line 369 of file world_state.cpp.
std::optional< T > bb::world_state::WorldState::get_leaf | ( | const WorldStateRevision & | revision, |
MerkleTreeId | tree_id, | ||
index_t | leaf_index | ||
) | const |
Gets the value of a leaf in a tree.
T | the type of the leaf. Either bb::fr, NullifierLeafValue, PublicDataLeafValue |
revision | The revision to query |
tree_id | The ID of the tree |
leaf_index | The index of the leaf |
Definition at line 469 of file world_state.hpp.
fr_sibling_path bb::world_state::WorldState::get_sibling_path | ( | const WorldStateRevision & | revision, |
MerkleTreeId | tree_id, | ||
index_t | leaf_index | ||
) | const |
Get the sibling path object for a leaf in a tree.
revision | The revision to query |
tree_id | The ID of the tree |
leaf_index | The index of the leaf |
Definition at line 433 of file world_state.cpp.
StateReference bb::world_state::WorldState::get_state_reference | ( | const WorldStateRevision & | revision | ) | const |
Gets the state reference for all the trees in the world state.
revision | The revision to query |
Definition at line 364 of file world_state.cpp.
|
staticprivate |
Definition at line 376 of file world_state.cpp.
void bb::world_state::WorldState::get_status_summary | ( | WorldStateStatusSummary & | status | ) | const |
Definition at line 1004 of file world_state.cpp.
|
staticprivate |
Definition at line 1012 of file world_state.cpp.
TreeMetaResponse bb::world_state::WorldState::get_tree_info | ( | const WorldStateRevision & | revision, |
MerkleTreeId | tree_id | ||
) | const |
Get tree metadata for a particular tree.
revision | The revision to query |
tree_id | The ID of the tree |
Definition at line 292 of file world_state.cpp.
|
private |
SequentialInsertionResult< T > bb::world_state::WorldState::insert_indexed_leaves | ( | MerkleTreeId | tree_id, |
const std::vector< T > & | leaves, | ||
Fork::Id | fork_id = CANONICAL_FORK_ID |
||
) |
Inserts a set of leaves sequentially into an indexed Merkle Tree.
T | The type of the leaves. |
tree_id | The ID of the Merkle Tree. |
leaves | The leaves to insert. |
Definition at line 703 of file world_state.hpp.
|
private |
Definition at line 987 of file world_state.cpp.
|
private |
Definition at line 1034 of file world_state.cpp.
|
staticprivate |
Definition at line 1022 of file world_state.cpp.
|
private |
Definition at line 214 of file world_state.cpp.
|
private |
Definition at line 413 of file world_state.hpp.
|
private |
Definition at line 883 of file world_state.cpp.
WorldStateStatusFull bb::world_state::WorldState::remove_historical_blocks | ( | const block_number_t & | toBlockNumber | ) |
Definition at line 761 of file world_state.cpp.
|
private |
Definition at line 186 of file world_state.cpp.
void bb::world_state::WorldState::revert_all_checkpoints | ( | const uint64_t & | forkId | ) |
Definition at line 1173 of file world_state.cpp.
void bb::world_state::WorldState::revert_checkpoint | ( | const uint64_t & | forkId | ) |
Definition at line 1119 of file world_state.cpp.
void bb::world_state::WorldState::rollback | ( | ) |
Rolls back any uncommitted changes made to the world state.
Definition at line 567 of file world_state.cpp.
|
private |
Definition at line 790 of file world_state.cpp.
WorldStateStatusSummary bb::world_state::WorldState::set_finalized_blocks | ( | const block_number_t & | toBlockNumber | ) |
Definition at line 719 of file world_state.cpp.
WorldStateStatusFull bb::world_state::WorldState::sync_block | ( | const StateReference & | block_state_ref, |
const bb::fr & | block_header_hash, | ||
const std::vector< bb::fr > & | notes, | ||
const std::vector< bb::fr > & | l1_to_l2_messages, | ||
const std::vector< crypto::merkle_tree::NullifierLeafValue > & | nullifiers, | ||
const std::vector< crypto::merkle_tree::PublicDataLeafValue > & | public_writes | ||
) |
Definition at line 582 of file world_state.cpp.
|
private |
Definition at line 817 of file world_state.cpp.
WorldStateStatusFull bb::world_state::WorldState::unwind_blocks | ( | const block_number_t & | toBlockNumber | ) |
Definition at line 727 of file world_state.cpp.
|
private |
Definition at line 393 of file world_state.hpp.
void bb::world_state::WorldState::update_archive | ( | const StateReference & | block_state_ref, |
const bb::fr & | block_header_hash, | ||
Fork::Id | fork_id = CANONICAL_FORK_ID |
||
) |
Updates the archive tree with a new block.
block_state_ref | The state reference of the block. |
block_hash | The hash of the block. |
fork_id | The fork ID to update. |
Definition at line 511 of file world_state.cpp.
void bb::world_state::WorldState::update_public_data | ( | const crypto::merkle_tree::PublicDataLeafValue & | new_value, |
Fork::Id | fork_id = CANONICAL_FORK_ID |
||
) |
Updates a leaf in an existing Merkle Tree.
new_value | The new value of the leaf. |
Definition at line 496 of file world_state.cpp.
|
private |
Definition at line 1039 of file world_state.cpp.
|
private |
Definition at line 304 of file world_state.hpp.
|
private |
Definition at line 303 of file world_state.hpp.
|
private |
Definition at line 305 of file world_state.hpp.
|
private |
Definition at line 301 of file world_state.hpp.
|
private |
Definition at line 298 of file world_state.hpp.
|
private |
Definition at line 300 of file world_state.hpp.
|
private |
Definition at line 297 of file world_state.hpp.
|
mutableprivate |
Definition at line 302 of file world_state.hpp.