diff --git a/contribs/gnodev/go.mod b/contribs/gnodev/go.mod index d705e753269..52ceb547f90 100644 --- a/contribs/gnodev/go.mod +++ b/contribs/gnodev/go.mod @@ -11,6 +11,7 @@ require ( ) require ( + dario.cat/mergo v1.0.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/btcutil v1.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect diff --git a/contribs/gnodev/go.sum b/contribs/gnodev/go.sum index 4a7f6a96c0b..8957131a347 100644 --- a/contribs/gnodev/go.sum +++ b/contribs/gnodev/go.sum @@ -1,4 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= diff --git a/contribs/gnokeykc/go.mod b/contribs/gnokeykc/go.mod index 5dd13801ab1..6c2cfa690df 100644 --- a/contribs/gnokeykc/go.mod +++ b/contribs/gnokeykc/go.mod @@ -10,6 +10,7 @@ require ( ) require ( + dario.cat/mergo v1.0.0 // indirect github.com/alessio/shellescape v1.4.1 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/btcutil v1.1.3 // indirect diff --git a/contribs/gnokeykc/go.sum b/contribs/gnokeykc/go.sum index 32d2b524117..c5f601b5ec2 100644 --- a/contribs/gnokeykc/go.sum +++ b/contribs/gnokeykc/go.sum @@ -1,4 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -278,4 +280,5 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/gno.land/cmd/gnoland/start.go b/gno.land/cmd/gnoland/start.go index 9ca2369c6eb..40d33a218cc 100644 --- a/gno.land/cmd/gnoland/start.go +++ b/gno.land/cmd/gnoland/start.go @@ -190,7 +190,7 @@ func execStart(c *startCfg, io commands.IO) error { cfg, loadCfgErr = config.LoadConfigFile(c.nodeConfigPath) } else { // Load the default node configuration - cfg, loadCfgErr = config.LoadOrMakeConfigWithOptions(dataDir, nil) + cfg, loadCfgErr = config.LoadOrMakeConfigWithOptions(dataDir) } if loadCfgErr != nil { diff --git a/go.mod b/go.mod index 903b4bb3d85..3c83a12ec3c 100644 --- a/go.mod +++ b/go.mod @@ -40,6 +40,8 @@ require ( gopkg.in/yaml.v3 v3.0.1 ) +require dario.cat/mergo v1.0.0 + require ( github.com/btcsuite/btcd/btcec/v2 v2.3.2 github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect diff --git a/go.sum b/go.sum index b0a973c5b91..13cee4401f9 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= diff --git a/misc/loop/go.mod b/misc/loop/go.mod index f21da6e1a14..1dfc778e000 100644 --- a/misc/loop/go.mod +++ b/misc/loop/go.mod @@ -8,6 +8,7 @@ require ( ) require ( + dario.cat/mergo v1.0.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/btcutil v1.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect diff --git a/misc/loop/go.sum b/misc/loop/go.sum index 783b38bff8b..d67564b4c46 100644 --- a/misc/loop/go.sum +++ b/misc/loop/go.sum @@ -1,4 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -282,4 +284,5 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/tm2/pkg/bft/blockchain/reactor_test.go b/tm2/pkg/bft/blockchain/reactor_test.go index fef640b0f82..c9ff0ff5f93 100644 --- a/tm2/pkg/bft/blockchain/reactor_test.go +++ b/tm2/pkg/bft/blockchain/reactor_test.go @@ -6,8 +6,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" - abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types" cfg "github.com/gnolang/gno/tm2/pkg/bft/config" "github.com/gnolang/gno/tm2/pkg/bft/mempool/mock" @@ -21,6 +19,7 @@ import ( "github.com/gnolang/gno/tm2/pkg/log" "github.com/gnolang/gno/tm2/pkg/p2p" "github.com/gnolang/gno/tm2/pkg/testutils" + "github.com/stretchr/testify/assert" ) var config *cfg.Config diff --git a/tm2/pkg/bft/config/config.go b/tm2/pkg/bft/config/config.go index 3785759c960..e5c331b448c 100644 --- a/tm2/pkg/bft/config/config.go +++ b/tm2/pkg/bft/config/config.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" + "dario.cat/mergo" abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types" cns "github.com/gnolang/gno/tm2/pkg/bft/consensus/config" mem "github.com/gnolang/gno/tm2/pkg/bft/mempool/config" @@ -21,11 +22,11 @@ type Config struct { BaseConfig `toml:",squash"` // Options for services - RPC *rpc.RPCConfig `toml:"rpc"` - P2P *p2p.P2PConfig `toml:"p2p"` - Mempool *mem.MempoolConfig `toml:"mempool"` - Consensus *cns.ConsensusConfig `toml:"consensus"` - TxEventStore *eventstore.Config `toml:"tx_event_store"` + RPC *rpc.RPCConfig `toml:"rpc" comment:"##### rpc server configuration options #####"` + P2P *p2p.P2PConfig `toml:"p2p" comment:"##### peer to peer configuration options #####"` + Mempool *mem.MempoolConfig `toml:"mempool" comment:"##### mempool configuration options #####"` + Consensus *cns.ConsensusConfig `toml:"consensus" comment:"##### consensus configuration options #####"` + TxEventStore *eventstore.Config `toml:"tx_event_store" comment:"##### event store #####"` } // DefaultConfig returns a default configuration for a Tendermint node @@ -40,37 +41,65 @@ func DefaultConfig() *Config { } } -type ConfigOptions func(cfg *Config) - -// LoadOrMakeConfigWithOptions loads configuration or saves one -// made by modifying the default config with override options -func LoadOrMakeConfigWithOptions(root string, options ConfigOptions) (*Config, error) { - var cfg *Config +type Option func(cfg *Config) + +// LoadOrMakeConfigWithOptions loads the configuration located in the given +// root directory, at [defaultConfigFilePath]. +// +// If the config does not exist, it is created, starting from the values in +// `DefaultConfig` and applying the defaults in opts. +func LoadOrMakeConfigWithOptions(root string, opts ...Option) (*Config, error) { + // Initialize the config as default + var ( + cfg = DefaultConfig() + configPath = join(root, defaultConfigFilePath) + ) + + // Config doesn't exist, create it + // from the default one + for _, opt := range opts { + opt(cfg) + } - configPath := join(root, defaultConfigFilePath) + // Check if the config exists if osm.FileExists(configPath) { - var loadErr error - // Load the configuration - if cfg, loadErr = LoadConfigFile(configPath); loadErr != nil { + loadedCfg, loadErr := LoadConfigFile(configPath) + if loadErr != nil { return nil, loadErr } - cfg.SetRootDir(root) - cfg.EnsureDirs() - } else { - cfg = DefaultConfig() - if options != nil { - options(cfg) + // Merge the loaded config with the default values + if err := mergo.Merge(loadedCfg, cfg); err != nil { + return nil, err } - cfg.SetRootDir(root) - cfg.EnsureDirs() - WriteConfigFile(configPath, cfg) - // Validate the configuration - if validateErr := cfg.ValidateBasic(); validateErr != nil { - return nil, fmt.Errorf("unable to validate config, %w", validateErr) + // Set the root directory + loadedCfg.SetRootDir(root) + + // Make sure the directories are initialized + if err := loadedCfg.EnsureDirs(); err != nil { + return nil, err } + + return loadedCfg, nil + } + + cfg.SetRootDir(root) + + // Make sure the directories are initialized + if err := cfg.EnsureDirs(); err != nil { + return nil, err + } + + // Validate the configuration + if validateErr := cfg.ValidateBasic(); validateErr != nil { + return nil, fmt.Errorf("unable to validate config, %w", validateErr) + } + + // Save the config + if err := WriteConfigFile(configPath, cfg); err != nil { + return nil, err } return cfg, nil @@ -79,7 +108,7 @@ func LoadOrMakeConfigWithOptions(root string, options ConfigOptions) (*Config, e // TestConfig returns a configuration that can be used for testing func TestConfig() *Config { return &Config{ - BaseConfig: TestBaseConfig(), + BaseConfig: testBaseConfig(), RPC: rpc.TestRPCConfig(), P2P: p2p.TestP2PConfig(), Mempool: mem.TestMempoolConfig(), @@ -95,21 +124,27 @@ func (cfg *Config) SetRootDir(root string) *Config { cfg.P2P.RootDir = root cfg.Mempool.RootDir = root cfg.Consensus.RootDir = root + return cfg } // EnsureDirs ensures default directories in root dir (and root dir). -func (cfg *Config) EnsureDirs() { +func (cfg *Config) EnsureDirs() error { rootDir := cfg.BaseConfig.RootDir + if err := osm.EnsureDir(rootDir, DefaultDirPerm); err != nil { - panic(err.Error()) + return fmt.Errorf("no root directory, %w", err) } + if err := osm.EnsureDir(filepath.Join(rootDir, defaultConfigDir), DefaultDirPerm); err != nil { - panic(err.Error()) + return fmt.Errorf("no config directory, %w", err) } + if err := osm.EnsureDir(filepath.Join(rootDir, defaultDataDir), DefaultDirPerm); err != nil { - panic(err.Error()) + return fmt.Errorf("no data directory, %w", err) } + + return nil } // ValidateBasic performs basic validation (checking param bounds, etc.) and @@ -172,18 +207,18 @@ type BaseConfig struct { // TCP or UNIX socket address of the ABCI application, // or the name of an ABCI application compiled in with the Tendermint binary, // or empty if local application instance. - ProxyApp string `toml:"proxy_app"` + ProxyApp string `toml:"proxy_app" comment:"TCP or UNIX socket address of the ABCI application, \n or the name of an ABCI application compiled in with the Tendermint binary"` // Local application instance in lieu of remote app. LocalApp abci.Application // A custom human readable name for this node - Moniker string `toml:"moniker"` + Moniker string `toml:"moniker" comment:"A custom human readable name for this node"` // If this node is many blocks behind the tip of the chain, FastSync // allows them to catchup quickly by downloading blocks in parallel // and verifying their commits - FastSyncMode bool `toml:"fast_sync"` + FastSyncMode bool `toml:"fast_sync" comment:"If this node is many blocks behind the tip of the chain, FastSync\n allows them to catchup quickly by downloading blocks in parallel\n and verifying their commits"` // Database backend: goleveldb | cleveldb | boltdb // * goleveldb (github.com/gnolang/goleveldb - most popular implementation) @@ -197,42 +232,42 @@ type BaseConfig struct { // - EXPERIMENTAL // - may be faster is some use-cases (random reads - indexer) // - use boltdb build tag (go build -tags boltdb) - DBBackend string `toml:"db_backend"` + DBBackend string `toml:"db_backend" comment:"Database backend: goleveldb | cleveldb | boltdb\n * goleveldb (github.com/gnolang/goleveldb - most popular implementation)\n - pure go\n - stable\n * cleveldb (uses levigo wrapper)\n - fast\n - requires gcc\n - use cleveldb build tag (go build -tags cleveldb)\n * boltdb (uses etcd's fork of bolt - go.etcd.io/bbolt)\n - EXPERIMENTAL\n - may be faster is some use-cases (random reads - indexer)\n - use boltdb build tag (go build -tags boltdb)"` // Database directory - DBPath string `toml:"db_dir"` + DBPath string `toml:"db_dir" comment:"Database directory"` // Output level for logging - LogLevel string `toml:"log_level"` + LogLevel string `toml:"log_level" comment:"Output level for logging, including package level options"` // Output format: 'plain' (colored text) or 'json' - LogFormat string `toml:"log_format"` + LogFormat string `toml:"log_format" comment:"Output format: 'plain' (colored text) or 'json'"` // Path to the JSON file containing the initial validator set and other meta data - Genesis string `toml:"genesis_file"` + Genesis string `toml:"genesis_file" comment:"Path to the JSON file containing the initial validator set and other meta data"` // Path to the JSON file containing the private key to use as a validator in the consensus protocol - PrivValidatorKey string `toml:"priv_validator_key_file"` + PrivValidatorKey string `toml:"priv_validator_key_file" comment:"Path to the JSON file containing the private key to use as a validator in the consensus protocol"` // Path to the JSON file containing the last sign state of a validator - PrivValidatorState string `toml:"priv_validator_state_file"` + PrivValidatorState string `toml:"priv_validator_state_file" comment:"Path to the JSON file containing the last sign state of a validator"` // TCP or UNIX socket address for Tendermint to listen on for // connections from an external PrivValidator process - PrivValidatorListenAddr string `toml:"priv_validator_laddr"` + PrivValidatorListenAddr string `toml:"priv_validator_laddr" comment:"TCP or UNIX socket address for Tendermint to listen on for\n connections from an external PrivValidator process"` // A JSON file containing the private key to use for p2p authenticated encryption - NodeKey string `toml:"node_key_file"` + NodeKey string `toml:"node_key_file" comment:"Path to the JSON file containing the private key to use for node authentication in the p2p protocol"` // Mechanism to connect to the ABCI application: local | socket - ABCI string `toml:"abci"` + ABCI string `toml:"abci" comment:"Mechanism to connect to the ABCI application: socket | grpc"` // TCP or UNIX socket address for the profiling server to listen on - ProfListenAddress string `toml:"prof_laddr"` + ProfListenAddress string `toml:"prof_laddr" comment:"TCP or UNIX socket address for the profiling server to listen on"` // If true, query the ABCI app on connecting to a new peer // so the app can decide if we should keep the connection or not - FilterPeers bool `toml:"filter_peers"` // false + FilterPeers bool `toml:"filter_peers" comment:"If true, query the ABCI app on connecting to a new peer\n so the app can decide if we should keep the connection or not"` // false } // DefaultBaseConfig returns a default base configuration for a Tendermint node @@ -255,8 +290,8 @@ func DefaultBaseConfig() BaseConfig { } } -// TestBaseConfig returns a base configuration for testing a Tendermint node -func TestBaseConfig() BaseConfig { +// testBaseConfig returns a base configuration for testing a Tendermint node +func testBaseConfig() BaseConfig { cfg := DefaultBaseConfig() cfg.chainID = "tendermint_test" cfg.ProxyApp = "mock://kvstore" diff --git a/tm2/pkg/bft/config/config_test.go b/tm2/pkg/bft/config/config_test.go new file mode 100644 index 00000000000..1ed58767f2b --- /dev/null +++ b/tm2/pkg/bft/config/config_test.go @@ -0,0 +1,90 @@ +package config + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestConfig_LoadOrMakeConfigWithOptions(t *testing.T) { + t.Parallel() + + t.Run("existing configuration", func(t *testing.T) { + t.Parallel() + + // Provide an empty directory + cfgDir := t.TempDir() + cfgPath := join(cfgDir, defaultConfigFilePath) + + // Create a default config + cfg := DefaultConfig() + cfg.SetRootDir(cfgDir) + + // Make an incremental changes + cfg.Moniker = "custom moniker" + + // Make sure the cfg paths are initialized + require.NoError(t, cfg.EnsureDirs()) + + // Write the config + require.NoError(t, WriteConfigFile(cfgPath, cfg)) + + // Load the config + loadedCfg, loadErr := LoadOrMakeConfigWithOptions(cfgDir) + require.NoError(t, loadErr) + + assert.Equal(t, cfg, loadedCfg) + }) + + t.Run("no existing config", func(t *testing.T) { + t.Parallel() + + // Provide an empty directory + cfgDir := t.TempDir() + cfgPath := join(cfgDir, defaultConfigFilePath) + + cfg, err := LoadOrMakeConfigWithOptions(cfgDir) + require.NoError(t, err) + + // Make sure the returned cfg is the default one + expectedCfg := DefaultConfig() + expectedCfg.SetRootDir(cfgDir) + + assert.Equal(t, expectedCfg, cfg) + + // Make sure the returned config was saved + loadedCfg, loadErr := LoadConfigFile(cfgPath) + require.NoError(t, loadErr) + + loadedCfg.SetRootDir(cfgDir) + + assert.Equal(t, cfg, loadedCfg) + }) + + t.Run("no existing config, with options", func(t *testing.T) { + t.Parallel() + + moniker := "dummy moniker" + + // Provide an empty directory + cfgDir := t.TempDir() + cfgPath := join(cfgDir, defaultConfigFilePath) + + cfg, err := LoadOrMakeConfigWithOptions( + cfgDir, + func(cfg *Config) { + cfg.BaseConfig.Moniker = moniker + }, + ) + require.NoError(t, err) + + // Make sure the returned config was saved + loadedCfg, loadErr := LoadConfigFile(cfgPath) + require.NoError(t, loadErr) + + loadedCfg.SetRootDir(cfgDir) + + assert.Equal(t, cfg, loadedCfg) + }) +} diff --git a/tm2/pkg/bft/config/toml.go b/tm2/pkg/bft/config/toml.go index c7e94c735f2..f813d23b8fb 100644 --- a/tm2/pkg/bft/config/toml.go +++ b/tm2/pkg/bft/config/toml.go @@ -1,11 +1,9 @@ package config import ( - "bytes" "fmt" "os" "path/filepath" - "text/template" osm "github.com/gnolang/gno/tm2/pkg/os" "github.com/pelletier/go-toml" @@ -14,15 +12,6 @@ import ( // DefaultDirPerm is the default permissions used when creating directories. const DefaultDirPerm = 0o700 -var configTemplate *template.Template - -func init() { - var err error - if configTemplate, err = template.New("configFileTemplate").Parse(defaultConfigTemplate); err != nil { - panic(err) - } -} - // LoadConfigFile loads the TOML node configuration from the specified path func LoadConfigFile(path string) (*Config, error) { // Read the config file @@ -49,256 +38,20 @@ func LoadConfigFile(path string) (*Config, error) { /****** these are for production settings ***********/ // WriteConfigFile renders config using the template and writes it to configFilePath. -func WriteConfigFile(configFilePath string, config *Config) { - var buffer bytes.Buffer +func WriteConfigFile(configFilePath string, config *Config) error { + // Marshal the config + configRaw, err := toml.Marshal(config) + if err != nil { + return fmt.Errorf("unable to TOML marshal config, %w", err) + } - if err := configTemplate.Execute(&buffer, config); err != nil { - panic(err) + if err := osm.WriteFile(configFilePath, configRaw, 0o644); err != nil { + return fmt.Errorf("unable to write config file, %w", err) } - osm.MustWriteFile(configFilePath, buffer.Bytes(), 0o644) + return nil } -// Note: any changes to the comments/variables/field-names -// must be reflected in the appropriate struct in config/config.go -const defaultConfigTemplate = `# This is a TOML config file. -# For more information, see https://github.com/toml-lang/toml - -##### main base config options ##### - -# TCP or UNIX socket address of the ABCI application, -# or the name of an ABCI application compiled in with the Tendermint binary -proxy_app = "{{ .BaseConfig.ProxyApp }}" - -# A custom human readable name for this node -moniker = "{{ .BaseConfig.Moniker }}" - -# If this node is many blocks behind the tip of the chain, FastSync -# allows them to catchup quickly by downloading blocks in parallel -# and verifying their commits -fast_sync = {{ .BaseConfig.FastSyncMode }} - -# Database backend: goleveldb | cleveldb | boltdb -# * goleveldb (github.com/gnolang/goleveldb - most popular implementation) -# - pure go -# - stable -# * cleveldb (uses levigo wrapper) -# - fast -# - requires gcc -# - use cleveldb build tag (go build -tags cleveldb) -# * boltdb (uses etcd's fork of bolt - go.etcd.io/bbolt) -# - EXPERIMENTAL -# - may be faster is some use-cases (random reads - indexer) -# - use boltdb build tag (go build -tags boltdb) -db_backend = "{{ .BaseConfig.DBBackend }}" - -# Database directory -db_dir = "{{ js .BaseConfig.DBPath }}" - -# Output level for logging, including package level options -log_level = "{{ .BaseConfig.LogLevel }}" - -# Output format: 'plain' (colored text) or 'json' -log_format = "{{ .BaseConfig.LogFormat }}" - -##### additional base config options ##### - -# Path to the JSON file containing the initial validator set and other meta data -genesis_file = "{{ js .BaseConfig.Genesis }}" - -# Path to the JSON file containing the private key to use as a validator in the consensus protocol -priv_validator_key_file = "{{ js .BaseConfig.PrivValidatorKey }}" - -# Path to the JSON file containing the last sign state of a validator -priv_validator_state_file = "{{ js .BaseConfig.PrivValidatorState }}" - -# TCP or UNIX socket address for Tendermint to listen on for -# connections from an external PrivValidator process -priv_validator_laddr = "{{ .BaseConfig.PrivValidatorListenAddr }}" - -# Path to the JSON file containing the private key to use for node authentication in the p2p protocol -node_key_file = "{{ js .BaseConfig.NodeKey }}" - -# Mechanism to connect to the ABCI application: socket | grpc -abci = "{{ .BaseConfig.ABCI }}" - -# TCP or UNIX socket address for the profiling server to listen on -prof_laddr = "{{ .BaseConfig.ProfListenAddress }}" - -# If true, query the ABCI app on connecting to a new peer -# so the app can decide if we should keep the connection or not -filter_peers = {{ .BaseConfig.FilterPeers }} - -##### advanced configuration options ##### - -##### rpc server configuration options ##### -[rpc] - -# TCP or UNIX socket address for the RPC server to listen on -laddr = "{{ .RPC.ListenAddress }}" - -# A list of origins a cross-domain request can be executed from -# Default value '[]' disables cors support -# Use '["*"]' to allow any origin -cors_allowed_origins = [{{ range .RPC.CORSAllowedOrigins }}{{ printf "%q, " . }}{{end}}] - -# A list of methods the client is allowed to use with cross-domain requests -cors_allowed_methods = [{{ range .RPC.CORSAllowedMethods }}{{ printf "%q, " . }}{{end}}] - -# A list of non simple headers the client is allowed to use with cross-domain requests -cors_allowed_headers = [{{ range .RPC.CORSAllowedHeaders }}{{ printf "%q, " . }}{{end}}] - -# TCP or UNIX socket address for the gRPC server to listen on -# NOTE: This server only supports /broadcast_tx_commit -grpc_laddr = "{{ .RPC.GRPCListenAddress }}" - -# Maximum number of simultaneous connections. -# Does not include RPC (HTTP&WebSocket) connections. See max_open_connections -# If you want to accept a larger number than the default, make sure -# you increase your OS limits. -# 0 - unlimited. -# Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files} -# 1024 - 40 - 10 - 50 = 924 = ~900 -grpc_max_open_connections = {{ .RPC.GRPCMaxOpenConnections }} - -# Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool -unsafe = {{ .RPC.Unsafe }} - -# Maximum number of simultaneous connections (including WebSocket). -# Does not include gRPC connections. See grpc_max_open_connections -# If you want to accept a larger number than the default, make sure -# you increase your OS limits. -# 0 - unlimited. -# Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files} -# 1024 - 40 - 10 - 50 = 924 = ~900 -max_open_connections = {{ .RPC.MaxOpenConnections }} - -# How long to wait for a tx to be committed during /broadcast_tx_commit. -# WARNING: Using a value larger than 10s will result in increasing the -# global HTTP write timeout, which applies to all connections and endpoints. -# See https://github.com/tendermint/classic/issues/3435 -timeout_broadcast_tx_commit = "{{ .RPC.TimeoutBroadcastTxCommit }}" - -# Maximum size of request body, in bytes -max_body_bytes = {{ .RPC.MaxBodyBytes }} - -# Maximum size of request header, in bytes -max_header_bytes = {{ .RPC.MaxHeaderBytes }} - -# The path to a file containing certificate that is used to create the HTTPS server. -# Might be either absolute path or path related to tendermint's config directory. -# If the certificate is signed by a certificate authority, -# the certFile should be the concatenation of the server's certificate, any intermediates, -# and the CA's certificate. -# NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. Otherwise, HTTP server is run. -tls_cert_file = "{{ .RPC.TLSCertFile }}" - -# The path to a file containing matching private key that is used to create the HTTPS server. -# Might be either absolute path or path related to tendermint's config directory. -# NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. Otherwise, HTTP server is run. -tls_key_file = "{{ .RPC.TLSKeyFile }}" - -##### peer to peer configuration options ##### -[p2p] - -# Address to listen for incoming connections -laddr = "{{ .P2P.ListenAddress }}" - -# Address to advertise to peers for them to dial -# If empty, will use the same port as the laddr, -# and will introspect on the listener or use UPnP -# to figure out the address. -external_address = "{{ .P2P.ExternalAddress }}" - -# Comma separated list of seed nodes to connect to -seeds = "{{ .P2P.Seeds }}" - -# Comma separated list of nodes to keep persistent connections to -persistent_peers = "{{ .P2P.PersistentPeers }}" - -# UPNP port forwarding -upnp = {{ .P2P.UPNP }} - -# Maximum number of inbound peers -max_num_inbound_peers = {{ .P2P.MaxNumInboundPeers }} - -# Maximum number of outbound peers to connect to, excluding persistent peers -max_num_outbound_peers = {{ .P2P.MaxNumOutboundPeers }} - -# Time to wait before flushing messages out on the connection -flush_throttle_timeout = "{{ .P2P.FlushThrottleTimeout }}" - -# Maximum size of a message packet payload, in bytes -max_packet_msg_payload_size = {{ .P2P.MaxPacketMsgPayloadSize }} - -# Rate at which packets can be sent, in bytes/second -send_rate = {{ .P2P.SendRate }} - -# Rate at which packets can be received, in bytes/second -recv_rate = {{ .P2P.RecvRate }} - -# Set true to enable the peer-exchange reactor -pex = {{ .P2P.PexReactor }} - -# Seed mode, in which node constantly crawls the network and looks for -# peers. If another node asks it for addresses, it responds and disconnects. -# -# Does not work if the peer-exchange reactor is disabled. -seed_mode = {{ .P2P.SeedMode }} - -# Comma separated list of peer IDs to keep private (will not be gossiped to other peers) -private_peer_ids = "{{ .P2P.PrivatePeerIDs }}" - -# Toggle to disable guard against peers connecting from the same ip. -allow_duplicate_ip = {{ .P2P.AllowDuplicateIP }} - -# Peer connection configuration. -handshake_timeout = "{{ .P2P.HandshakeTimeout }}" -dial_timeout = "{{ .P2P.DialTimeout }}" - -##### mempool configuration options ##### -[mempool] - -recheck = {{ .Mempool.Recheck }} -broadcast = {{ .Mempool.Broadcast }} -wal_dir = "{{ js .Mempool.WalPath }}" - -# Maximum number of transactions in the mempool -size = {{ .Mempool.Size }} - -# Limit the total size of all txs in the mempool. -# This only accounts for raw transactions (e.g. given 1MB transactions and -# max_txs_bytes=5MB, mempool will only accept 5 transactions). -max_pending_txs_bytes = {{ .Mempool.MaxPendingTxsBytes }} - -# Size of the cache (used to filter transactions we saw earlier) in transactions -cache_size = {{ .Mempool.CacheSize }} - -##### consensus configuration options ##### -[consensus] - -wal_file = "{{ js .Consensus.WalPath }}" - -timeout_propose = "{{ .Consensus.TimeoutPropose }}" -timeout_propose_delta = "{{ .Consensus.TimeoutProposeDelta }}" -timeout_prevote = "{{ .Consensus.TimeoutPrevote }}" -timeout_prevote_delta = "{{ .Consensus.TimeoutPrevoteDelta }}" -timeout_precommit = "{{ .Consensus.TimeoutPrecommit }}" -timeout_precommit_delta = "{{ .Consensus.TimeoutPrecommitDelta }}" -timeout_commit = "{{ .Consensus.TimeoutCommit }}" - -# Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) -skip_timeout_commit = {{ .Consensus.SkipTimeoutCommit }} - -# EmptyBlocks mode and possible interval between empty blocks -create_empty_blocks = {{ .Consensus.CreateEmptyBlocks }} -create_empty_blocks_interval = "{{ .Consensus.CreateEmptyBlocksInterval }}" - -# Reactor sleep duration parameters -peer_gossip_sleep_duration = "{{ .Consensus.PeerGossipSleepDuration }}" -peer_query_maj23_sleep_duration = "{{ .Consensus.PeerQueryMaj23SleepDuration }}" -` - /****** these are for test settings ***********/ func ResetTestRoot(testName string) *Config { diff --git a/tm2/pkg/bft/config/toml_test.go b/tm2/pkg/bft/config/toml_test.go index d1d70155cb8..b75057a52dd 100644 --- a/tm2/pkg/bft/config/toml_test.go +++ b/tm2/pkg/bft/config/toml_test.go @@ -1,7 +1,9 @@ package config import ( + "io" "os" + "reflect" "strings" "testing" @@ -24,21 +26,19 @@ func ensureFiles(t *testing.T, rootDir string, files ...string) { func TestEnsureRoot(t *testing.T) { t.Parallel() - require := require.New(t) - // setup temp dir for test tmpDir := t.TempDir() // create root dir throwaway := DefaultConfig() throwaway.SetRootDir(tmpDir) - throwaway.EnsureDirs() + require.NoError(t, throwaway.EnsureDirs()) configPath := join(tmpDir, defaultConfigFilePath) - WriteConfigFile(configPath, throwaway) + require.NoError(t, WriteConfigFile(configPath, throwaway)) // make sure config is set properly data, err := os.ReadFile(join(tmpDir, defaultConfigFilePath)) - require.Nil(err) + require.Nil(t, err) if !checkConfig(string(data)) { t.Fatalf("config file missing some information") @@ -161,3 +161,68 @@ func TestTOML_LoadConfig(t *testing.T) { assert.Empty(t, defaultConfig.TxEventStore.Params, cfg.TxEventStore.Params) }) } + +func TestTOML_ConfigComments(t *testing.T) { + t.Parallel() + + collectCommentTags := func(v reflect.Value) []string { + var ( + comments = make([]string, 0) + structStack = []reflect.Value{v} + ) + + // Descend on and parse all child fields + for len(structStack) > 0 { + structVal := structStack[len(structStack)-1] + structStack = structStack[:len(structStack)-1] + + // Process all fields of the struct + for i := 0; i < structVal.NumField(); i++ { + fieldVal := structVal.Field(i) + fieldType := structVal.Type().Field(i) + + // If the field is a struct, push it onto the stack for further processing + if fieldVal.Kind() == reflect.Struct { + structStack = append(structStack, fieldVal) + + continue + } + + // Collect the comment tag value from the field + if commentTag := fieldType.Tag.Get("comment"); commentTag != "" { + comments = append(comments, commentTag) + } + } + } + + return comments + } + + cleanComments := func(original string) string { + return strings.ReplaceAll(original, "#", "") + } + + // Create test config file + configFile, cleanup := testutils.NewTestFile(t) + t.Cleanup(cleanup) + + // Create the default config + defaultConfig := DefaultConfig() + + // Write valid TOML + require.NoError(t, WriteConfigFile(configFile.Name(), defaultConfig)) + + // Collect config comments + comments := collectCommentTags(reflect.ValueOf(*defaultConfig)) + require.NotEmpty(t, comments) + + // Read the entire config file + rawConfig, err := io.ReadAll(configFile) + require.NoError(t, err) + + // Verify TOML comments are present + content := cleanComments(string(rawConfig)) + for _, comment := range comments { + assert.Contains(t, content, cleanComments(comment)) + } +} diff --git a/tm2/pkg/bft/consensus/config/config.go b/tm2/pkg/bft/consensus/config/config.go index 234def843e9..dbd4ffc6364 100644 --- a/tm2/pkg/bft/consensus/config/config.go +++ b/tm2/pkg/bft/consensus/config/config.go @@ -6,7 +6,7 @@ import ( "time" ) -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // ConsensusConfig const ( @@ -29,14 +29,14 @@ type ConsensusConfig struct { TimeoutCommit time.Duration `toml:"timeout_commit"` // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) - SkipTimeoutCommit bool `toml:"skip_timeout_commit"` + SkipTimeoutCommit bool `toml:"skip_timeout_commit" comment:"Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)"` // EmptyBlocks mode and possible interval between empty blocks - CreateEmptyBlocks bool `toml:"create_empty_blocks"` + CreateEmptyBlocks bool `toml:"create_empty_blocks" comment:"EmptyBlocks mode and possible interval between empty blocks"` CreateEmptyBlocksInterval time.Duration `toml:"create_empty_blocks_interval"` // Reactor sleep duration parameters - PeerGossipSleepDuration time.Duration `toml:"peer_gossip_sleep_duration"` + PeerGossipSleepDuration time.Duration `toml:"peer_gossip_sleep_duration" comment:"Reactor sleep duration parameters"` PeerQueryMaj23SleepDuration time.Duration `toml:"peer_query_maj23_sleep_duration"` } diff --git a/tm2/pkg/bft/mempool/config/config.go b/tm2/pkg/bft/mempool/config/config.go index 06e8d98672f..198b34291bc 100644 --- a/tm2/pkg/bft/mempool/config/config.go +++ b/tm2/pkg/bft/mempool/config/config.go @@ -2,7 +2,7 @@ package config import "github.com/gnolang/gno/tm2/pkg/errors" -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // MempoolConfig // MempoolConfig defines the configuration options for the Tendermint mempool @@ -11,9 +11,9 @@ type MempoolConfig struct { Recheck bool `toml:"recheck"` Broadcast bool `toml:"broadcast"` WalPath string `toml:"wal_dir"` - Size int `toml:"size"` - MaxPendingTxsBytes int64 `toml:"max_pending_txs_bytes"` - CacheSize int `toml:"cache_size"` + Size int `toml:"size" comment:"Maximum number of transactions in the mempool"` + MaxPendingTxsBytes int64 `toml:"max_pending_txs_bytes" comment:"Limit the total size of all txs in the mempool.\n This only accounts for raw transactions (e.g. given 1MB transactions and\n max_txs_bytes=5MB, mempool will only accept 5 transactions)."` + CacheSize int `toml:"cache_size" comment:"Size of the cache (used to filter transactions we saw earlier) in transactions"` } // DefaultMempoolConfig returns a default configuration for the Tendermint mempool diff --git a/tm2/pkg/bft/rpc/config/config.go b/tm2/pkg/bft/rpc/config/config.go index 2c24e713fc5..76c490bf94c 100644 --- a/tm2/pkg/bft/rpc/config/config.go +++ b/tm2/pkg/bft/rpc/config/config.go @@ -19,33 +19,33 @@ type RPCConfig struct { RootDir string `toml:"home"` // TCP or UNIX socket address for the RPC server to listen on - ListenAddress string `toml:"laddr"` + ListenAddress string `toml:"laddr" comment:"TCP or UNIX socket address for the RPC server to listen on"` // A list of origins a cross-domain request can be executed from. // If the special '*' value is present in the list, all origins will be allowed. // An origin may contain a wildcard (*) to replace 0 or more characters (i.e.: http://*.domain.com). // Only one wildcard can be used per origin. - CORSAllowedOrigins []string `toml:"cors_allowed_origins"` + CORSAllowedOrigins []string `toml:"cors_allowed_origins" comment:"A list of origins a cross-domain request can be executed from\n Default value '[]' disables cors support\n Use '[\"*\"]' to allow any origin"` // A list of methods the client is allowed to use with cross-domain requests. - CORSAllowedMethods []string `toml:"cors_allowed_methods"` + CORSAllowedMethods []string `toml:"cors_allowed_methods" comment:"A list of methods the client is allowed to use with cross-domain requests"` // A list of non simple headers the client is allowed to use with cross-domain requests. - CORSAllowedHeaders []string `toml:"cors_allowed_headers"` + CORSAllowedHeaders []string `toml:"cors_allowed_headers" comment:"A list of non simple headers the client is allowed to use with cross-domain requests"` // TCP or UNIX socket address for the gRPC server to listen on // NOTE: This server only supports /broadcast_tx_commit - GRPCListenAddress string `toml:"grpc_laddr"` + GRPCListenAddress string `toml:"grpc_laddr" comment:"TCP or UNIX socket address for the gRPC server to listen on\n NOTE: This server only supports /broadcast_tx_commit"` // Maximum number of simultaneous connections. // Does not include RPC (HTTP&WebSocket) connections. See max_open_connections // If you want to accept a larger number than the default, make sure // you increase your OS limits. // 0 - unlimited. - GRPCMaxOpenConnections int `toml:"grpc_max_open_connections"` + GRPCMaxOpenConnections int `toml:"grpc_max_open_connections" comment:"Maximum number of simultaneous connections.\n Does not include RPC (HTTP&WebSocket) connections. See max_open_connections\n If you want to accept a larger number than the default, make sure\n you increase your OS limits.\n 0 - unlimited.\n Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}\n 1024 - 40 - 10 - 50 = 924 = ~900"` // Activate unsafe RPC commands like /dial_persistent_peers and /unsafe_flush_mempool - Unsafe bool `toml:"unsafe"` + Unsafe bool `toml:"unsafe" comment:"Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool"` // Maximum number of simultaneous connections (including WebSocket). // Does not include gRPC connections. See grpc_max_open_connections @@ -54,19 +54,19 @@ type RPCConfig struct { // 0 - unlimited. // Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files} // 1024 - 40 - 10 - 50 = 924 = ~900 - MaxOpenConnections int `toml:"max_open_connections"` + MaxOpenConnections int `toml:"max_open_connections" comment:"Maximum number of simultaneous connections (including WebSocket).\n Does not include gRPC connections. See grpc_max_open_connections\n If you want to accept a larger number than the default, make sure\n you increase your OS limits.\n 0 - unlimited.\n Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}\n 1024 - 40 - 10 - 50 = 924 = ~900"` // How long to wait for a tx to be committed during /broadcast_tx_commit // WARNING: Using a value larger than 10s will result in increasing the // global HTTP write timeout, which applies to all connections and endpoints. // See https://github.com/gnolang/gno/tm2/pkg/bft/issues/3435 - TimeoutBroadcastTxCommit time.Duration `toml:"timeout_broadcast_tx_commit"` + TimeoutBroadcastTxCommit time.Duration `toml:"timeout_broadcast_tx_commit" comment:"How long to wait for a tx to be committed during /broadcast_tx_commit.\n WARNING: Using a value larger than 10s will result in increasing the\n global HTTP write timeout, which applies to all connections and endpoints.\n See https://github.com/tendermint/classic/issues/3435"` // Maximum size of request body, in bytes - MaxBodyBytes int64 `toml:"max_body_bytes"` + MaxBodyBytes int64 `toml:"max_body_bytes" comment:"Maximum size of request body, in bytes"` // Maximum size of request header, in bytes - MaxHeaderBytes int `toml:"max_header_bytes"` + MaxHeaderBytes int `toml:"max_header_bytes" comment:"Maximum size of request header, in bytes"` // The path to a file containing certificate that is used to create the HTTPS server. // Might be either absolute path or path related to tendermint's config directory. @@ -76,13 +76,13 @@ type RPCConfig struct { // and the CA's certificate. // // NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. Otherwise, HTTP server is run. - TLSCertFile string `toml:"tls_cert_file"` + TLSCertFile string `toml:"tls_cert_file" comment:"The path to a file containing certificate that is used to create the HTTPS server.\n Might be either absolute path or path related to tendermint's config directory.\n If the certificate is signed by a certificate authority,\n the certFile should be the concatenation of the server's certificate, any intermediates,\n and the CA's certificate.\n NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. Otherwise, HTTP server is run."` // The path to a file containing matching private key that is used to create the HTTPS server. // Might be either absolute path or path related to tendermint's config directory. // // NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. Otherwise, HTTP server is run. - TLSKeyFile string `toml:"tls_key_file"` + TLSKeyFile string `toml:"tls_key_file" comment:"The path to a file containing matching private key that is used to create the HTTPS server.\n Might be either absolute path or path related to tendermint's config directory.\n NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server. Otherwise, HTTP server is run."` } // DefaultRPCConfig returns a default configuration for the RPC server diff --git a/tm2/pkg/bft/state/eventstore/types/config.go b/tm2/pkg/bft/state/eventstore/types/config.go index 08e25870b4d..5b152f254fd 100644 --- a/tm2/pkg/bft/state/eventstore/types/config.go +++ b/tm2/pkg/bft/state/eventstore/types/config.go @@ -7,8 +7,8 @@ type EventStoreParams map[string]any // Config defines the specific event store configuration type Config struct { - EventStoreType string - Params EventStoreParams + EventStoreType string `toml:"event_store_type" comment:"Type of event store"` + Params EventStoreParams `toml:"event_store_params" comment:"Event store parameters"` } // GetParam fetches the specific config param, if any. @@ -25,5 +25,6 @@ func (c *Config) GetParam(name string) any { func DefaultEventStoreConfig() *Config { return &Config{ EventStoreType: null.EventStoreType, + Params: make(EventStoreParams), } } diff --git a/tm2/pkg/p2p/config/config.go b/tm2/pkg/p2p/config/config.go index 830f84ad137..a0ed2d39381 100644 --- a/tm2/pkg/p2p/config/config.go +++ b/tm2/pkg/p2p/config/config.go @@ -21,56 +21,56 @@ type P2PConfig struct { RootDir string `toml:"home"` // Address to listen for incoming connections - ListenAddress string `toml:"laddr"` + ListenAddress string `toml:"laddr" comment:"Address to listen for incoming connections"` // Address to advertise to peers for them to dial - ExternalAddress string `toml:"external_address"` + ExternalAddress string `toml:"external_address" comment:"Address to advertise to peers for them to dial\n If empty, will use the same port as the laddr,\n and will introspect on the listener or use UPnP\n to figure out the address."` // Comma separated list of seed nodes to connect to - Seeds string `toml:"seeds"` + Seeds string `toml:"seeds" comment:"Comma separated list of seed nodes to connect to"` // Comma separated list of nodes to keep persistent connections to - PersistentPeers string `toml:"persistent_peers"` + PersistentPeers string `toml:"persistent_peers" comment:"Comma separated list of nodes to keep persistent connections to"` // UPNP port forwarding - UPNP bool `toml:"upnp"` + UPNP bool `toml:"upnp" comment:"UPNP port forwarding"` // Maximum number of inbound peers - MaxNumInboundPeers int `toml:"max_num_inbound_peers"` + MaxNumInboundPeers int `toml:"max_num_inbound_peers" comment:"Maximum number of inbound peers"` // Maximum number of outbound peers to connect to, excluding persistent peers - MaxNumOutboundPeers int `toml:"max_num_outbound_peers"` + MaxNumOutboundPeers int `toml:"max_num_outbound_peers" comment:"Maximum number of outbound peers to connect to, excluding persistent peers"` // Time to wait before flushing messages out on the connection - FlushThrottleTimeout time.Duration `toml:"flush_throttle_timeout"` + FlushThrottleTimeout time.Duration `toml:"flush_throttle_timeout" comment:"Time to wait before flushing messages out on the connection"` // Maximum size of a message packet payload, in bytes - MaxPacketMsgPayloadSize int `toml:"max_packet_msg_payload_size"` + MaxPacketMsgPayloadSize int `toml:"max_packet_msg_payload_size" comment:"Maximum size of a message packet payload, in bytes"` // Rate at which packets can be sent, in bytes/second - SendRate int64 `toml:"send_rate"` + SendRate int64 `toml:"send_rate" comment:"Rate at which packets can be sent, in bytes/second"` // Rate at which packets can be received, in bytes/second - RecvRate int64 `toml:"recv_rate"` + RecvRate int64 `toml:"recv_rate" comment:"Rate at which packets can be received, in bytes/second"` // Set true to enable the peer-exchange reactor - PexReactor bool `toml:"pex"` + PexReactor bool `toml:"pex" comment:"Set true to enable the peer-exchange reactor"` // Seed mode, in which node constantly crawls the network and looks for // peers. If another node asks it for addresses, it responds and disconnects. // // Does not work if the peer-exchange reactor is disabled. - SeedMode bool `toml:"seed_mode"` + SeedMode bool `toml:"seed_mode" comment:"Seed mode, in which node constantly crawls the network and looks for\n peers. If another node asks it for addresses, it responds and disconnects.\n\n Does not work if the peer-exchange reactor is disabled."` // Comma separated list of peer IDs to keep private (will not be gossiped to // other peers) - PrivatePeerIDs string `toml:"private_peer_ids"` + PrivatePeerIDs string `toml:"private_peer_ids" comment:"Comma separated list of peer IDs to keep private (will not be gossiped to other peers)"` // Toggle to disable guard against peers connecting from the same ip. - AllowDuplicateIP bool `toml:"allow_duplicate_ip"` + AllowDuplicateIP bool `toml:"allow_duplicate_ip" comment:"Toggle to disable guard against peers connecting from the same ip."` // Peer connection configuration. - HandshakeTimeout time.Duration `toml:"handshake_timeout"` + HandshakeTimeout time.Duration `toml:"handshake_timeout" comment:"Peer connection configuration."` DialTimeout time.Duration `toml:"dial_timeout"` // Testing params.