Skip to content

Commit

Permalink
feat: fill efficiency field in dashboard group summary
Browse files Browse the repository at this point in the history
See: BEDS-1065
  • Loading branch information
LuccaBitfly committed Jan 8, 2025
1 parent cfe2495 commit 71cc094
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions backend/pkg/api/data_access/vdb_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,13 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
totalBlockChance := float64(0)
totalInclusionDelaySum := int64(0)
totalInclusionDelayDivisor := int64(0)

totalSyncExpected := float64(0)
totalProposals := uint32(0)
totalSyncScheduled := uint32(0)
totalSyncExecuted := uint32(0)

totalBlocksScheduled := uint32(0)
totalBlocksProposed := uint32(0)

validatorArr := make([]t.VDBValidator, 0)
for _, row := range rows {
Expand All @@ -699,15 +704,18 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
if row.ValidatorIndex == 0 && row.BlocksProposed > 0 && row.BlocksProposed != row.BlocksScheduled {
row.BlocksProposed-- // subtract the genesis block from validator 0 (TODO: remove when fixed in the dashoard data exporter)
}

totalProposals += row.BlocksScheduled
totalBlocksProposed += row.BlocksProposed
totalBlocksScheduled += row.BlocksScheduled
if row.BlocksScheduled > 0 {
if ret.ProposalValidators == nil {
ret.ProposalValidators = make([]t.VDBValidator, 0, 10)
}
ret.ProposalValidators = append(ret.ProposalValidators, t.VDBValidator(row.ValidatorIndex))
}

totalSyncScheduled += row.SyncScheduled
totalSyncExecuted += row.SyncExecuted

ret.SyncCommittee.StatusCount.Success += uint64(row.SyncExecuted)
ret.SyncCommittee.StatusCount.Failed += uint64(row.SyncScheduled) - uint64(row.SyncExecuted)

Expand Down Expand Up @@ -773,7 +781,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
}

if totalBlockChance > 0 {
ret.Luck.Proposal.Percent = (float64(totalProposals)) / totalBlockChance * 100
ret.Luck.Proposal.Percent = (float64(totalBlocksScheduled)) / totalBlockChance * 100

// calculate the average time it takes for the set of validators to propose a single block on average
ret.Luck.Proposal.AverageIntervalSeconds = uint64(time.Duration((luckHours / totalBlockChance) * float64(time.Hour)).Seconds())
Expand Down Expand Up @@ -825,6 +833,20 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
ret.SyncCommittee.Validators = ret.SyncCommittee.Validators[:3]
}
}
var attestationEfficiency, proposerEfficiency, syncEfficiency sql.NullFloat64
if totalIdealAttestationRewards > 0 {
attestationEfficiency.Float64 = decimal.NewFromInt(totalAttestationRewards).Div(decimal.NewFromInt(totalIdealAttestationRewards)).InexactFloat64()
attestationEfficiency.Valid = true
}
if totalBlocksScheduled > 0 {
proposerEfficiency.Float64 = float64(totalBlocksProposed) / float64(totalBlocksScheduled)
proposerEfficiency.Valid = true
}
if totalSyncScheduled > 0 {
syncEfficiency.Float64 = float64(totalSyncExecuted) / float64(totalSyncScheduled)
syncEfficiency.Valid = true
}
ret.Efficiency = utils.CalculateTotalEfficiency(attestationEfficiency, proposerEfficiency, syncEfficiency)

return ret, nil
}
Expand Down

0 comments on commit 71cc094

Please sign in to comment.