config

package
v0.67.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2023 License: MIT Imports: 52 Imported by: 1

README

Config

Config is a central place where all sub-system specific configurations come together. Sub-system specific config are defined on each corresponding packages. The CLI defines all its parameters as structs. Out of this structs we generate a configuration file (in toml format) and CLI flags (via go-flags).

Ideally all parameters defined in the toml config should be exposed via flags, we might have a case where a parameter exists as a flag but not in the config, like -c | --config which defines the path of the config. Thereby, cli flags are a super set of the config parameters.

How to use it

Structs define fields which maps to parameters:

// Config is the configuration of the execution package
type Config struct {
  ...
  Level encoding.LogLevel             `long:"log-level"`
  InsurancePoolInitialBalance uint64  `long:"insurance-pool-initial-balance" description:"Some description"`
  Matching   matching.Config          `group:"Matching" namespace:"matching"`
  ...
}

A Config struct can hold native to types like uint64, custom types like encoding.LogLevel and other structures like matching.Config. The long:log-level tag will be mapped to a --log-level= flag, also the description: tag will be displayed as documentation for that particular flag. These are the two main tag that we use, see Available field tags for reference. When there are nested structs, we use the group and namespace tag. While the group tag will be displayed in the help to group the documentation, the namespace tag will affect the final flag name. In this case the Matching options are going to be prefixed with the --matching. See matching.Config for reference

$ vega node --help
Usage:
  vega [OPTIONS] node [node-OPTIONS]

Runs a vega node

    Execution:
          --execution.log-level=
          --execution.insurance-pool-initial-balance=         Some description (default: 

    Execution::Matching:
          --execution.matching.log-level=
          --execution.matching.log-price-levels-debug
          --execution.matching.log-removed-orders-debug
Default values

Default values are displayed in the help if a) description annotation is set and b) if the value of the parameter is anything different from its zero value

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPassphraseDoNotMatch = errors.New("passphrase do not match")
)

Functions

func EnsureNodeConfig

func EnsureNodeConfig(vegaPaths paths.Paths) (*Loader, *Config, error)

Types

type Config

type Config struct {
	Admin             admin.Config           `group:"Admin" namespace:"admin"`
	API               api.Config             `group:"API" namespace:"api"`
	Blockchain        blockchain.Config      `group:"Blockchain" namespace:"blockchain"`
	Collateral        collateral.Config      `group:"Collateral" namespace:"collateral"`
	CoreAPI           coreapi.Config         `group:"CoreAPI" namespace:"coreapi"`
	Execution         execution.Config       `group:"Execution" namespace:"execution"`
	Ethereum          eth.Config             `group:"Ethereum" namespace:"ethereum"`
	Processor         processor.Config       `group:"Processor" namespace:"processor"`
	Logging           logging.Config         `group:"Logging" namespace:"logging"`
	Oracles           oracles.Config         `group:"Oracles" namespace:"oracles"`
	Time              vegatime.Config        `group:"Time" namespace:"time"`
	Epoch             epochtime.Config       `group:"Epoch" namespace:"epochtime"`
	Metrics           metrics.Config         `group:"Metrics" namespace:"metrics"`
	Governance        governance.Config      `group:"Governance" namespace:"governance"`
	NodeWallet        nodewallets.Config     `group:"NodeWallet" namespace:"nodewallet"`
	Assets            assets.Config          `group:"Assets" namespace:"assets"`
	Notary            notary.Config          `group:"Notary" namespace:"notary"`
	EvtForward        evtforward.Config      `group:"EvtForward" namespace:"evtForward"`
	Genesis           genesis.Config         `group:"Genesis" namespace:"genesis"`
	Validators        validators.Config      `group:"Validators" namespace:"validators"`
	Banking           banking.Config         `group:"Banking" namespace:"banking"`
	Stats             stats.Config           `group:"Stats" namespace:"stats"`
	NetworkParameters netparams.Config       `group:"NetworkParameters" namespace:"netparams"`
	Limits            limits.Config          `group:"Limits" namespace:"limits"`
	Checkpoint        checkpoint.Config      `group:"Checkpoint" namespace:"checkpoint"`
	Staking           staking.Config         `group:"Staking" namespace:"staking"`
	Broker            broker.Config          `group:"Broker" namespace:"broker"`
	Rewards           rewards.Config         `group:"Rewards" namespace:"rewards"`
	Delegation        delegation.Config      `group:"Delegation" namespace:"delegation"`
	Spam              spam.Config            `group:"Spam" namespace:"spam"`
	PoW               pow.Config             `group:"ProofOfWork" namespace:"pow"`
	Snapshot          snapshot.Config        `group:"Snapshot" namespace:"snapshot"`
	StateVar          statevar.Config        `group:"StateVar" namespace:"statevar"`
	ERC20MultiSig     erc20multisig.Config   `group:"ERC20MultiSig" namespace:"erc20multisig"`
	ProtocolUpgrade   protocolupgrade.Config `group:"ProtocolUpgrade" namespace:"protocolupgrade"`
	Pprof             pprof.Config           `group:"Pprof" namespace:"pprof"`

	NodeMode         cfgencoding.NodeMode `long:"mode" description:"The mode of the vega node [validator, full]"`
	MaxMemoryPercent uint8                `long:"max-memory-percent" description:"The maximum amount of memory reserved for the vega node (default: 33%)"`
}

