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

feat: allow for the default consensus params to be set by the applica… #345

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions x/genutil/client/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
genDoc.Validators = nil
genDoc.AppState = appState

if serverCtx.DefaultConsensusParams != nil {
genDoc.ConsensusParams = serverCtx.DefaultConsensusParams
}

if err = genutil.ExportGenesisFile(genDoc, genFile); err != nil {
return errors.Wrap(err, "Failed to export genesis file")
}
Expand Down
38 changes: 38 additions & 0 deletions x/genutil/client/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
abci_server "github.com/tendermint/tendermint/abci/server"
"github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
coretypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -283,6 +284,43 @@ func TestInitConfig(t *testing.T) {
require.Contains(t, out, "\"chain_id\": \"foo\"")
}

func TestInitWithConsensusParams(t *testing.T) {
home := t.TempDir()
logger := log.NewNopLogger()
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)

serverCtx := server.NewContext(viper.New(), cfg, logger)

// set new default consensus params
cps := coretypes.DefaultConsensusParams()
cps.Block.MaxBytes = 100000000
cps.Block.MaxGas = 420420420
serverCtx.DefaultConsensusParams = cps

interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
clientCtx := client.Context{}.
WithCodec(marshaler).
WithLegacyAmino(makeCodec()).
WithHomeDir(home)

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)

cmd := genutilcli.InitCmd(testMbm, home)
cmd.SetArgs([]string{"testnode"})

err = cmd.ExecuteContext(ctx)
require.NoError(t, err)

genDoc, err := coretypes.GenesisDocFromFile(cfg.GenesisFile())
require.NoError(t, err)

require.Equal(t, genDoc.ConsensusParams, cps)
}

// custom tx codec
func makeCodec() *codec.LegacyAmino {
cdc := codec.NewLegacyAmino()
Expand Down
Loading