Skip to content

Remove omitempty from *pb.go#3889

Merged
melekes merged 13 commits intomasterfrom
marko/remove_omitEmpty
Sep 18, 2019
Merged

Remove omitempty from *pb.go#3889
melekes merged 13 commits intomasterfrom
marko/remove_omitEmpty

Conversation

@tac0turtle
Copy link
Contributor

@tac0turtle tac0turtle commented Aug 8, 2019

ref #3882

Signed-off-by: Marko Baricevic marbar3778@yahoo.com

  • Referenced an issue explaining the need for the change
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

- remove omitempty from *pb.go files
- added command to makefile for everytime `make protoc_all` is run

- open question:
  - Do we want to further remove omitempty from other places
	- https://github.com/tendermint/tendermint/blob/master/rpc/lib/types/types.go#L151
	- and other places
ref #3882

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>
@tac0turtle tac0turtle added C:abci Component: Application Blockchain Interface T:ux Type: Issue or Pull Request related to developer experience labels Aug 8, 2019
@tac0turtle tac0turtle requested a review from melekes August 8, 2019 10:10
@tac0turtle tac0turtle requested review from ebuchman and xla as code owners August 8, 2019 10:10
@codecov-io
Copy link

codecov-io commented Aug 8, 2019

Codecov Report

Merging #3889 into master will decrease coverage by 0.07%.
The diff coverage is 0%.

@@            Coverage Diff            @@
##           master   #3889      +/-   ##
=========================================
- Coverage   66.87%   66.8%   -0.08%     
=========================================
  Files         219     221       +2     
  Lines       18486   18510      +24     
=========================================
+ Hits        12363   12365       +2     
- Misses       5197    5222      +25     
+ Partials      926     923       -3
Impacted Files Coverage Δ
libs/common/result.go 0% <0%> (ø)
crypto/merkle/result.go 0% <0%> (ø)
consensus/state.go 78.96% <0%> (-0.36%) ⬇️
consensus/reactor.go 77.96% <0%> (-0.12%) ⬇️
blockchain/v0/reactor.go 79.71% <0%> (+0.94%) ⬆️
privval/signer_endpoint.go 84% <0%> (+2.66%) ⬆️
privval/signer_server.go 100% <0%> (+4.34%) ⬆️

@safareli
Copy link

safareli commented Aug 8, 2019

Do we want to further remove omitempty from other places https://github.com/tendermint/tendermint/blob/master/rpc/lib/types/types.go#L151

omitempty shouldn't be removed from RPCResponse as it would be violation of (JSON-RPC v2 spec)[https://www.jsonrpc.org/specification#response_object], this parts in particular:

result
This member is REQUIRED on success.
This member MUST NOT exist if there was an error invoking the method.
The value of this member is determined by the method invoked on the Server.

error
This member is REQUIRED on error.
This member MUST NOT exist if there was no error triggered during invocation.
The value for this member MUST be an Object as defined in section 5.1.

(I had issue with use of omitempty for all fields in record.)

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

@martyall
Copy link

martyall commented Aug 22, 2019

I'm looking at your most recent commit and I'm not if we're on the same page, so I just want to lay out how we understand the problem.

If you have omitempty in any field for JSON codecs, it causes the key to be omitted during serialization if the field is uninitialized. This makes it difficult for strongly typed languages (in our case Haskell) to parse the data idiomatically. For example this addition you've made b50aa9a#diff-e41225101b540b7e08bbbcddb8f8ffdcR499 defines

type RequestEcho struct {
	Message              string   `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`

Doesn't this mean that in the event that the Message field wasn't initialized, then the JSON object will not include a message field?

Sorry if I'm wrong, but again just wanting to make sure we're on the same page. Long story short, if keys sometimes appear, sometimes don't it makes it really hard for us. If they don't have a value, you are still free to use JSON's null value, but it has to be there. Thanks!

@tac0turtle
Copy link
Contributor Author

tac0turtle commented Aug 22, 2019

Yes, I believe we are on the same page. @melekes requested to change to use jsonpb and not remove omitempty from the *pb.go files. So it would be handled by the marshler instead of the script to remove from the pb.go files. This is how I understood #3889 (comment)

@martyall
Copy link

🙏

Copy link
Contributor

@ebuchman ebuchman left a comment

Choose a reason for hiding this comment

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

Looks like latest commit can replace #3912

@martyall
Copy link

Just checking in, if I were to build a docker image on this branch would it do what we need?

@tac0turtle tac0turtle force-pushed the marko/remove_omitEmpty branch from af16790 to 61fed2a Compare September 6, 2019 13:25
//---------------------------------------------------------------------------
// override JSON marshalling so we emit defaults (ie. disable omitempty)
// note we need Unmarshal functions too because protobuf had the bright idea
// to marshal int64->string. cool. cool, cool, cool: https://developers.google.com/protocol-buffers/docs/proto3#json
Copy link

Choose a reason for hiding this comment

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

I might be misunderstanding something but AFAIK int64, fixed64 and uint64 should be encoded as strings?
#3898 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, we should probably remove the "note we need ..."

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

utACK

@melekes
Copy link
Contributor

melekes commented Sep 13, 2019

=== RUN   TestTransportMultiplexValidateNodeInfo
panic: send on closed channel

goroutine 3027 [running]:
github.com/tendermint/tendermint/p2p.TestTransportMultiplexAcceptNonBlocking.func1(0xc000d1c100, 0xc000cca240, 0xc000cca300, 0xc000cca2a0)
	/go/src/github.com/tendermint/tendermint/p2p/transport_test.go:255 +0x55c
created by github.com/tendermint/tendermint/p2p.TestTransportMultiplexAcceptNonBlocking
	/go/src/github.com/tendermint/tendermint/p2p/transport_test.go:224 +0x271

not sure if it's related. probably not

@tac0turtle
Copy link
Contributor Author

@blinky3713 you can give the branch a try now, sorry for the delay

@tac0turtle tac0turtle removed the WIP label Sep 15, 2019
// override JSON marshalling so we emit defaults (ie. disable omitempty)
// note we need Unmarshal functions too because protobuf had the bright idea
// to marshal int64->string. cool. cool, cool, cool: https://developers.google.com/protocol-buffers/docs/proto3#json
// override JSON marshalling so we emit defaults (ie. enable omitempty)
Copy link
Contributor

Choose a reason for hiding this comment

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

"disable omitempty" was correct. sorry for confusion

@tac0turtle tac0turtle force-pushed the marko/remove_omitEmpty branch from 537971a to 32b3eba Compare September 16, 2019 10:27
@melekes
Copy link
Contributor

melekes commented Sep 16, 2019

@marbar3778 can you also update the changelog?

@melekes melekes merged commit 1b54369 into master Sep 18, 2019
@melekes melekes deleted the marko/remove_omitEmpty branch September 18, 2019 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C:abci Component: Application Blockchain Interface T:ux Type: Issue or Pull Request related to developer experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants