oasisprotocol / oasisprotocol/oasis-core
go: Avoid global config and pass it explicitly instead
Nobody has claimed this yet.
- 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:
- Oasis node global configuration (corresponding to yaml file) is set during
cmdpackage initialization (config.GlobalConfig). - Often, for
ServiceAyaml section, we have aserviceA/config.Configfield in theconfig.Configstruct, that is used also as a service configuration. - 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:
- Keep existing
serviceA/config.Configpattern for yaml config. - Every service should have explicit configuration passed into
Newconstructor:- 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
configpackage 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:
- Referencing
serviceA.Configdirectly if there is1:1mapping between yaml section for the service. - Defining a new struct for the yaml section, together with a helper that transforms yaml to corresponding service config.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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