Skip to content

Commit

Permalink
feat: allow for the default consensus params to be set by the applica…
Browse files Browse the repository at this point in the history
…tion (#317) (#345)

* feat: allow for the default consensus params to be set by the application

* chore: add test

* fix: spelling



---------

Co-authored-by: CHAMI Rachid <[email protected]>
  • Loading branch information
evan-forbes and rach-id authored Sep 5, 2023
1 parent 7babe18 commit 233165b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
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

0 comments on commit 233165b

Please sign in to comment.