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 const std::vector<bb::fr>& prefilled_nullifiers,
86 uint32_t initial_header_generator_point,
87 uint64_t genesis_timestamp = 0,
88 bool ephemeral = false);
89
100 WorldState(uint64_t thread_pool_size,
101 const std::string& data_dir,
103 const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
104 const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
105 const std::vector<PublicDataLeafValue>& prefilled_public_data,
106 const std::vector<bb::fr>& prefilled_nullifiers,
107 uint32_t initial_header_generator_point,
108 uint64_t genesis_timestamp = 0,
109 bool ephemeral = false);
110
117 void copy_stores(const std::string& dstPath, bool compact) const;
118
127
135
142
152 MerkleTreeId tree_id,
153 index_t leaf_index) const;
154
156 MerkleTreeId tree_id,
157 const std::vector<index_t>& leafIndices,
158 std::vector<std::optional<block_number_t>>& blockNumbers) const;
159
169 template <typename T>
171 MerkleTreeId tree_id,
172 index_t leaf_index) const;
173
183 template <typename T>
184 std::optional<T> get_leaf(const WorldStateRevision& revision, MerkleTreeId tree_id, index_t leaf_index) const;
185
196 MerkleTreeId tree_id,
197 const bb::fr& leaf_key) const;
198
208 template <typename T>
209 void find_leaf_indices(const WorldStateRevision& revision,
210 MerkleTreeId tree_id,
211 const std::vector<T>& leaves,
212 std::vector<std::optional<index_t>>& indices,
213 index_t start_index = 0) const;
214
223 template <typename T>
224 void find_sibling_paths(const WorldStateRevision& revision,
225 MerkleTreeId tree_id,
226 const std::vector<T>& leaves,
227 std::vector<std::optional<SiblingPathAndIndex>>& paths) const;
228
236 template <typename T>
237 void append_leaves(MerkleTreeId tree_id, const std::vector<T>& leaves, Fork::Id fork_id = CANONICAL_FORK_ID);
238
247 template <typename T>
249 const std::vector<T>& leaves,
250 uint32_t subtree_depth,
251 Fork::Id fork_id = CANONICAL_FORK_ID);
252
261 template <typename T>
263 const std::vector<T>& leaves,
264 Fork::Id fork_id = CANONICAL_FORK_ID);
265
272 Fork::Id fork_id = CANONICAL_FORK_ID);
273
281 void update_archive(const StateReference& block_state_ref,
282 const bb::fr& block_header_hash,
283 Fork::Id fork_id = CANONICAL_FORK_ID);
284
289
293 void rollback();
294
295 uint64_t create_fork(const std::optional<block_number_t>& blockNumber);
296 void delete_fork(const uint64_t& forkId);
297
301
303 WorldStateStatusFull sync_block(const StateReference& block_state_ref,
304 const bb::fr& block_header_hash,
305 const std::vector<bb::fr>& notes,
306 const std::vector<bb::fr>& l1_to_l2_messages,
309 const std::optional<bb::fr>& expected_archive_root = std::nullopt,
310 const std::optional<bb::fr>& expected_previous_archive_root = std::nullopt);
311
312 uint32_t checkpoint(const uint64_t& forkId);
313 void commit_checkpoint(const uint64_t& forkId);
314 void revert_checkpoint(const uint64_t& forkId);
315 void commit_all_checkpoints_to(const uint64_t& forkId, uint32_t depth);
316 void revert_all_checkpoints_to(const uint64_t& forkId, uint32_t depth);
317
318 private:
319 std::shared_ptr<bb::ThreadPool> _workers;
321
322 std::unordered_map<MerkleTreeId, uint32_t> _tree_heights;
323 std::unordered_map<MerkleTreeId, index_t> _initial_tree_size;
324 mutable std::mutex mtx;
325 std::unordered_map<uint64_t, Fork::SharedPtr> _forks;
326 uint64_t _forkId = 0;
329
331 void create_canonical_fork(const std::string& dataDir,
333 const std::vector<PublicDataLeafValue>& prefilled_public_data,
334 const std::vector<bb::fr>& prefilled_nullifiers,
335 uint64_t maxReaders,
336 bool ephemeral);
337
338 Fork::SharedPtr retrieve_fork(const uint64_t& forkId) const;
340 void remove_forks_for_block(const block_number_t& blockNumber);
341
342 bool unwind_block(const block_number_t& blockNumber, WorldStateStatusFull& status);
343 bool remove_historical_block(const block_number_t& blockNumber, WorldStateStatusFull& status);
344 bool set_finalized_block(const block_number_t& blockNumber);
345
347
349
351
352 static bool block_state_matches_world_state(const StateReference& block_state_ref,
353 const StateReference& tree_state_ref);
354
355 bool is_archive_tip(const WorldStateRevision& revision, const bb::fr& block_header_hash) const;
356
357 bool is_same_state_reference(const WorldStateRevision& revision, const StateReference& state_ref) const;
358 static bb::fr compute_initial_block_header_hash(const StateReference& initial_state_ref,
359 uint32_t generator_point,
360 uint64_t genesis_timestamp = 0);
361
363 Fork::SharedPtr fork,
364 bool initial_state = false);
365
366 static bool determine_if_synched(std::array<TreeMeta, NUM_TREES>& metaResponses);
367
369 std::array<TreeMeta, NUM_TREES>& metaResponses);
370
372
373 template <typename TreeType>
374 void commit_tree(TreeDBStats& dbStats,
375 Signal& signal,
376 TreeType& tree,
377 std::atomic_bool& success,
378 std::string& message,
379 TreeMeta& meta);
380
381 template <typename TreeType>
382 void unwind_tree(TreeDBStats& dbStats,
383 Signal& signal,
384 TreeType& tree,
385 std::atomic_bool& success,
386 std::string& message,
387 TreeMeta& meta,
388 const block_number_t& blockNumber);
389
390 template <typename TreeType>
392 Signal& signal,
393 TreeType& tree,
394 std::atomic_bool& success,
395 std::string& message,
396 TreeMeta& meta,
397 const block_number_t& blockNumber);
398};
399
400template <typename TreeType>
402 Signal& signal,
403 TreeType& tree,
404 std::atomic_bool& success,
405 std::string& message,
406 TreeMeta& meta)
407{
408 tree.commit([&](TypedResponse<CommitResponse>& 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.unwind_block(blockNumber, [&](TypedResponse<UnwindResponse>& 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 TreeType>
441 Signal& signal,
442 TreeType& tree,
443 std::atomic_bool& success,
444 std::string& message,
445 TreeMeta& meta,
446 const block_number_t& blockNumber)
447{
448 tree.remove_historic_block(blockNumber, [&](TypedResponse<RemoveHistoricResponse>& response) {
449 bool expected = true;
450 if (!response.success && success.compare_exchange_strong(expected, false)) {
451 message = response.message;
452 }
453 dbStats = std::move(response.inner.stats);
454 meta = std::move(response.inner.meta);
455 signal.signal_decrement();
456 });
457}
458
459template <typename T>
461 MerkleTreeId id,
462 index_t leaf) const
463{
466
469
470 if (auto* const wrapper = std::get_if<TreeWithStore<Tree>>(&fork->_trees.at(id))) {
471
472 Signal signal;
473 auto callback = [&](TypedResponse<GetIndexedLeafResponse<T>>& response) {
474 local = std::move(response);
475 signal.signal_level(0);
476 };
477
478 if (rev.is_historical()) {
479 wrapper->tree->get_leaf(leaf, rev.blockNumber, rev.includeUncommitted, callback);
480 } else {
481 wrapper->tree->get_leaf(leaf, rev.includeUncommitted, callback);
482 }
483 signal.wait_for_level();
484
485 if (!local.success) {
486 throw std::runtime_error("Failed to find indexed leaf: " + local.message);
487 }
488
489 return local.inner.indexed_leaf;
490 }
491
492 throw std::runtime_error("Invalid tree type");
493}
494
495template <typename T>
497 MerkleTreeId tree_id,
498 index_t leaf_index) const
499{
500 using namespace crypto::merkle_tree;
501
502 Fork::SharedPtr fork = retrieve_fork(revision.forkId);
503
504 std::optional<T> leaf;
505 bool success = true;
506 std::string error_msg;
507 Signal signal;
508 if constexpr (std::is_same_v<bb::fr, T>) {
509 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(tree_id));
510 auto callback = [&signal, &leaf, &success, &error_msg](const TypedResponse<GetLeafResponse>& response) {
511 if (!response.success || !response.inner.leaf.has_value()) {
512 // TODO(#17755): Permeate errors to TS? (native_world_state_instance.ts -> call() translates this to
513 // null)
514 success = false;
515 error_msg = response.message;
516 } else {
517 leaf = response.inner.leaf;
518 }
519 signal.signal_level();
520 };
521
522 if (revision.is_historical()) {
523 wrapper.tree->get_leaf(leaf_index, revision.blockNumber, revision.includeUncommitted, callback);
524 } else {
525 wrapper.tree->get_leaf(leaf_index, revision.includeUncommitted, callback);
526 }
527 } else {
530
531 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(tree_id));
532 auto callback =
533 [&signal, &leaf, &success, &error_msg](const TypedResponse<GetIndexedLeafResponse<T>>& response) {
534 if (!response.success || !response.inner.indexed_leaf.has_value()) {
535 success = false;
536 error_msg = response.message;
537 } else {
538 leaf = response.inner.indexed_leaf.value().leaf;
539 }
540 signal.signal_level();
541 };
542
543 if (revision.is_historical()) {
544 wrapper.tree->get_leaf(leaf_index, revision.blockNumber, revision.includeUncommitted, callback);
545 } else {
546 wrapper.tree->get_leaf(leaf_index, revision.includeUncommitted, callback);
547 }
548 }
549
550 signal.wait_for_level();
551
552 return leaf;
553}
554
555template <typename T>
557 MerkleTreeId id,
558 const std::vector<T>& leaves,
559 std::vector<std::optional<index_t>>& indices,
560 index_t start_index) const
561{
562 using namespace crypto::merkle_tree;
563
566
567 Signal signal;
568 auto callback = [&](TypedResponse<FindLeafIndexResponse>& response) {
569 local = std::move(response);
570 signal.signal_level(0);
571 };
572 if constexpr (std::is_same_v<bb::fr, T>) {
573 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
574 if (rev.is_historical()) {
575 wrapper.tree->find_leaf_indices_from(
576 leaves, start_index, rev.blockNumber, rev.includeUncommitted, callback);
577 } else {
578 wrapper.tree->find_leaf_indices_from(leaves, start_index, rev.includeUncommitted, callback);
579 }
580
581 } else {
584
585 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
586 if (rev.is_historical()) {
587 wrapper.tree->find_leaf_indices_from(
588 leaves, start_index, rev.blockNumber, rev.includeUncommitted, callback);
589 } else {
590 wrapper.tree->find_leaf_indices_from(leaves, start_index, rev.includeUncommitted, callback);
591 }
592 }
593
594 signal.wait_for_level(0);
595
596 if (!local.success || local.inner.leaf_indices.size() != leaves.size()) {
597 throw std::runtime_error(local.message);
598 }
599
600 indices = std::move(local.inner.leaf_indices);
601}
602
603template <typename T>
605 MerkleTreeId id,
606 const std::vector<T>& leaves,
607 std::vector<std::optional<SiblingPathAndIndex>>& paths) const
608{
609 using namespace crypto::merkle_tree;
610
613
614 Signal signal;
615 auto callback = [&](TypedResponse<FindLeafPathResponse>& response) {
616 local = std::move(response);
617 signal.signal_level(0);
618 };
619 if constexpr (std::is_same_v<bb::fr, T>) {
620 const auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
621 if (rev.is_historical()) {
622 wrapper.tree->find_leaf_sibling_paths(leaves, rev.blockNumber, rev.includeUncommitted, callback);
623 } else {
624 wrapper.tree->find_leaf_sibling_paths(leaves, rev.includeUncommitted, callback);
625 }
626
627 } else {
630
631 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
632 if (rev.is_historical()) {
633 wrapper.tree->find_leaf_sibling_paths(leaves, rev.blockNumber, rev.includeUncommitted, callback);
634 } else {
635 wrapper.tree->find_leaf_sibling_paths(leaves, rev.includeUncommitted, callback);
636 }
637 }
638
639 signal.wait_for_level(0);
640
641 if (!local.success || local.inner.leaf_paths.size() != leaves.size()) {
642 throw std::runtime_error(local.message);
643 }
644
645 paths = std::move(local.inner.leaf_paths);
646}
647
648template <typename T> void WorldState::append_leaves(MerkleTreeId id, const std::vector<T>& leaves, Fork::Id fork_id)
649{
650 using namespace crypto::merkle_tree;
651
652 Fork::SharedPtr fork = retrieve_fork(fork_id);
653
654 Signal signal;
655
656 bool success = true;
657 std::string error_msg;
658
659 if constexpr (std::is_same_v<bb::fr, T>) {
660 auto& wrapper = std::get<TreeWithStore<FrTree>>(fork->_trees.at(id));
661 auto callback = [&](const auto& resp) {
662 if (!resp.success) {
663 success = false;
664 error_msg = resp.message;
665 }
666 signal.signal_level(0);
667 };
668 wrapper.tree->add_values(leaves, callback);
669 } else {
672 auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
673 typename Tree::AddCompletionCallback callback = [&](const auto& resp) {
674 if (!resp.success) {
675 success = false;
676 error_msg = resp.message;
677 }
678 signal.signal_level(0);
679 };
680 wrapper.tree->add_or_update_values(leaves, 0, callback);
681 }
682
683 signal.wait_for_level(0);
684
685 if (!success) {
686 throw std::runtime_error(error_msg);
687 }
688}
689
690template <typename T>
692 const std::vector<T>& leaves,
693 uint32_t subtree_depth,
694 Fork::Id fork_id)
695{
696 using namespace crypto::merkle_tree;
699
700 Fork::SharedPtr fork = retrieve_fork(fork_id);
701
702 Signal signal;
704 const auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
705 bool success = true;
706 std::string error_msg;
707
708 wrapper.tree->add_or_update_values(
709 leaves, subtree_depth, [&](const TypedResponse<AddIndexedDataResponse<T>>& response) {
710 if (response.success) {
711 result.low_leaf_witness_data = *response.inner.low_leaf_witness_data;
712 result.sorted_leaves = *response.inner.sorted_leaves;
713 result.subtree_path = response.inner.subtree_path;
714 } else {
715 success = false;
716 error_msg = response.message;
717 }
718
719 signal.signal_level(0);
720 });
721
722 signal.wait_for_level();
723
724 if (!success) {
725 throw std::runtime_error(error_msg);
726 }
727
728 return result;
729}
730
731template <typename T>
733 const std::vector<T>& leaves,
734 Fork::Id fork_id)
735{
736 using namespace crypto::merkle_tree;
739
740 Fork::SharedPtr fork = retrieve_fork(fork_id);
741
742 Signal signal;
744 const auto& wrapper = std::get<TreeWithStore<Tree>>(fork->_trees.at(id));
745 bool success = true;
746 std::string error_msg;
747
748 wrapper.tree->add_or_update_values_sequentially(
749 leaves, [&](const TypedResponse<AddIndexedDataSequentiallyResponse<T>>& response) {
750 if (response.success) {
751 result.low_leaf_witness_data = *response.inner.low_leaf_witness_data;
752 result.insertion_witness_data = *response.inner.insertion_witness_data;
753 } else {
754 success = false;
755 error_msg = response.message;
756 }
757
758 signal.signal_level(0);
759 });
760
761 signal.wait_for_level();
762
763 if (!success) {
764 throw std::runtime_error(error_msg);
765 }
766
767 return result;
768}
769} // namespace bb::world_state
770
771MSGPACK_ADD_ENUM(bb::world_state::MerkleTreeId)
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)
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 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
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)
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, const std::optional< bb::fr > &expected_archive_root=std::nullopt, const std::optional< bb::fr > &expected_previous_archive_root=std::nullopt)
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.
WorldStateStatusSummary set_finalized_blocks(const block_number_t &toBlockNumber)
void create_canonical_fork(const std::string &dataDir, const std::unordered_map< MerkleTreeId, uint64_t > &dbSize, const std::vector< PublicDataLeafValue > &prefilled_public_data, const std::vector< bb::fr > &prefilled_nullifiers, uint64_t maxReaders, bool ephemeral)
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
VectorField result