Replace protobuf with JSON everywhere#168
Replace protobuf with JSON everywhere#168benthecarman wants to merge 1 commit intolightningdevkit:mainfrom
Conversation
|
🎉 This PR is now ready for review! |
tnull
left a comment
There was a problem hiding this comment.
Thanks! This is def. a good base for more concrete discussion. Might make sense, although as mentioned elsewhere not loving JSON efficiency and its idiosyncrasies in general.
Storage namespaces are changed from ("payments", "") to ("ldk-server", "payments") so existing protobuf-encoded data is silently ignored rather than failing to deserialize, avoiding the need for migration code or manual database wipes.
I don't think we should do this. Pre-0.1 we should be fine with breaking backwards compat rather than starting out with some weird tech debt, especially since AFAIK it's only @tankyleo and myself that run Server in production currently.
There was a problem hiding this comment.
If we did this, I do wonder if we should also do lightningdevkit/ldk-node#75 / continue lightningdevkit/rust-lightning#3157 to have the serializations for LDK / LDK Node types live in their origin crate rather than replicating the types here? This would also avoid the types getting out-of-date, etc.
There was a problem hiding this comment.
Yeah, however that comes with the trade off of needing to make sure those types handle backwards compat for ldk-server. If we do it here we can make sure ldk-node has a nice api and we just handle the uglyness of the backwards compat in ldk-server
There was a problem hiding this comment.
Maybe this might be a good thing to zoom in first? What will our API backwards compat. look like from the start? How would we enforce/check that with JSON vs protobuf? How will we deal with API breaks in LDK Node if Server's API needs to be stable? Maybe worth discussing offline?
|
Server-side events and serverless UI follow up: #171 |
reverted. For reference will need to do |
|
Thanks for the ping, good to do manual database operations. |
|
Manually tested all the apis and fixed places where we were reversing things like block hashes and txids. Also was able to do a lot of clean ups in the cli now that we use json serialization. Also added json serialization tests |
Protobuf added complexity without much benefit for our use case — the binary encoding is opaque, hard to debug with standard HTTP tools, and requires proto toolchain maintenance. JSON is human-readable, widely supported, and sufficient for our throughput needs. This removes prost and all .proto files entirely, renaming the ldk-server-protos crate to ldk-server-json-models. Types are rewritten as hand-written Rust structs and enums with serde derives rather than prost-generated code. Fixed-size byte fields (hashes, channel IDs, public keys) use [u8; 32] and [u8; 33] with hex serde instead of String, giving type safety at the model layer. Several proto-era patterns are cleaned up: wrapper structs that only existed because protobuf wraps oneof in a message are removed, fields that were Option only because proto message fields are nullable are made required where the server always provides them, and the EventEnvelope wrapper is dropped in favor of using Event directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| &payment.id.to_lower_hex_string(), | ||
| time, | ||
| &payment.encode_to_vec(), | ||
| &serde_json::to_vec(&payment).unwrap(), |
There was a problem hiding this comment.
Neither proto or json seems right here? I'd expect TLV to be used.
Protobuf added complexity without much benefit for our use case — the binary encoding is opaque, hard to debug with standard HTTP tools, and requires proto toolchain maintenance. JSON is human-readable, widely supported, and sufficient for our throughput needs.
This removes prost and all .proto files entirely, renaming the ldk-server-protos crate to ldk-server-json-models. Types are rewritten as hand-written Rust structs and enums with serde derives rather than prost-generated code. Fixed-size byte fields (hashes, channel IDs, public keys) use [u8; 32] and [u8; 33] with hex serde instead of String, giving type safety at the model layer.
Several proto-era patterns are cleaned up: wrapper structs that only existed because protobuf wraps oneof in a message are removed, fields that were Option only because proto message fields are nullable are made required where the server always provides them, and the EventEnvelope wrapper is dropped in favor of using Event directly.