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 application #317

Merged
merged 3 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 6 additions & 4 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
cmtproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

// DONTCOVER
Expand All @@ -43,9 +44,10 @@ const ServerContextKey = sdk.ContextKey("server.context")

// server context
type Context struct {
Viper *viper.Viper
Config *tmcfg.Config
Logger tmlog.Logger
Viper *viper.Viper
Config *tmcfg.Config
Logger tmlog.Logger
DefaultConsensusParams *cmtproto.ConsensusParams
}

// ErrorCode contains the exit code for server exit.
Expand All @@ -66,7 +68,7 @@ func NewDefaultContext() *Context {
}

func NewContext(v *viper.Viper, config *tmcfg.Config, logger tmlog.Logger) *Context {
return &Context{v, config, logger}
return &Context{v, config, logger, nil}
}

func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) {
Expand Down
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 defult consensus params
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
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