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

Enable proto JSON for genesis #7000

Merged
merged 12 commits into from
Aug 11, 2020
Merged

Enable proto JSON for genesis #7000

merged 12 commits into from
Aug 11, 2020

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Aug 10, 2020

Closes #5917. (Was originally part of #6859 but split out into a smaller PR)

A few important notes:

GenesisDoc now uses encoding/json

GenesisDoc is now marshaled/unmarshaled using the golang encoding/json instead of amino or proto JSON. Proto JSON will not work because GenesisDoc is not a proto.Message (cc @marbar3778).

As I understand it, this has the side effect that certain int64/uint64 types will be encoded as actual JSON integers as opposed to strings. If this is not okay we can either just use amino JSON or we will need proto support from tm.

Note that this affects both proto and amino configurations of the SDK (although currently only proto works).

ProposalStatus now uses default protobuf string formatting

ProposalStatus is now printed to JSON with its proto name, i.e. PROPOSAL_STATUS_DEPOSIT_PERIOD vs DepositPeriod

NewSimApp now takes a parameter for EncodingConfig

This is necessary to export genesis with protobuf and in general may be useful for testing.

Pointer types must be used for GenesisState everywhere

This is true for all proto.Message marshaling. JSONMarshaler should just require proto.Message to avoid runtime errors, to be followed up in #6982 .


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@codecov
Copy link

codecov bot commented Aug 10, 2020

Codecov Report

Merging #7000 into master will increase coverage by 2.84%.
The diff coverage is 53.38%.

@@            Coverage Diff             @@
##           master    #7000      +/-   ##
==========================================
+ Coverage   59.07%   61.91%   +2.84%     
==========================================
  Files         363      520     +157     
  Lines       21499    32151   +10652     
==========================================
+ Hits        12701    19907    +7206     
- Misses       7755    10629    +2874     
- Partials     1043     1615     +572     

@aaronc aaronc marked this pull request as ready for review August 10, 2020 17:39
@aaronc aaronc added C:Encoding C:genesis relating to chain genesis labels Aug 10, 2020
@aaronc aaronc added this to the v0.40 [Stargate] milestone Aug 10, 2020
@alexanderbez
Copy link
Contributor

As long as types can be deserialized into the corresponding GenesisState types, I see no reason why the stdlib can't be used.

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

ACK

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

lgtm, also not 100% clear on how the withProtoJSON middleware works, but i'm okay if it's temporary.

app = simapp.Setup(false)
appCodec, _ = simapp.MakeCodecs()
app = simapp.Setup(false)
appCodec, legacyAmino = simapp.MakeCodecs()
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably a refactor for another PR, but MakeCodecs is redundant since we have MakeEncodingConfig, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes more or less. It's a holdover from earlier versions

@aaronc aaronc added the A:automerge Automatically merge PR once all prerequisites pass. label Aug 11, 2020
@aaronc
Copy link
Member Author

aaronc commented Aug 11, 2020

lgtm, also not 100% clear on how the withProtoJSON middleware works, but i'm okay if it's temporary.

So it changes the JSON marshaler in the client context attached to the cobra command. Maybe worth studying that code a bit to understand how things work in the CLI

@mergify mergify bot merged commit 20c5ee3 into master Aug 11, 2020
@mergify mergify bot deleted the aaronc/enable-proto-genesis branch August 11, 2020 14:22
@colin-axner colin-axner mentioned this pull request Aug 24, 2020
9 tasks
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* Enable proto JSON for genesis

* Test fixes

* Cleanup

* Cleanup

* Cleanup

* Update CHANGELOG.md

* Protogen

Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: SaReN <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:Encoding C:genesis relating to chain genesis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Genesis Protobuf Migration
5 participants