Signed-off-by: fuyangpengqi <995764973@qq.com> Co-authored-by: samricotta <37125168+samricotta@users.noreply.github.com>
127 lines
4.4 KiB
Go
127 lines
4.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"strings"
|
|
|
|
cmtcfg "github.com/cometbft/cometbft/config"
|
|
|
|
clientconfig "github.com/cosmos/cosmos-sdk/client/config"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
|
|
)
|
|
|
|
// initCometBFTConfig helps to override default CometBFT Config values.
|
|
// return cmtcfg.DefaultConfig if no custom configuration is required for the application.
|
|
func initCometBFTConfig() *cmtcfg.Config {
|
|
cfg := cmtcfg.DefaultConfig()
|
|
|
|
// only display only error logs by default except for p2p and state
|
|
cfg.LogLevel = "*:error,p2p:info,state:info"
|
|
|
|
// these values put a higher strain on node memory
|
|
// cfg.P2P.MaxNumInboundPeers = 100
|
|
// cfg.P2P.MaxNumOutboundPeers = 40
|
|
|
|
return cfg
|
|
}
|
|
|
|
// initClientConfig helps to override default client config template and configs.
|
|
// return "", nil if no custom configuration is required for the application.
|
|
func initClientConfig() (string, interface{}) {
|
|
type GasConfig struct {
|
|
GasAdjustment float64 `mapstructure:"gas-adjustment"`
|
|
}
|
|
|
|
type CustomClientConfig struct {
|
|
clientconfig.Config `mapstructure:",squash"`
|
|
|
|
GasConfig GasConfig `mapstructure:"gas"`
|
|
}
|
|
|
|
// Optionally allow the chain developer to overwrite the SDK's default client config.
|
|
clientCfg := clientconfig.DefaultConfig()
|
|
|
|
// The SDK's default keyring backend is set to "os".
|
|
// This is more secure than "test" and is the recommended value.
|
|
//
|
|
// In simapp, we set the default keyring backend to test, as SimApp is meant
|
|
// to be an example and testing application.
|
|
clientCfg.KeyringBackend = keyring.BackendTest
|
|
|
|
// Now we set the custom config default values.
|
|
customClientConfig := CustomClientConfig{
|
|
Config: *clientCfg,
|
|
GasConfig: GasConfig{
|
|
GasAdjustment: 1.5,
|
|
},
|
|
}
|
|
|
|
// The default SDK app template is defined in serverconfig.DefaultConfigTemplate.
|
|
// We append the custom config template to the default one.
|
|
// And we set the default config to the custom app template.
|
|
customClientConfigTemplate := clientconfig.DefaultClientConfigTemplate + strings.TrimSpace(`
|
|
# This is default the gas adjustment factor used in tx commands.
|
|
# It can be overwritten by the --gas-adjustment flag in each tx command.
|
|
gas-adjustment = {{ .GasConfig.GasAdjustment }}
|
|
`)
|
|
|
|
return customClientConfigTemplate, customClientConfig
|
|
}
|
|
|
|
// initAppConfig helps to override default appConfig template and configs.
|
|
// return "", nil if no custom configuration is required for the application.
|
|
func initAppConfig() (string, interface{}) {
|
|
// The following code snippet is just for reference.
|
|
|
|
// CustomConfig defines an arbitrary custom config to extend app.toml.
|
|
// If you don't need it, you can remove it.
|
|
// If you wish to add fields that correspond to flags that aren't in the SDK server config,
|
|
// this custom config can as well help.
|
|
type CustomConfig struct {
|
|
CustomField string `mapstructure:"custom-field"`
|
|
}
|
|
|
|
type CustomAppConfig struct {
|
|
serverconfig.Config `mapstructure:",squash"`
|
|
|
|
Custom CustomConfig `mapstructure:"custom"`
|
|
}
|
|
|
|
// Optionally allow the chain developer to overwrite the SDK's default
|
|
// server config.
|
|
srvCfg := serverconfig.DefaultConfig()
|
|
// The SDK's default minimum gas price is set to "" (empty value) inside
|
|
// app.toml. If left empty by validators, the node will halt on startup.
|
|
// However, the chain developer can set a default app.toml value for their
|
|
// validators here.
|
|
//
|
|
// In summary:
|
|
// - if you leave srvCfg.MinGasPrices = "", all validators MUST tweak their
|
|
// own app.toml config,
|
|
// - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their
|
|
// own app.toml to override, or use this default value.
|
|
//
|
|
// In simapp, we set the min gas prices to 0.
|
|
srvCfg.MinGasPrices = "0stake"
|
|
// srvCfg.BaseConfig.IAVLDisableFastNode = true // disable fastnode by default
|
|
|
|
// Now we set the custom config default values.
|
|
customAppConfig := CustomAppConfig{
|
|
Config: *srvCfg,
|
|
Custom: CustomConfig{
|
|
CustomField: "anything",
|
|
},
|
|
}
|
|
|
|
// The default SDK app template is defined in serverconfig.DefaultConfigTemplate.
|
|
// We append the custom config template to the default one.
|
|
// And we set the default config to the custom app template.
|
|
customAppTemplate := serverconfig.DefaultConfigTemplate + `
|
|
[custom]
|
|
# That field will be parsed by server.InterceptConfigsPreRunHandler and held by viper.
|
|
# Do not forget to add quotes around the value if it is a string.
|
|
custom-field = "{{ .Custom.CustomField }}"`
|
|
|
|
return customAppTemplate, customAppConfig
|
|
}
|