Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
world_state.hpp
Go to the documentation of this file.
1#pragma once
2
21#include <algorithm>
22#include <cstdint>
23#include <exception>
24#include <iterator>
25#include <memory>
26#include <optional>
27#include <stdexcept>
28#include <type_traits>
29#include <unordered_map>
30#include <variant>
31
32namespace bb::world_state {
33
35
43
50
51const uint64_t DEFAULT_MIN_NUMBER_OF_READERS = 128;
52
60 public:
61 WorldState(uint64_t thread_pool_size,
62 const std::string& data_dir,
63 uint64_t map_size,
64 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
65 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
66 uint32_t initial_header_generator_point);
67
68 WorldState(uint64_t thread_pool_size,
69 const std::string& data_dir,
71 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
72 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
73 uint32_t initial_header_generator_point);
74
75 WorldState(uint64_t thread_pool_size,
76 const std::string& data_dir,
77 uint64_t map_size,
78 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
79 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
80 const std::vector<PublicDataLeafValue>& prefilled_public_data,
81 uint32_t initial_header_generator_point);
82
83 WorldState(uint64_t thread_pool_size,
84 const std::string& data_dir,
86 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
87 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
88 const std::vector<PublicDataLeafValue>& prefilled_public_data,
89 uint32_t initial_header_generator_point);
90
97 void copy_stores(const std::string& dstPath, bool compact) const;
98
107
115
122
132 MerkleTreeId tree_id,
133 index_t leaf_index) const;
134
136 MerkleTreeId tree_id,
137 const std::vector<index_t>& leafIndices,
138 std::vector<std::optional<block_number_t>>& blockNumbers) const;
139
149 template <typename T>
151 MerkleTreeId tree_id,
152 index_t leaf_index) const;
153
163 template <typename T>
164 std::optional<T> get_leaf(const WorldStateRevision& revision, MerkleTreeId tree_id, index_t leaf_index) const;
165
176 MerkleTreeId tree_id,
177 const bb::fr& leaf_key) const;
178
188 template <typename T>
189 void find_leaf_indices(const WorldStateRevision& revision,
190 MerkleTreeId tree_id,
191 const std::vector<T>& leaves,
192 std::vector<std::optional<index_t>>& indices,
193 index_t start_index = 0) const;
194
203 template <typename T>
204 void find_sibling_paths(const WorldStateRevision& revision,
205 MerkleTreeId tree_id,
206 const std::vector<T>& leaves,
207 std::vector<std::optional<SiblingPathAndIndex>>& paths) const;
208
216 template <typename T>
217 void append_leaves(MerkleTreeId tree_id, const std::vector<T>& leaves, Fork::Id fork_id = CANONICAL_FORK_ID);
218
227 template <typename T>
229 const std::vector<T>& leaves,
230 uint32_t subtree_depth,
231 Fork::Id fork_id = CANONICAL_FORK_ID);
232
241 template <typename T>
243 const std::vector<T>& leaves,
244 Fork::Id fork_id = CANONICAL_FORK_ID);
245
252 Fork::Id fork_id = CANONICAL_FORK_ID);
253
261 void update_archive(const StateReference& block_state_ref,
262 const bb::fr& block_header_hash,
263 Fork::Id fork_id = CANONICAL_FORK_ID);
264
269
273 void rollback();
274
275 uint64_t create_fork(const std::optional<block_number_t>& blockNumber);
276 void delete_fork(const uint64_t& forkId);
277
281
283 WorldStateStatusFull sync_block(const StateReference& block_state_ref,
284 const bb::fr& block_header_hash,
285 const std::vector<bb::fr>& notes,
286 const std::vector<bb::fr>& l1_to_l2_messages,
289
290 void checkpoint(const uint64_t& forkId);
291 void commit_checkpoint(const uint64_t& forkId);
292 void revert_checkpoint(const uint64_t& forkId);
293 void commit_all_checkpoints(const uint64_t& forkId);
294 void revert_all_checkpoints(const uint64_t& forkId);
295
296 private:
297 std::shared_ptr<bb::ThreadPool> _workers;
299
300 std::unordered_map<MerkleTreeId, uint32_t> _tree_heights;
301 std::unordered_map<MerkleTreeId, index_t> _initial_tree_size;
302 mutable std::mutex mtx;
303 std::unordered_map<uint64_t, Fork::SharedPtr> _forks;
304 uint64_t _forkId = 0;
306
308 void create_canonical_fork(const std::string& dataDir,
310 const std::vector<PublicDataLeafValue>& prefilled_public_data,
311 uint64_t maxReaders);
312
313 Fork::SharedPtr retrieve_fork(const uint64_t& forkId) const;
315 void remove_forks_for_block(const block_number_t& blockNumber);
316
317 bool unwind_block(const block_number_t& blockNumber, WorldStateStatusFull& status);
318 bool remove_historical_block(const block_number_t& blockNumber, WorldStateStatusFull& status);
319 bool set_finalized_block(const block_number_t& blockNumber);
320
322
324
326
327 static bool block_state_matches_world_state(const StateReference& block_state_ref,
328 const StateReference& tree_state_ref);
329
330 bool is_archive_tip(const WorldStateRevision& revision, const bb::fr& block_header_hash) const;
331
332 bool is_same_state_reference(const WorldStateRevision& revision, const StateReference& state_ref) const;
333 static bb::fr compute_initial_block_header_hash(const StateReference& initial_state_ref, uint32_t generator_point);
334
336 Fork::SharedPtr fork,
337 bool initial_state = false);
338
339 static bool determine_if_synched(std::array<TreeMeta, NUM_TREES>& metaResponses);
340
342 std::array<TreeMeta, NUM_TREES>& metaResponses);
343
345
346 template <typename TreeType>
347 void commit_tree(TreeDBStats& dbStats,
348 Signal& signal,
349 TreeType& tree,
350 std::atomic_bool& success,
351 std::string& message,
352 TreeMeta& meta);
353
354 template <typename TreeType>
355 void unwind_tree(TreeDBStats& dbStats,
356 Signal& signal,
357 TreeType& tree,
358 std::atomic_bool& success,
359 std::string& message,
360 TreeMeta& meta,
361 const block_number_t& blockNumber);
362
363 template <typename TreeType>
365 Signal& signal,
366 TreeType& tree,
367 std::atomic_bool& success,
368 std::string& message,
369 TreeMeta& meta,
370 const block_number_t& blockNumber);
371};
372
373template <typename TreeType>
375 Signal& signal,
376 TreeType& tree,
377 std::atomic_bool& success,
378 std::string& message,
379 TreeMeta& meta)
380{
381 tree.commit([&](TypedResponse<CommitResponse>& response) {
382 bool expected = true;
383 if (!response.success && success.compare_exchange_strong(expected, false)) {
384 message = response.message;
385 }
386 dbStats = std::move(response.inner.stats);
387 meta = std::move(response.inner.meta);
388 signal.signal_decrement();
389 });
390}
391
392template <typename TreeType>
394 Signal& signal,
395 TreeType& tree,
396 std::atomic_bool& success,
397 std::string& message,
398 TreeMeta& meta,
399 const block_number_t& blockNumber)
400{
401 tree.unwind_block(blockNumber, [&](TypedResponse<UnwindResponse>& response) {
402 bool expected = true;
403 if (!response.success && success.compare_exchange_strong(expected, false)) {
404 message = response.message;
405 }
406 dbStats = std::move(response.inner.stats);
407 meta = std::move(response.inner.meta);
408 signal.signal_decrement();
409 });
410}
411
412template <typename TreeType>
414 Signal& signal,
415 TreeType& tree,
416 std::atomic_bool& success,
417 std::string& message,
418 TreeMeta& meta,
419 const block_number_t& blockNumber)
420{
421 tree.remove_historic_block(blockNumber, [&](TypedResponse<RemoveHistoricResponse>& response) {
422 bool expected = true;
423 if (!response.success && success.compare_exchange_strong(expected, false)) {
424 message = response.message;
425 }
426 dbStats = std::move(response.inner.stats);
427 meta = std::move(response.inner.meta);
428 signal.signal_decrement();
429 });
430}
431
432template <typename T>
434 MerkleTreeId id,
435 index_t leaf) const
436{
439
442
443 if (auto* const wrapper = std::get_if<TreeWithStore<Tree>>(&fork->_trees.at(id))) {
444
445 Signal signal;
446 auto callback = [&](TypedResponse<GetIndexedLeafResponse<T>>& response) {
447 local = std::move(response);
448 signal.signal_level(0);
449 };
450
451 if (rev.blockNumber) {
452 wrapper->tree->get_leaf(leaf, rev.blockNumber, rev.includeUncommitted, callback);
453 } else {
454 wrapper->tree->get_leaf(leaf, rev.includeUncommitted, callback);
455 }
456 signal.wait_for_level();
457
458 if (!local.success) {
459 throw std::runtime_error("Failed to find indexed leaf: " + local.message);
460 }
461
462 return local.inner.indexed_leaf;
463 }
464
465 throw std::runtime_error("Invalid tree type");
466}
467
468template <typename T>
470 MerkleTreeId tree_id,
471 index_t leaf_index) const
472{
473 using namespace crypto::merkle_tree;
474
475 Fork::SharedPtr fork = retrieve_fork(revision.forkId);
476
477 std::optional<T> leaf;
478 bool success = true;
479 std::string error_msg;
480 Signal signal;
481 if constexpr (std::is_same_v<bb::fr, T>) {
482 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(tree_id));
483 auto callback = [&signal, &leaf, &success, &error_msg](const TypedResponse<GetLeafResponse>& response) {
484 if (!response.success || !response.inner.leaf.has_value()) {
485 // TODO(#17755): Permeate errors to TS? (native_world_state_instance.ts -> call() translates this to
486 // null)
487 success = false;
488 error_msg = response.message;
489 } else {
490 leaf = response.inner.leaf;
491 }
492 signal.signal_level();
493 };
494
495 if (revision.blockNumber) {
496 wrapper.tree->get_leaf(leaf_index, revision.blockNumber, revision.includeUncommitted, callback);
497 } else {
498 wrapper.tree->get_leaf(leaf_index, revision.includeUncommitted, callback);
499 }
500 } else {
503
504 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(tree_id));
505 auto callback =
506 [&signal, &leaf, &success, &error_msg](const TypedResponse<GetIndexedLeafResponse<T>>& response) {
507 if (!response.success || !response.inner.indexed_leaf.has_value()) {
508 success = false;
509 error_msg = response.message;
510 } else {
511 leaf = response.inner.indexed_leaf.value().leaf;
512 }
513 signal.signal_level();
514 };
515
516 if (revision.blockNumber) {
517 wrapper.tree->get_leaf(leaf_index, revision.blockNumber, revision.includeUncommitted, callback);
518 } else {
519 wrapper.tree->get_leaf(leaf_index, revision.includeUncommitted, callback);
520 }
521 }
522
523 signal.wait_for_level();
524
525 return leaf;
526}
527
528template <typename T>
530 MerkleTreeId id,
531 const std::vector<T>& leaves,
532 std::vector<std::optional<index_t>>& indices,
533 index_t start_index) const
534{
535 using namespace crypto::merkle_tree;
536
539
540 Signal signal;
541 auto callback = [&](TypedResponse<FindLeafIndexResponse>& response) {
542 local = std::move(response);
543 signal.signal_level(0);
544 };
545 if constexpr (std::is_same_v<bb::fr, T>) {
546 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
547 if (rev.blockNumber) {
548 wrapper.tree->find_leaf_indices_from(
549 leaves, start_index, rev.blockNumber, rev.includeUncommitted, callback);
550 } else {
551 wrapper.tree->find_leaf_indices_from(leaves, start_index, rev.includeUncommitted, callback);
552 }
553
554 } else {
557
558 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
559 if (rev.blockNumber) {
560 wrapper.tree->find_leaf_indices_from(
561 leaves, start_index, rev.blockNumber, rev.includeUncommitted, callback);
562 } else {
563 wrapper.tree->find_leaf_indices_from(leaves, start_index, rev.includeUncommitted, callback);
564 }
565 }
566
567 signal.wait_for_level(0);
568
569 if (!local.success || local.inner.leaf_indices.size() != leaves.size()) {
570 throw std::runtime_error(local.message);
571 }
572
573 indices = std::move(local.inner.leaf_indices);
574}
575
576template <typename T>
578 MerkleTreeId id,
579 const std::vector<T>& leaves,
580 std::vector<std::optional<SiblingPathAndIndex>>& paths) const
581{
582 using namespace crypto::merkle_tree;
583
586
587 Signal signal;
588 auto callback = [&](TypedResponse<FindLeafPathResponse>& response) {
589 local = std::move(response);
590 signal.signal_level(0);
591 };
592 if constexpr (std::is_same_v<bb::fr, T>) {
593 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
594 if (rev.blockNumber) {
595 wrapper.tree->find_leaf_sibling_paths(leaves, rev.blockNumber, rev.includeUncommitted, callback);
596 } else {
597 wrapper.tree->find_leaf_sibling_paths(leaves, rev.includeUncommitted, callback);
598 }
599
600 } else {
603
604 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
605 if (rev.blockNumber) {
606 wrapper.tree->find_leaf_sibling_paths(leaves, rev.blockNumber, rev.includeUncommitted, callback);
607 } else {
608 wrapper.tree->find_leaf_sibling_paths(leaves, rev.includeUncommitted, callback);
609 }
610 }
611
612 signal.wait_for_level(0);
613
614 if (!local.success || local.inner.leaf_paths.size() != leaves.size()) {
615 throw std::runtime_error(local.message);
616 }
617
618 paths = std::move(local.inner.leaf_paths);
619}
620
621template <typename T> void WorldState::append_leaves(MerkleTreeId id, const std::vector<T>& leaves, Fork::Id fork_id)
622{
623 using namespace crypto::merkle_tree;
624
625 Fork::SharedPtr fork = retrieve_fork(fork_id);
626
627 Signal signal;
628
629 bool success = true;
630 std::string error_msg;
631
632 if constexpr (std::is_same_v<bb::fr, T>) {
633 auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
634 auto callback = [&](const auto& resp) {
635 if (!resp.success) {
636 success = false;
637 error_msg = resp.message;
638 }
639 signal.signal_level(0);
640 };
641 wrapper.tree->add_values(leaves, callback);
642 } else {
645 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
646 typename Tree::AddCompletionCallback callback = [&](const auto& resp) {
647 if (!resp.success) {
648 success = false;
649 error_msg = resp.message;
650 }
651 signal.signal_level(0);
652 };
653 wrapper.tree->add_or_update_values(leaves, 0, callback);
654 }
655
656 signal.wait_for_level(0);
657
658 if (!success) {
659 throw std::runtime_error(error_msg);
660 }
661}
662
663template <typename T>
665 const std::vector<T>& leaves,
666 uint32_t subtree_depth,
667 Fork::Id fork_id)
668{
669 using namespace crypto::merkle_tree;
672
673 Fork::SharedPtr fork = retrieve_fork(fork_id);
674
675 Signal signal;
677 const auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
678 bool success = true;
679 std::string error_msg;
680
681 wrapper.tree->add_or_update_values(
682 leaves, subtree_depth, [&](const TypedResponse<AddIndexedDataResponse<T>>& response) {
683 if (response.success) {
684 result.low_leaf_witness_data = *response.inner.low_leaf_witness_data;
685 result.sorted_leaves = *response.inner.sorted_leaves;
686 result.subtree_path = response.inner.subtree_path;
687 } else {
688 success = false;
689 error_msg = response.message;
690 }
691
692 signal.signal_level(0);
693 });
694
695 signal.wait_for_level();
696
697 if (!success) {
698 throw std::runtime_error(error_msg);
699 }
700
701 return result;
702}
703
704template <typename T>
706 const std::vector<T>& leaves,
707 Fork::Id fork_id)
708{
709 using namespace crypto::merkle_tree;
712
713 Fork::SharedPtr fork = retrieve_fork(fork_id);
714
715 Signal signal;
717 const auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
718 bool success = true;
719 std::string error_msg;
720
721 wrapper.tree->add_or_update_values_sequentially(
722 leaves, [&](const TypedResponse<AddIndexedDataSequentiallyResponse<T>>& response) {
723 if (response.success) {
724 result.low_leaf_witness_data = *response.inner.low_leaf_witness_data;
725 result.insertion_witness_data = *response.inner.insertion_witness_data;
726 } else {
727 success = false;
728 error_msg = response.message;
729 }
730
731 signal.signal_level(0);
732 });
733
734 signal.wait_for_level();
735
736 if (!success) {
737 throw std::runtime_error(error_msg);
738 }
739
740 return result;
741}
742} // namespace bb::world_state
743
744MSGPACK_ADD_ENUM(bb::world_state::MerkleTreeId)
std::shared_ptr< Napi::ThreadSafeFunction > revert_checkpoint
std::shared_ptr< Napi::ThreadSafeFunction > commit_checkpoint
bb::bbapi::CommandResponse responses
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_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.
Serves as a key-value node store for merkle trees. Caches all changes in memory before persisting the...
Implements a parallelized batch insertion indexed tree Accepts template argument of the type of store...
Used in parallel insertions in the the IndexedTree. Workers signal to other following workes as they ...
Definition signal.hpp:17
void signal_level(uint32_t level=0)
Signals that the given level has been passed.
Definition signal.hpp:54
void signal_decrement(uint32_t delta=1)
Definition signal.hpp:60
void wait_for_level(uint32_t level=0)
Causes the thread to wait until the required level has been signalled.
Definition signal.hpp:40
Holds the Merkle trees responsible for storing the state of the Aztec protocol.
WorldStateStatusFull remove_historical_blocks(const block_number_t &toBlockNumber)
std::shared_ptr< bb::ThreadPool > _workers
void remove_forks_for_block(const block_number_t &blockNumber)
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.
bool unwind_block(const block_number_t &blockNumber, WorldStateStatusFull &status)
static void get_status_summary_from_meta_responses(WorldStateStatusSummary &status, std::array< TreeMeta, NUM_TREES > &metaResponses)
void commit_tree(TreeDBStats &dbStats, Signal &signal, TreeType &tree, std::atomic_bool &success, std::string &message, TreeMeta &meta)
TreeStateReference get_tree_snapshot(MerkleTreeId id)
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.
StateReference get_initial_state_reference() const
Gets the initial state reference for all the trees in the world state.
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.
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.
WorldStateStatusFull attempt_tree_resync()
crypto::merkle_tree::TreeMetaResponse get_tree_info(const WorldStateRevision &revision, MerkleTreeId tree_id) const
Get tree metadata for a particular tree.
static void populate_status_summary(WorldStateStatusFull &status)
void unwind_tree(TreeDBStats &dbStats, Signal &signal, TreeType &tree, std::atomic_bool &success, std::string &message, TreeMeta &meta, const block_number_t &blockNumber)
std::unordered_map< uint64_t, Fork::SharedPtr > _forks
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)
std::pair< bool, std::string > commit(WorldStateStatusFull &status)
Commits the current state of the world state.
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)
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 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
StateReference get_state_reference(const WorldStateRevision &revision) const
Gets the state reference for all the trees in the world state.
WorldStateStatusFull unwind_blocks(const block_number_t &toBlockNumber)
bool is_archive_tip(const WorldStateRevision &revision, const bb::fr &block_header_hash) const
static bool determine_if_synched(std::array< TreeMeta, NUM_TREES > &metaResponses)
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.
Fork::SharedPtr create_new_fork(const block_number_t &blockNumber)
void get_status_summary(WorldStateStatusSummary &status) const
void revert_all_checkpoints(const uint64_t &forkId)
void rollback()
Rolls back any uncommitted changes made to the world state.
void commit_all_checkpoints(const uint64_t &forkId)
WorldStateStatusFull 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)
WorldStateStatusSummary set_finalized_blocks(const block_number_t &toBlockNumber)
static bb::fr compute_initial_block_header_hash(const StateReference &initial_state_ref, uint32_t generator_point)
std::unordered_map< MerkleTreeId, index_t > _initial_tree_size
void delete_fork(const uint64_t &forkId)
bool remove_historical_block(const block_number_t &blockNumber, WorldStateStatusFull &status)
std::unordered_map< MerkleTreeId, uint32_t > _tree_heights
uint64_t create_fork(const std::optional< block_number_t > &blockNumber)
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 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.
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.
void checkpoint(const uint64_t &forkId)
static bool block_state_matches_world_state(const StateReference &block_state_ref, const StateReference &tree_state_ref)
bool is_same_state_reference(const WorldStateRevision &revision, const StateReference &state_ref) const
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 in...
void copy_stores(const std::string &dstPath, bool compact) const
Copies all underlying LMDB stores to the target directory while acquiring a write lock.
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.
bool set_finalized_block(const block_number_t &blockNumber)
WorldStateStores::Ptr _persistentStores
Fork::SharedPtr retrieve_fork(const uint64_t &forkId) const
void get_all_tree_info(const WorldStateRevision &revision, std::array< TreeMeta, NUM_TREES > &responses) const
uint32_t block_number_t
Definition types.hpp:19
std::vector< fr > fr_sibling_path
Definition hash_path.hpp:16
std::variant< TreeWithStore< FrTree >, TreeWithStore< NullifierTree >, TreeWithStore< PublicDataTree > > Tree
Definition fork.hpp:25
const uint64_t DEFAULT_MIN_NUMBER_OF_READERS
std::pair< bb::fr, bb::crypto::merkle_tree::index_t > TreeStateReference
Definition types.hpp:31
const uint64_t CANONICAL_FORK_ID
Definition types.hpp:26
std::unordered_map< MerkleTreeId, TreeStateReference > StateReference
Definition types.hpp:32
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::vector< crypto::merkle_tree::LeafUpdateWitnessData< LeafValueType > > low_leaf_witness_data
std::vector< std::pair< LeafValueType, index_t > > sorted_leaves
MSGPACK_FIELDS(low_leaf_witness_data, sorted_leaves, subtree_path)
crypto::merkle_tree::fr_sibling_path subtree_path
std::shared_ptr< Fork > SharedPtr
Definition fork.hpp:29
MSGPACK_FIELDS(low_leaf_witness_data, insertion_witness_data)
std::vector< crypto::merkle_tree::LeafUpdateWitnessData< LeafValueType > > low_leaf_witness_data
std::vector< crypto::merkle_tree::LeafUpdateWitnessData< LeafValueType > > insertion_witness_data
std::shared_ptr< WorldStateStores > Ptr