oasisprotocol / oasisprotocol/oasis-core

go: Avoid global config and pass it explicitly instead

Open
#6,271 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

go
Dominant language
Go
Stars
369
Forks
151
Avg merge
1d 3h
Merged PRs (30d)
6

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining global configuration initialization in the cmd package, especially config.GlobalConfig, and the existing service configuration patterns described in config.Config. Trace how service constructors receive configuration and how dynamic YAML parsing is handled. Done means a defined incremental refactor of one or more non-trivial services that removes their reliance on global configuration and passes explicit configuration instead.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.