You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB

  1. //nolint: goconst
  2. package main
  3. import (
  4. "errors"
  5. "fmt"
  6. "github.com/BurntSushi/toml"
  7. "github.com/tendermint/tendermint/test/e2e/app"
  8. )
  9. // Config is the application configuration.
  10. type Config struct {
  11. ChainID string `toml:"chain_id"`
  12. Listen string
  13. Protocol string
  14. Dir string
  15. Mode string `toml:"mode"`
  16. PersistInterval uint64 `toml:"persist_interval"`
  17. SnapshotInterval uint64 `toml:"snapshot_interval"`
  18. RetainBlocks uint64 `toml:"retain_blocks"`
  19. ValidatorUpdates map[string]map[string]uint8 `toml:"validator_update"`
  20. PrivValServer string `toml:"privval_server"`
  21. PrivValKey string `toml:"privval_key"`
  22. PrivValState string `toml:"privval_state"`
  23. Misbehaviors map[string]string `toml:"misbehaviors"`
  24. KeyType string `toml:"key_type"`
  25. }
  26. // App extracts out the application specific configuration parameters
  27. func (cfg *Config) App() *app.Config {
  28. return &app.Config{
  29. Dir: cfg.Dir,
  30. SnapshotInterval: cfg.SnapshotInterval,
  31. RetainBlocks: cfg.RetainBlocks,
  32. KeyType: cfg.KeyType,
  33. ValidatorUpdates: cfg.ValidatorUpdates,
  34. PersistInterval: cfg.PersistInterval,
  35. }
  36. }
  37. // LoadConfig loads the configuration from disk.
  38. func LoadConfig(file string) (*Config, error) {
  39. cfg := &Config{
  40. Listen: "unix:///var/run/app.sock",
  41. Protocol: "socket",
  42. PersistInterval: 1,
  43. }
  44. _, err := toml.DecodeFile(file, &cfg)
  45. if err != nil {
  46. return nil, fmt.Errorf("failed to load config from %q: %w", file, err)
  47. }
  48. return cfg, cfg.Validate()
  49. }
  50. // Validate validates the configuration. We don't do exhaustive config
  51. // validation here, instead relying on Testnet.Validate() to handle it.
  52. func (cfg Config) Validate() error {
  53. switch {
  54. case cfg.ChainID == "":
  55. return errors.New("chain_id parameter is required")
  56. case cfg.Listen == "" && cfg.Protocol != "builtin":
  57. return errors.New("listen parameter is required")
  58. default:
  59. return nil
  60. }
  61. }