Skip to content

Commit

Permalink
Merge pull request #79 from blinklabs-io/fix/crash-current-epoch
Browse files Browse the repository at this point in the history
fix: crash around setting current epoch
  • Loading branch information
wolf31o2 authored Sep 24, 2023
2 parents db010f8 + 758ce23 commit 14ffd7e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ func main() {
)
}
// Set current epoch from Prometheus metrics
currentEpoch = uint32(metrics.EpochNum)
// TODO: temp hack to use currentEpoch
if currentEpoch > 0 {
// Do something non-useful
text.SetText(fmt.Sprintf("%d", currentEpoch))
if metrics != nil {
currentEpoch = uint32(metrics.EpochNum)
} else {
currentEpoch = 0
}

// Populate initial text from metrics
Expand Down Expand Up @@ -418,7 +417,7 @@ func getHomeText(ctx context.Context, promMetrics *PromMetrics) string {
if role != "Core" {
role = "Core"
}
} else if promMetrics.AboutToLead > 0 {
} else if promMetrics != nil && promMetrics.AboutToLead > 0 {
if role != "Core" {
role = "Core"
}
Expand Down Expand Up @@ -487,7 +486,9 @@ func getHomeText(ctx context.Context, promMetrics *PromMetrics) string {
// Epoch progress
var epochProgress float32
genesisConfig := getGenesisConfig(cfg)
if promMetrics.EpochNum >= uint64(cfg.Node.ShelleyTransEpoch) {
if promMetrics == nil {
epochProgress = float32(0.0)
} else if promMetrics.EpochNum >= uint64(cfg.Node.ShelleyTransEpoch) {
epochProgress = float32(
(float32(promMetrics.SlotInEpoch) / float32(genesisConfig.EpochLength)) * 100,
)
Expand All @@ -500,10 +501,13 @@ func getHomeText(ctx context.Context, promMetrics *PromMetrics) string {
// epochTimeLeft := timeLeft(timeUntilNextEpoch())

// Epoch
if promMetrics != nil {
currentEpoch = uint32(promMetrics.EpochNum)
}
sb.WriteString(
fmt.Sprintf(
" Epoch [blue]%d[white] [[blue]%s%%[white]], [blue]%s[white] %-12s\n",
promMetrics.EpochNum,
currentEpoch,
epochProgress1dec,
"N/A",
"remaining",
Expand Down

0 comments on commit 14ffd7e

Please sign in to comment.