package
0.28.0
Repository: https://github.com/ten-protocol/go-ten.git
Documentation: pkg.go.dev

# README

All go processes in the TEN ecosystem will use the config mechanism here to load their configuration.

Ten config has a hierarchical structure, so every field has a unique field name. Some fields are used by multiple processes, while others are only used by a single process.

For example, network.chainId is a field that might be used by multiple processes, but host.rpc.httpPort is only used by the host processes.

The fields are defined in a single place, in the Config structs declared in config.go. These declarations include their type, the mapstructure annotation that gives their yaml field name and any comments about their usage.

This library provides a loading mechanism powered by viper, it reads 0-base-config.yaml to initialise the config and then overrides fields with any other yaml files provided and finally overrides with environment variables.

Environment variable keys are the same as the yaml keys but are uppercased and have dots replaced with underscores. For example, network.chainId would be NETWORK_CHAINID, and host.rpc.httpPort would be HOST_RPC_HTTPPORT.

The ability to set them with environment variables is important, it allows for easy configuration of the system in a docker environment.

Loading the config

The loading method allows an ordered list of yaml files to be provided, values in later files will override values in earlier files.

The loading method will also apply environment variables, overriding any values set in the yaml files.

In practice for production deployments, we expect that the 0-base-config.yaml will be the only file that is always provided and config will be provided by the orchestration engine as env variables.

Defining a new field

Defining a new field requires adding it in 2 or 3 places:

  1. The Config struct in config.go
  2. The 0-base-config.yaml file
  3. The enclave(-test).json file (if the field is used by the enclave process)

The config struct (1) is the source of truth for the field, it defines the type and the yaml field name. (2) and (3) are required because:

  • Environment variable values are only applied by viper when the field is defined in at least one of the yaml files. For this reason, we want to make sure that all fields are defined in the base config file even if just with trivial or empty values.

  • The ego enclave restricts the environment variables that can be accessed by the enclave process. This means that the enclave process will not be able to access environment variables that are not whitelisted. This is a security feature of the ego enclave.

    The enclave.json file used to produce the signed ego artifact allows environment variables to be specified, either with a hardcoded value which we will use for fixed constants that are not allowed to change or with a 'fromHost' flag which will allow the enclave to access the environment variable from the host process. This is useful for configuration values that are allowed to change between deployments.

    So any configuration value that is expected to be set by an environment variable should be whitelisted in the enclave.json file.

# Functions

LoadTenConfig reads the base config file and applying additional files provided as well as any env variables, returns a TenConfig struct.

# Structs

BatchConfig contains the configuration for the batch processing on the Ten network yaml: `network.batch`.
CrossChainConfig contains the configuration for the cross chain processing on the Ten network yaml: `network.crossChain`.
EnclaveConfig is the configuration struct for the enclave service.
EnclaveDB contains the configuration for the enclave database.
EnclaveDebug contains the configuration for the enclave debug.
EnclaveL1 contains the configuration related to the L1 chain.
EnclaveLog contains the configuration for the enclave logger.
EnclaveRPC contains the configuration for the enclave RPC server.
GasConfig contains the gas configuration for the Ten network yaml: `network.gas`.
HostConfig is the configuration struct for the host service.
HostDB contains the configuration for the host database.
HostDebug contains the configuration for the host's debug settings.
HostEnclave contains the configuration for the host's enclave(s) yaml: `host.enclave`.
HostL1 contains the configuration for the host's L1 client and interactions.
HostLog contains the configuration for the host logger.
HostP2P contains the configuration for the host P2P server.
HostRPC contains the configuration for the host RPC server.
L1Config contains config about the L1 network that the Ten network is rolling up to yaml: `network.l1`.
L1Contracts contains the addresses of Ten contracts on the L1 network yaml: `network.l1.contracts`.
NetworkConfig contains the static configuration for this instance of the Ten network yaml: `network`.
NodeConfig contains the configuration for this Ten node (maybe relevant to multiple processes, host and enclave) yaml: `node`.
RollupConfig contains the configuration for the rollup processing on the Ten network yaml: `network.rollup`.
Sequencer contains the configuration for how the L2 sequencer will operate for the Ten network yaml: `network.sequencer`.
TenConfig is the top-level configuration struct for all TEN services.