Skip to content

Commit

Permalink
Merge pull request #2961 from gobitfly/NOBIDS/cache_validator_status_…
Browse files Browse the repository at this point in the history
…counts

fix(validators): refresh status count only once per hour
  • Loading branch information
guybrush authored Sep 30, 2024
2 parents ec286c7 + 5b0dcab commit 08cc84f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion handlers/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Validators(w http.ResponseWriter, r *http.Request) {

currentStateCounts := services.LatestValidatorStateCounts()

for _, state := range currentStateCounts {
for _, state := range *currentStateCounts {
switch state.Name {
case "pending":
validatorsPageData.PendingCount = state.Count
Expand Down
2 changes: 1 addition & 1 deletion services/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func startServicesMonitoringService() {
"statistics": time.Minute * 90,
"ethStoreStatistics": time.Minute * 15,
"lastExportedStatisticDay": time.Minute * 15,
"validatorStateCountsUpdater": time.Minute * 15,
"validatorStateCountsUpdater": time.Minute * 90,
//"notification-sender", //exclude for now as the sender is only running on mainnet
}

Expand Down
10 changes: 5 additions & 5 deletions services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1797,17 +1797,17 @@ func validatorStateCountsUpdater(wg *sync.WaitGroup) {
}
}
ReportStatus("validatorStateCountsUpdater", "Running", nil)
time.Sleep(time.Minute)
time.Sleep(time.Minute * 60)
}
}

func LatestValidatorStateCounts() []types.ValidatorStateCountRow {
func LatestValidatorStateCounts() *[]types.ValidatorStateCountRow {
wanted := []types.ValidatorStateCountRow{}
cacheKey := fmt.Sprintf("%d:frontend:validator_state_counts", utils.Config.Chain.ClConfig.DepositChainID)
if wanted, err := cache.TieredCache.GetWithLocalTimeout(cacheKey, time.Minute, wanted); err == nil {
return wanted.([]types.ValidatorStateCountRow)
if wanted, err := cache.TieredCache.GetWithLocalTimeout(cacheKey, time.Minute, &wanted); err == nil {
return wanted.(*[]types.ValidatorStateCountRow)
} else {
logger.Errorf("error retrieving validator state count data from cache: %v", err)
}
return wanted
return &wanted
}

0 comments on commit 08cc84f

Please sign in to comment.