Skip to content

Replace protobuf with JSON everywhere#168

Open
benthecarman wants to merge 1 commit intolightningdevkit:mainfrom
benthecarman:rest-json
Open

Replace protobuf with JSON everywhere#168
benthecarman wants to merge 1 commit intolightningdevkit:mainfrom
benthecarman:rest-json

Conversation

@benthecarman
Copy link
Collaborator

@benthecarman benthecarman commented Mar 24, 2026

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.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Mar 24, 2026

🎉 This PR is now ready for review!
Please choose at least one reviewer by assigning them on the right bar.
If no reviewers are assigned within 10 minutes, I'll automatically assign one.
Once the first reviewer has submitted a review, a second will be assigned if required.

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

@benthecarman benthecarman Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator

@tnull tnull Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@joostjager
Copy link
Contributor

Server-side events and serverless UI follow up: #171

@benthecarman
Copy link
Collaborator Author

benthecarman commented Mar 24, 2026

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,

reverted.

For reference will need to do DELETE FROM ldk_paginated_data WHERE primary_namespace IN ('payments', 'forwarded_payments') AND secondary_namespace = '';

@tankyleo
Copy link
Contributor

Thanks for the ping, good to do manual database operations.

@benthecarman
Copy link
Collaborator Author

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

@benthecarman benthecarman marked this pull request as ready for review March 24, 2026 22:07
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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither proto or json seems right here? I'd expect TLV to be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants