Skip to content

Commit

Permalink
Merge pull request #97 from blinklabs-io/chore/golines
Browse files Browse the repository at this point in the history
chore: run golines
  • Loading branch information
wolf31o2 authored Oct 26, 2023
2 parents 0bf59d1 + 1365b9b commit f97b49a
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 73 deletions.
14 changes: 11 additions & 3 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func getNodeMetrics(ctx context.Context) ([]byte, int, error) {
return respBodyBytes, http.StatusInternalServerError, err
}
// Set a 3 second timeout
ctx, cancel := context.WithTimeout(ctx, time.Second*time.Duration(cfg.Prometheus.Timeout))
ctx, cancel := context.WithTimeout(
ctx,
time.Second*time.Duration(cfg.Prometheus.Timeout),
)
defer cancel()
req = req.WithContext(ctx)
// Get metrics from the node
Expand Down Expand Up @@ -86,7 +89,9 @@ func getEpoch() uint64 {
func getSlotTipRef(g *localstatequery.GenesisConfigResult) uint64 {
cfg := config.GetConfig()
currentTimeSec := uint64(time.Now().Unix() - 1)
byronSlots := uint64(cfg.Node.ShelleyTransEpoch) * cfg.Node.ByronGenesis.EpochLength
byronSlots := uint64(
cfg.Node.ShelleyTransEpoch,
) * cfg.Node.ByronGenesis.EpochLength
byronEndTime := cfg.Node.ByronGenesis.StartTime + ((uint64(cfg.Node.ShelleyTransEpoch) * cfg.Node.ByronGenesis.EpochLength * cfg.Node.ByronGenesis.SlotLength) / 1000)
if currentTimeSec < byronEndTime {
return ((currentTimeSec - cfg.Node.ByronGenesis.StartTime) * 1000) / cfg.Node.ByronGenesis.SlotLength
Expand All @@ -95,7 +100,10 @@ func getSlotTipRef(g *localstatequery.GenesisConfigResult) uint64 {
}

// Calculate KES expiration from node metrics
func kesExpiration(g *localstatequery.GenesisConfigResult, p *PromMetrics) time.Time {
func kesExpiration(
g *localstatequery.GenesisConfigResult,
p *PromMetrics,
) time.Time {
currentTimeSec := uint64(time.Now().Unix() - 1)
expirationTimeSec := currentTimeSec - (uint64(g.SlotLength/1000000) * (getSlotTipRef(g) % uint64(g.SlotsPerKESPeriod))) + (uint64(g.SlotLength/1000000) + uint64(g.SlotsPerKESPeriod)*p.RemainingKesPeriods)
return time.Unix(int64(expirationTimeSec), 0)
Expand Down
Loading

0 comments on commit f97b49a

Please sign in to comment.