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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e20e717
Remove HybridCodec
aaronc Jul 27, 2020
6788a6c
Merge branch 'master' into aaronc/6837-final
jgimeno Jul 29, 2020
46bf0ee
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into aa…
aaronc Jul 30, 2020
3732302
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into aa…
aaronc Aug 7, 2020
6bd19c4
WIP on fixing proto JSON issues
aaronc Aug 7, 2020
4b41af5
WIP on fixing proto JSON issues
aaronc Aug 7, 2020
675d9f7
WIP on fixing proto JSON issues
aaronc Aug 7, 2020
ce3ae55
WIP on fixing proto JSON issues
aaronc Aug 7, 2020
c208575
WIP on fixing proto JSON issues
aaronc Aug 7, 2020
4c067a2
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into aa…
aaronc Aug 10, 2020
81beade
Test fixes
aaronc Aug 10, 2020
0acdd2a
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into aa…
aaronc Aug 11, 2020
63ebec3
Delete hybrid_codec.go
aaronc Aug 11, 2020
48adb63
Fixes
aaronc Aug 11, 2020
8cc6084
Fixes
aaronc Aug 11, 2020
06b012b
Fixes
aaronc Aug 11, 2020
42bd0a8
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into aa…
aaronc Aug 11, 2020
722da0b
Test fixes
aaronc Aug 11, 2020
053b77f
Test fixes
aaronc Aug 11, 2020
f651177
Test fixes
aaronc Aug 11, 2020
eed9418
Lint
aaronc Aug 11, 2020
7b62fad
Sim fixes
aaronc Aug 11, 2020
9d88118
Sim fixes
aaronc Aug 11, 2020
40f8816
Revert
aaronc Aug 11, 2020
7dbeffd
Remove vesting account JSON tests
aaronc Aug 11, 2020
fab24c6
Update CHANGELOG.md
aaronc Aug 11, 2020
11d5c04
Lint
aaronc Aug 11, 2020
9e8a745
Sim fixes
aaronc Aug 11, 2020
b52ab51
Sim fixes
aaronc Aug 11, 2020
d0c1263
Docs
aaronc Aug 11, 2020
66ca469
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into aa…
aaronc Aug 12, 2020
e98c8d2
Migrate more amino usages
aaronc Aug 12, 2020
55d681d
Merge branch 'master' into aaronc/6837-final
aaronc Aug 12, 2020
7a91e69
Remove custom VoteOption String() and json marshaling
aaronc Aug 12, 2020
0d929fa
Merge branch 'master' into aaronc/6837-final
alexanderbez Aug 12, 2020
2b0f52b
Fix tests
aaronc Aug 12, 2020
d6643ba
Add comments, update CHANGELOG.md
aaronc Aug 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ older clients.
* (client/keys) [\#5889](https://github.com/cosmos/cosmos-sdk/pull/5889) Remove `keys update` command.
* (x/evidence) [\#5952](https://github.com/cosmos/cosmos-sdk/pull/5952) Remove CLI and REST handlers for querying `x/evidence` parameters.
* (server) [\#5982](https://github.com/cosmos/cosmos-sdk/pull/5982) `--pruning` now must be set to `custom` if you want to customise the granular options.
* (x/gov) [\#7000](https://github.com/cosmos/cosmos-sdk/pull/7000) `ProposalStatus` is now JSON serialized using its protobuf name, so expect names like `PROPOSAL_STATUS_DEPOSIT_PERIOD` as opposed to `DepositPeriod`.
* (x/gov) [\#7000](https://github.com/cosmos/cosmos-sdk/pull/7000) [\#6859](https://github.com/cosmos/cosmos-sdk/pull/6859) `ProposalStatus` and `VoteOption` are now JSON serialized using its protobuf name, so expect names like `PROPOSAL_STATUS_DEPOSIT_PERIOD` as opposed to `DepositPeriod`.
* (x/auth/vesting) [\#6859](https://github.com/cosmos/cosmos-sdk/pull/6859) Custom JSON marshaling of vesting accounts was removed. Vesting accounts are now marshaled using their default proto or amino JSON representation.

### API Breaking Changes

Expand Down
69 changes: 0 additions & 69 deletions codec/hybrid_codec.go

This file was deleted.

108 changes: 0 additions & 108 deletions codec/hybrid_codec_test.go

This file was deleted.

4 changes: 3 additions & 1 deletion codec/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
// ProtoMarshalJSON provides an auxiliary function to return Proto3 JSON encoded
// bytes of a message.
func ProtoMarshalJSON(msg proto.Message) ([]byte, error) {
jm := &jsonpb.Marshaler{OrigName: true}
// We use the OrigName because camel casing fields just doesn't make sense.
// EmitDefaults is also often the more expected behavior for CLI users
jm := &jsonpb.Marshaler{OrigName: true, EmitDefaults: true}
err := types.UnpackInterfaces(msg, types.ProtoJSONPacker{JSONPBMarshaler: jm})
if err != nil {
return nil, err
Expand Down
2 changes: 0 additions & 2 deletions proto/cosmos/gov/v1beta1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ option (gogoproto.goproto_getters_all) = false;

// VoteOption defines a vote option
enum VoteOption {
option (gogoproto.enum_stringer) = false;
option (gogoproto.goproto_enum_stringer) = false;
option (gogoproto.goproto_enum_prefix) = false;

// VOTE_OPTION_UNSPECIFIED defines a no-op vote option.
Expand Down
10 changes: 7 additions & 3 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ which accepts a path for the resulting pprof file.

serverCtx.Logger.Info("starting ABCI with Tendermint")

err := startInProcess(serverCtx, clientCtx.JSONMarshaler, appCreator)
// amino is needed here for backwards compatibility of REST routes
err := startInProcess(serverCtx, clientCtx.LegacyAmino, appCreator)
return err
},
}
Expand Down Expand Up @@ -177,7 +178,8 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error {
select {}
}

func startInProcess(ctx *Context, cdc codec.JSONMarshaler, appCreator types.AppCreator) error {
// legacyAminoCdc is used for the legacy REST API
func startInProcess(ctx *Context, legacyAminoCdc *codec.LegacyAmino, appCreator types.AppCreator) error {
cfg := ctx.Config
home := cfg.RootDir

Expand Down Expand Up @@ -230,7 +232,9 @@ func startInProcess(ctx *Context, cdc codec.JSONMarshaler, appCreator types.AppC
clientCtx := client.Context{}.
WithHomeDir(home).
WithChainID(genDoc.ChainID).
WithJSONMarshaler(cdc).
WithJSONMarshaler(legacyAminoCdc).
aaronc marked this conversation as resolved.
Show resolved Hide resolved
// amino is needed here for backwards compatibility of REST routes
WithLegacyAmino(legacyAminoCdc).
WithClient(local.New(tmNode))

apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server"))
Expand Down
15 changes: 9 additions & 6 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func NewSimApp(
memKeys: memKeys,
}

app.ParamsKeeper = initParamsKeeper(appCodec, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])

// set the BaseApp's parameter store
bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(std.ConsensusParamsKeyTable()))
Expand Down Expand Up @@ -503,9 +503,12 @@ func (app *SimApp) SimulationManager() *module.SimulationManager {
// RegisterAPIRoutes registers all application module routes with the provided
// API server.
func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server) {
rpc.RegisterRoutes(apiSvr.ClientCtx, apiSvr.Router)
authrest.RegisterTxRoutes(apiSvr.ClientCtx, apiSvr.Router)
ModuleBasics.RegisterRESTRoutes(apiSvr.ClientCtx, apiSvr.Router)
clientCtx := apiSvr.ClientCtx
// amino is needed here for backwards compatibility of REST routes
clientCtx = clientCtx.WithJSONMarshaler(clientCtx.LegacyAmino)
aaronc marked this conversation as resolved.
Show resolved Hide resolved
rpc.RegisterRoutes(clientCtx, apiSvr.Router)
authrest.RegisterTxRoutes(clientCtx, apiSvr.Router)
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
}

// GetMaccPerms returns a copy of the module account permissions
Expand All @@ -518,8 +521,8 @@ func GetMaccPerms() map[string][]string {
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(appCodec codec.Marshaler, key, tkey sdk.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, key, tkey)
func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
Expand Down
5 changes: 2 additions & 3 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package simapp

import (
"encoding/json"
"os"
"testing"

"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/codec"

abci "github.com/tendermint/tendermint/abci/types"
)

Expand All @@ -18,7 +17,7 @@ func TestSimAppExport(t *testing.T) {
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())

genesisState := NewDefaultGenesisState()
stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)

// Initialize the chain
Expand Down
3 changes: 1 addition & 2 deletions simapp/params/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (
func MakeEncodingConfig() EncodingConfig {
cdc := codec.New()
interfaceRegistry := types.NewInterfaceRegistry()
// TODO: switch to using AminoCodec here once amino compatibility is fixed
marshaler := codec.NewHybridCodec(cdc, interfaceRegistry)
marshaler := codec.NewAminoCodec(cdc)

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Expand Down
4 changes: 2 additions & 2 deletions simapp/params/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
func MakeEncodingConfig() EncodingConfig {
amino := codec.New()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewHybridCodec(amino, interfaceRegistry)
txCfg := tx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), std.DefaultPublicKeyCodec{}, tx.DefaultSignModes)
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, std.DefaultPublicKeyCodec{}, tx.DefaultSignModes)

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Expand Down
8 changes: 4 additions & 4 deletions simapp/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func BenchmarkFullAppSimulation(b *testing.B) {

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
b, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()),
SimulationOperations(app, app.LegacyAmino(), config),
b, os.Stdout, app.BaseApp, AppStateFn(app.AppCodec(), app.SimulationManager()),
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(), config,
)

Expand Down Expand Up @@ -69,8 +69,8 @@ func BenchmarkInvariants(b *testing.B) {

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
b, os.Stdout, app.BaseApp, AppStateFn(app.LegacyAmino(), app.SimulationManager()),
SimulationOperations(app, app.LegacyAmino(), config),
b, os.Stdout, app.BaseApp, AppStateFn(app.AppCodec(), app.SimulationManager()),
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(), config,
)

Expand Down
Loading