Skip to content

Commit 9685f11

Browse files
committed
refactor: extract wsdb, lmdblib, and kvdb into native-packages
Moves the world-state DB server (+ persistent merkle), the lmdb C++ wrapper (lmdblib), and the kv-store NAPI (kvdb) out of barretenberg into native-packages siblings, leaving barretenberg free of DB code. The standalone aztec-wsdb binary and the kvdb .node build against prebuilt barretenberg; lmdblib/kvdb are fully barretenberg-free. Squashed from the ipc stack's wsdb branch (17 commits).
1 parent e5982db commit 9685f11

170 files changed

Lines changed: 3572 additions & 1069 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ endef
4747
# PHONY TARGETS - List every target that has a file/dir of the same name.
4848
#==============================================================================
4949

50-
.PHONY: noir barretenberg noir-projects l1-contracts release-image boxes playground docs aztec-up spartan wsdb bb-avm-sim
50+
.PHONY: noir barretenberg noir-projects l1-contracts release-image boxes playground docs aztec-up spartan lmdblib kvdb wsdb bb-avm-sim
5151

5252
#==============================================================================
5353
# BOOTSTRAP TARGETS
@@ -321,11 +321,20 @@ ipc-runtime-cross-arm64-macos:
321321
ipc-runtime-cross: ipc-runtime ipc-runtime-cross-arm64-linux ipc-runtime-cross-amd64-macos ipc-runtime-cross-arm64-macos
322322

323323
#==============================================================================
324-
# WSDB
324+
# Native packages (lmdblib, kvdb, wsdb)
325325
#==============================================================================
326326

327-
wsdb: ipc-codegen ipc-runtime bb-cpp-native
328-
$(call build,$@,wsdb)
327+
# lmdblib and kvdb are barretenberg-free: they build against their own deps
328+
# (lmdb, msgpack-c, node-addon-api) only, never bb.
329+
.PHONY: lmdblib kvdb
330+
lmdblib:
331+
$(call build,$@,native-packages/lmdblib)
332+
333+
kvdb: lmdblib
334+
$(call build,$@,native-packages/kvdb)
335+
336+
wsdb: ipc-codegen ipc-runtime bb-cpp-native lmdblib
337+
$(call build,$@,native-packages/wsdb)
329338

330339
#==============================================================================
331340
# .claude tooling
@@ -402,7 +411,7 @@ l1-contracts-tests: l1-contracts-verifier
402411
# Yarn Project - TypeScript monorepo with all TS packages
403412
#==============================================================================
404413

405-
yarn-project: bb-ts noir-projects l1-contracts wsdb bb-avm-sim
414+
yarn-project: bb-ts noir-projects l1-contracts wsdb kvdb bb-avm-sim
406415
$(call build,$@,yarn-project)
407416

408417
yarn-project-tests: yarn-project

aztec-up/bootstrap.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
#!/usr/bin/env bash
22
source $(git rev-parse --show-toplevel)/ci3/source_bootstrap
33

4-
hash=$(hash_str $(cache_content_hash ^aztec-up/) $(../ipc-runtime/bootstrap.sh hash) $(../wsdb/bootstrap.sh hash) $(../barretenberg/ts/bootstrap.sh hash) $(../yarn-project/bootstrap.sh hash))
4+
hash=$(hash_str $(cache_content_hash ^aztec-up/) $(../ipc-runtime/bootstrap.sh hash) $(../native-packages/kvdb/bootstrap.sh hash) $(../native-packages/wsdb/bootstrap.sh hash) $(../barretenberg/ts/bootstrap.sh hash) $(../yarn-project/bootstrap.sh hash))
55

66
# Bare aliases ("nightly", "latest") resolve to this major version.
77
DEFAULT_MAJOR_VERSION=${AZTEC_TOOLCHAIN_DEFAULT_MAJOR_VERSION:-4}
88

99
function wsdb_package_dirs {
10-
for package_dir in "$root"/wsdb/ts/packages/*; do
10+
for package_dir in "$root"/native-packages/wsdb/ts/packages/*; do
1111
[ -d "$package_dir" ] && echo "$package_dir"
1212
done
13-
echo "$root/wsdb/ts"
13+
echo "$root/native-packages/wsdb/ts"
14+
}
15+
16+
function kvdb_package_dirs {
17+
for package_dir in "$root"/native-packages/kvdb/ts/packages/*; do
18+
[ -d "$package_dir" ] && echo "$package_dir"
19+
done
20+
echo "$root/native-packages/kvdb/ts"
1421
}
1522

1623
function barretenberg_ts_package_dirs {
@@ -117,6 +124,7 @@ EOF
117124
echo $root/ipc-runtime/ts
118125
barretenberg_ts_package_dirs
119126
wsdb_package_dirs
127+
kvdb_package_dirs
120128
# l1-artifacts lives under l1-contracts, so it isn't enumerated by yarn-project's get_projects;
121129
# publish it explicitly or @aztec/aztec's portal dependency can't resolve from the local registry.
122130
echo $root/l1-contracts/l1-artifacts

barretenberg/cpp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ project(
1212
# === Platform Guard Reference ===
1313
# __wasm__ : Compiler-defined for WebAssembly. Guards threading, file I/O, networking.
1414
# _WIN32 : Compiler-defined for Windows. Guards POSIX APIs (mmap, signals, IPC).
15-
# BB_LITE : CMake option. Excludes server-side subsystems (lmdb, world_state, ipc, nodejs_module).
15+
# BB_LITE : CMake option. Excludes server-side subsystems (ipc, vm2_wsdb, cdb, avm).
1616
# Enabled for: iOS, Android, Windows cross-compiles.
1717
# WASM : CMake variable mirroring __wasm__ for CMake-level logic.
1818

@@ -45,7 +45,7 @@ option(ENABLE_PIC "Builds with position independent code" OFF)
4545
option(SYNTAX_ONLY "only check syntax (-fsyntax-only)" OFF)
4646
option(ENABLE_WASM_BENCH "Enable BB_BENCH benchmarking support in WASM builds (dev only, not for releases)" OFF)
4747
option(AVM "enable building of vm2 module and bb-avm" ON)
48-
option(BB_LITE "Exclude server-side subsystems: lmdb, world_state, ipc, nodejs_module" OFF)
48+
option(BB_LITE "Exclude server-side subsystems: ipc, vm2_wsdb, cdb, avm" OFF)
4949

5050
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
5151
message(STATUS "Compiling for ARM.")

barretenberg/cpp/CMakePresets.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,25 +801,25 @@
801801
"name": "amd64-linux",
802802
"configurePreset": "amd64-linux",
803803
"inheritConfigureEnvironment": true,
804-
"targets": ["bb", "nodejs_module", "bb-external", "aztec-wsdb", "bb-avm-sim"]
804+
"targets": ["bb", "nodejs_module", "bb-external", "bb-avm-sim"]
805805
},
806806
{
807807
"name": "arm64-linux",
808808
"configurePreset": "arm64-linux",
809809
"inheritConfigureEnvironment": true,
810-
"targets": ["bb", "nodejs_module", "bb-external", "aztec-wsdb", "bb-avm-sim"]
810+
"targets": ["bb", "nodejs_module", "bb-external", "bb-avm-sim"]
811811
},
812812
{
813813
"name": "amd64-macos",
814814
"configurePreset": "amd64-macos",
815815
"inheritConfigureEnvironment": true,
816-
"targets": ["bb", "nodejs_module", "bb-external", "aztec-wsdb", "bb-avm-sim"]
816+
"targets": ["bb", "nodejs_module", "bb-external", "bb-avm-sim"]
817817
},
818818
{
819819
"name": "arm64-macos",
820820
"configurePreset": "arm64-macos",
821821
"inheritConfigureEnvironment": true,
822-
"targets": ["bb", "nodejs_module", "bb-external", "aztec-wsdb", "bb-avm-sim"]
822+
"targets": ["bb", "nodejs_module", "bb-external", "bb-avm-sim"]
823823
},
824824
{
825825
"name": "amd64-windows",

barretenberg/cpp/scripts/audit/audit_scopes/merkle_tree_audit_scope.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Note: Paths relative to `aztec-packages/barretenberg/cpp/src/barretenberg`
2020
### Node Store (Cache + Metadata)
2121
8. `crypto/merkle_tree/node_store/cached_content_addressed_tree_store.hpp`
2222
9. `crypto/merkle_tree/node_store/content_addressed_cache.hpp`
23-
10. `crypto/merkle_tree/node_store/tree_meta.hpp`
23+
10. `crypto/merkle_tree/tree_meta.hpp`
2424

2525
### Append-Only Tree
2626
11. `crypto/merkle_tree/append_only_tree/content_addressed_append_only_tree.hpp`
2727

2828
### Indexed Tree
2929
12. `crypto/merkle_tree/indexed_tree/content_addressed_indexed_tree.hpp`
30-
13. `crypto/merkle_tree/indexed_tree/indexed_leaf.hpp`
30+
13. `crypto/merkle_tree/indexed_leaf.hpp`
3131

3232
## Summary of Module
3333

barretenberg/cpp/src/CMakeLists.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,17 @@ add_subdirectory(barretenberg/ultra_honk)
115115
add_subdirectory(barretenberg/vm2_stub)
116116
add_subdirectory(barretenberg/wasi)
117117

118-
if(NOT BB_LITE)
119-
add_subdirectory(barretenberg/lmdblib)
120-
endif()
121-
122118
if(NOT FUZZING AND NOT WASM AND NOT BB_LITE)
123-
# Fuzzing preset cannot be built with world_state as world_state cannot compile with MULTITHREADING=OFF
124-
# Mobile builds exclude these modules that require LMDB or aren't needed on mobile
119+
# Mobile builds exclude these modules that aren't needed on mobile
125120
add_subdirectory(barretenberg/aztec)
126-
add_subdirectory(barretenberg/world_state)
127121
# NOTE: Do not conditionally base this on the AVM flag as it defines a necessary vm2_sim library.
128122
add_subdirectory(barretenberg/vm2)
129123
add_subdirectory(barretenberg/ipc)
130-
add_subdirectory(barretenberg/wsdb)
131124
add_subdirectory(barretenberg/vm2_wsdb)
132125
add_subdirectory(barretenberg/cdb)
133126
add_subdirectory(barretenberg/avm)
127+
# nodejs_module hosts only the msgpack_client NAPI wrappers now (bb.js's SHM
128+
# transport). The lmdb_store kv-store NAPI moved to native-packages/kvdb.
134129
add_subdirectory(barretenberg/nodejs_module)
135130
endif()
136131

@@ -146,7 +141,6 @@ if(FUZZING_AVM)
146141
if(FUZZING)
147142
# Only add these if they weren't added above (when NOT FUZZING AND NOT WASM)
148143
add_subdirectory(barretenberg/aztec)
149-
add_subdirectory(barretenberg/world_state)
150144
add_subdirectory(barretenberg/vm2)
151145
endif()
152146
add_subdirectory(barretenberg/avm_fuzzer)
@@ -215,11 +209,9 @@ set(BARRETENBERG_TARGET_OBJECTS
215209
set(BB_EXTERNAL_TARGET_OBJECTS ${BARRETENBERG_TARGET_OBJECTS})
216210

217211
if(NOT WASM AND NOT FUZZING AND NOT BB_LITE)
218-
# enable merkle trees and lmdb (not for mobile builds)
212+
# enable merkle trees (not for mobile builds)
219213
list(APPEND BARRETENBERG_TARGET_OBJECTS $<TARGET_OBJECTS:crypto_merkle_tree_objects>)
220-
list(APPEND BARRETENBERG_TARGET_OBJECTS $<TARGET_OBJECTS:lmdblib_objects>)
221214
list(APPEND BARRETENBERG_TARGET_OBJECTS $<TARGET_OBJECTS:api_objects>)
222-
list(APPEND BARRETENBERG_TARGET_OBJECTS $<TARGET_OBJECTS:world_state_objects>)
223215
endif()
224216

225217
add_library(

barretenberg/cpp/src/barretenberg/avm/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ target_link_libraries(
4949
barretenberg
5050
vm2_sim
5151
wsdb_ipc_merkle_db
52-
wsdb_ipc_client
5352
cdb_ipc_client
5453
ipc_runtime
5554
env

barretenberg/cpp/src/barretenberg/avm/avm_execute.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace bb::avm {
1212

1313
using namespace bb::avm2;
14-
using namespace bb::world_state;
14+
using bb::crypto::merkle_tree::WorldStateRevision;
1515

1616
// Cancellation for the single in-flight simulation. bb-avm-sim runs exactly one
1717
// simulation at a time; the SIGUSR1 handler (which may run on any thread) cancels

barretenberg/cpp/src/barretenberg/avm/avm_execute.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "barretenberg/avm/generated/avm_ipc_server.hpp"
88
#include "barretenberg/cdb/cdb_ipc_client.hpp"
99
#include "barretenberg/vm2/simulation/lib/cancellation_token.hpp"
10-
#include "barretenberg/wsdb/generated/wsdb_ipc_client.hpp"
10+
#include "barretenberg/vm2_wsdb/generated/wsdb_ipc_client.hpp"
1111

1212
#include <atomic>
1313

barretenberg/cpp/src/barretenberg/avm/avm_ipc_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "barretenberg/avm/avm_execute.hpp"
33
#include "barretenberg/cdb/cdb_ipc_client.hpp"
44
#include "barretenberg/common/log.hpp"
5-
#include "barretenberg/wsdb/generated/wsdb_ipc_client.hpp"
5+
#include "barretenberg/vm2_wsdb/generated/wsdb_ipc_client.hpp"
66
#include "ipc_runtime/ipc_server.hpp"
77
#include "ipc_runtime/serve_helper.hpp"
88
#include "ipc_runtime/signal_handlers.hpp"

0 commit comments

Comments
 (0)