Skip to content

Commit e7812bd

Browse files
remoteramienzo-bitfly
authored andcommitted
refactor: unified percent scaling
1 parent cdad4b6 commit e7812bd

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

backend/pkg/api/data_access/vdb_helpers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ func calcAPR(rewards, cumulativeDivisor decimal.Decimal, duration time.Duration)
212212
return 0
213213
}
214214
annualizationFactor := decimal.NewFromInt(utils.Year.Nanoseconds()).Div(decimal.NewFromInt(duration.Nanoseconds()))
215-
percentScaleFactor := decimal.NewFromInt(100) // TODO remove BEDS-1147
216-
return rewards.Div(cumulativeDivisor).Mul(annualizationFactor).Mul(percentScaleFactor).InexactFloat64()
215+
return rewards.Div(cumulativeDivisor).Mul(annualizationFactor).InexactFloat64()
217216
}
218217

219218
// converts a cl amount to the main currency

backend/pkg/api/data_access/vdb_management.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ func (d *DataAccessService) GetValidatorDashboardOverview(ctx context.Context, d
412412
}
413413

414414
*efficiency, err = runQuery[float64](ctx, d.clickhouseReader, ds)
415-
*efficiency *= 100
416415
return err
417416
})
418417
}

backend/pkg/api/data_access/vdb_rewards.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,15 @@ func (d *DataAccessService) GetValidatorDashboardRewards(ctx context.Context, da
367367
for _, res := range queryResult {
368368
duty := t.VDBRewardsTableDuty{}
369369
if res.AttestationsScheduled > 0 {
370-
attestationPercentage := (float64(res.AttestationsExecuted) / float64(res.AttestationsScheduled)) * 100.0
370+
attestationPercentage := (float64(res.AttestationsExecuted) / float64(res.AttestationsScheduled))
371371
duty.Attestation = &attestationPercentage
372372
}
373373
if res.BlocksScheduled > 0 {
374-
ProposalPercentage := (float64(res.BlocksProposed) / float64(res.BlocksScheduled)) * 100.0
374+
ProposalPercentage := (float64(res.BlocksProposed) / float64(res.BlocksScheduled))
375375
duty.Proposal = &ProposalPercentage
376376
}
377377
if res.SyncScheduled > 0 {
378-
SyncPercentage := (float64(res.SyncExecuted) / float64(res.SyncScheduled)) * 100.0
378+
SyncPercentage := (float64(res.SyncExecuted) / float64(res.SyncScheduled))
379379
duty.Sync = &SyncPercentage
380380
}
381381

@@ -425,15 +425,15 @@ func (d *DataAccessService) GetValidatorDashboardRewards(ctx context.Context, da
425425

426426
duty := t.VDBRewardsTableDuty{}
427427
if totalInfo.AttestationsScheduled > 0 {
428-
attestationPercentage := (float64(totalInfo.AttestationsExecuted) / float64(totalInfo.AttestationsScheduled)) * 100.0
428+
attestationPercentage := (float64(totalInfo.AttestationsExecuted) / float64(totalInfo.AttestationsScheduled))
429429
duty.Attestation = &attestationPercentage
430430
}
431431
if totalInfo.BlocksScheduled > 0 {
432-
proposalPercentage := (float64(totalInfo.BlocksProposed) / float64(totalInfo.BlocksScheduled)) * 100.0
432+
proposalPercentage := (float64(totalInfo.BlocksProposed) / float64(totalInfo.BlocksScheduled))
433433
duty.Proposal = &proposalPercentage
434434
}
435435
if totalInfo.SyncScheduled > 0 {
436-
SyncPercentage := (float64(totalInfo.SyncExecuted) / float64(totalInfo.SyncScheduled)) * 100.0
436+
SyncPercentage := (float64(totalInfo.SyncExecuted) / float64(totalInfo.SyncScheduled))
437437
duty.Sync = &SyncPercentage
438438
}
439439

backend/pkg/api/data_access/vdb_summary.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (d *DataAccessService) GetValidatorDashboardSummary(ctx context.Context, da
9393
}
9494
var averageNetworkEfficiency float64
9595
if efficiency.TotalEfficiency[period].Valid {
96-
averageNetworkEfficiency = efficiency.TotalEfficiency[period].Float64 * 100
96+
averageNetworkEfficiency = efficiency.TotalEfficiency[period].Float64
9797
}
9898

9999
// ------------------------------------------------------------------------------------------------------------------
@@ -738,7 +738,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
738738
}
739739

740740
if totalBlockChance > 0 {
741-
ret.Luck.Proposal.Percent = (float64(totalBlocksScheduled)) / totalBlockChance * 100
741+
ret.Luck.Proposal.Percent = (float64(totalBlocksScheduled)) / totalBlockChance
742742

743743
// calculate the average time it takes for the set of validators to propose a single block on average
744744
ret.Luck.Proposal.AverageIntervalSeconds = uint64(time.Duration((luckHours / totalBlockChance) * float64(time.Hour)).Seconds())
@@ -754,7 +754,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
754754
totalSyncSlotDuties := float64(ret.SyncCommittee.StatusCount.Failed) + float64(ret.SyncCommittee.StatusCount.Success)
755755
slotDutiesPerSyncCommittee := float64(utils.SlotsPerSyncCommittee())
756756
syncCommittees := math.Ceil(totalSyncSlotDuties / slotDutiesPerSyncCommittee) // gets the number of sync committees
757-
ret.Luck.Sync.Percent = syncCommittees / totalSyncExpected * 100
757+
ret.Luck.Sync.Percent = syncCommittees / totalSyncExpected
758758

759759
// calculate the average time it takes for the set of validators to be elected into a sync committee on average
760760
ret.Luck.Sync.AverageIntervalSeconds = uint64(time.Duration((luckHours / totalSyncExpected) * float64(time.Hour)).Seconds())
@@ -817,7 +817,7 @@ func calcEfficiency(dividend, divisor decimal.Decimal) float64 {
817817
if divisor.IsZero() {
818818
return 0
819819
}
820-
return dividend.Div(divisor).InexactFloat64() * 100
820+
return dividend.Div(divisor).InexactFloat64()
821821
}
822822

823823
// for summary charts: series id is group id, no stack
@@ -945,9 +945,9 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
945945
if data[row.Timestamp][row.GroupId] == 0 {
946946
continue
947947
}
948-
if data[row.Timestamp][row.GroupId] > 100 {
948+
if data[row.Timestamp][row.GroupId] > 1 {
949949
log.Error(nil, "efficiency is greater than 100%", 0, map[string]interface{}{"efficiency": efficiency})
950-
data[row.Timestamp][row.GroupId] = 100
950+
data[row.Timestamp][row.GroupId] = 1
951951
}
952952
groupMap[row.GroupId] = true
953953
}
@@ -971,7 +971,7 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
971971
}
972972
var averageNetworkEfficiency float64
973973
if efficiency.AttestationEfficiency[enums.Last24h].Valid {
974-
averageNetworkEfficiency = efficiency.AttestationEfficiency[enums.Last24h].Float64 * 100
974+
averageNetworkEfficiency = efficiency.AttestationEfficiency[enums.Last24h].Float64
975975
}
976976

977977
for ts := range tsMap {
@@ -990,9 +990,9 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
990990
if data[row.Timestamp][totalLineGroupId] == 0 {
991991
continue
992992
}
993-
if data[row.Timestamp][totalLineGroupId] > 100 {
993+
if data[row.Timestamp][totalLineGroupId] > 1 {
994994
log.Error(nil, "efficiency is greater than 100%", 0, map[string]interface{}{"efficiency": efficiency})
995-
data[row.Timestamp][totalLineGroupId] = 100
995+
data[row.Timestamp][totalLineGroupId] = 1
996996
}
997997
}
998998
groupMap[totalLineGroupId] = true

0 commit comments

Comments
 (0)