Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion aztec-up/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/usr/bin/env bash
source $(git rev-parse --show-toplevel)/ci3/source_bootstrap

hash=$(hash_str $(cache_content_hash ^aztec-up/) $(../yarn-project/bootstrap.sh hash))
hash=$(hash_str $(cache_content_hash ^aztec-up/) $(../ipc-runtime/bootstrap.sh hash) $(../wsdb/bootstrap.sh hash) $(../yarn-project/bootstrap.sh hash))

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

function wsdb_package_dirs {
for package_dir in "$root"/wsdb/ts/packages/*; do
[ -d "$package_dir" ] && echo "$package_dir"
done
echo "$root/wsdb/ts"
}

function build {
# Noop if user doesn't have docker.
if ! command -v docker &>/dev/null; then
Expand Down Expand Up @@ -103,7 +110,9 @@ EOF
# TODO(AD): we have kludged a retry here. a local NPM install ought to be robust enough not to.
echo "Deploying packages to local npm registry (version: $version)..."
{
echo $root/ipc-runtime/ts
echo $root/barretenberg/ts
wsdb_package_dirs
$root/noir/bootstrap.sh get_projects
$root/yarn-project/bootstrap.sh get_projects
} | DRY_RUN= parallel --tag --line-buffer --halt now,fail=1 "retry 'cd {} && dump_fail \"deploy_npm $version\" >/dev/null'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ string(REGEX REPLACE "[\r\n\"]" "" NODE_API_HEADERS_DIR ${NODE_API_HEADERS_DIR})
add_library(nodejs_module SHARED ${SOURCE_FILES})
set_target_properties(nodejs_module PROPERTIES PREFIX "" SUFFIX ".node")
target_include_directories(nodejs_module PRIVATE ${NODE_API_HEADERS_DIR} ${NODE_ADDON_API_DIR})
target_link_libraries(nodejs_module PRIVATE world_state ipc vm2_sim)
target_link_libraries(nodejs_module PRIVATE ipc ipc_runtime vm2_sim wsdb_ipc_merkle_db)

# On macOS, Node.js N-API symbols are provided by the runtime, not at link time
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "barretenberg/vm2/avm_sim_api.hpp"
#include "barretenberg/vm2/common/avm_io.hpp"
#include "barretenberg/vm2/simulation/lib/cancellation_token.hpp"
#include "barretenberg/vm2_wsdb/wsdb_ipc_merkle_db.hpp"
#include "barretenberg/wsdb/generated/wsdb_ipc_client.hpp"

namespace bb::nodejs {
namespace {
Expand Down Expand Up @@ -227,15 +229,13 @@ Napi::Value AvmSimulateNapi::simulate(const Napi::CallbackInfo& cb_info)
env, ContractCallbacks::get(contract_provider, CALLBACK_REVERT_CHECKPOINT), CALLBACK_REVERT_CHECKPOINT),
};

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

/***************************
*** LogLevel (optional) ***
Expand Down Expand Up @@ -281,10 +281,8 @@ Napi::Value AvmSimulateNapi::simulate(const Napi::CallbackInfo& cb_info)
**********************************************************/

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

// Create AVM API and run simulation with the callback-based contracts DB,
// WorldState reference, and optional cancellation token
// Connect to aztec-wsdb and wrap in a WsdbIpcMerkleDB that implements
// LowLevelMerkleDBInterface. The connection is per-simulation; aztec-wsdb is a
// long-running server that the TS layer spawned and owns.
bb::wsdb::WsdbIpcClient wsdb_client(wsdb_ipc_path);
bb::avm2::simulation::WsdbIpcMerkleDB merkle_db(wsdb_client, inputs.ws_revision);

avm2::AvmSimAPI avm;
avm2::TxSimulationResult result = avm.simulate(inputs, contract_db, *ws_ptr, cancellation_token);
avm2::TxSimulationResult result = avm.simulate(inputs, contract_db, merkle_db, cancellation_token);

// Serialize the simulation result with msgpack into the return buffer to TS.
msgpack::pack(result_buffer, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AvmSimulateNapi {
* - info[1]: Object with contract provider callbacks:
* - getContractInstance(address: string): Promise<Buffer | undefined>
* - getContractClass(classId: string): Promise<Buffer | undefined>
* - info[2]: External WorldState handle (pointer to world_state::WorldState)
* - info[2]: WSDB IPC path (string) — TS layer spawned aztec-wsdb at this path
* - info[3]: Log level number (0-7)
* - info[4]: External CancellationToken handle (optional)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
#include "barretenberg/nodejs_module/lmdb_store/lmdb_store_wrapper.hpp"
#include "barretenberg/nodejs_module/msgpack_client/msgpack_client_async.hpp"
#include "barretenberg/nodejs_module/msgpack_client/msgpack_client_wrapper.hpp"
#include "barretenberg/nodejs_module/world_state/world_state.hpp"
#include "napi.h"

Napi::Object Init(Napi::Env env, Napi::Object exports)
{
exports.Set(Napi::String::New(env, "WorldState"), bb::nodejs::WorldStateWrapper::get_class(env));
exports.Set(Napi::String::New(env, "LMDBStore"), bb::nodejs::lmdb_store::LMDBStoreWrapper::get_class(env));
exports.Set(Napi::String::New(env, "MsgpackClient"),
bb::nodejs::msgpack_client::MsgpackClientWrapper::get_class(env));
Expand Down
Loading
Loading