From a144ec1824b0d9b332b227c1c503c59c0b98223f Mon Sep 17 00:00:00 2001 From: Evan Forbes <42654277+evan-forbes@users.noreply.github.com> Date: Fri, 12 May 2023 13:20:35 -0500 Subject: [PATCH] feat: allow for the default consensus params to be set by the application (#317) * feat: allow for the default consensus params to be set by the application * chore: add test * fix: spelling Co-authored-by: CHAMI Rachid --------- Co-authored-by: CHAMI Rachid --- x/genutil/client/cli/init.go | 4 ++++ x/genutil/client/cli/init_test.go | 38 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index f3a186b77fe..91d0255dc80 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -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") } diff --git a/x/genutil/client/cli/init_test.go b/x/genutil/client/cli/init_test.go index 705af61cace..058c088565a 100644 --- a/x/genutil/client/cli/init_test.go +++ b/x/genutil/client/cli/init_test.go @@ -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" @@ -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()