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
69 WorldState(uint64_t thread_pool_size,
70 const std::string& data_dir,
72 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
73 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
74 uint32_t initial_header_generator_point,
75 uint64_t genesis_timestamp = 0);
76
77 WorldState(uint64_t thread_pool_size,
78 const std::string& data_dir,
79 uint64_t map_size,
80 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
81 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
82 const std::vector<PublicDataLeafValue>& prefilled_public_data,
83 uint32_t initial_header_generator_point,
84 uint64_t genesis_timestamp = 0);
85
86 WorldState(uint64_t thread_pool_size,
87 const std::string& data_dir,
89 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
90 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
91 const std::vector<PublicDataLeafValue>& prefilled_public_data,
92 uint32_t initial_header_generator_point,
93 uint64_t genesis_timestamp = 0);
94
101 void copy_stores(const std::string& dstPath, bool compact) const;
102
111
119
126
136 MerkleTreeId tree_id,
137 index_t leaf_index) const;
138
140 MerkleTreeId tree_id,
141 const std::vector<index_t>& leafIndices,
142 std::vector<std::optional<block_number_t>>& blockNumbers) const;
143
153 template <typename T>
155 MerkleTreeId tree_id,
156 index_t leaf_index) const;
157
167 template <typename T>
168 std::optional<T> get_leaf(const WorldStateRevision& revision, MerkleTreeId tree_id, index_t leaf_index) const;
169
180 MerkleTreeId tree_id,
181 const bb::fr& leaf_key) const;
182
192 template <typename T>
193 void find_leaf_indices(const WorldStateRevision& revision,
194 MerkleTreeId tree_id,
195 const std::vector<T>& leaves,
196 std::vector<std::optional<index_t>>& indices,
197 index_t start_index = 0) const;
198
207 template <typename T>
208 void find_sibling_paths(const WorldStateRevision& revision,
209 MerkleTreeId tree_id,
210 const std::vector<T>& leaves,
211 std::vector<std::optional<SiblingPathAndIndex>>& paths) const;
212
220 template <typename T>
221 void append_leaves(MerkleTreeId tree_id, const std::vector<T>& leaves, Fork::Id fork_id = CANONICAL_FORK_ID);
222
231 template <typename T>
233 const std::vector<T>& leaves,
234 uint32_t subtree_depth,
235 Fork::Id fork_id = CANONICAL_FORK_ID);
236
245 template <typename T>
247 const std::vector<T>& leaves,
248 Fork::Id fork_id = CANONICAL_FORK_ID);
249
256 Fork::Id fork_id = CANONICAL_FORK_ID);
257
265 void update_archive(const StateReference& block_state_ref,
266 const bb::fr& block_header_hash,
267 Fork::Id fork_id = CANONICAL_FORK_ID);
268
273
277 void rollback();
278
279 uint64_t create_fork(const std::optional<block_number_t>& blockNumber);
280 void delete_fork(const uint64_t& forkId);
281
285
287 WorldStateStatusFull sync_block(const StateReference& block_state_ref,
288 const bb::fr& block_header_hash,
289 const std::vector<bb::fr>& notes,
290 const std::vector<bb::fr>& l1_to_l2_messages,
293
294 uint32_t checkpoint(const uint64_t& forkId);
295 void commit_checkpoint(const uint64_t& forkId);
296 void revert_checkpoint(const uint64_t& forkId);
297 void commit_all_checkpoints_to(const uint64_t& forkId, uint32_t depth);
298 void revert_all_checkpoints_to(const uint64_t& forkId, uint32_t depth);
299
300 private:
301 std::shared_ptr<bb::ThreadPool> _workers;
303
304 std::unordered_map<MerkleTreeId, uint32_t> _tree_heights;
305 std::unordered_map<MerkleTreeId, index_t> _initial_tree_size;
306 mutable std::mutex mtx;
307 std::unordered_map<uint64_t, Fork::SharedPtr> _forks;
308 uint64_t _forkId = 0;
311
313 void create_canonical_fork(const std::string& dataDir,
315 const std::vector<PublicDataLeafValue>& prefilled_public_data,
316 uint64_t maxReaders);
317
318 Fork::SharedPtr retrieve_fork(const uint64_t& forkId) const;
320 void remove_forks_for_block(const block_number_t& blockNumber);
321
322 bool unwind_block(const block_number_t& blockNumber, WorldStateStatusFull& status);
323 bool remove_historical_block(const block_number_t& blockNumber, WorldStateStatusFull& status);
324 bool set_finalized_block(const block_number_t& blockNumber);
325
327
329
331
332 static bool block_state_matches_world_state(const StateReference& block_state_ref,
333 const StateReference& tree_state_ref);
334
335 bool is_archive_tip(const WorldStateRevision& revision, const bb::fr& block_header_hash) const;
336
337 bool is_same_state_reference(const WorldStateRevision& revision, const StateReference& state_ref) const;
338 static bb::fr compute_initial_block_header_hash(const StateReference& initial_state_ref,
339 uint32_t generator_point,
340 uint64_t genesis_timestamp = 0);
341
343 Fork::SharedPtr fork,
344 bool initial_state = false);
345
346 static bool determine_if_synched(std::array<TreeMeta, NUM_TREES>& metaResponses);
347
349 std::array<TreeMeta, NUM_TREES>& metaResponses);
350
352
353 template <typename TreeType>
354 void commit_tree(TreeDBStats& dbStats,
355 Signal& signal,
356 TreeType& tree,
357 std::atomic_bool& success,
358 std::string& message,
359 TreeMeta& meta);
360
361 template <typename TreeType>
362 void unwind_tree(TreeDBStats& dbStats,
363 Signal& signal,
364 TreeType& tree,
365 std::atomic_bool& success,
366 std::string& message,
367 TreeMeta& meta,
368 const block_number_t& blockNumber);
369
370 template <typename TreeType>
372 Signal& signal,
373 TreeType& tree,
374 std::atomic_bool& success,
375 std::string& message,
376 TreeMeta& meta,
377 const block_number_t& blockNumber);
378};
379
380template <typename TreeType>
382 Signal& signal,
383 TreeType& tree,
384 std::atomic_bool& success,
385 std::string& message,
386 TreeMeta& meta)
387{
388 tree.commit([&](TypedResponse<CommitResponse>& response) {
389 bool expected = true;
390 if (!response.success && success.compare_exchange_strong(expected, false)) {
391 message = response.message;
392 }
393 dbStats = std::move(response.inner.stats);
394 meta = std::move(response.inner.meta);
395 signal.signal_decrement();
396 });
397}
398
399template <typename TreeType>
401 Signal& signal,
402 TreeType& tree,
403 std::atomic_bool& success,
404 std::string& message,
405 TreeMeta& meta,
406 const block_number_t& blockNumber)
407{
408 tree.unwind_block(blockNumber, [&](TypedResponse<UnwindResponse>& response) {
409 bool expected = true;
410 if (!response.success && success.compare_exchange_strong(expected, false)) {
411 message = response.message;
412 }
413 dbStats = std::move(response.inner.stats);
414 meta = std::move(response.inner.meta);
415 signal.signal_decrement();
416 });
417}
418
419template <typename TreeType>
421 Signal& signal,
422 TreeType& tree,
423 std::atomic_bool& success,
424 std::string& message,
425 TreeMeta& meta,
426 const block_number_t& blockNumber)
427{
428 tree.remove_historic_block(blockNumber, [&](TypedResponse<RemoveHistoricResponse>& response) {
429 bool expected = true;
430 if (!response.success && success.compare_exchange_strong(expected, false)) {
431 message = response.message;
432 }
433 dbStats = std::move(response.inner.stats);
434 meta = std::move(response.inner.meta);
435 signal.signal_decrement();
436 });
437}
438
439template <typename T>
441 MerkleTreeId id,
442 index_t leaf) const
443{
446
449
450 if (auto* const wrapper = std::get_if<TreeWithStore<Tree>>(&fork->_trees.at(id))) {
451
452 Signal signal;
453 auto callback = [&](TypedResponse<GetIndexedLeafResponse<T>>& response) {
454 local = std::move(response);
455 signal.signal_level(0);
456 };
457
458 if (rev.is_historical()) {
459 wrapper->tree->get_leaf(leaf, rev.blockNumber, rev.includeUncommitted, callback);
460 } else {
461 wrapper->tree->get_leaf(leaf, rev.includeUncommitted, callback);
462 }
463 signal.wait_for_level();
464
465 if (!local.success) {
466 throw std::runtime_error("Failed to find indexed leaf: " + local.message);
467 }
468
469 return local.inner.indexed_leaf;
470 }
471
472 throw std::runtime_error("Invalid tree type");
473}
474
475template <typename T>
477 MerkleTreeId tree_id,
478 index_t leaf_index) const
479{
480 using namespace crypto::merkle_tree;
481
482 Fork::SharedPtr fork = retrieve_fork(revision.forkId);
483
484 std::optional<T> leaf;
485 bool success = true;
486 std::string error_msg;
487 Signal signal;
488 if constexpr (std::is_same_v<bb::fr, T>) {
489 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(tree_id));
490 auto callback = [&signal, &leaf, &success, &error_msg](const TypedResponse<GetLeafResponse>& response) {
491 if (!response.success || !response.inner.leaf.has_value()) {
492 // TODO(#17755): Permeate errors to TS? (native_world_state_instance.ts -> call() translates this to
493 // null)
494 success = false;
495 error_msg = response.message;
496 } else {
497 leaf = response.inner.leaf;
498 }
499 signal.signal_level();
500 };
501
502 if (revision.is_historical()) {
503 wrapper.tree->get_leaf(leaf_index, revision.blockNumber, revision.includeUncommitted, callback);
504 } else {
505 wrapper.tree->get_leaf(leaf_index, revision.includeUncommitted, callback);
506 }
507 } else {
510
511 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(tree_id));
512 auto callback =
513 [&signal, &leaf, &success, &error_msg](const TypedResponse<GetIndexedLeafResponse<T>>& response) {
514 if (!response.success || !response.inner.indexed_leaf.has_value()) {
515 success = false;
516 error_msg = response.message;
517 } else {
518 leaf = response.inner.indexed_leaf.value().leaf;
519 }
520 signal.signal_level();
521 };
522
523 if (revision.is_historical()) {
524 wrapper.tree->get_leaf(leaf_index, revision.blockNumber, revision.includeUncommitted, callback);
525 } else {
526 wrapper.tree->get_leaf(leaf_index, revision.includeUncommitted, callback);
527 }
528 }
529
530 signal.wait_for_level();
531
532 return leaf;
533}
534
535template <typename T>
537 MerkleTreeId id,
538 const std::vector<T>& leaves,
539 std::vector<std::optional<index_t>>& indices,
540 index_t start_index) const
541{
542 using namespace crypto::merkle_tree;
543
546
547 Signal signal;
548 auto callback = [&](TypedResponse<FindLeafIndexResponse>& response) {
549 local = std::move(response);
550 signal.signal_level(0);
551 };
552 if constexpr (std::is_same_v<bb::fr, T>) {
553 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
554 if (rev.is_historical()) {
555 wrapper.tree->find_leaf_indices_from(
556 leaves, start_index, rev.blockNumber, rev.includeUncommitted, callback);
557 } else {
558 wrapper.tree->find_leaf_indices_from(leaves, start_index, rev.includeUncommitted, callback);
559 }
560
561 } else {
564
565 auto& wrapper = std::get<TreeWithStore<Tree>>(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
574 signal.wait_for_level(0);
575
576 if (!local.success || local.inner.leaf_indices.size() != leaves.size()) {
577 throw std::runtime_error(local.message);
578 }
579
580 indices = std::move(local.inner.leaf_indices);
581}
582
583template <typename T>
585 MerkleTreeId id,
586 const std::vector<T>& leaves,
587 std::vector<std::optional<SiblingPathAndIndex>>& paths) const
588{
589 using namespace crypto::merkle_tree;
590
593
594 Signal signal;
595 auto callback = [&](TypedResponse<FindLeafPathResponse>& response) {
596 local = std::move(response);
597 signal.signal_level(0);
598 };
599 if constexpr (std::is_same_v<bb::fr, T>) {
600 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
601 if (rev.is_historical()) {
602 wrapper.tree->find_leaf_sibling_paths(leaves, rev.blockNumber, rev.includeUncommitted, callback);
603 } else {
604 wrapper.tree->find_leaf_sibling_paths(leaves, rev.includeUncommitted, callback);
605 }
606
607 } else {
610
611 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
612 if (rev.is_historical()) {
613 wrapper.tree->find_leaf_sibling_paths(leaves, rev.blockNumber, rev.includeUncommitted, callback);
614 } else {
615 wrapper.tree->find_leaf_sibling_paths(leaves, rev.includeUncommitted, callback);
616 }
617 }
618
619 signal.wait_for_level(0);
620
621 if (!local.success || local.inner.leaf_paths.size() != leaves.size()) {
622 throw std::runtime_error(local.message);
623 }
624
625 paths = std::move(local.inner.leaf_paths);
626}
627
628template <typename T> void WorldState::append_leaves(MerkleTreeId id, const std::vector<T>& leaves, Fork::Id fork_id)
629{
630 using namespace crypto::merkle_tree;
631
632 Fork::SharedPtr fork = retrieve_fork(fork_id);
633
634 Signal signal;
635
636 bool success = true;
637 std::string error_msg;
638
639 if constexpr (std::is_same_v<bb::fr, T>) {
640 auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
641 auto callback = [&](const auto& resp) {
642 if (!resp.success) {
643 success = false;
644 error_msg = resp.message;
645 }
646 signal.signal_level(0);
647 };
648 wrapper.tree->add_values(leaves, callback);
649 } else {
652 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
653 typename Tree::AddCompletionCallback 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_or_update_values(leaves, 0, callback);
661 }
662
663 signal.wait_for_level(0);
664
665 if (!success) {
666 throw std::runtime_error(error_msg);
667 }
668}
669
670template <typename T>
672 const std::vector<T>& leaves,
673 uint32_t subtree_depth,
674 Fork::Id fork_id)
675{
676 using namespace crypto::merkle_tree;
679
680 Fork::SharedPtr fork = retrieve_fork(fork_id);
681
682 Signal signal;
684 const auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
685 bool success = true;
686 std::string error_msg;
687
688 wrapper.tree->add_or_update_values(
689 leaves, subtree_depth, [&](const TypedResponse<AddIndexedDataResponse<T>>& response) {
690 if (response.success) {
691 result.low_leaf_witness_data = *response.inner.low_leaf_witness_data;
692 result.sorted_leaves = *response.inner.sorted_leaves;
693 result.subtree_path = response.inner.subtree_path;
694 } else {
695 success = false;
696 error_msg = response.message;
697 }
698
699 signal.signal_level(0);
700 });
701
702 signal.wait_for_level();
703
704 if (!success) {
705 throw std::runtime_error(error_msg);
706 }
707
708 return result;
709}
710
711template <typename T>
713 const std::vector<T>& leaves,
714 Fork::Id fork_id)
715{
716 using namespace crypto::merkle_tree;
719
720 Fork::SharedPtr fork = retrieve_fork(fork_id);
721
722 Signal signal;
724 const auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
725 bool success = true;
726 std::string error_msg;
727
728 wrapper.tree->add_or_update_values_sequentially(
729 leaves, [&](const TypedResponse<AddIndexedDataSequentiallyResponse<T>>& response) {
730 if (response.success) {
731 result.low_leaf_witness_data = *response.inner.low_leaf_witness_data;
732 result.insertion_witness_data = *response.inner.insertion_witness_data;
733 } else {
734 success = false;
735 error_msg = response.message;
736 }
737
738 signal.signal_level(0);
739 });
740
741 signal.wait_for_level();
742
743 if (!success) {
744 throw std::runtime_error(error_msg);
745 }
746
747 return result;
748}
749} // namespace bb::world_state
750
751MSGPACK_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)
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