Skip to content
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

lncli+proto: use original name in jsonpb marshaler and remove json_name fields in proto #3996

Merged
merged 12 commits into from
Mar 7, 2020

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Feb 11, 2020

We now use the jsonpb marshaler to convert the RPC responses to JSON in lncli and REST.
The jsonpb has a setting (OrigName: true) to use the original name as defined in the proto file and the explicit json_name definition is not necessary any more.

This PR also formats all .proto files to remove some inconsistencies with white space use.

@guggero guggero added this to the 0.10.0 milestone Feb 11, 2020
@guggero guggero added the code health Related to code commenting, refactoring, and other non-behaviour improvements label Feb 11, 2020
@halseth
Copy link
Contributor

halseth commented Feb 11, 2020

This is cool. Did you check that all fields get the exact same json names after doing it this way? In case we had typos in the manually crafted names...

@guggero
Copy link
Collaborator Author

guggero commented Feb 11, 2020

Hmm... Good thinking!
I did a little regex magic and found 4 discrepancies:

// 1: autopilot.proto, message QueryScoresRequest
bool ignore_local_state = 2 [json_name = "no_state"];

// 2: rpc.proto, message Utxo: 
AddressType type = 1 [json_name = "address_type"];

// 3: rpc.proto, message ChannelFeeReport:
string chan_point = 1 [json_name = "channel_point"];

// 4: rpc.proto, message PolicyUpdateRequest
bool min_htlc_msat_specified = 8 [json_name = "set_min_htlc_msat"];
  1. Should was superfluous anyway because it's a request message and we don't have REST for the subservers yet (so no JSON is involved anywhere).
  2. Would be a breaking change for those that use the output of lncli listunspent with other tools by parsing the output.
  3. Same here, possibly breaking stuff for people that parse the output of lncli feereport.
  4. Would break for users that use REST and specify the field with set_min_htlc_msat instead of min_htlc_msat_specified (both work before this PR). But the API documentation only mentions min_htlc_msat_specified so nobody should be using the shorter form anyway I think.

@halseth
Copy link
Contributor

halseth commented Feb 12, 2020

  1. Should was superfluous anyway because it's a request message and we don't have REST for the subservers yet (so no JSON is involved anywhere).

👍

  1. Would be a breaking change for those that use the output of lncli listunspent with other tools by parsing the output.

What if we change the proto field name to address_type?

  1. Same here, possibly breaking stuff for people that parse the output of lncli feereport.

same, rename to channel_point?

  1. Would break for users that use REST and specify the field with set_min_htlc_msat instead of min_htlc_msat_specified (both work before this PR). But the API documentation only mentions min_htlc_msat_specified so nobody should be using the shorter form anyway I think.

How come both work?

@guggero
Copy link
Collaborator Author

guggero commented Feb 12, 2020

Yes, it looks like renaming address to address_type and chan_point to channel_point in the RPC shouldn't break older clients: https://stackoverflow.com/a/45431953

Only projects using our code directly (lndclient doesn't use the RPCs in question) will need to rename also but then it's a compile time error when updating the referenced lnd version.
That's why I renamed the two fields 2 and 3.

How come both work?

The json_name in the .proto file affects the json= part in the rpc.pb.go:
protobuf:"varint,8,opt,name=min_htlc_msat_specified,json=set_min_htlc_msag,proto3" and apparently the REST library just tried both.

@cfromknecht
Copy link
Contributor

thanks for looking into this @guggero. i'm okay the breaking changes for address_type and channel_point as they are fairly contained. i don't think we have a strong requirement for backwards compat in lncli as it is primarily a debugging tool, e.g. in 0.9 we modified all base64 values to hex. changing the field name actually seems like a safer change, since it fail harder rather than giving a possibly bad value. unless there are strong arguments otherwise i think this should be good to go for 0.10.

Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

So now we'll intentionally rename the grpc names for AddressType and ChannelPoint, while the other two ingore_local_state and set_min_whatever will work as before both for grpc and REST?

I think that sounds like a good solution.

Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

@guggero needs rebase but otherwise LGTM

Because we now use printRespJSON everywhere where we print RPC
responses as JSON, we can simply instruct the jsonpb marshaler to
use the original snake_case name specified in the proto file for
the JSON field names and not the default camelCase.
We now use the jsonpb marshaler to convert the RPC responses to
JSON in lncli and REST. The jsonpb has a setting to use the
original name as defined in the proto file and the explicit
json_name definition is not necessary any more.
The jsonpb setting is called OrigName and needs to be true.
We now use the jsonpb marshaler to convert the RPC responses to
JSON in lncli and REST. The jsonpb has a setting to use the
original name as defined in the proto file and the explicit
json_name definition is not necessary any more.
The jsonpb setting is called OrigName and needs to be true.
We now use the jsonpb marshaler to convert the RPC responses to
JSON in lncli and REST. The jsonpb has a setting to use the
original name as defined in the proto file and the explicit
json_name definition is not necessary any more.
The jsonpb setting is called OrigName and needs to be true.
We now use the jsonpb marshaler to convert the RPC responses to
JSON in lncli and REST. The jsonpb has a setting to use the
original name as defined in the proto file and the explicit
json_name definition is not necessary any more.
The jsonpb setting is called OrigName and needs to be true.
We now use the jsonpb marshaler to convert the RPC responses to
JSON in lncli and REST. The jsonpb has a setting to use the
original name as defined in the proto file and the explicit
json_name definition is not necessary any more.
The jsonpb setting is called OrigName and needs to be true.
We now use the jsonpb marshaler to convert the RPC responses to
JSON in lncli and REST. The jsonpb has a setting to use the
original name as defined in the proto file and the explicit
json_name definition is not necessary any more.
The jsonpb setting is called OrigName and needs to be true.
We now use the jsonpb marshaler to convert the RPC responses to
JSON in lncli and REST. The jsonpb has a setting to use the
original name as defined in the proto file and the explicit
json_name definition is not necessary any more.
The jsonpb setting is called OrigName and needs to be true.
@guggero
Copy link
Collaborator Author

guggero commented Mar 7, 2020

Rebased.

@cfromknecht cfromknecht merged commit 8a5d846 into lightningnetwork:master Mar 7, 2020
@guggero guggero deleted the lncli-json branch March 8, 2020 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code health Related to code commenting, refactoring, and other non-behaviour improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants