Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
cli.cpp
Go to the documentation of this file.
7
9#include <cstdint>
10#include <iostream>
11#include <string>
12#include <unordered_map>
13#include <vector>
14
15namespace bb::wsdb {
16
17using namespace bb::world_state;
18using namespace bb::crypto::merkle_tree;
19
20namespace {
21
22struct WsdbApi {
25 SERIALIZATION_FIELDS(commands, responses);
26};
27
28std::string get_wsdb_schema_as_json()
29{
30 return msgpack_schema_to_string(WsdbApi{});
31}
32
33} // namespace
34
35int parse_and_run_wsdb(int argc, char* argv[])
36{
37 CLI::App app{ "aztec-wsdb: Standalone world state database server" };
38 app.require_subcommand(1);
39
40 // -----------------------------------------------------------------------
41 // Subcommand: msgpack
42 // -----------------------------------------------------------------------
43 CLI::App* msgpack_command = app.add_subcommand("msgpack", "Msgpack API interface.");
44
45 // msgpack schema
46 CLI::App* msgpack_schema_command =
47 msgpack_command->add_subcommand("schema", "Output a msgpack schema encoded as JSON to stdout.");
48
49 // msgpack run
50 CLI::App* msgpack_run_command =
51 msgpack_command->add_subcommand("run", "Start the world state database IPC server.");
52
53 std::string input_path;
54 msgpack_run_command->add_option(
55 "-i,--input", input_path, "IPC socket/shm path (.sock for UDS, .shm for shared memory)");
56
57 std::string data_dir;
58 msgpack_run_command->add_option("-d,--data-dir", data_dir, "Data directory for LMDB stores")->required();
59
60 // Tree heights (JSON map: treeId -> height)
61 std::string tree_heights_json;
62 msgpack_run_command->add_option("--tree-heights", tree_heights_json, "Tree heights as JSON: {0:40,1:32,...}");
63
64 // Tree prefill sizes
65 std::string tree_prefill_json;
66 msgpack_run_command->add_option(
67 "--tree-prefill", tree_prefill_json, "Tree prefill sizes as JSON: {0:128,2:128,...}");
68
69 // Map sizes (KB)
70 std::string map_sizes_json;
71 msgpack_run_command->add_option("--map-sizes", map_sizes_json, "LMDB map sizes in KB as JSON: {0:1024,...}");
72
73 uint32_t threads = 16;
74 msgpack_run_command->add_option("-t,--threads", threads, "Thread pool size (default: 16)")
75 ->check(CLI::PositiveNumber);
76
77 uint32_t initial_header_generator_point = 0;
78 msgpack_run_command->add_option(
79 "--initial-header-generator-point", initial_header_generator_point, "Header generator point (default: 0)");
80
81 // Prefilled public data as JSON array of [slot_hex, value_hex] pairs
82 std::string prefilled_public_data_json;
83 msgpack_run_command->add_option(
84 "--prefilled-public-data", prefilled_public_data_json, "Prefilled public data as JSON array");
85
86 uint64_t genesis_timestamp = 0;
87 msgpack_run_command->add_option("--genesis-timestamp", genesis_timestamp, "Genesis block timestamp (default: 0)");
88
89 size_t request_ring_size = 1024 * 1024;
90 msgpack_run_command
91 ->add_option(
92 "--request-ring-size", request_ring_size, "Request ring buffer size for shared memory IPC (default: 1MB)")
93 ->check(CLI::PositiveNumber);
94
95 size_t response_ring_size = 1024 * 1024;
96 msgpack_run_command
97 ->add_option("--response-ring-size",
98 response_ring_size,
99 "Response ring buffer size for shared memory IPC (default: 1MB)")
100 ->check(CLI::PositiveNumber);
101
102 // Parse CLI
103 try {
104 app.parse(argc, argv);
105 } catch (const CLI::ParseError& e) {
106 return app.exit(e);
107 }
108
109 try {
110 if (msgpack_schema_command->parsed()) {
111 std::cout << get_wsdb_schema_as_json() << std::endl;
112 return 0;
113 }
114
115 if (msgpack_run_command->parsed()) {
116 return execute_wsdb_server(input_path,
117 data_dir,
118 tree_heights_json,
119 tree_prefill_json,
120 map_sizes_json,
121 threads,
122 initial_header_generator_point,
123 prefilled_public_data_json,
124 genesis_timestamp,
125 request_ring_size,
126 response_ring_size);
127 }
128 } catch (const std::exception& e) {
129 std::cerr << "Error: " << e.what() << '\n';
130 return 1;
131 }
132
133 return 0;
134}
135
136} // namespace bb::wsdb
Command commands
bb::bbapi::CommandResponse responses
#define SERIALIZATION_FIELDS(...)
Definition msgpack.hpp:121
NamedUnion< WsdbErrorResponse, WsdbGetTreeInfo::Response, WsdbGetStateReference::Response, WsdbGetInitialStateReference::Response, WsdbGetLeafValue::Response, WsdbGetLeafPreimage::Response, WsdbGetSiblingPath::Response, WsdbGetBlockNumbersForLeafIndices::Response, WsdbFindLeafIndices::Response, WsdbFindLowLeaf::Response, WsdbFindSiblingPaths::Response, WsdbAppendLeaves::Response, WsdbBatchInsert::Response, WsdbSequentialInsert::Response, WsdbUpdateArchive::Response, WsdbCommit::Response, WsdbRollback::Response, WsdbSyncBlock::Response, WsdbCreateFork::Response, WsdbDeleteFork::Response, WsdbFinalizeBlocks::Response, WsdbUnwindBlocks::Response, WsdbRemoveHistoricalBlocks::Response, WsdbGetStatus::Response, WsdbCreateCheckpoint::Response, WsdbCommitCheckpoint::Response, WsdbRevertCheckpoint::Response, WsdbCommitAllCheckpoints::Response, WsdbRevertAllCheckpoints::Response, WsdbCopyStores::Response, WsdbShutdown::Response > WsdbCommandResponse
Union of all wsdb response types.
int execute_wsdb_server(const std::string &input_path, const std::string &data_dir, const std::string &tree_heights_json, const std::string &tree_prefill_json, const std::string &map_sizes_json, uint32_t threads, uint32_t initial_header_generator_point, const std::string &prefilled_public_data_json, uint64_t genesis_timestamp, size_t request_ring_size, size_t response_ring_size)
Start the aztec-wsdb IPC server.
int parse_and_run_wsdb(int argc, char *argv[])
Definition cli.cpp:35
NamedUnion< WsdbGetTreeInfo, WsdbGetStateReference, WsdbGetInitialStateReference, WsdbGetLeafValue, WsdbGetLeafPreimage, WsdbGetSiblingPath, WsdbGetBlockNumbersForLeafIndices, WsdbFindLeafIndices, WsdbFindLowLeaf, WsdbFindSiblingPaths, WsdbAppendLeaves, WsdbBatchInsert, WsdbSequentialInsert, WsdbUpdateArchive, WsdbCommit, WsdbRollback, WsdbSyncBlock, WsdbCreateFork, WsdbDeleteFork, WsdbFinalizeBlocks, WsdbUnwindBlocks, WsdbRemoveHistoricalBlocks, WsdbGetStatus, WsdbCreateCheckpoint, WsdbCommitCheckpoint, WsdbRevertCheckpoint, WsdbCommitAllCheckpoints, WsdbRevertAllCheckpoints, WsdbCopyStores, WsdbShutdown > WsdbCommand
Union of all wsdb commands (request types).
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string msgpack_schema_to_string(const auto &obj)
Print's an object's derived msgpack schema as a string.
WsdbCommand NamedUnion, WsdbRequest context, and dispatch function.