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 success = false;
486 error_msg = response.message;
487 } else {
488 leaf = response.inner.leaf;
489 }
490 signal.signal_level();
491 };
492
493 if (revision.blockNumber) {
494 wrapper.tree->get_leaf(leaf_index, revision.blockNumber, revision.includeUncommitted, callback);
495 } else {
496 wrapper.tree->get_leaf(leaf_index, revision.includeUncommitted, callback);
497 }
498 } else {
501
502 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(tree_id));
503 auto callback =
504 [&signal, &leaf, &success, &error_msg](const TypedResponse<GetIndexedLeafResponse<T>>& response) {
505 if (!response.success || !response.inner.indexed_leaf.has_value()) {
506 success = false;
507 error_msg = response.message;
508 } else {
509 leaf = response.inner.indexed_leaf.value().leaf;
510 }
511 signal.signal_level();
512 };
513
514 if (revision.blockNumber) {
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 }
520
521 signal.wait_for_level();
522
523 return leaf;
524}
525
526template <typename T>
528 MerkleTreeId id,
529 const std::vector<T>& leaves,
530 std::vector<std::optional<index_t>>& indices,
531 index_t start_index) const
532{
533 using namespace crypto::merkle_tree;
534
537
538 Signal signal;
539 auto callback = [&](TypedResponse<FindLeafIndexResponse>& response) {
540 local = std::move(response);
541 signal.signal_level(0);
542 };
543 if constexpr (std::is_same_v<bb::fr, T>) {
544 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
545 if (rev.blockNumber) {
546 wrapper.tree->find_leaf_indices_from(
547 leaves, start_index, rev.blockNumber, rev.includeUncommitted, callback);
548 } else {
549 wrapper.tree->find_leaf_indices_from(leaves, start_index, rev.includeUncommitted, callback);
550 }
551
552 } else {
555
556 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
557 if (rev.blockNumber) {
558 wrapper.tree->find_leaf_indices_from(
559 leaves, start_index, rev.blockNumber, rev.includeUncommitted, callback);
560 } else {
561 wrapper.tree->find_leaf_indices_from(leaves, start_index, rev.includeUncommitted, callback);
562 }
563 }
564
565 signal.wait_for_level(0);
566
567 if (!local.success || local.inner.leaf_indices.size() != leaves.size()) {
568 throw std::runtime_error(local.message);
569 }
570
571 indices = std::move(local.inner.leaf_indices);
572}
573
574template <typename T>
576 MerkleTreeId id,
577 const std::vector<T>& leaves,
578 std::vector<std::optional<SiblingPathAndIndex>>& paths) const
579{
580 using namespace crypto::merkle_tree;
581
584
585 Signal signal;
586 auto callback = [&](TypedResponse<FindLeafPathResponse>& response) {
587 local = std::move(response);
588 signal.signal_level(0);
589 };
590 if constexpr (std::is_same_v<bb::fr, T>) {
591 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
592 if (rev.blockNumber) {
593 wrapper.tree->find_leaf_sibling_paths(leaves, rev.blockNumber, rev.includeUncommitted, callback);
594 } else {
595 wrapper.tree->find_leaf_sibling_paths(leaves, rev.includeUncommitted, callback);
596 }
597
598 } else {
601
602 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
603 if (rev.blockNumber) {
604 wrapper.tree->find_leaf_sibling_paths(leaves, rev.blockNumber, rev.includeUncommitted, callback);
605 } else {
606 wrapper.tree->find_leaf_sibling_paths(leaves, rev.includeUncommitted, callback);
607 }
608 }
609
610 signal.wait_for_level(0);
611
612 if (!local.success || local.inner.leaf_paths.size() != leaves.size()) {
613 throw std::runtime_error(local.message);
614 }
615
616 paths = std::move(local.inner.leaf_paths);
617}
618
619template <typename T> void WorldState::append_leaves(MerkleTreeId id, const std::vector<T>& leaves, Fork::Id fork_id)
620{
621 using namespace crypto::merkle_tree;
622
623 Fork::SharedPtr fork = retrieve_fork(fork_id);
624
625 Signal signal;
626
627 bool success = true;
628 std::string error_msg;
629
630 if constexpr (std::is_same_v<bb::fr, T>) {
631 auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
632 auto callback = [&](const auto& resp) {
633 if (!resp.success) {
634 success = false;
635 error_msg = resp.message;
636 }
637 signal.signal_level(0);
638 };
639 wrapper.tree->add_values(leaves, callback);
640 } else {
643 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
644 typename Tree::AddCompletionCallback callback = [&](const auto& resp) {
645 if (!resp.success) {
646 success = false;
647 error_msg = resp.message;
648 }
649 signal.signal_level(0);
650 };
651 wrapper.tree->add_or_update_values(leaves, 0, callback);
652 }
653
654 signal.wait_for_level(0);
655
656 if (!success) {
657 throw std::runtime_error(error_msg);
658 }
659}
660
661template <typename T>
663 const std::vector<T>& leaves,
664 uint32_t subtree_depth,
665 Fork::Id fork_id)
666{
667 using namespace crypto::merkle_tree;
670
671 Fork::SharedPtr fork = retrieve_fork(fork_id);
672
673 Signal signal;
675 const auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
676 bool success = true;
677 std::string error_msg;
678
679 wrapper.tree->add_or_update_values(
680 leaves, subtree_depth, [&](const TypedResponse<AddIndexedDataResponse<T>>& response) {
681 if (response.success) {
682 result.low_leaf_witness_data = *response.inner.low_leaf_witness_data;
683 result.sorted_leaves = *response.inner.sorted_leaves;
684 result.subtree_path = response.inner.subtree_path;
685 } else {
686 success = false;
687 error_msg = response.message;
688 }
689
690 signal.signal_level(0);
691 });
692
693 signal.wait_for_level();
694
695 if (!success) {
696 throw std::runtime_error(error_msg);
697 }
698
699 return result;
700}
701
702template <typename T>
704 const std::vector<T>& leaves,
705 Fork::Id fork_id)
706{
707 using namespace crypto::merkle_tree;
710
711 Fork::SharedPtr fork = retrieve_fork(fork_id);
712
713 Signal signal;
715 const auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
716 bool success = true;
717 std::string error_msg;
718
719 wrapper.tree->add_or_update_values_sequentially(
720 leaves, [&](const TypedResponse<AddIndexedDataSequentiallyResponse<T>>& response) {
721 if (response.success) {
722 result.low_leaf_witness_data = *response.inner.low_leaf_witness_data;
723 result.insertion_witness_data = *response.inner.insertion_witness_data;
724 } else {
725 success = false;
726 error_msg = response.message;
727 }
728
729 signal.signal_level(0);
730 });
731
732 signal.wait_for_level();
733
734 if (!success) {
735 throw std::runtime_error(error_msg);
736 }
737
738 return result;
739}
740} // namespace bb::world_state
741
742MSGPACK_ADD_ENUM(bb::world_state::MerkleTreeId)
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.
void revert_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 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.
void commit_checkpoint(const uint64_t &forkId)
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< std::pair< LeafValueType, size_t > > sorted_leaves
std::vector< crypto::merkle_tree::LeafUpdateWitnessData< LeafValueType > > low_leaf_witness_data
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