1515package config
1616
1717import (
18+ "errors"
1819 "flag"
1920 "fmt"
2021 "os"
@@ -24,21 +25,79 @@ import (
2425 "gopkg.in/yaml.v2"
2526)
2627
28+ // ByronGenesisConfig holds Byron era genesis parameters
29+ type ByronGenesisConfig struct {
30+ EpochLength uint64 `yaml:"epoch_length"`
31+ ByronSlotsPerEpoch uint64 `yaml:"byron_slots_per_epoch"`
32+ EndSlot * uint64 `yaml:"end_slot"`
33+ Epochs * uint64 `yaml:"epochs"`
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 ("ByronGenesisConfig: EndSlot must be set (can be zero for Byron-less networks)" )
69+ }
70+ if cfg .Epochs == nil {
71+ return errors .New ("ByronGenesisConfig: Epochs must be set (can be zero for Byron-less networks)" )
72+ }
73+ return nil
74+ }
75+
76+ // populateShelleyGenesis sets defaults and validates ShelleyGenesisConfig
77+ func (c * Config ) populateShelleyGenesis () {
78+ cfg := & c .ShelleyGenesis
79+ if cfg .EpochLength == 0 {
80+ cfg .EpochLength = 432000
81+ }
82+ }
83+
2784const (
2885 DefaultInputPlugin = "chainsync"
2986 DefaultOutputPlugin = "log"
3087)
3188
3289type 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:"-"`
90+ Plugin map [string ]map [string ]map [any ]any `yaml:"plugins"`
91+ Logging LoggingConfig `yaml:"logging"`
92+ ConfigFile string `yaml:"-"`
93+ Input string `yaml:"input" envconfig:"INPUT"`
94+ Output string `yaml:"output" envconfig:"OUTPUT"`
95+ KupoUrl string `yaml:"kupo_url" envconfig:"KUPO_URL"`
96+ Api ApiConfig `yaml:"api"`
97+ Debug DebugConfig `yaml:"debug"`
98+ ByronGenesis ByronGenesisConfig `yaml:"byron_genesis" envconfig:"BYRON_GENESIS"`
99+ ShelleyGenesis ShelleyGenesisConfig `yaml:"shelley_genesis" envconfig:"SHELLEY_GENESIS"`
100+ Version bool `yaml:"-"`
42101}
43102
44103type ApiConfig struct {
@@ -71,6 +130,14 @@ var globalConfig = &Config{
71130 Input : DefaultInputPlugin ,
72131 Output : DefaultOutputPlugin ,
73132 KupoUrl : "" ,
133+ ByronGenesis : ByronGenesisConfig {
134+ EpochLength : 21600 ,
135+ EndSlot : func () * uint64 { v := uint64 (4492799 ); return & v }(),
136+ Epochs : func () * uint64 { v := uint64 (208 ); return & v }(),
137+ },
138+ ShelleyGenesis : ShelleyGenesisConfig {
139+ EpochLength : 432000 ,
140+ },
74141}
75142
76143func (c * Config ) Load (configFile string ) error {
@@ -86,12 +153,15 @@ func (c *Config) Load(configFile string) error {
86153 }
87154 }
88155 // 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
91156 err := envconfig .Process ("dummy" , c )
92157 if err != nil {
93158 return fmt .Errorf ("error processing environment: %w" , err )
94159 }
160+ // Populate Byron and Shelley genesis configs (from nview)
161+ if err := c .populateByronGenesis (); err != nil {
162+ return fmt .Errorf ("error populating Byron genesis: %w" , err )
163+ }
164+ c .populateShelleyGenesis ()
95165 return nil
96166}
97167
0 commit comments