1515package config
1616
1717import (
18+ "errors"
1819 "flag"
1920 "fmt"
2021 "os"
@@ -24,21 +25,83 @@ import (
2425 "gopkg.in/yaml.v2"
2526)
2627
28+ // ByronGenesisConfig holds Byron era genesis parameters
29+ type ByronGenesisConfig struct {
30+ EndSlot * uint64 `yaml:"end_slot"`
31+ Epochs * uint64 `yaml:"epochs"`
32+ EpochLength uint64 `yaml:"epoch_length"`
33+ ByronSlotsPerEpoch uint64 `yaml:"byron_slots_per_epoch"`
34+ }
35+
36+ // ShelleyGenesisConfig holds Shelley era genesis parameters
37+ type ShelleyGenesisConfig struct {
38+ EpochLength uint64 `yaml:"epoch_length"`
39+ }
40+
41+ // ShelleyTransEpoch holds transition slot/epoch info
42+ type ShelleyTransEpoch struct {
43+ FirstShelleySlot uint64 `yaml:"first_shelley_slot"`
44+ FirstShelleyEpoch uint64 `yaml:"first_shelley_epoch"`
45+ }
46+
47+ // populateByronGenesis sets defaults and validates ByronGenesisConfig
48+ func (c * Config ) populateByronGenesis () error {
49+ cfg := & c .ByronGenesis
50+ if cfg .EpochLength == 0 {
51+ cfg .EpochLength = 21600
52+ }
53+ if cfg .ByronSlotsPerEpoch == 0 {
54+ cfg .ByronSlotsPerEpoch = cfg .EpochLength
55+ }
56+ if cfg .EndSlot == nil {
57+ defaultEndSlot := uint64 (4492799 )
58+ cfg .EndSlot = & defaultEndSlot
59+ }
60+ if cfg .Epochs == nil {
61+ defaultEpochs := uint64 (208 )
62+ cfg .Epochs = & defaultEpochs
63+ }
64+ if cfg .EpochLength == 0 {
65+ return errors .New ("ByronGenesisConfig: EpochLength must be nonzero" )
66+ }
67+ if cfg .EndSlot == nil {
68+ return errors .New (
69+ "ByronGenesisConfig: EndSlot must be set (can be zero for Byron-less networks)" ,
70+ )
71+ }
72+ if cfg .Epochs == nil {
73+ return errors .New (
74+ "ByronGenesisConfig: Epochs must be set (can be zero for Byron-less networks)" ,
75+ )
76+ }
77+ return nil
78+ }
79+
80+ // populateShelleyGenesis sets defaults and validates ShelleyGenesisConfig
81+ func (c * Config ) populateShelleyGenesis () {
82+ cfg := & c .ShelleyGenesis
83+ if cfg .EpochLength == 0 {
84+ cfg .EpochLength = 432000
85+ }
86+ }
87+
2788const (
2889 DefaultInputPlugin = "chainsync"
2990 DefaultOutputPlugin = "log"
3091)
3192
3293type Config struct {
33- Plugin map [string ]map [string ]map [any ]any `yaml:"plugins"`
34- Logging LoggingConfig `yaml:"logging"`
35- ConfigFile string `yaml:"-"`
36- Input string `yaml:"input" envconfig:"INPUT"`
37- Output string `yaml:"output" envconfig:"OUTPUT"`
38- KupoUrl string `yaml:"kupo_url" envconfig:"KUPO_URL"`
39- Api ApiConfig `yaml:"api"`
40- Debug DebugConfig `yaml:"debug"`
41- Version bool `yaml:"-"`
94+ ByronGenesis ByronGenesisConfig `yaml:"byron_genesis" envconfig:"BYRON_GENESIS"`
95+ Plugin map [string ]map [string ]map [any ]any `yaml:"plugins"`
96+ Logging LoggingConfig `yaml:"logging"`
97+ ConfigFile string `yaml:"-"`
98+ Input string `yaml:"input" envconfig:"INPUT"`
99+ Output string `yaml:"output" envconfig:"OUTPUT"`
100+ KupoUrl string `yaml:"kupo_url" envconfig:"KUPO_URL"`
101+ Api ApiConfig `yaml:"api"`
102+ Debug DebugConfig `yaml:"debug"`
103+ ShelleyGenesis ShelleyGenesisConfig `yaml:"shelley_genesis" envconfig:"SHELLEY_GENESIS"`
104+ Version bool `yaml:"-"`
42105}
43106
44107type ApiConfig struct {
@@ -71,6 +134,14 @@ var globalConfig = &Config{
71134 Input : DefaultInputPlugin ,
72135 Output : DefaultOutputPlugin ,
73136 KupoUrl : "" ,
137+ ByronGenesis : ByronGenesisConfig {
138+ EpochLength : 21600 ,
139+ EndSlot : func () * uint64 { v := uint64 (4492799 ); return & v }(),
140+ Epochs : func () * uint64 { v := uint64 (208 ); return & v }(),
141+ },
142+ ShelleyGenesis : ShelleyGenesisConfig {
143+ EpochLength : 432000 ,
144+ },
74145}
75146
76147func (c * Config ) Load (configFile string ) error {
@@ -86,12 +157,15 @@ func (c *Config) Load(configFile string) error {
86157 }
87158 }
88159 // Load config values from environment variables
89- // We use "dummy" as the app name here to (mostly) prevent picking up env
90- // vars that we hadn't explicitly specified in annotations above
91160 err := envconfig .Process ("dummy" , c )
92161 if err != nil {
93162 return fmt .Errorf ("error processing environment: %w" , err )
94163 }
164+ // Populate Byron and Shelley genesis configs (from nview)
165+ if err := c .populateByronGenesis (); err != nil {
166+ return fmt .Errorf ("error populating Byron genesis: %w" , err )
167+ }
168+ c .populateShelleyGenesis ()
95169 return nil
96170}
97171
0 commit comments