Skip to content
Closed
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
10 changes: 10 additions & 0 deletions barretenberg/cpp/src/barretenberg/serialize/msgpack.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#pragma once

// Opt out of ipc-codegen's bundled struct-map msgpack adaptor: barretenberg
// ships an equivalent under msgpack_impl/struct_map_impl.hpp with overlapping
// partial specialisations on the same primary template. Predefining this
// guard means any codegen-emitted msgpack_struct_map_impl.hpp pulled into the
// same TU yields to the framework's adaptor instead of fighting it.
#ifndef IPC_CODEGEN_USE_BB_MSGPACK_ADAPTORS
#define IPC_CODEGEN_USE_BB_MSGPACK_ADAPTORS
#endif

/* Minimal header for declaring msgpack fields.
This should be included as "barretenberg/serialize/msgpack.hpp" unless a translation wants
to use msgpack for bindings, then "barretenberg/serialize/cbind.hpp" should be included.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,19 @@
#include "barretenberg/common/log.hpp"
#include "barretenberg/serialize/msgpack.hpp"
#include "barretenberg/serialize/msgpack_impl.hpp"
#include "barretenberg/wsdb/wsdb_wire_convert.hpp"

#include <cstring>

namespace bb::avm2::simulation {

// ---------------------------------------------------------------------------
// Wire <-> Domain conversion helpers
//
// ipc-codegen emits a wire-typed client (std::array<uint8_t,32> for field
// elements, primitive ints for enums, plain structs for domain types). This
// translation unit owns the inline conversions to/from barretenberg's domain
// types so the public interface stays unchanged.
// ---------------------------------------------------------------------------

namespace {

inline ::Fr fr_to_wire(const bb::fr& d)
{
::Fr r{};
bb::fr::serialize_to_buffer(d, r.data());
return r;
}

inline bb::fr fr_from_wire(const ::Fr& w)
{
return bb::fr::serialize_from_buffer(w.data());
}

inline std::vector<bb::fr> fr_vec_from_wire(const std::vector<::Fr>& wire)
{
std::vector<bb::fr> result;
result.reserve(wire.size());
for (const auto& w : wire) {
result.push_back(fr_from_wire(w));
}
return result;
}

inline wsdb::wire::WorldStateRevision revision_to_wire(const world_state::WorldStateRevision& r)
{
return wsdb::wire::WorldStateRevision{
.forkId = r.forkId,
.blockNumber = r.blockNumber,
.includeUncommitted = r.includeUncommitted,
};
}

inline uint32_t tree_id_to_wire(MerkleTreeId id)
{
return static_cast<uint32_t>(id);
}

} // anonymous namespace
// Wire <-> domain conversion helpers are shared with the server handlers
// (see wsdb_handlers.cpp) so both sides use the same encoding boundary.
using bb::wsdb::fr_from_wire;
using bb::wsdb::fr_to_wire;
using bb::wsdb::fr_vec_from_wire;
using bb::wsdb::revision_to_wire;
using bb::wsdb::tree_id_to_wire;

// ---------------------------------------------------------------------------
// Helpers
Expand Down
7 changes: 4 additions & 3 deletions barretenberg/cpp/src/barretenberg/wsdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if(NOT(FUZZING) AND NOT(WASM))
set(WSDB_GEN_OUTPUTS
${WSDB_GEN_DIR}/wsdb_ipc_client.cpp
${WSDB_GEN_DIR}/wsdb_ipc_client.hpp
${WSDB_GEN_DIR}/wsdb_ipc_server.hpp
${WSDB_GEN_DIR}/wsdb_types.hpp
${WSDB_GEN_DIR}/msgpack_struct_map_impl.hpp
)
Expand All @@ -24,11 +25,11 @@ if(NOT(FUZZING) AND NOT(WASM))
--schema ${WSDB_SCHEMA}
--lang cpp
--out ${WSDB_GEN_DIR}
--client
--client --server
--cpp-namespace bb::wsdb
--prefix Wsdb
DEPENDS ${WSDB_SCHEMA} ${IPC_CODEGEN_SRC}
COMMENT "Generating WSDB IPC client from wsdb_schema.json"
COMMENT "Generating WSDB IPC client + server from wsdb_schema.json"
VERBATIM
)
add_library(
Expand All @@ -48,7 +49,7 @@ if(NOT(FUZZING) AND NOT(WASM))
aztec-wsdb
main.cpp
cli.cpp
wsdb_execute.cpp
wsdb_handlers.cpp
wsdb_ipc_server.cpp
)
target_link_libraries(
Expand Down
16 changes: 8 additions & 8 deletions barretenberg/cpp/src/barretenberg/wsdb/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "barretenberg/common/log.hpp"
#include "barretenberg/common/throw_or_abort.hpp"
#include "barretenberg/serialize/msgpack.hpp"
#include "barretenberg/wsdb/wsdb_execute.hpp"
#include "barretenberg/world_state/world_state.hpp"
#include "barretenberg/wsdb/wsdb_ipc_server.hpp"

#include "barretenberg/bb/deps/cli11.hpp"
Expand All @@ -19,15 +19,15 @@ using namespace bb::crypto::merkle_tree;

namespace {

struct WsdbApi {
WsdbCommand commands;
WsdbCommandResponse responses;
SERIALIZATION_FIELDS(commands, responses);
};

// Wire-format schema authority is barretenberg/cpp/src/barretenberg/wsdb/
// wsdb_schema.json — that's what every language's codegen consumes. The
// `msgpack schema` subcommand kept the old NamedUnion-derived dump as a
// secondary introspection path; it's now redundant, so we just point at
// the canonical source.
std::string get_wsdb_schema_as_json()
{
return msgpack_schema_to_string(WsdbApi{});
return "{\"note\":\"Wire format authority is "
"barretenberg/cpp/src/barretenberg/wsdb/wsdb_schema.json.\"}";
}

} // namespace
Expand Down
Loading
Loading