You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Shared Go library providing unified configuration types, mode-aware defaults, validation, and serialization for all Sei node components (`seid`, `seictl`, `sei-k8s-controller`).
4
+
5
+
## Architecture
6
+
7
+
-**Package**: `seiconfig` (import as `github.com/sei-protocol/sei-config`)
8
+
-**Unified struct**: `SeiConfig` — single type covering all fields from both `config.toml` (Tendermint) and `app.toml` (Cosmos SDK + Sei)
9
+
-**Legacy IO**: Reads/writes the existing two-file layout via intermediate legacy types in `legacy.go`; atomic writes (temp + rename) prevent corruption
-**Idiomatic Go above all.** Prefer clarity over cleverness. Three explicit lines beat a cryptic one-liner.
29
+
-**No unnecessary abstractions.** This is a leaf library — keep it flat. Don't add interfaces until there are two concrete implementations.
30
+
-**Zero `panic`.** Every failure path must return an error. Callers (seid, seictl, controller) decide how to handle it.
31
+
-**All code must pass `golangci-lint`** (config in `.golangci.yml`). Fix lint issues at the source — do not add `nolint` directives without a comment explaining why suppression is the only option.
32
+
-**Imports grouped**: stdlib, external, then `github.com/sei-protocol/sei-config` (enforced by goimports).
33
+
-**Exported types are the contract.** Every exported type, function, and constant must have a doc comment. Unexported helpers don't need them unless the logic is non-obvious.
34
+
-**Struct tags are the schema.** TOML tags on `SeiConfig` define the unified `sei.toml` key names. Legacy TOML tags on `legacy*.go` types must exactly match the existing `config.toml`/`app.toml` key names — do not change them without a migration plan.
35
+
-**Keep `SeiConfig` and legacy types in sync.** Every field added to `SeiConfig` must have corresponding legacy mapping in `toLegacyTendermint()`/`toLegacyApp()` and `fromLegacy()`. Tests enforce round-trip fidelity.
36
+
37
+
### Defaults & Modes
38
+
39
+
-`DefaultForMode(mode)` is the single entry point. Baseline defaults live in `baseDefaults()`, mode overrides in `apply*Overrides()`.
40
+
- When adding a new field: add to `baseDefaults()` with the safe/common default, then add mode-specific values only where they differ.
41
+
- Every mode's defaults must pass `Validate()` — this is enforced by `TestDefaultForMode_AllModesValid`.
42
+
43
+
### Validation
44
+
45
+
- Validation returns `*ValidationResult` with typed `Diagnostic` entries — never `error` directly.
46
+
-`SeverityError` = blocks startup. `SeverityWarning` = logged. Use the right severity.
47
+
- Cross-field checks go in `validateCrossField()`.
48
+
49
+
### Testing
50
+
51
+
- Tests use the `testing` package only — no assertion libraries, no test frameworks.
52
+
- Run tests with `make test` before submitting changes.
53
+
- Every new field should be exercised in at least one round-trip test (`WriteConfigToDir` → `ReadConfigFromDir`).
54
+
- Test file naming: `config_test.go` for the main test file. Add `*_test.go` files when a single file grows past ~500 lines.
55
+
56
+
## Build & Validate
57
+
58
+
```bash
59
+
make test# Run all tests
60
+
make lint # Run golangci-lint
61
+
make vet # Run go vet
62
+
make fmt # Format all code (gofmt -s)
63
+
make ci # lint + vet + test (what CI runs)
64
+
make test-cover # Tests with coverage report
65
+
```
66
+
67
+
## Design Constraints
68
+
69
+
-**This is a library, not a binary.** There is no `main` package. Consumers are `seid`, `seictl`, and `sei-k8s-controller`.
70
+
-**Minimal dependencies.** Think hard before adding a new `require`. Every dependency here transitively affects three other repos.
71
+
-**Phase-aware IO.**`ReadConfigFromDir`/`WriteConfigToDir` currently handle the two-file layout (Phase 2). When Phase 3 ships unified `sei.toml`, the IO layer switches internally — callers should not need to change.
72
+
-**Backward compatibility matters.** The legacy types in `legacy.go` must produce TOML files that existing `seid` binaries can read. Changing a legacy TOML tag is a breaking change.
0 commit comments