39 uint64_t thread_pool_size = 16;
48 std::unordered_map<MerkleTreeId, uint32_t> tree_height;
49 std::unordered_map<MerkleTreeId, index_t> tree_prefill;
52 MerkleTreeId::NULLIFIER_TREE, MerkleTreeId::NOTE_HASH_TREE, MerkleTreeId::PUBLIC_DATA_TREE,
53 MerkleTreeId::L1_TO_L2_MESSAGE_TREE, MerkleTreeId::ARCHIVE,
55 uint32_t initial_header_generator_point = 0;
57 Napi::Env env =
info.Env();
59 size_t data_dir_index = 0;
60 if (
info.Length() > data_dir_index &&
info[data_dir_index].IsString()) {
61 data_dir =
info[data_dir_index].As<Napi::String>();
63 throw Napi::TypeError::New(env,
"Directory needs to be a string");
66 size_t tree_height_index = 1;
67 if (
info.Length() > tree_height_index &&
info[tree_height_index].IsObject()) {
68 Napi::Object obj =
info[tree_height_index].As<Napi::Object>();
70 for (
auto tree_id : tree_ids) {
71 if (obj.Has(tree_id)) {
72 tree_height[tree_id] = obj.Get(tree_id).As<Napi::Number>().Uint32Value();
76 throw Napi::TypeError::New(env,
"Tree heights must be a map");
79 size_t tree_prefill_index = 2;
80 if (
info.Length() > tree_prefill_index &&
info[tree_prefill_index].IsObject()) {
81 Napi::Object obj =
info[tree_prefill_index].As<Napi::Object>();
83 for (
auto tree_id : tree_ids) {
84 if (obj.Has(tree_id)) {
85 tree_prefill[tree_id] = obj.Get(tree_id).As<Napi::Number>().Uint32Value();
89 throw Napi::TypeError::New(env,
"Tree prefill must be a map");
92 size_t prefilled_public_data_index = 3;
93 if (
info.Length() > prefilled_public_data_index &&
info[prefilled_public_data_index].IsArray()) {
94 Napi::Array arr =
info[prefilled_public_data_index].As<Napi::Array>();
95 for (uint32_t i = 0; i < arr.Length(); ++i) {
96 Napi::Array deserialized = arr.Get(i).As<Napi::Array>();
97 if (deserialized.Length() != 2 || !deserialized.Get(uint32_t(0)).IsBuffer() ||
98 !deserialized.Get(uint32_t(1)).IsBuffer()) {
99 throw Napi::TypeError::New(env,
"Prefilled public data value must be a buffer array of size 2");
101 Napi::Buffer<uint8_t> slot_buf = deserialized.Get(uint32_t(0)).As<Napi::Buffer<uint8_t>>();
102 Napi::Buffer<uint8_t> value_buf = deserialized.Get(uint32_t(1)).As<Napi::Buffer<uint8_t>>();
105 for (
size_t j = 0; j < 32; ++j) {
112 throw Napi::TypeError::New(env,
"Prefilled public data must be an array");
115 size_t initial_header_generator_point_index = 4;
116 if (
info.Length() > initial_header_generator_point_index &&
info[initial_header_generator_point_index].IsNumber()) {
117 initial_header_generator_point =
info[initial_header_generator_point_index].As<Napi::Number>().Uint32Value();
119 throw Napi::TypeError::New(env,
"Header generator point needs to be a number");
122 uint64_t genesis_timestamp = 0;
123 size_t genesis_timestamp_index = 5;
124 if (
info.Length() > genesis_timestamp_index) {
125 if (
info[genesis_timestamp_index].IsNumber()) {
126 genesis_timestamp =
static_cast<uint64_t
>(
info[genesis_timestamp_index].As<Napi::Number>().Int64Value());
128 throw Napi::TypeError::New(env,
"Genesis timestamp needs to be a number");
133 size_t map_size_index = 6;
134 if (
info.Length() > map_size_index) {
135 if (
info[map_size_index].IsObject()) {
136 Napi::Object obj =
info[map_size_index].As<Napi::Object>();
138 for (
auto tree_id : tree_ids) {
139 if (obj.Has(tree_id)) {
141 int64_t val = obj.Get(tree_id).As<Napi::Number>().Int64Value();
143 throw Napi::TypeError::New(env,
"Map size must be a positive number");
145 map_size[tree_id] =
static_cast<uint64_t
>(val);
148 }
else if (
info[map_size_index].IsNumber()) {
150 int64_t val =
info[map_size_index].As<Napi::Number>().Int64Value();
152 throw Napi::TypeError::New(env,
"Map size must be a positive number");
154 uint64_t size =
static_cast<uint64_t
>(val);
155 for (
auto tree_id : tree_ids) {
156 map_size[tree_id] = size;
159 throw Napi::TypeError::New(env,
"Map size must be a number or an object");
163 size_t thread_pool_size_index = 7;
164 if (
info.Length() > thread_pool_size_index) {
165 if (!
info[thread_pool_size_index].IsNumber()) {
166 throw Napi::TypeError::New(env,
"Thread pool size must be a number");
169 thread_pool_size =
info[thread_pool_size_index].As<Napi::Number>().Uint32Value();
177 prefilled_public_data,
178 initial_header_generator_point,
206 [
this](msgpack::object& obj, msgpack::sbuffer&
buffer) {
239 [
this](msgpack::object& obj, msgpack::sbuffer&
buffer) {
return commit(obj,
buffer); });
262 [
this](msgpack::object& obj, msgpack::sbuffer&
buffer) {
return unwind(obj,
buffer); });
273 [
this](msgpack::object& obj, msgpack::sbuffer&
buffer) {
return close(obj,
buffer); });