18#include "barretenberg/wsdb/generated/wsdb_ipc_server.hpp"
36 return wire::WsdbGetTreeInfoResponse{
38 .root = fr_to_wire(
info.meta.root),
39 .size =
info.meta.size,
40 .depth =
info.meta.depth,
51 wire::WsdbGetInitialStateReference&&)
65 auto leaf_index =
static_cast<index_t>(cmd.leafIndex);
72 return wire::WsdbGetLeafValueResponse{ .value = leaf.has_value() ?
std::optional<Fr>(fr_to_wire(*leaf))
76 throw std::runtime_error(
"Unsupported tree type for get_leaf_value");
81 wire::WsdbGetPublicDataLeafValue&& cmd)
85 static_cast<index_t>(cmd.leafIndex));
86 return wire::WsdbGetPublicDataLeafValueResponse{
93 wire::WsdbGetNullifierLeafValue&& cmd)
97 static_cast<index_t>(cmd.leafIndex));
104 WsdbRequest& ctx, wire::WsdbGetPublicDataLeafPreimage&& cmd)
108 static_cast<index_t>(cmd.leafIndex));
109 return wire::WsdbGetPublicDataLeafPreimageResponse{
110 .preimage = leaf.has_value()
117 wire::WsdbGetNullifierLeafPreimage&& cmd)
121 static_cast<index_t>(cmd.leafIndex));
122 return wire::WsdbGetNullifierLeafPreimageResponse{ .preimage = leaf.has_value()
132 return wire::WsdbGetSiblingPathResponse{ .path =
fr_vec_to_wire(path) };
136 WsdbRequest& ctx, wire::WsdbGetBlockNumbersForLeafIndices&& cmd)
138 std::vector<index_t> leaf_indices;
139 leaf_indices.reserve(cmd.leafIndices.size());
140 for (
auto i : cmd.leafIndices) {
141 leaf_indices.push_back(
static_cast<index_t>(i));
147 wire_block_numbers.reserve(block_numbers.size());
148 for (
const auto& bn : block_numbers) {
149 wire_block_numbers.push_back(bn);
151 return wire::WsdbGetBlockNumbersForLeafIndicesResponse{ .blockNumbers =
std::move(wire_block_numbers) };
162 auto start_index =
static_cast<index_t>(cmd.startIndex);
169 auto typed_leaves = fr_vec_from_wire(cmd.leaves);
174 throw std::runtime_error(
"Unsupported tree type for find_leaf_indices");
177 wire_indices.reserve(indices.size());
178 for (
const auto& i : indices) {
181 return wire::WsdbFindLeafIndicesResponse{ .indices =
std::move(wire_indices) };
185 WsdbRequest& ctx, wire::WsdbFindPublicDataLeafIndices&& cmd)
192 static_cast<index_t>(cmd.startIndex));
194 wire_indices.reserve(indices.size());
195 for (
const auto& i : indices) {
198 return wire::WsdbFindPublicDataLeafIndicesResponse{ .indices =
std::move(wire_indices) };
202 wire::WsdbFindNullifierLeafIndices&& cmd)
209 static_cast<index_t>(cmd.startIndex));
211 wire_indices.reserve(indices.size());
212 for (
const auto& i : indices) {
215 return wire::WsdbFindNullifierLeafIndicesResponse{ .indices =
std::move(wire_indices) };
222 return wire::WsdbFindLowLeafResponse{
224 .index =
static_cast<uint64_t
>(low_leaf_info.index),
237 auto typed_leaves = fr_vec_from_wire(cmd.leaves);
242 throw std::runtime_error(
"Unsupported tree type for find_sibling_paths");
245 wire_paths.reserve(paths.size());
246 for (
const auto& p : paths) {
247 if (!p.has_value()) {
251 wire_paths.push_back(wire::SiblingPathAndIndex{
252 .index =
static_cast<uint64_t
>(p->index),
256 return wire::WsdbFindSiblingPathsResponse{ .paths =
std::move(wire_paths) };
260 WsdbRequest& ctx, wire::WsdbFindPublicDataSiblingPaths&& cmd)
268 wire_paths.reserve(paths.size());
269 for (
const auto& p : paths) {
270 wire_paths.push_back(p.has_value()
272 .index =
static_cast<uint64_t
>(p->index), .path =
fr_vec_to_wire(p->path) })
275 return wire::WsdbFindPublicDataSiblingPathsResponse{ .paths =
std::move(wire_paths) };
279 WsdbRequest& ctx, wire::WsdbFindNullifierSiblingPaths&& cmd)
287 wire_paths.reserve(paths.size());
288 for (
const auto& p : paths) {
289 wire_paths.push_back(p.has_value()
291 .index =
static_cast<uint64_t
>(p->index), .path =
fr_vec_to_wire(p->path) })
294 return wire::WsdbFindNullifierSiblingPathsResponse{ .paths =
std::move(wire_paths) };
312 throw std::runtime_error(
"Unsupported tree type for append_leaves");
314 return wire::WsdbAppendLeavesResponse{};
318 wire::WsdbAppendPublicDataLeaves&& cmd)
322 return wire::WsdbAppendPublicDataLeavesResponse{};
326 wire::WsdbAppendNullifierLeaves&& cmd)
330 return wire::WsdbAppendNullifierLeavesResponse{};
334 wire::WsdbBatchInsertPublicData&& cmd)
345 wire::WsdbBatchInsertNullifier&& cmd)
356 WsdbRequest& ctx, wire::WsdbSequentialInsertPublicData&& cmd)
364 WsdbRequest& ctx, wire::WsdbSequentialInsertNullifier&& cmd)
375 return wire::WsdbUpdateArchiveResponse{};
386 return wire::WsdbCommitResponse{
394 return wire::WsdbRollbackResponse{};
405 auto padded_note_hashes = fr_vec_from_wire(cmd.paddedNoteHashes);
406 auto padded_l1_to_l2_messages = fr_vec_from_wire(cmd.paddedL1ToL2Messages);
409 padded_nullifiers.reserve(cmd.paddedNullifiers.size());
410 for (
const auto& w : cmd.paddedNullifiers) {
415 public_data_writes.reserve(cmd.publicDataWrites.size());
416 for (
const auto& w : cmd.publicDataWrites) {
423 padded_l1_to_l2_messages,
426 return wire::WsdbSyncBlockResponse{
439 return wire::WsdbCreateForkResponse{ .forkId =
id };
445 return wire::WsdbDeleteForkResponse{};
455 return wire::WsdbFinalizeBlocksResponse{
463 return wire::WsdbUnwindBlocksResponse{
469 wire::WsdbRemoveHistoricalBlocks&& cmd)
472 return wire::WsdbRemoveHistoricalBlocksResponse{
485 return wire::WsdbGetStatusResponse{
497 return wire::WsdbCreateCheckpointResponse{};
503 return wire::WsdbCommitCheckpointResponse{};
509 return wire::WsdbRevertCheckpointResponse{};
513 wire::WsdbCommitAllCheckpoints&& cmd)
516 return wire::WsdbCommitAllCheckpointsResponse{};
520 wire::WsdbRevertAllCheckpoints&& cmd)
523 return wire::WsdbRevertAllCheckpointsResponse{};
533 return wire::WsdbCopyStoresResponse{};
WorldStateStatusFull remove_historical_blocks(const block_number_t &toBlockNumber)
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.
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)
crypto::merkle_tree::TreeMetaResponse get_tree_info(const WorldStateRevision &revision, MerkleTreeId tree_id) const
Get tree metadata for a particular tree.
void commit_all_checkpoints_to(const uint64_t &forkId, uint32_t depth)
std::pair< bool, std::string > commit(WorldStateStatusFull &status)
Commits the current state of the world state.
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)
void commit_checkpoint(const uint64_t &forkId)
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 > ¬es, 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)
void delete_fork(const uint64_t &forkId)
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 revert_all_checkpoints_to(const uint64_t &forkId, uint32_t depth)
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.
std::vector< fr > fr_sibling_path
world_state::StateReference state_reference_from_wire(const std::vector< wire::TreeStateReference > &w)
wire::WsdbFindNullifierLeafIndicesResponse handle_find_nullifier_leaf_indices(WsdbRequest &ctx, wire::WsdbFindNullifierLeafIndices &&cmd)
wire::WsdbAppendNullifierLeavesResponse handle_append_nullifier_leaves(WsdbRequest &ctx, wire::WsdbAppendNullifierLeaves &&cmd)
wire::WsdbGetPublicDataLeafPreimageResponse handle_get_public_data_leaf_preimage(WsdbRequest &ctx, wire::WsdbGetPublicDataLeafPreimage &&cmd)
std::vector< crypto::merkle_tree::PublicDataLeafValue > public_data_leaf_vec_from_wire(const std::vector< wire::PublicDataLeafValue > &w)
wire::WsdbGetSiblingPathResponse handle_get_sibling_path(WsdbRequest &ctx, wire::WsdbGetSiblingPath &&cmd)
wire::WsdbUpdateArchiveResponse handle_update_archive(WsdbRequest &ctx, wire::WsdbUpdateArchive &&cmd)
std::vector< Fr > fr_vec_to_wire(const std::vector< bb::fr > &d)
wire::SequentialInsertionResultNullifier sequential_nullifier_to_wire(const world_state::SequentialInsertionResult< crypto::merkle_tree::NullifierLeafValue > &d)
wire::BatchInsertionResultPublicData batch_public_data_to_wire(const world_state::BatchInsertionResult< crypto::merkle_tree::PublicDataLeafValue > &d)
wire::WsdbFindPublicDataSiblingPathsResponse handle_find_public_data_sibling_paths(WsdbRequest &ctx, wire::WsdbFindPublicDataSiblingPaths &&cmd)
std::vector< crypto::merkle_tree::NullifierLeafValue > nullifier_leaf_vec_from_wire(const std::vector< wire::NullifierLeafValue > &w)
wire::NullifierLeafValue nullifier_leaf_to_wire(const crypto::merkle_tree::NullifierLeafValue &d)
wire::WsdbGetPublicDataLeafValueResponse handle_get_public_data_leaf_value(WsdbRequest &ctx, wire::WsdbGetPublicDataLeafValue &&cmd)
wire::IndexedNullifierLeafValue indexed_nullifier_leaf_to_wire(const crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::NullifierLeafValue > &d)
wire::WsdbFindPublicDataLeafIndicesResponse handle_find_public_data_leaf_indices(WsdbRequest &ctx, wire::WsdbFindPublicDataLeafIndices &&cmd)
wire::WsdbRollbackResponse handle_rollback(WsdbRequest &ctx, wire::WsdbRollback &&)
wire::WsdbFindSiblingPathsResponse handle_find_sibling_paths(WsdbRequest &ctx, wire::WsdbFindSiblingPaths &&cmd)
wire::WsdbGetStatusResponse handle_get_status(WsdbRequest &ctx, wire::WsdbGetStatus &&)
wire::WsdbSequentialInsertPublicDataResponse handle_sequential_insert_public_data(WsdbRequest &ctx, wire::WsdbSequentialInsertPublicData &&cmd)
wire::WsdbFindNullifierSiblingPathsResponse handle_find_nullifier_sibling_paths(WsdbRequest &ctx, wire::WsdbFindNullifierSiblingPaths &&cmd)
wire::WsdbGetTreeInfoResponse handle_get_tree_info(WsdbRequest &ctx, wire::WsdbGetTreeInfo &&cmd)
world_state::WorldStateRevision revision_from_wire(const wire::WorldStateRevision &w)
wire::WsdbGetStateReferenceResponse handle_get_state_reference(WsdbRequest &ctx, wire::WsdbGetStateReference &&cmd)
bb::fr public_data_slot_from_wire(const PublicDataSlot &w)
world_state::MerkleTreeId tree_id_from_wire(MerkleTreeId w)
wire::WsdbGetNullifierLeafPreimageResponse handle_get_nullifier_leaf_preimage(WsdbRequest &ctx, wire::WsdbGetNullifierLeafPreimage &&cmd)
wire::SequentialInsertionResultPublicData sequential_public_data_to_wire(const world_state::SequentialInsertionResult< crypto::merkle_tree::PublicDataLeafValue > &d)
wire::WsdbBatchInsertNullifierResponse handle_batch_insert_nullifier(WsdbRequest &ctx, wire::WsdbBatchInsertNullifier &&cmd)
wire::WsdbUnwindBlocksResponse handle_unwind_blocks(WsdbRequest &ctx, wire::WsdbUnwindBlocks &&cmd)
wire::IndexedPublicDataLeafValue indexed_public_data_leaf_to_wire(const crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::PublicDataLeafValue > &d)
wire::WsdbAppendLeavesResponse handle_append_leaves(WsdbRequest &ctx, wire::WsdbAppendLeaves &&cmd)
wire::WsdbGetInitialStateReferenceResponse handle_get_initial_state_reference(WsdbRequest &ctx, wire::WsdbGetInitialStateReference &&)
wire::WsdbRevertAllCheckpointsResponse handle_revert_all_checkpoints(WsdbRequest &ctx, wire::WsdbRevertAllCheckpoints &&cmd)
wire::BatchInsertionResultNullifier batch_nullifier_to_wire(const world_state::BatchInsertionResult< crypto::merkle_tree::NullifierLeafValue > &d)
wire::WsdbBatchInsertPublicDataResponse handle_batch_insert_public_data(WsdbRequest &ctx, wire::WsdbBatchInsertPublicData &&cmd)
wire::WsdbSyncBlockResponse handle_sync_block(WsdbRequest &ctx, wire::WsdbSyncBlock &&cmd)
wire::WsdbFindLeafIndicesResponse handle_find_leaf_indices(WsdbRequest &ctx, wire::WsdbFindLeafIndices &&cmd)
wire::WsdbRevertCheckpointResponse handle_revert_checkpoint(WsdbRequest &ctx, wire::WsdbRevertCheckpoint &&cmd)
wire::WorldStateStatusFull world_state_status_full_to_wire(const bb::world_state::WorldStateStatusFull &d)
wire::WsdbAppendPublicDataLeavesResponse handle_append_public_data_leaves(WsdbRequest &ctx, wire::WsdbAppendPublicDataLeaves &&cmd)
bb::fr public_data_value_from_wire(const PublicDataValue &w)
wire::PublicDataLeafValue public_data_leaf_to_wire(const crypto::merkle_tree::PublicDataLeafValue &d)
bb::fr nullifier_from_wire(const Nullifier &w)
wire::WsdbRemoveHistoricalBlocksResponse handle_remove_historical_blocks(WsdbRequest &ctx, wire::WsdbRemoveHistoricalBlocks &&cmd)
wire::WsdbCommitResponse handle_commit(WsdbRequest &ctx, wire::WsdbCommit &&)
wire::WsdbCommitAllCheckpointsResponse handle_commit_all_checkpoints(WsdbRequest &ctx, wire::WsdbCommitAllCheckpoints &&cmd)
bb::fr block_header_hash_from_wire(const BlockHeaderHash &w)
wire::WsdbGetBlockNumbersForLeafIndicesResponse handle_get_block_numbers_for_leaf_indices(WsdbRequest &ctx, wire::WsdbGetBlockNumbersForLeafIndices &&cmd)
wire::WsdbFindLowLeafResponse handle_find_low_leaf(WsdbRequest &ctx, wire::WsdbFindLowLeaf &&cmd)
wire::WsdbSequentialInsertNullifierResponse handle_sequential_insert_nullifier(WsdbRequest &ctx, wire::WsdbSequentialInsertNullifier &&cmd)
wire::WsdbDeleteForkResponse handle_delete_fork(WsdbRequest &ctx, wire::WsdbDeleteFork &&cmd)
wire::WsdbGetLeafValueResponse handle_get_leaf_value(WsdbRequest &ctx, wire::WsdbGetLeafValue &&cmd)
wire::WsdbGetNullifierLeafValueResponse handle_get_nullifier_leaf_value(WsdbRequest &ctx, wire::WsdbGetNullifierLeafValue &&cmd)
wire::WorldStateStatusSummary world_state_status_summary_to_wire(const bb::world_state::WorldStateStatusSummary &d)
wire::WsdbCommitCheckpointResponse handle_commit_checkpoint(WsdbRequest &ctx, wire::WsdbCommitCheckpoint &&cmd)
wire::WsdbFinalizeBlocksResponse handle_finalize_blocks(WsdbRequest &ctx, wire::WsdbFinalizeBlocks &&cmd)
wire::WsdbCreateForkResponse handle_create_fork(WsdbRequest &ctx, wire::WsdbCreateFork &&cmd)
std::vector< wire::TreeStateReference > state_reference_to_wire(const world_state::StateReference &d)
wire::WsdbCreateCheckpointResponse handle_create_checkpoint(WsdbRequest &ctx, wire::WsdbCreateCheckpoint &&cmd)
wire::WsdbCopyStoresResponse handle_copy_stores(WsdbRequest &ctx, wire::WsdbCopyStores &&cmd)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
world_state::WorldState & world_state
Non-template handler declarations for the wsdb service.
Wire <-> domain conversion helpers for the aztec-wsdb service.