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 uint64_t genesis_timestamp = 0,
68 bool ephemeral = false);
69
70 WorldState(uint64_t thread_pool_size,
71 const std::string& data_dir,
73 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
74 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
75 uint32_t initial_header_generator_point,
76 uint64_t genesis_timestamp = 0,
77 bool ephemeral = false);
78
79 WorldState(uint64_t thread_pool_size,
80 const std::string& data_dir,
81 uint64_t map_size,
82 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
83 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
84 const std::vector<PublicDataLeafValue>& prefilled_public_data,
85 uint32_t initial_header_generator_point,
86 uint64_t genesis_timestamp = 0,
87 bool ephemeral = false);
88
96 WorldState(uint64_t thread_pool_size,
97 const std::string& data_dir,
99 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
100 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
101 const std::vector<PublicDataLeafValue>& prefilled_public_data,
102 uint32_t initial_header_generator_point,
103 uint64_t genesis_timestamp = 0,
104 bool ephemeral = false);
105
112 void copy_stores(const std::string& dstPath, bool compact) const;
113
122
130
137
147 MerkleTreeId tree_id,
148 index_t leaf_index) const;
149
151 MerkleTreeId tree_id,
152 const std::vector<index_t>& leafIndices,
153 std::vector<std::optional<block_number_t>>& blockNumbers) const;
154
164 template <typename T>
166 MerkleTreeId tree_id,
167 index_t leaf_index) const;
168
178 template <typename T>
179 std::optional<T> get_leaf(const WorldStateRevision& revision, MerkleTreeId tree_id, index_t leaf_index) const;
180
191 MerkleTreeId tree_id,
192 const bb::fr& leaf_key) const;
193
203 template <typename T>
204 void find_leaf_indices(const WorldStateRevision& revision,
205 MerkleTreeId tree_id,
206 const std::vector<T>& leaves,
207 std::vector<std::optional<index_t>>& indices,
208 index_t start_index = 0) const;
209
218 template <typename T>
219 void find_sibling_paths(const WorldStateRevision& revision,
220 MerkleTreeId tree_id,
221 const std::vector<T>& leaves,
222 std::vector<std::optional<SiblingPathAndIndex>>& paths) const;
223
231 template <typename T>
232 void append_leaves(MerkleTreeId tree_id, const std::vector<T>& leaves, Fork::Id fork_id = CANONICAL_FORK_ID);
233
242 template <typename T>
244 const std::vector<T>& leaves,
245 uint32_t subtree_depth,
246 Fork::Id fork_id = CANONICAL_FORK_ID);
247
256 template <typename T>
258 const std::vector<T>& leaves,
259 Fork::Id fork_id = CANONICAL_FORK_ID);
260
267 Fork::Id fork_id = CANONICAL_FORK_ID);
268
276 void update_archive(const StateReference& block_state_ref,
277 const bb::fr& block_header_hash,
278 Fork::Id fork_id = CANONICAL_FORK_ID);
279
284
288 void rollback();
289
290 uint64_t create_fork(const std::optional<block_number_t>& blockNumber);
291 void delete_fork(const uint64_t& forkId);
292
296
298 WorldStateStatusFull sync_block(const StateReference& block_state_ref,
299 const bb::fr& block_header_hash,
300 const std::vector<bb::fr>& notes,
301 const std::vector<bb::fr>& l1_to_l2_messages,
304
305 uint32_t checkpoint(const uint64_t& forkId);
306 void commit_checkpoint(const uint64_t& forkId);
307 void revert_checkpoint(const uint64_t& forkId);
308 void commit_all_checkpoints_to(const uint64_t& forkId, uint32_t depth);
309 void revert_all_checkpoints_to(const uint64_t& forkId, uint32_t depth);
310
311 private:
312 std::shared_ptr<bb::ThreadPool> _workers;
314
315 std::unordered_map<MerkleTreeId, uint32_t> _tree_heights;
316 std::unordered_map<MerkleTreeId, index_t> _initial_tree_size;
317 mutable std::mutex mtx;
318 std::unordered_map<uint64_t, Fork::SharedPtr> _forks;
319 uint64_t _forkId = 0;
322
324 void create_canonical_fork(const std::string& dataDir,
326 const std::vector<PublicDataLeafValue>& prefilled_public_data,
327 uint64_t maxReaders,
328 bool ephemeral);
329
330 Fork::SharedPtr retrieve_fork(const uint64_t& forkId) const;
332 void remove_forks_for_block(const block_number_t& blockNumber);
333
334 bool unwind_block(const block_number_t& blockNumber, WorldStateStatusFull& status);
335 bool remove_historical_block(const block_number_t& blockNumber, WorldStateStatusFull& status);
336 bool set_finalized_block(const block_number_t& blockNumber);
337
339
341
343
344 static bool block_state_matches_world_state(const StateReference& block_state_ref,
345 const StateReference& tree_state_ref);
346
347 bool is_archive_tip(const WorldStateRevision& revision, const bb::fr& block_header_hash) const;
348
349 bool is_same_state_reference(const WorldStateRevision& revision, const StateReference& state_ref) const;
350 static bb::fr compute_initial_block_header_hash(const StateReference& initial_state_ref,
351 uint32_t generator_point,
352 uint64_t genesis_timestamp = 0);
353
355 Fork::SharedPtr fork,
356 bool initial_state = false);
357
358 static bool determine_if_synched(std::array<TreeMeta, NUM_TREES>& metaResponses);
359
361 std::array<TreeMeta, NUM_TREES>& metaResponses);
362
364
365 template <typename TreeType>
366 void commit_tree(TreeDBStats& dbStats,
367 Signal& signal,
368 TreeType& tree,
369 std::atomic_bool& success,
370 std::string& message,
371 TreeMeta& meta);
372
373 template <typename TreeType>
374 void unwind_tree(TreeDBStats& dbStats,
375 Signal& signal,
376 TreeType& tree,
377 std::atomic_bool& success,
378 std::string& message,
379 TreeMeta& meta,
380 const block_number_t& blockNumber);
381
382 template <typename TreeType>
384 Signal& signal,
385 TreeType& tree,
386 std::atomic_bool& success,
387 std::string& message,
388 TreeMeta& meta,
389 const block_number_t& blockNumber);
390};
391
392template <typename TreeType>
394 Signal& signal,
395 TreeType& tree,
396 std::atomic_bool& success,
397 std::string& message,
398 TreeMeta& meta)
399{
400 tree.commit([&](TypedResponse<CommitResponse>& response) {
401 bool expected = true;
402 if (!response.success && success.compare_exchange_strong(expected, false)) {
403 message = response.message;
404 }
405 dbStats = std::move(response.inner.stats);
406 meta = std::move(response.inner.meta);
407 signal.signal_decrement();
408 });
409}
410
411template <typename TreeType>
413 Signal& signal,
414 TreeType& tree,
415 std::atomic_bool& success,
416 std::string& message,
417 TreeMeta& meta,
418 const block_number_t& blockNumber)
419{
420 tree.unwind_block(blockNumber, [&](TypedResponse<UnwindResponse>& response) {
421 bool expected = true;
422 if (!response.success && success.compare_exchange_strong(expected, false)) {
423 message = response.message;
424 }
425 dbStats = std::move(response.inner.stats);
426 meta = std::move(response.inner.meta);
427 signal.signal_decrement();
428 });
429}
430
431template <typename TreeType>
433 Signal& signal,
434 TreeType& tree,
435 std::atomic_bool& success,
436 std::string& message,
437 TreeMeta& meta,
438 const block_number_t& blockNumber)
439{
440 tree.remove_historic_block(blockNumber, [&](TypedResponse<RemoveHistoricResponse>& response) {
441 bool expected = true;
442 if (!response.success && success.compare_exchange_strong(expected, false)) {
443 message = response.message;
444 }
445 dbStats = std::move(response.inner.stats);
446 meta = std::move(response.inner.meta);
447 signal.signal_decrement();
448 });
449}
450
451template <typename T>
453 MerkleTreeId id,
454 index_t leaf) const
455{
458
461
462 if (auto* const wrapper = std::get_if<TreeWithStore<Tree>>(&fork->_trees.at(id))) {
463
464 Signal signal;
465 auto callback = [&](TypedResponse<GetIndexedLeafResponse<T>>& response) {
466 local = std::move(response);
467 signal.signal_level(0);
468 };
469
470 if (rev.is_historical()) {
471 wrapper->tree->get_leaf(leaf, rev.blockNumber, rev.includeUncommitted, callback);
472 } else {
473 wrapper->tree->get_leaf(leaf, rev.includeUncommitted, callback);
474 }
475 signal.wait_for_level();
476
477 if (!local.success) {
478 throw std::runtime_error("Failed to find indexed leaf: " + local.message);
479 }
480
481 return local.inner.indexed_leaf;
482 }
483
484 throw std::runtime_error("Invalid tree type");
485}
486
487template <typename T>
489 MerkleTreeId tree_id,
490 index_t leaf_index) const
491{
492 using namespace crypto::merkle_tree;
493
494 Fork::SharedPtr fork = retrieve_fork(revision.forkId);
495
496 std::optional<T> leaf;
497 bool success = true;
498 std::string error_msg;
499 Signal signal;
500 if constexpr (std::is_same_v<bb::fr, T>) {
501 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(tree_id));
502 auto callback = [&signal, &leaf, &success, &error_msg](const TypedResponse<GetLeafResponse>& response) {
503 if (!response.success || !response.inner.leaf.has_value()) {
504 // TODO(#17755): Permeate errors to TS? (native_world_state_instance.ts -> call() translates this to
505 // null)
506 success = false;
507 error_msg = response.message;
508 } else {
509 leaf = response.inner.leaf;
510 }
511 signal.signal_level();
512 };
513
514 if (revision.is_historical()) {
515 wrapper.tree->get_leaf(leaf_index, revision.blockNumber, revision.includeUncommitted, callback);
516 } else {
517 wrapper.tree->get_leaf(leaf_index, revision.includeUncommitted, callback);
518 }
519 } else {
522
523 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(tree_id));
524 auto callback =
525 [&signal, &leaf, &success, &error_msg](const TypedResponse<GetIndexedLeafResponse<T>>& response) {
526 if (!response.success || !response.inner.indexed_leaf.has_value()) {
527 success = false;
528 error_msg = response.message;
529 } else {
530 leaf = response.inner.indexed_leaf.value().leaf;
531 }
532 signal.signal_level();
533 };
534
535 if (revision.is_historical()) {
536 wrapper.tree->get_leaf(leaf_index, revision.blockNumber, revision.includeUncommitted, callback);
537 } else {
538 wrapper.tree->get_leaf(leaf_index, revision.includeUncommitted, callback);
539 }
540 }
541
542 signal.wait_for_level();
543
544 return leaf;
545}
546
547template <typename T>
549 MerkleTreeId id,
550 const std::vector<T>& leaves,
551 std::vector<std::optional<index_t>>& indices,
552 index_t start_index) const
553{
554 using namespace crypto::merkle_tree;
555
558
559 Signal signal;
560 auto callback = [&](TypedResponse<FindLeafIndexResponse>& response) {
561 local = std::move(response);
562 signal.signal_level(0);
563 };
564 if constexpr (std::is_same_v<bb::fr, T>) {
565 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
566 if (rev.is_historical()) {
567 wrapper.tree->find_leaf_indices_from(
568 leaves, start_index, rev.blockNumber, rev.includeUncommitted, callback);
569 } else {
570 wrapper.tree->find_leaf_indices_from(leaves, start_index, rev.includeUncommitted, callback);
571 }
572
573 } else {
576
577 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
578 if (rev.is_historical()) {
579 wrapper.tree->find_leaf_indices_from(
580 leaves, start_index, rev.blockNumber, rev.includeUncommitted, callback);
581 } else {
582 wrapper.tree->find_leaf_indices_from(leaves, start_index, rev.includeUncommitted, callback);
583 }
584 }
585
586 signal.wait_for_level(0);
587
588 if (!local.success || local.inner.leaf_indices.size() != leaves.size()) {
589 throw std::runtime_error(local.message);
590 }
591
592 indices = std::move(local.inner.leaf_indices);
593}
594
595template <typename T>
597 MerkleTreeId id,
598 const std::vector<T>& leaves,
599 std::vector<std::optional<SiblingPathAndIndex>>& paths) const
600{
601 using namespace crypto::merkle_tree;
602
605
606 Signal signal;
607 auto callback = [&](TypedResponse<FindLeafPathResponse>& response) {
608 local = std::move(response);
609 signal.signal_level(0);
610 };
611 if constexpr (std::is_same_v<bb::fr, T>) {
612 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
613 if (rev.is_historical()) {
614 wrapper.tree->find_leaf_sibling_paths(leaves, rev.blockNumber, rev.includeUncommitted, callback);
615 } else {
616 wrapper.tree->find_leaf_sibling_paths(leaves, rev.includeUncommitted, callback);
617 }
618
619 } else {
622
623 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
624 if (rev.is_historical()) {
625 wrapper.tree->find_leaf_sibling_paths(leaves, rev.blockNumber, rev.includeUncommitted, callback);
626 } else {
627 wrapper.tree->find_leaf_sibling_paths(leaves, rev.includeUncommitted, callback);
628 }
629 }
630
631 signal.wait_for_level(0);
632
633 if (!local.success || local.inner.leaf_paths.size() != leaves.size()) {
634 throw std::runtime_error(local.message);
635 }
636
637 paths = std::move(local.inner.leaf_paths);
638}
639
640template <typename T> void WorldState::append_leaves(MerkleTreeId id, const std::vector<T>& leaves, Fork::Id fork_id)
641{
642 using namespace crypto::merkle_tree;
643
644 Fork::SharedPtr fork = retrieve_fork(fork_id);
645
646 Signal signal;
647
648 bool success = true;
649 std::string error_msg;
650
651 if constexpr (std::is_same_v<bb::fr, T>) {
652 auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
653 auto callback = [&](const auto& resp) {
654 if (!resp.success) {
655 success = false;
656 error_msg = resp.message;
657 }
658 signal.signal_level(0);
659 };
660 wrapper.tree->add_values(leaves, callback);
661 } else {
664 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
665 typename Tree::AddCompletionCallback callback = [&](const auto& resp) {
666 if (!resp.success) {
667 success = false;
668 error_msg = resp.message;
669 }
670 signal.signal_level(0);
671 };
672 wrapper.tree->add_or_update_values(leaves, 0, callback);
673 }
674
675 signal.wait_for_level(0);
676
677 if (!success) {
678 throw std::runtime_error(error_msg);
679 }
680}
681
682template <typename T>
684 const std::vector<T>& leaves,
685 uint32_t subtree_depth,
686 Fork::Id fork_id)
687{
688 using namespace crypto::merkle_tree;
691
692 Fork::SharedPtr fork = retrieve_fork(fork_id);
693
694 Signal signal;
696 const auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
697 bool success = true;
698 std::string error_msg;
699
700 wrapper.tree->add_or_update_values(
701 leaves, subtree_depth, [&](const TypedResponse<AddIndexedDataResponse<T>>& response) {
702 if (response.success) {
703 result.low_leaf_witness_data = *response.inner.low_leaf_witness_data;
704 result.sorted_leaves = *response.inner.sorted_leaves;
705 result.subtree_path = response.inner.subtree_path;
706 } else {
707 success = false;
708 error_msg = response.message;
709 }
710
711 signal.signal_level(0);
712 });
713
714 signal.wait_for_level();
715
716 if (!success) {
717 throw std::runtime_error(error_msg);
718 }
719
720 return result;
721}
722
723template <typename T>
725 const std::vector<T>& leaves,
726 Fork::Id fork_id)
727{
728 using namespace crypto::merkle_tree;
731
732 Fork::SharedPtr fork = retrieve_fork(fork_id);
733
734 Signal signal;
736 const auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
737 bool success = true;
738 std::string error_msg;
739
740 wrapper.tree->add_or_update_values_sequentially(
741 leaves, [&](const TypedResponse<AddIndexedDataSequentiallyResponse<T>>& response) {
742 if (response.success) {
743 result.low_leaf_witness_data = *response.inner.low_leaf_witness_data;
744 result.insertion_witness_data = *response.inner.insertion_witness_data;
745 } else {
746 success = false;
747 error_msg = response.message;
748 }
749
750 signal.signal_level(0);
751 });
752
753 signal.wait_for_level();
754
755 if (!success) {
756 throw std::runtime_error(error_msg);
757 }
758
759 return result;
760}
761} // namespace bb::world_state
762
763MSGPACK_ADD_ENUM(bb::world_state::MerkleTreeId)
std::shared_ptr< Napi::ThreadSafeFunction > revert_checkpoint
std::shared_ptr< Napi::ThreadSafeFunction > commit_checkpoint
bb::bbapi::CommandResponse responses
Implements a simple append-only merkle tree All methods are asynchronous unless specified as otherwis...
void remove_historic_block(const block_number_t &blockNumber, const RemoveHistoricBlockCallback &on_completion)
void commit(const CommitCallback &on_completion)
Commit the tree to the backing store.
void unwind_block(const block_number_t &blockNumber, const UnwindBlockCallback &on_completion)
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.
uint32_t checkpoint(const uint64_t &forkId)
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 commit_all_checkpoints_to(const uint64_t &forkId, uint32_t depth)
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, bool ephemeral)
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 rollback()
Rolls back any uncommitted changes made to the world state.
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)
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
static bb::fr compute_initial_block_header_hash(const StateReference &initial_state_ref, uint32_t generator_point, uint64_t genesis_timestamp=0)
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.
static bool block_state_matches_world_state(const StateReference &block_state_ref, const StateReference &tree_state_ref)
void revert_all_checkpoints_to(const uint64_t &forkId, uint32_t depth)
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:14
std::variant< TreeWithStore< FrTree >, TreeWithStore< NullifierTree >, TreeWithStore< PublicDataTree > > Tree
Definition fork.hpp:28
const uint64_t DEFAULT_MIN_NUMBER_OF_READERS
std::pair< bb::fr, bb::crypto::merkle_tree::index_t > TreeStateReference
Definition types.hpp:32
const uint64_t CANONICAL_FORK_ID
Definition types.hpp:27
std::unordered_map< MerkleTreeId, TreeStateReference > StateReference
Definition types.hpp:33
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::vector< crypto::merkle_tree::LeafUpdateWitnessData< LeafValueType > > low_leaf_witness_data
SERIALIZATION_FIELDS(low_leaf_witness_data, sorted_leaves, subtree_path)
std::vector< std::pair< LeafValueType, index_t > > sorted_leaves
crypto::merkle_tree::fr_sibling_path subtree_path
std::shared_ptr< Fork > SharedPtr
Definition fork.hpp:32
SERIALIZATION_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