Config ties together all other application configuration types.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig returns a set of default configs for all vega packages, as specified at the per package config level, if there is an error initialising any of the configs then this is returned.

func (Config) GetMaxMemoryFactor added in v0.66.0

func (c Config) GetMaxMemoryFactor() (float64, error)

func (Config) HaveEthClient

func (c Config) HaveEthClient() bool

func (Config) IsValidator

func (c Config) IsValidator() bool

func (*Config) SetDefaultMaxMemoryPercent added in v0.66.0

func (c *Config) SetDefaultMaxMemoryPercent()

type Empty

type Empty struct{}

Empty is used when a command or sub-command receives no argument and has no execution.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

func InitialiseLoader

func InitialiseLoader(vegaPaths paths.Paths) (*Loader, error)

func (*Loader) ConfigExists

func (l *Loader) ConfigExists() (bool, error)

func (*Loader) ConfigFilePath

func (l *Loader) ConfigFilePath() string

func (*Loader) Get

func (l *Loader) Get() (*Config, error)

func (*Loader) Remove

func (l *Loader) Remove()

func (*Loader) Save

func (l *Loader) Save(cfg *Config) error

type Option

type Option func(w *Watcher)

func Use

func Use(use func(*Config) error) Option

type Output

type Output string

func (Output) IsHuman

func (o Output) IsHuman() bool

func (Output) IsJSON

func (o Output) IsJSON() bool

type OutputFlag

type OutputFlag struct {
	Output Output `long:"output" description:"Specify the output format: json,human" default:"human" required:"true"`
}

func (OutputFlag) GetOutput

func (f OutputFlag) GetOutput() (Output, error)

type Passphrase

type Passphrase string

func (Passphrase) Get

func (p Passphrase) Get(prompt string, withConfirmation bool) (string, error)

type PassphraseFlag

type PassphraseFlag struct {
	PassphraseFile Passphrase `` /* 126-byte string literal not displayed */
}

type PromptString

type PromptString string

func (PromptString) Get

func (p PromptString) Get(prompt, name string) (string, error)

Get returns a string if set or prompts user otherwise.

type VegaHomeFlag

type VegaHomeFlag struct {
	VegaHome string `long:"home" description:"Path to the custom home for vega"`
}

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher is looking for updates in the configurations files.

func NewWatcher

func NewWatcher(ctx context.Context, log *logging.Logger, vegaPaths paths.Paths, opts ...Option) (*Watcher, error)

NewWatcher instantiate a new watcher from the vega config files.

func (*Watcher) Get

func (w *Watcher) Get() Config

Get return the last update of the configuration.

func (*Watcher) OnConfigUpdate

func (w *Watcher) OnConfigUpdate(fns ...func(Config))

OnConfigUpdate register a function to be called when the configuration is getting updated.

func (*Watcher) OnConfigUpdateWithID

func (w *Watcher) OnConfigUpdateWithID(fns ...func(Config)) []int

OnConfigUpdate register a function to be called when the configuration is getting updated.

func (*Watcher) OnTimeUpdate

func (w *Watcher) OnTimeUpdate(_ context.Context, _ time.Time)

func (*Watcher) Unregister

func (w *Watcher) Unregister(ids []int)

func (*Watcher) Use

func (w *Watcher) Use(fns ...func(*Config) error)

Use registers a function that modify the config when the configuration is updated.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL