Skip to content

Commit 01b5f7f

Browse files
committed
refactor: cut TS world state and NAPI AVM over to WSDB IPC; delete NAPI WSDB
1 parent d0239d1 commit 01b5f7f

51 files changed

Lines changed: 1810 additions & 2542 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.

aztec-up/bootstrap.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
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/) $(../yarn-project/bootstrap.sh hash))
4+
hash=$(hash_str $(cache_content_hash ^aztec-up/) $(../ipc-runtime/bootstrap.sh hash) $(../wsdb/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

9+
function wsdb_package_dirs {
10+
for package_dir in "$root"/wsdb/ts/packages/*; do
11+
[ -d "$package_dir" ] && echo "$package_dir"
12+
done
13+
echo "$root/wsdb/ts"
14+
}
15+
916
function build {
1017
# Noop if user doesn't have docker.
1118
if ! command -v docker &>/dev/null; then
@@ -103,7 +110,9 @@ EOF
103110
# TODO(AD): we have kludged a retry here. a local NPM install ought to be robust enough not to.
104111
echo "Deploying packages to local npm registry (version: $version)..."
105112
{
113+
echo $root/ipc-runtime/ts
106114
echo $root/barretenberg/ts
115+
wsdb_package_dirs
107116
$root/noir/bootstrap.sh get_projects
108117
$root/yarn-project/bootstrap.sh get_projects
109118
} | DRY_RUN= parallel --tag --line-buffer --halt now,fail=1 "retry 'cd {} && dump_fail \"deploy_npm $version\" >/dev/null'"

barretenberg/cpp/src/barretenberg/nodejs_module/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ string(REGEX REPLACE "[\r\n\"]" "" NODE_API_HEADERS_DIR ${NODE_API_HEADERS_DIR})
2727
add_library(nodejs_module SHARED ${SOURCE_FILES})
2828
set_target_properties(nodejs_module PROPERTIES PREFIX "" SUFFIX ".node")
2929
target_include_directories(nodejs_module PRIVATE ${NODE_API_HEADERS_DIR} ${NODE_ADDON_API_DIR})
30-
target_link_libraries(nodejs_module PRIVATE world_state ipc vm2_sim)
30+
target_link_libraries(nodejs_module PRIVATE ipc ipc_runtime vm2_sim wsdb_ipc_merkle_db)
3131

3232
# On macOS, Node.js N-API symbols are provided by the runtime, not at link time
3333
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")

barretenberg/cpp/src/barretenberg/nodejs_module/avm_simulate/avm_simulate_napi.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "barretenberg/vm2/avm_sim_api.hpp"
1313
#include "barretenberg/vm2/common/avm_io.hpp"
1414
#include "barretenberg/vm2/simulation/lib/cancellation_token.hpp"
15+
#include "barretenberg/vm2_wsdb/wsdb_ipc_merkle_db.hpp"
16+
#include "barretenberg/wsdb/generated/wsdb_ipc_client.hpp"
1517

1618
namespace bb::nodejs {
1719
namespace {
@@ -227,15 +229,13 @@ Napi::Value AvmSimulateNapi::simulate(const Napi::CallbackInfo& cb_info)
227229
env, ContractCallbacks::get(contract_provider, CALLBACK_REVERT_CHECKPOINT), CALLBACK_REVERT_CHECKPOINT),
228230
};
229231

230-
/*****************************
231-
*** WorldState (required) ***
232-
*****************************/
233-
if (!cb_info[2].IsExternal()) {
234-
throw Napi::TypeError::New(env, "Third argument must be a WorldState handle (External)");
232+
/**********************************
233+
*** WSDB IPC path (required) ***
234+
**********************************/
235+
if (!cb_info[2].IsString()) {
236+
throw Napi::TypeError::New(env, "Third argument must be a WSDB IPC path (string)");
235237
}
236-
// Extract WorldState handle (3rd argument)
237-
auto external = cb_info[2].As<Napi::External<world_state::WorldState>>();
238-
world_state::WorldState* ws_ptr = external.Data();
238+
std::string wsdb_ipc_path = cb_info[2].As<Napi::String>().Utf8Value();
239239

240240
/***************************
241241
*** LogLevel (optional) ***
@@ -281,10 +281,8 @@ Napi::Value AvmSimulateNapi::simulate(const Napi::CallbackInfo& cb_info)
281281
**********************************************************/
282282

283283
auto deferred = std::make_shared<Napi::Promise::Deferred>(env);
284-
// Run on a dedicated std::thread (not libuv pool) to prevent libuv thread pool
285-
// exhaustion when callbacks need libuv threads for I/O.
286284
ThreadedAsyncOperation::Run(
287-
env, deferred, [data, tsfns, logger_tsfn, ws_ptr, cancellation_token](msgpack::sbuffer& result_buffer) {
285+
env, deferred, [data, tsfns, logger_tsfn, wsdb_ipc_path, cancellation_token](msgpack::sbuffer& result_buffer) {
288286
// Collect all thread-safe functions including logger for cleanup
289287
auto all_tsfns = tsfns.to_vector();
290288
all_tsfns.push_back(logger_tsfn);
@@ -309,10 +307,14 @@ Napi::Value AvmSimulateNapi::simulate(const Napi::CallbackInfo& cb_info)
309307
*tsfns.commit_checkpoint,
310308
*tsfns.revert_checkpoint);
311309

312-
// Create AVM API and run simulation with the callback-based contracts DB,
313-
// WorldState reference, and optional cancellation token
310+
// Connect to aztec-wsdb and wrap in a WsdbIpcMerkleDB that implements
311+
// LowLevelMerkleDBInterface. The connection is per-simulation; aztec-wsdb is a
312+
// long-running server that the TS layer spawned and owns.
313+
bb::wsdb::WsdbIpcClient wsdb_client(wsdb_ipc_path);
314+
bb::avm2::simulation::WsdbIpcMerkleDB merkle_db(wsdb_client, inputs.ws_revision);
315+
314316
avm2::AvmSimAPI avm;
315-
avm2::TxSimulationResult result = avm.simulate(inputs, contract_db, *ws_ptr, cancellation_token);
317+
avm2::TxSimulationResult result = avm.simulate(inputs, contract_db, merkle_db, cancellation_token);
316318

317319
// Serialize the simulation result with msgpack into the return buffer to TS.
318320
msgpack::pack(result_buffer, result);

barretenberg/cpp/src/barretenberg/nodejs_module/avm_simulate/avm_simulate_napi.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AvmSimulateNapi {
2525
* - info[1]: Object with contract provider callbacks:
2626
* - getContractInstance(address: string): Promise<Buffer | undefined>
2727
* - getContractClass(classId: string): Promise<Buffer | undefined>
28-
* - info[2]: External WorldState handle (pointer to world_state::WorldState)
28+
* - info[2]: WSDB IPC path (string) — TS layer spawned aztec-wsdb at this path
2929
* - info[3]: Log level number (0-7)
3030
* - info[4]: External CancellationToken handle (optional)
3131
*

barretenberg/cpp/src/barretenberg/nodejs_module/init_module.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
#include "barretenberg/nodejs_module/lmdb_store/lmdb_store_wrapper.hpp"
33
#include "barretenberg/nodejs_module/msgpack_client/msgpack_client_async.hpp"
44
#include "barretenberg/nodejs_module/msgpack_client/msgpack_client_wrapper.hpp"
5-
#include "barretenberg/nodejs_module/world_state/world_state.hpp"
65
#include "napi.h"
76

87
Napi::Object Init(Napi::Env env, Napi::Object exports)
98
{
10-
exports.Set(Napi::String::New(env, "WorldState"), bb::nodejs::WorldStateWrapper::get_class(env));
119
exports.Set(Napi::String::New(env, "LMDBStore"), bb::nodejs::lmdb_store::LMDBStoreWrapper::get_class(env));
1210
exports.Set(Napi::String::New(env, "MsgpackClient"),
1311
bb::nodejs::msgpack_client::MsgpackClientWrapper::get_class(env));

0 commit comments

Comments
 (0)