Skip to content

go: Avoid global config and pass it explicitly instead #6271

@martintomazic

Description

@martintomazic

This would enable us to write better integration/unit tests. Moreover, it encourages better abstractions and documentation.

I suggest to do this incremental, i.e. deprecate global config and refactor 1-3 non-trivial services for the start. Remaining refactor could be done ad-hoc when working on the new features/fixing stuff...

Current status:

  1. Oasis node global configuration (corresponding to yaml file) is set during cmd package initialization (config.GlobalConfig).
  2. Often, for ServiceA yaml section, we have a serviceA/config.Config field in the config.Config struct, that is used also as a service configuration.
  3. Sometimes, service configuration is dynamic or comes from multiple yaml sections (e.g. p2p service):
    • Existing pattern is to dynamically parse yaml (global config) inside service package into service config.

Naive/simpler solution:

  1. Keep existing serviceA/config.Config pattern for yaml config.
  2. Every service should have explicit configuration passed into New constructor:
    • When 1:1 mapping between yaml config and service config just pass config from 1..
    • Otherwise:
      • Create additional struct for config (this is how is done now).
      • What changes is that parsing it from yaml (if not 1:1) should be moved into config package under [service].go.
    • As a consequence config package will import all services (is the case already).

Ideal Solution
Every service should have serviceA.Config and it should not know anything about node and yaml.

On the other hand, we should configure the service in yaml ( config.Config) by:

  1. Referencing serviceA.Config directly if there is 1:1 mapping between yaml section for the service.
  2. Defining a new struct for the yaml section, together with a helper that transforms yaml to corresponding service config.

Metadata

Metadata

Assignees

Labels

goPull requests that update Go code

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions