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 21 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
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 original proto name because camel case just doesn't make sense
// EmitDefaults is also 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
8 changes: 5 additions & 3 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ which accepts a path for the resulting pprof file.

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

err := startInProcess(serverCtx, clientCtx.JSONMarshaler, appCreator)
err := startInProcess(serverCtx, clientCtx.LegacyAmino, appCreator)
return err
},
}
Expand Down Expand Up @@ -177,7 +177,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 +231,8 @@ 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
WithLegacyAmino(legacyAminoCdc).
WithClient(local.New(tmNode))

apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server"))
Expand Down
14 changes: 8 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,11 @@ 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
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 +520,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
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
36 changes: 6 additions & 30 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Marshaler)).
WithAccountRetriever(types.NewAccountRetriever(encodingConfig.Amino)).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(simapp.DefaultNodeHome)
)
Expand All @@ -79,12 +79,12 @@ func init() {
authclient.Codec = encodingConfig.Marshaler

rootCmd.AddCommand(
withProtoJSON(genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome)),
withProtoJSON(genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome)),
genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome),
genutilcli.MigrateGenesisCmd(),
withProtoJSON(genutilcli.GenTxCmd(simapp.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome)),
withProtoJSON(genutilcli.ValidateGenesisCmd(simapp.ModuleBasics, encodingConfig.TxConfig)),
withProtoJSON(AddGenesisAccountCmd(simapp.DefaultNodeHome)),
genutilcli.GenTxCmd(simapp.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome),
genutilcli.ValidateGenesisCmd(simapp.ModuleBasics, encodingConfig.TxConfig),
AddGenesisAccountCmd(simapp.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
testnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
Expand Down Expand Up @@ -202,27 +202,3 @@ func exportAppStateAndTMValidators(

return simApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
}

// This is a temporary command middleware to enable proto JSON marshaling for testing.
// Once proto JSON works everywhere we can remove this and set ProtoCodec as default
func withProtoJSON(command *cobra.Command) *cobra.Command {
existing := command.PersistentPreRunE
if existing != nil {
command.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
err := existing(cmd, args)
if err != nil {
return err
}
return setProtoJSON(cmd, args)
}
} else {
command.PersistentPreRunE = setProtoJSON
}
return command
}

func setProtoJSON(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx = clientCtx.WithJSONMarshaler(codec.NewProtoCodec(clientCtx.InterfaceRegistry))
return client.SetCmdClientContext(cmd, clientCtx)
}
11 changes: 5 additions & 6 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -53,7 +52,7 @@ func Setup(isCheckTx bool) *SimApp {
if !isCheckTx {
// init chain must be called to stop deliverState from being nil
genesisState := NewDefaultGenesisState()
stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -83,7 +82,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs

// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(authGenesis)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))
Expand Down Expand Up @@ -111,7 +110,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs

// set validators and delegations
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations)
genesisState[stakingtypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(stakingGenesis)
genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenesis)

totalSupply := sdk.NewCoins()
for _, b := range balances {
Expand All @@ -121,9 +120,9 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs

// update total supply
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
genesisState[banktypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(bankGenesis)
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

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

// init chain will set the validator set and initialize the genesis accounts
Expand Down
2 changes: 1 addition & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func DefaultConfig() Config {
Codec: encCfg.Marshaler,
TxConfig: encCfg.TxConfig,
LegacyAmino: encCfg.Amino,
AccountRetriever: authtypes.NewAccountRetriever(encCfg.Marshaler),
AccountRetriever: authtypes.NewAccountRetriever(encCfg.Amino),
AppConstructor: NewSimApp,
GenesisState: simapp.ModuleBasics.DefaultGenesis(encCfg.Marshaler),
TimeoutCommit: 2 * time.Second,
Expand Down
Loading