-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: native world state #7516
feat: native world state #7516
Changes from 29 commits
46b24db
87a2642
bd0aab7
eb8ad58
8448cdc
7fbb305
30a0d5e
f8cba90
5b6284e
af13709
b21d995
60664e8
bd0bae9
c86cb35
1697a23
8db2c50
01bd840
cee7209
115e9be
91f37cc
dd914ef
8997dd3
72b5fa8
a0d3b33
7ee00f8
7558d8e
b93ad74
6a6ad5e
a9a39fa
fb9dc9b
37a06fa
d8698ab
3afcd81
f1d7803
99248c5
67a8c27
815e6c4
a101fd8
af77f8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,22 @@ | |
"TARGET_ARCH": "skylake" | ||
} | ||
}, | ||
{ | ||
"name": "default-pic", | ||
"displayName": "Build with Clang with Position Independent Code", | ||
"description": "Build with globally installed Clang with Position Independent Code", | ||
"binaryDir": "build-pic", | ||
"generator": "Ninja", | ||
"environment": { | ||
"CC": "clang", | ||
"CXX": "clang++", | ||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON" | ||
}, | ||
"cacheVariables": { | ||
"TARGET_ARCH": "skylake", | ||
"ENABLE_PIC": "ON" | ||
} | ||
}, | ||
{ | ||
"name": "homebrew", | ||
"displayName": "Homebrew + Clang", | ||
|
@@ -66,6 +82,16 @@ | |
"CXX": "clang++-16" | ||
} | ||
}, | ||
{ | ||
"name": "clang16-pic", | ||
"displayName": "Release build with Position Independent Code", | ||
"description": "Build with globally installed Clang-16 using Position Independent Code", | ||
"inherits": "clang16", | ||
"binaryDir": "build-pic", | ||
"cacheVariables": { | ||
"ENABLE_PIC": "ON" | ||
} | ||
}, | ||
{ | ||
"name": "clang16-dbg", | ||
"displayName": "Debugging build with Clang-16", | ||
|
@@ -172,6 +198,20 @@ | |
"CXX": "g++" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need all these presets? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the gcc ones. |
||
} | ||
}, | ||
{ | ||
"name": "gcc-pic", | ||
"displayName": "Build with GCC using PIC", | ||
"description": "Build with globally installed GCC using PIC", | ||
"inherits": "gcc", | ||
"binaryDir": "build-gcc-pic", | ||
"environment": { | ||
"CC": "gcc", | ||
"CXX": "g++" | ||
}, | ||
"cacheVariables": { | ||
"ENABLE_PIC": "ON" | ||
} | ||
}, | ||
{ | ||
"name": "gcc10", | ||
"displayName": "Build with GCC-10", | ||
|
@@ -446,6 +486,11 @@ | |
"inherits": "default", | ||
"configurePreset": "tracy" | ||
}, | ||
{ | ||
"name": "clang16-pic", | ||
"inherits": "default", | ||
"configurePreset": "clang16-pic" | ||
}, | ||
{ | ||
"name": "tracy-gates", | ||
"inherits": "default", | ||
|
@@ -476,6 +521,11 @@ | |
"inherits": "default", | ||
"configurePreset": "gcc" | ||
}, | ||
{ | ||
"name": "gcc-pic", | ||
"inherits": "default", | ||
"configurePreset": "gcc-pic" | ||
}, | ||
{ | ||
"name": "gcc10", | ||
"inherits": "default", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,11 @@ preset-release: | |
RUN cmake --preset clang16 -Bbuild && cmake --build build --target bb && rm -rf build/{deps,lib,src} | ||
SAVE ARTIFACT build/bin | ||
|
||
preset-release-pic: | ||
FROM +source | ||
RUN cmake --preset clang16-pic -Bbuild && cmake --build build --target world_state_napi && cp ./build/lib/world_state_napi.node ./build/bin && rm -rf build/{deps,lib,src} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a fan of the pic name, this is a low level detail for a high level feature. This preset and this earthly command could likely be preset-aztec-world-state or similar There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed |
||
SAVE ARTIFACT build/bin | ||
|
||
preset-release-assert: | ||
FROM +source | ||
RUN cmake --preset clang16-assert -Bbuild && cmake --build build --target bb crypto_merkle_tree_tests && rm -rf build/{deps,lib,src} | ||
|
@@ -102,6 +107,11 @@ preset-gcc: | |
RUN cmake --preset gcc -Bbuild && cmake --build build && rm -rf build/{deps,lib,src} | ||
SAVE ARTIFACT build/bin | ||
|
||
preset-gcc-pic: | ||
FROM +source | ||
RUN cmake --preset gcc-pic -Bbuild && cmake --build build && rm -rf build/{deps,lib,src} | ||
SAVE ARTIFACT build/bin | ||
|
||
preset-fuzzing: | ||
FROM +source | ||
RUN cmake --preset fuzzing -Bbuild && cmake --build build && rm -rf build/{deps,lib,src} | ||
|
@@ -264,3 +274,4 @@ build: | |
BUILD +preset-wasm | ||
BUILD +preset-wasm-threads | ||
BUILD +preset-release | ||
BUILD +preset-release-pic |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
# run commands relative to parent directory | ||
cd $(dirname $0)/.. | ||
|
||
TEST=${1:-*} | ||
PRESET=${PRESET:-clang16} | ||
|
||
cmake --build --preset $PRESET --target world_state_tests | ||
./build/bin/world_state_tests --gtest_filter=WorldStateTest.${TEST} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include "barretenberg/messaging/header.hpp" | ||
#include "barretenberg/serialize/cbind.hpp" | ||
#include <cstdint> | ||
#include <functional> | ||
#include <stdexcept> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace bb::messaging { | ||
|
||
using message_handler = std::function<bool(msgpack::object&, msgpack::sbuffer&)>; | ||
|
||
class MessageDispatcher { | ||
private: | ||
std::unordered_map<uint32_t, message_handler> messageHandlers; | ||
|
||
public: | ||
MessageDispatcher() = default; | ||
|
||
bool onNewData(msgpack::object& obj, msgpack::sbuffer& buffer) | ||
{ | ||
bb::messaging::HeaderOnlyMessage header; | ||
obj.convert(header); | ||
|
||
auto iter = messageHandlers.find(header.msgType); | ||
if (iter == messageHandlers.end()) { | ||
throw std::runtime_error("No registered handler for message of type " + std::to_string(header.msgType)); | ||
} | ||
|
||
return (iter->second)(obj, buffer); | ||
} | ||
|
||
void registerTarget(uint32_t msgType, const message_handler& handler) | ||
{ | ||
messageHandlers.insert({ msgType, handler }); | ||
} | ||
}; | ||
|
||
} // namespace bb::messaging |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
barretenberg_module(world_state crypto_merkle_tree stdlib_poseidon2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
namespace bb::world_state { | ||
|
||
template <typename Tree> struct TreeWithStore { | ||
using TreeType = Tree; | ||
std::unique_ptr<Tree> tree; | ||
std::unique_ptr<typename Tree::StoreType> store; | ||
std::unique_ptr<typename Tree::StoreType::PersistedStoreType> persisted_store; | ||
|
||
TreeWithStore(std::unique_ptr<Tree> t, | ||
std::unique_ptr<typename Tree::StoreType> s, | ||
std::unique_ptr<typename Tree::StoreType::PersistedStoreType> p) | ||
: tree(std::move(t)) | ||
, store(std::move(s)) | ||
, persisted_store(std::move(p)) | ||
{} | ||
|
||
TreeWithStore(TreeWithStore&& other) noexcept | ||
: tree(std::move(other.tree)) | ||
, store(std::move(other.store)) | ||
, persisted_store(std::move(other.persisted_store)) | ||
{} | ||
|
||
TreeWithStore(const TreeWithStore& other) = delete; | ||
~TreeWithStore() = default; | ||
|
||
TreeWithStore& operator=(TreeWithStore&& other) = delete; | ||
TreeWithStore& operator=(const TreeWithStore& other) = delete; | ||
}; | ||
|
||
} // namespace bb::world_state |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include "barretenberg/crypto/merkle_tree/indexed_tree/indexed_leaf.hpp" | ||
#include "barretenberg/crypto/merkle_tree/types.hpp" | ||
#include "barretenberg/ecc/curves/bn254/fr.hpp" | ||
#include <cstdint> | ||
#include <variant> | ||
|
||
namespace bb::world_state { | ||
|
||
enum MerkleTreeId { | ||
NULLIFIER_TREE = 0, | ||
NOTE_HASH_TREE = 1, | ||
PUBLIC_DATA_TREE = 2, | ||
L1_TO_L2_MESSAGE_TREE = 3, | ||
ARCHIVE = 4, | ||
}; | ||
|
||
using TreeStateReference = std::pair<bb::fr, bb::crypto::merkle_tree::index_t>; | ||
using StateReference = std::unordered_map<MerkleTreeId, TreeStateReference>; | ||
|
||
struct WorldStateRevision { | ||
struct FinalisedBlock { | ||
uint32_t block; | ||
}; | ||
|
||
struct CurrentState { | ||
bool uncommitted; | ||
}; | ||
|
||
using Revision = std::variant<WorldStateRevision::FinalisedBlock, WorldStateRevision::CurrentState>; | ||
Revision inner; | ||
|
||
static WorldStateRevision committed() { return { CurrentState{ false } }; } | ||
static WorldStateRevision uncommitted() { return { CurrentState{ true } }; } | ||
static WorldStateRevision finalised_block(uint32_t block_number) { return { FinalisedBlock{ block_number } }; } | ||
}; | ||
} // namespace bb::world_state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we using gcc for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed