refactor(wsdb): drop parallel domain types; handlers operate on wire types#23522
Open
charlielye wants to merge 1 commit into
Open
refactor(wsdb): drop parallel domain types; handlers operate on wire types#23522charlielye wants to merge 1 commit into
charlielye wants to merge 1 commit into
Conversation
…types
Eliminates the dual type hierarchy that's been sitting under wsdb:
- generated/wsdb_types.hpp (codegen wire types: POD, schema-driven)
- wsdb_commands.hpp / wsdb_execute.cpp (hand-written domain types with
identical fields but semantic typedefs and execute() methods)
After this change there's just one type system per command. Handlers in
wsdb_handlers.cpp take wire types directly, convert fields to/from domain
types at the entry/exit boundary, call the existing world_state APIs, and
return wire response types. The codegen's --server emission becomes the
dispatch entry point; wsdb_ipc_server.cpp shrinks to construction +
make_wsdb_handler<WsdbRequest> + server->run.
Codegen changes (ipc-codegen/src/cpp_codegen.ts):
- Emit Fr as a `struct Fr { std::array<uint8_t, 32> bytes; }` plus an
explicit `msgpack::adaptor::pack<Fr>` / `convert<Fr>` specialization
that packs as msgpack `bin` (matching the schema's ["fr","bin32"]
alias, matching bb::fr's wire bytes, matching what Rust's
serialize_bytes and TS's msgpackr already produce). The default
std::array<T,N> adapter packs as `array<uint8>` which would have
produced wire-incompatible bytes the moment any consumer used wire
types as the encoder.
- convert<Fr> also accepts `array<uint8>` on the read side for forward
compatibility with msgpack producers that don't emit `bin`.
Codegen-emitted msgpack_struct_map_impl.hpp now opts out when
IPC_CODEGEN_USE_BB_MSGPACK_ADAPTORS is predefined (barretenberg's
serialize/msgpack.hpp sets it). Otherwise both barretenberg's framework
adaptor and the codegen's bundled one partially-specialize
`msgpack::adaptor::convert<HasMsgPack T>` on overlapping concepts in the
same TU, producing "ambiguous partial specializations" errors.
CMakeLists: wsdb codegen now passes --server (emitting
generated/wsdb_ipc_server.hpp) and the aztec-wsdb target compiles
wsdb_handlers.cpp instead of wsdb_execute.cpp.
The AVM's wsdb_ipc_merkle_db now uses the same shared wire-convert
helpers (wsdb_wire_convert.hpp) instead of its own private copies.
Net diff: +846 / -1194. Same dispatch logic, smaller surface, single
source of truth for command/response shapes (wsdb_schema.json).
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #23499 → #23498 → #23497 → #23316.
Eliminates the dual type hierarchy that's been sitting under wsdb. Before: `generated/wsdb_types.hpp` (codegen wire types) AND `wsdb_commands.hpp` + `wsdb_execute.cpp` (hand-written domain types with the same fields but semantic typedefs and `execute()` methods). After: one type system. Handlers in `wsdb_handlers.cpp` take wire types in, convert to/from domain types at the boundary, return wire types out. The codegen's `--server` emission is the dispatch entry point; `wsdb_ipc_server.cpp` is now a thin make_server + install_default_signal_handlers + make_wsdb_handler + run.
Net diff: +846 / -1194. Same dispatch logic, smaller surface, single source of truth for command/response shapes (`wsdb_schema.json`).
Codegen changes (`ipc-codegen/src/cpp_codegen.ts`)
What about bbapi?
bbapi has the same dual-type structure but is much bigger:
That's a ~3000 LOC PR on its own. I'd rather land this wsdb migration as the validated pattern and do bbapi as PR-E, applying the same conventions (wire-convert helpers, handler overloads, codegen --server, deleting hand-written types). Same shape, just bigger.
Test plan