Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ int index_key_cmp(const MDB_val* a, const MDB_val* b)
return value_cmp<uint64_t>(a, b);
}

LMDBTreeStore::LMDBTreeStore(std::string directory, std::string name, uint64_t mapSizeKb, uint64_t maxNumReaders)
: LMDBStoreBase(directory, mapSizeKb, maxNumReaders, 5)
LMDBTreeStore::LMDBTreeStore(
std::string directory, std::string name, uint64_t mapSizeKb, uint64_t maxNumReaders, bool ephemeral)
: LMDBStoreBase(directory, mapSizeKb, maxNumReaders, 5, ephemeral)
, _name(std::move(name))
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ class LMDBTreeStore : public LMDBStoreBase {
using SharedPtr = std::shared_ptr<LMDBTreeStore>;
using ReadTransaction = LMDBReadTransaction;
using WriteTransaction = LMDBWriteTransaction;
LMDBTreeStore(std::string directory, std::string name, uint64_t mapSizeKb, uint64_t maxNumReaders);
LMDBTreeStore(
std::string directory, std::string name, uint64_t mapSizeKb, uint64_t maxNumReaders, bool ephemeral = false);
LMDBTreeStore(const LMDBTreeStore& other) = delete;
LMDBTreeStore(LMDBTreeStore&& other) = delete;
LMDBTreeStore& operator=(const LMDBTreeStore& other) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

namespace bb::lmdblib {

LMDBEnvironment::LMDBEnvironment(const std::string& directory,
uint64_t mapSizeKB,
uint32_t maxNumDBs,
uint32_t maxNumReaders)
LMDBEnvironment::LMDBEnvironment(
const std::string& directory, uint64_t mapSizeKB, uint32_t maxNumDBs, uint32_t maxNumReaders, bool ephemeral)
: _id(0)
, _directory(directory)
, _readGuard(maxNumReaders)
Expand All @@ -21,6 +19,9 @@ LMDBEnvironment::LMDBEnvironment(const std::string& directory,
uint64_t kb = 1024;
uint64_t totalMapSize = kb * mapSizeKB;
uint32_t flags = MDB_NOTLS;
if (ephemeral) {
flags |= MDB_NOSYNC | MDB_NOMETASYNC;
}
try {
call_lmdb_func("mdb_env_set_mapsize", mdb_env_set_mapsize, _mdbEnv, static_cast<size_t>(totalMapSize));
call_lmdb_func("mdb_env_set_maxdbs", mdb_env_set_maxdbs, _mdbEnv, static_cast<MDB_dbi>(maxNumDBs));
Expand Down
13 changes: 12 additions & 1 deletion barretenberg/cpp/src/barretenberg/lmdblib/lmdb_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ class LMDBEnvironment {
* @param mapSizeKb The maximum size of the database, can be increased from a previously used value
* @param maxNumDbs The maximum number of databases that can be created withn this environment
* @param maxNumReaders The maximum number of concurrent read transactions permitted.
* @param ephemeral When true, opens the env with `MDB_NOSYNC | MDB_NOMETASYNC`. Commits
* return as soon as the dirty pages are queued; the kernel flushes them
* lazily and never blocks the commit. Files stay sparse (we deliberately
* avoid `MDB_WRITEMAP`, which would eagerly allocate the full map size
* on disk). Intended for short-lived ephemeral world states (e.g. TXE
* test sessions) that discard the directory on close; never use for a
* real node — a crash mid-write yields an unrecoverable env.
*/
LMDBEnvironment(const std::string& directory, uint64_t mapSizeKb, uint32_t maxNumDBs, uint32_t maxNumReaders);
LMDBEnvironment(const std::string& directory,
uint64_t mapSizeKb,
uint32_t maxNumDBs,
uint32_t maxNumReaders,
bool ephemeral = false);
LMDBEnvironment(const LMDBEnvironment& other) = delete;
LMDBEnvironment(LMDBEnvironment&& other) = delete;
LMDBEnvironment& operator=(const LMDBEnvironment& other) = delete;
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/lmdblib/lmdb_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <stdexcept>

namespace bb::lmdblib {
LMDBStore::LMDBStore(std::string directory, uint64_t mapSizeKb, uint64_t maxNumReaders, uint64_t maxDbs)
: LMDBStoreBase(std::move(directory), mapSizeKb, maxNumReaders, maxDbs)
LMDBStore::LMDBStore(std::string directory, uint64_t mapSizeKb, uint64_t maxNumReaders, uint64_t maxDbs, bool ephemeral)
: LMDBStoreBase(std::move(directory), mapSizeKb, maxNumReaders, maxDbs, ephemeral)
{}

void LMDBStore::open_database(const std::string& name, bool duplicateKeysPermitted)
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/lmdblib/lmdb_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class LMDBStore : public LMDBStoreBase {
std::string name;
};

LMDBStore(std::string directory, uint64_t mapSizeKb, uint64_t maxNumReaders, uint64_t maxDbs);
LMDBStore(
std::string directory, uint64_t mapSizeKb, uint64_t maxNumReaders, uint64_t maxDbs, bool ephemeral = false);
LMDBStore(const LMDBStore& other) = delete;
LMDBStore(LMDBStore&& other) = delete;
LMDBStore& operator=(const LMDBStore& other) = delete;
Expand Down
5 changes: 3 additions & 2 deletions barretenberg/cpp/src/barretenberg/lmdblib/lmdb_store_base.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "barretenberg/lmdblib/lmdb_store_base.hpp"

namespace bb::lmdblib {
LMDBStoreBase::LMDBStoreBase(std::string directory, uint64_t mapSizeKb, uint64_t maxNumReaders, uint64_t maxDbs)
LMDBStoreBase::LMDBStoreBase(
std::string directory, uint64_t mapSizeKb, uint64_t maxNumReaders, uint64_t maxDbs, bool ephemeral)
: _dbDirectory(std::move(directory))
, _environment((std::make_shared<LMDBEnvironment>(_dbDirectory, mapSizeKb, maxDbs, maxNumReaders)))
, _environment(std::make_shared<LMDBEnvironment>(_dbDirectory, mapSizeKb, maxDbs, maxNumReaders, ephemeral))
{}
LMDBStoreBase::~LMDBStoreBase() = default;
LMDBStoreBase::ReadTransaction::Ptr LMDBStoreBase::create_read_transaction() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class LMDBStoreBase {
using ReadTransaction = LMDBReadTransaction;
using WriteTransaction = LMDBWriteTransaction;
using DBCreationTransaction = LMDBDatabaseCreationTransaction;
LMDBStoreBase(std::string directory, uint64_t mapSizeKb, uint64_t maxNumReaders, uint64_t maxDbs);
LMDBStoreBase(
std::string directory, uint64_t mapSizeKb, uint64_t maxNumReaders, uint64_t maxDbs, bool ephemeral = false);
LMDBStoreBase(const LMDBStoreBase& other) = delete;
LMDBStoreBase& operator=(const LMDBStoreBase& other) = delete;
LMDBStoreBase(LMDBStoreBase&& other) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,21 @@ LMDBStoreWrapper::LMDBStoreWrapper(const Napi::CallbackInfo& info)
}
}

_store = std::make_unique<lmdblib::LMDBStore>(data_dir, map_size, max_readers, 2);
// `ephemeral` opens the LMDB env with `MDB_NOSYNC | MDB_NOMETASYNC`, so commits return
// without waiting for fsync. The on-disk file is unrecoverable after a crash but stays
// sparse on every byte LMDB doesn't touch; the trade-off is appropriate for tmp stores
// that get cleaned up on close (see `openTmpStore`).
size_t ephemeral_index = 3;
bool ephemeral = false;
if (info.Length() > ephemeral_index) {
if (info[ephemeral_index].IsBoolean()) {
ephemeral = info[ephemeral_index].As<Napi::Boolean>().Value();
} else if (!info[ephemeral_index].IsUndefined()) {
throw Napi::TypeError::New(env, "The ephemeral flag must be a boolean");
}
}

_store = std::make_unique<lmdblib::LMDBStore>(data_dir, map_size, max_readers, 2, ephemeral);

_msg_processor.register_handler(LMDBStoreMessageType::OPEN_DATABASE, this, &LMDBStoreWrapper::open_database);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,27 @@ WorldStateWrapper::WorldStateWrapper(const Napi::CallbackInfo& info)
thread_pool_size = info[thread_pool_size_index].As<Napi::Number>().Uint32Value();
}

// `ephemeral` opens each underlying LMDB env with `MDB_NOSYNC | MDB_NOMETASYNC` —
// commits never block on fsync, files stay sparse, and a crash mid-write yields an
// unrecoverable env. Intended for throwaway scratch state (TXE test sessions).
bool ephemeral = false;
size_t ephemeral_index = 8;
if (info.Length() > ephemeral_index) {
if (!info[ephemeral_index].IsBoolean()) {
throw Napi::TypeError::New(env, "Ephemeral flag must be a boolean");
}
ephemeral = info[ephemeral_index].As<Napi::Boolean>().Value();
}

_ws = std::make_unique<WorldState>(thread_pool_size,
data_dir,
map_size,
tree_height,
tree_prefill,
prefilled_public_data,
initial_header_generator_point,
genesis_timestamp);
genesis_timestamp,
ephemeral);

_dispatcher.register_target(
WorldStateMessageType::GET_TREE_INFO,
Expand Down
28 changes: 18 additions & 10 deletions barretenberg/cpp/src/barretenberg/world_state/world_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ WorldState::WorldState(uint64_t thread_pool_size,
const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
const std::vector<PublicDataLeafValue>& prefilled_public_data,
uint32_t initial_header_generator_point,
uint64_t genesis_timestamp)
uint64_t genesis_timestamp,
bool ephemeral)
: _workers(std::make_shared<ThreadPool>(thread_pool_size))
, _tree_heights(tree_heights)
, _initial_tree_size(tree_prefill)
Expand All @@ -50,7 +51,7 @@ WorldState::WorldState(uint64_t thread_pool_size,
{
// We set the max readers to be high, at least the number of given threads or the default if higher
uint64_t maxReaders = std::max(thread_pool_size, DEFAULT_MIN_NUMBER_OF_READERS);
create_canonical_fork(data_dir, map_size, prefilled_public_data, maxReaders);
create_canonical_fork(data_dir, map_size, prefilled_public_data, maxReaders, ephemeral);
try {
attempt_tree_resync();
} catch (std::exception& e) {
Expand All @@ -64,15 +65,17 @@ WorldState::WorldState(uint64_t thread_pool_size,
const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
uint32_t initial_header_generator_point,
uint64_t genesis_timestamp)
uint64_t genesis_timestamp,
bool ephemeral)
: WorldState::WorldState(thread_pool_size,
data_dir,
map_size,
tree_heights,
tree_prefill,
std::vector<PublicDataLeafValue>(),
initial_header_generator_point,
genesis_timestamp)
genesis_timestamp,
ephemeral)
{}

WorldState::WorldState(uint64_t thread_pool_size,
Expand All @@ -82,7 +85,8 @@ WorldState::WorldState(uint64_t thread_pool_size,
const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
const std::vector<PublicDataLeafValue>& prefilled_public_data,
uint32_t initial_header_generator_point,
uint64_t genesis_timestamp)
uint64_t genesis_timestamp,
bool ephemeral)
: WorldState(thread_pool_size,
data_dir,
{
Expand All @@ -96,7 +100,8 @@ WorldState::WorldState(uint64_t thread_pool_size,
tree_prefill,
prefilled_public_data,
initial_header_generator_point,
genesis_timestamp)
genesis_timestamp,
ephemeral)
{}

WorldState::WorldState(uint64_t thread_pool_size,
Expand All @@ -105,29 +110,32 @@ WorldState::WorldState(uint64_t thread_pool_size,
const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
uint32_t initial_header_generator_point,
uint64_t genesis_timestamp)
uint64_t genesis_timestamp,
bool ephemeral)
: WorldState(thread_pool_size,
data_dir,
map_size,
tree_heights,
tree_prefill,
std::vector<PublicDataLeafValue>(),
initial_header_generator_point,
genesis_timestamp)
genesis_timestamp,
ephemeral)
{}

void WorldState::create_canonical_fork(const std::string& dataDir,
const std::unordered_map<MerkleTreeId, uint64_t>& dbSize,
const std::vector<PublicDataLeafValue>& prefilled_public_data,
uint64_t maxReaders)
uint64_t maxReaders,
bool ephemeral)
{
// create the underlying stores
auto createStore = [&](MerkleTreeId id) {
auto name = getMerkleTreeName(id);
std::filesystem::path directory = dataDir;
directory /= name;
std::filesystem::create_directories(directory);
return std::make_shared<LMDBTreeStore>(directory, name, dbSize.at(id), maxReaders);
return std::make_shared<LMDBTreeStore>(directory, name, dbSize.at(id), maxReaders, ephemeral);
};
_persistentStores = std::make_unique<WorldStateStores>(createStore(MerkleTreeId::NULLIFIER_TREE),
createStore(MerkleTreeId::PUBLIC_DATA_TREE),
Expand Down
22 changes: 17 additions & 5 deletions barretenberg/cpp/src/barretenberg/world_state/world_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ class WorldState {
const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
uint32_t initial_header_generator_point,
uint64_t genesis_timestamp = 0);
uint64_t genesis_timestamp = 0,
bool ephemeral = false);

WorldState(uint64_t thread_pool_size,
const std::string& data_dir,
const std::unordered_map<MerkleTreeId, uint64_t>& map_size,
const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
uint32_t initial_header_generator_point,
uint64_t genesis_timestamp = 0);
uint64_t genesis_timestamp = 0,
bool ephemeral = false);

WorldState(uint64_t thread_pool_size,
const std::string& data_dir,
Expand All @@ -81,16 +83,25 @@ class WorldState {
const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
const std::vector<PublicDataLeafValue>& prefilled_public_data,
uint32_t initial_header_generator_point,
uint64_t genesis_timestamp = 0);
uint64_t genesis_timestamp = 0,
bool ephemeral = false);

/**
* @param ephemeral When true, every underlying LMDB env opens with `MDB_NOSYNC |
* MDB_NOMETASYNC`. Commits return without waiting for fsync; the kernel
* flushes lazily, files stay sparse. Intended for throwaway scratch
* state. A crash mid-write yields an unrecoverable
* env, so never enable on a node that needs to survive a restart.
*/
WorldState(uint64_t thread_pool_size,
const std::string& data_dir,
const std::unordered_map<MerkleTreeId, uint64_t>& map_size,
const std::unordered_map<MerkleTreeId, uint32_t>& tree_heights,
const std::unordered_map<MerkleTreeId, index_t>& tree_prefill,
const std::vector<PublicDataLeafValue>& prefilled_public_data,
uint32_t initial_header_generator_point,
uint64_t genesis_timestamp = 0);
uint64_t genesis_timestamp = 0,
bool ephemeral = false);

/**
* @brief Copies all underlying LMDB stores to the target directory while acquiring a write lock
Expand Down Expand Up @@ -313,7 +324,8 @@ class WorldState {
void create_canonical_fork(const std::string& dataDir,
const std::unordered_map<MerkleTreeId, uint64_t>& dbSize,
const std::vector<PublicDataLeafValue>& prefilled_public_data,
uint64_t maxReaders);
uint64_t maxReaders,
bool ephemeral);

Fork::SharedPtr retrieve_fork(const uint64_t& forkId) const;
Fork::SharedPtr create_new_fork(const block_number_t& blockNumber);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/scripts/aztec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ case $cmd in
fi
while ! nc -z 127.0.0.1 8081 &>/dev/null; do sleep 0.2; done
export NARGO_FOREIGN_CALL_TIMEOUT=300000
nargo test --silence-warnings --oracle-resolver http://127.0.0.1:8081 --test-threads 16 "$@"
Comment thread
Thunkar marked this conversation as resolved.
nargo test --silence-warnings --oracle-resolver http://127.0.0.1:8081 "$@"
;;
start)
if [ "${1:-}" == "--local-network" ]; then
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec/src/cli/cmds/start_txe.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
import type { Logger } from '@aztec/foundation/log';
import { createTXERpcServer } from '@aztec/txe';
import { createTXERpcServer } from '@aztec/txe/server';

export async function startTXE(options: any, signalHandlers: Array<() => Promise<void>>, debugLogger: Logger) {
debugLogger.info(`Setting up TXE...`);

const txeServer = createTXERpcServer(debugLogger);
const txeServer = await createTXERpcServer(debugLogger);
const httpServer = await startHttpRpcServer(txeServer, {
port: options.port,
timeoutMs: 1e3 * 60 * 5,
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ function compile_all {

get_projects | compile_project

cd txe && yarn build
cd ..

# Run oracle version checks after compilation
cd pxe && yarn check_oracle_version
cd ..
Expand Down
Loading
Loading