Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash around setting current epoch #79

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,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 @@ -417,7 +416,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 @@ -486,7 +485,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 @@ -499,10 +500,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
Loading