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
20 changes: 11 additions & 9 deletions barretenberg/cpp/src/barretenberg/world_state/world_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "barretenberg/world_state/tree_with_store.hpp"
#include "barretenberg/world_state/types.hpp"
#include <memory>
#include <mutex>
#include <stdexcept>
#include <tuple>
#include <unordered_map>
Expand Down Expand Up @@ -96,18 +97,19 @@ StateReference WorldState::get_state_reference(WorldStateRevision revision) cons
{
Signal signal(static_cast<uint32_t>(_trees.size()));
StateReference state_reference;
// multiple threads want to write to state_reference
std::mutex state_ref_mutex;

bool uncommitted = include_uncommitted(revision);

for (const auto& [id, tree] : _trees) {
std::visit(
[&signal, &state_reference, id, uncommitted](auto&& wrapper) {
auto callback = [&signal, &state_reference, id](const TypedResponse<TreeMetaResponse>& meta) {
state_reference.insert({ id, { meta.inner.root, meta.inner.size } });
signal.signal_decrement();
};
wrapper.tree->get_meta_data(uncommitted, callback);
},
tree);
auto callback = [&signal, &state_reference, &state_ref_mutex, id](const TypedResponse<TreeMetaResponse>& meta) {
std::lock_guard<std::mutex> lock(state_ref_mutex);
state_reference.insert({ id, { meta.inner.root, meta.inner.size } });
signal.signal_decrement();
};
std::visit([&callback, uncommitted](auto&& wrapper) { wrapper.tree->get_meta_data(uncommitted, callback); },
tree);
}

signal.wait_for_level(0);
Expand Down
7 changes: 4 additions & 3 deletions yarn-project/world-state/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ set -e
cd "$(dirname "$0")/.."

# relatiev path from the directory containing package.json
WORLD_STATE_LIB_PATH=../../barretenberg/cpp/build/bin/world_state_napi.node
WORLD_STATE_LIB_PATH=../../barretenberg/cpp/build-pic/lib/world_state_napi.node
PRESET=${PRESET:-clang16-pic}

build_addon() {
(cd ../../barretenberg/cpp; cmake --preset clang16-pic -DCMAKE_BUILD_TYPE=RelWithAssert; cmake --build --preset clang16-pic --target world_state_napi; echo $PWD; mkdir -p build/bin; cp ./build-pic/lib/world_state_napi.node ./build/bin/world_state_napi.node)
(cd ../../barretenberg/cpp; cmake --preset $PRESET -DCMAKE_BUILD_TYPE=RelWithAssert; cmake --build --preset $PRESET --target world_state_napi; echo $PWD; mkdir -p build/bin; cp ./build-pic/lib/world_state_napi.node ./build/bin/world_state_napi.node)
}

cp_addon_lib() {
if [ -f $WORLD_STATE_LIB_PATH ]; then
echo "Copying world_state_napi.node to build directory"
echo "Copying $(realpath $WORLD_STATE_LIB_PATH) to build directory"
rm -rf build
mkdir build
cp $WORLD_STATE_LIB_PATH build/world_state_napi.node
Expand Down