Skip to content

Commit

Permalink
Fallback to self-healing defaults (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman authored Jun 22, 2022
1 parent d896799 commit 9ed581d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,8 @@ golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s=
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
21 changes: 20 additions & 1 deletion helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ func InitHeimdallConfigWith(homeDir string, heimdallConfigFilePath string) {
heimdallViper.SetConfigFile(heimdallConfigFilePath) // set config file explicitly
}

// Handle errors reading the config file
err := heimdallViper.ReadInConfig()
if err != nil { // Handle errors reading the config file
if err != nil {
log.Fatal(err)
}

Expand Down Expand Up @@ -228,6 +229,24 @@ func InitHeimdallConfigWith(homeDir string, heimdallConfigFilePath string) {
conf.BorRPCTimeout = DefaultBorRPCTimeout
}

if conf.SHStateSyncedInterval == 0 {
// fallback to default
Logger.Debug("Invalid self-healing StateSynced interval provided, falling back to default value", "interval", DefaultSHStateSyncedInterval)
conf.SHStateSyncedInterval = DefaultSHStateSyncedInterval
}

if conf.SHStakeUpdateInterval == 0 {
// fallback to default
Logger.Debug("Invalid self-healing StakeUpdate interval provided, falling back to default value", "interval", DefaultSHStakeUpdateInterval)
conf.SHStakeUpdateInterval = DefaultSHStakeUpdateInterval
}

if conf.SHMaxDepthDuration == 0 {
// fallback to default
Logger.Debug("Invalid self-healing max depth duration provided, falling back to default value", "duration", DefaultSHMaxDepthDuration)
conf.SHMaxDepthDuration = DefaultSHMaxDepthDuration
}

if mainRPCClient, err = rpc.Dial(conf.EthRPCUrl); err != nil {
log.Fatalln("Unable to dial via ethClient", "URL=", conf.EthRPCUrl, "chain=eth", "Error", err)
}
Expand Down
9 changes: 4 additions & 5 deletions helper/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ func init() {
}
}

// ParseConfig retrieves the default environment configuration for the
// application.
// ParseConfig retrieves the default environment configuration for the application.
func ParseConfig() (*Configuration, error) {
conf := GetDefaultHeimdallConfig()
err := viper.Unmarshal(conf)
return &conf, err
defaultConf := GetDefaultHeimdallConfig()
err := viper.Unmarshal(defaultConf)
return &defaultConf, err
}

// WriteConfigFile renders config using the template and writes it to
Expand Down

0 comments on commit 9ed581d

Please sign in to comment.