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 generally and remove HybridCodec #6859

Merged
merged 37 commits into from
Aug 13, 2020
Merged

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Jul 27, 2020

Closes #6837

A few notes:

  • all of the legacy REST and querier endpoints need to use LegacyAmino explicitly. That is a lot of what is happening here
  • x/params is still using amino JSON and requires it explicitly now because HybridCodec is gone (to be addressed in Migrate x/params JSON state #6983)
  • EmitDefaults was turned on for proto JSON. This should overall produce a better UX but sometimes adds empty fields which aren't too informative. We may need to experiment with this.
  • AccountRetriever still uses amino JSON (to be cleaned up in Migrate AccountRetriever to proto #6985)
  • vesting accounts simply can't have all that custom JSON marshaling and work with jsonpb, therefore it was removed with a CHANGELOG entry added

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

@aaronc aaronc changed the title DNM: Remove HybridCodec Enable proto JSON generally and remove HybridCodec Aug 7, 2020
@codecov
Copy link

codecov bot commented Aug 7, 2020

Codecov Report

Merging #6859 into master will increase coverage by 0.92%.
The diff coverage is 46.77%.

@@            Coverage Diff             @@
##           master    #6859      +/-   ##
==========================================
+ Coverage   61.02%   61.95%   +0.92%     
==========================================
  Files         381      520     +139     
  Lines       24844    32036    +7192     
==========================================
+ Hits        15162    19848    +4686     
- Misses       8486    10559    +2073     
- Partials     1196     1629     +433     

@anilcse anilcse mentioned this pull request Aug 7, 2020
8 tasks
@tac0turtle
Copy link
Member

One important thing to note: 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).

the genesis is encoded with a similar json style as amino. is the current approach a problem?

@aaronc
Copy link
Member Author

aaronc commented Aug 10, 2020

One important thing to note: 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).

the genesis is encoded with a similar json style as amino. is the current approach a problem?

Is it okay if we just use encoding/json instead of amino for this?

@tac0turtle
Copy link
Member

Is it okay if we just use encoding/json instead of amino for this?

Applications should be free to use whatever format they want with Tendermint because the application state is json.RawMessage.

@aaronc
Copy link
Member Author

aaronc commented Aug 11, 2020

Not sure how to debug the failing sims. Any thoughts @alexanderbez ? Quite sure it has to do with amino being used somewhere for genesis, just not sure where

@alexanderbez
Copy link
Contributor

alexanderbez commented Aug 12, 2020

Seems only to be involved with export/import, I reran one of the seeds from CI:

$ go test ./simapp -run TestAppImportExport -Enabled=true -NumBlocks=50 -Genesis= -Verbose=true -Commit=true -Seed=7 -Period=5 -v -timeout 24h
...
exporting genesis...
importing genesis...
--- FAIL: TestAppImportExport (89.33s)
panic: unknown value "NoWithVeto" for enum cosmos.gov.v1beta1.VoteOption [recovered]
        panic: unknown value "NoWithVeto" for enum cosmos.gov.v1beta1.VoteOption

goroutine 50 [running]:
testing.tRunner.func1.1(0x5027600, 0xc00273ee90)
        /usr/local/go/src/testing/testing.go:1057 +0x30d
testing.tRunner.func1(0xc0005d2d80)
        /usr/local/go/src/testing/testing.go:1060 +0x41a
panic(0x5027600, 0xc00273ee90)
        /usr/local/go/src/runtime/panic.go:969 +0x175
github.com/cosmos/cosmos-sdk/codec.(*ProtoCodec).MustUnmarshalJSON(0xc000e36aa0, 0xc00572e000, 0xc9d6b, 0xca000, 0x51b8d20, 0xc003d9be60)
        /Users/aleksbez/code/cosmos/cosmos-sdk/codec/proto_codec.go:132 +0x8a
github.com/cosmos/cosmos-sdk/x/gov.AppModule.InitGenesis(0x55afce0, 0xc0013f0320, 0x0, 0x0, 0x0, 0x5588280, 0xc00247cd80, 0x559e000, 0xc0001ad200, 0x2df4c710, ...)
        /Users/aleksbez/code/cosmos/cosmos-sdk/x/gov/module.go:162 +0xa4
github.com/cosmos/cosmos-sdk/types/module.(*Manager).InitGenesis(0xc004476a10, 0x559cf40, 0xc0000400b0, 0x55adae0, 0xc00302ed80, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /Users/aleksbez/code/cosmos/cosmos-sdk/types/module/module.go:293 +0x2b5
github.com/cosmos/cosmos-sdk/simapp.TestAppImportExport(0xc0005d2d80)
        /Users/aleksbez/code/cosmos/cosmos-sdk/simapp/sim_test.go:145 +0xe52
testing.tRunner(0xc0005d2d80, 0x5406428)
        /usr/local/go/src/testing/testing.go:1108 +0xef
created by testing.(*T).Run
        /usr/local/go/src/testing/testing.go:1159 +0x386
FAIL    github.com/cosmos/cosmos-sdk/simapp     90.985s
FAIL

@aaronc
Copy link
Member Author

aaronc commented Aug 12, 2020

Thanks @alexanderbez that gave me a helpful clue. Seems related to #7010. How did you get that seed command to run btw?

@alexanderbez
Copy link
Contributor

@aaronc it's in the original comment:

Run the following from the root dir:

$ go test ./simapp -run TestAppImportExport -Enabled=true -NumBlocks=50 -Genesis= -Verbose=true -Commit=true -Seed=7 -Period=5 -v -timeout 24h

If you take a look at the CI output, it'll actually show you the command to run for all the failed seeds.

The issue makes sense though. We need to remove custom JSON marshaling for types?

@aaronc
Copy link
Member Author

aaronc commented Aug 12, 2020

If you take a look at the CI output, it'll actually show you the command to run for all the failed seeds.

Okay thanks.

The issue makes sense though. We need to remove custom JSON marshaling for types?

Well, it appears to work in some cases. For instance AccAddress is getting JSON marshaled as bech32 and we haven't run into any problems. That seems desirable, but it doesn't conform to the specification. That's probably okay though - we just need to have docs somewhere that describe our extensions to the default proto3 JSON. We were having the problems with enums mainly and there I don't think we should have custom JSON. But bech32 addresses make sense. The alternative would be encoding addresses as string instead of bytes in proto.

@alexanderbez
Copy link
Contributor

Yeah makes sense. Can we just address enums for now?

@aaronc
Copy link
Member Author

aaronc commented Aug 12, 2020

Yeah makes sense. Can we just address enums for now?

That's the only thing this PR takes care of, just for the failing test cases.

@aaronc aaronc added the A:automerge Automatically merge PR once all prerequisites pass. label Aug 12, 2020
@aaronc aaronc mentioned this pull request Aug 12, 2020
4 tasks
@aaronc
Copy link
Member Author

aaronc commented Aug 12, 2020

Okay, I think this is ready. Unit tests are passing again and sims were fixed in the last build

server/start.go Show resolved Hide resolved
simapp/app.go Show resolved Hide resolved
Copy link
Contributor

@sahith-narahari sahith-narahari left a comment

Choose a reason for hiding this comment

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

lgtm

@mergify mergify bot merged commit 816c5a3 into master Aug 13, 2020
@mergify mergify bot deleted the aaronc/6837-final branch August 13, 2020 13:20
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.

Ah, @sahith-narahari beat me to it. LGTM.

@@ -41,7 +41,7 @@ var (
//
// The actual codec used for serialization should be provided to x/distribution and
// defined at the application level.
ModuleCdc = codec.NewHybridCodec(amino, types.NewInterfaceRegistry())
ModuleCdc = codec.NewAminoCodec(amino)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these used in queriers or in REST?

larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* Remove HybridCodec

* WIP on fixing proto JSON issues

* WIP on fixing proto JSON issues

* WIP on fixing proto JSON issues

* WIP on fixing proto JSON issues

* WIP on fixing proto JSON issues

* Test fixes

* Delete hybrid_codec.go

* Fixes

* Fixes

* Fixes

* Test fixes

* Test fixes

* Test fixes

* Lint

* Sim fixes

* Sim fixes

* Revert

* Remove vesting account JSON tests

* Update CHANGELOG.md

* Lint

* Sim fixes

* Sim fixes

* Docs

* Migrate more amino usages

* Remove custom VoteOption String() and json marshaling

* Fix tests

* Add comments, update CHANGELOG.md

Co-authored-by: Jonathan Gimeno <jgimeno@gmail.com>
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
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:x/auth C:x/params
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove HybridCodec
7 participants