Skip to content

Commit

Permalink
add(dashboard): missed EL rewards for group summary
Browse files Browse the repository at this point in the history
* See BEDS-175
  • Loading branch information
sasha-bitfly committed Jan 15, 2025
1 parent 5c40cb5 commit 7faa26a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions backend/pkg/api/data_access/vdb_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,45 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
return nil, err
}

getMissedELRewards := func(validatorId uint32, epochStart, epochEnd uint64) (float64, error) {
// Initialize the result variable
var missedElRewards float64

// Execute the query
err := d.readerDb.GetContext(ctx, &missedElRewards,
`SELECT
COALESCE(SUM(v), 0) AS total_median_rewards
FROM (
SELECT
a.slot,
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY b.value)::numeric(76,0) AS v
FROM (
SELECT
b.slot AS slot
FROM
blocks b
WHERE
b.proposer = $1
AND b.status != '1'
AND b.epoch BETWEEN $2 AND $3
) a
LEFT JOIN
execution_rewards_finalized b
ON
(b.slot BETWEEN a.slot - 16 AND a.slot + 16)
GROUP BY
a.slot
) res;`, validatorId, epochStart, epochEnd)

// Handle query execution error
if err != nil {
return 0, fmt.Errorf("failed to execute query: %w", err)
}

// Return the computed total median rewards
return missedElRewards, nil
}

getLastScheduledBlockAndSyncDate := func() (time.Time, time.Time, error) {
// we need to go to the all time table for last scheduled block/sync committee epoch
clickhouseTotalTable, _, err := d.getTablesForPeriod(enums.AllTime)
Expand Down Expand Up @@ -569,6 +608,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
Select(
goqu.L("validator_index"),
goqu.L("epoch_start"),
goqu.L("epoch_end"),
goqu.L("attestations_reward"),
goqu.L("attestations_ideal_reward"),
goqu.L("attestations_scheduled"),
Expand Down Expand Up @@ -604,6 +644,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
type QueryResult struct {
ValidatorIndex uint32 `db:"validator_index"`
EpochStart uint64 `db:"epoch_start"`
EpochEnd uint64 `db:"epoch_end"`
AttestationReward int64 `db:"attestations_reward"`
AttestationsIdealReward int64 `db:"attestations_ideal_reward"`

Expand Down Expand Up @@ -679,6 +720,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
totalBlocksScheduled := uint32(0)
totalBlocksProposed := uint32(0)

totalMissedRewardsEl := float64(0)
totalMissedRewardsCl := int64(0)
totalMissedRewardsAttestations := int64(0)
totalMissedRewardsSync := int64(0)
Expand All @@ -698,6 +740,12 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
ret.AttestationsTarget.Success += uint64(row.AttestationsTargetExecuted)
ret.AttestationsTarget.Failed += uint64(row.AttestationsScheduled) - uint64(row.AttestationsTargetExecuted)

missedRewards, err := getMissedELRewards(row.ValidatorIndex, row.EpochStart, row.EpochEnd)
if err != nil {
return nil, err
}

totalMissedRewardsEl += missedRewards
totalMissedRewardsCl += row.BlocksCLMissedReward
totalMissedRewardsAttestations += row.AttestationsIdealReward - row.AttestationsRewardRewardsOnly
totalMissedRewardsSync += row.SyncLocalizedMaxRewards - row.SyncRewardRewardsOnly
Expand Down Expand Up @@ -754,6 +802,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
ret.MissedRewards.Attestations = utils.GWeiToWei(big.NewInt(totalMissedRewardsAttestations))
ret.MissedRewards.Sync = utils.GWeiToWei(big.NewInt(totalMissedRewardsSync))
ret.MissedRewards.ProposerRewards.Cl = utils.GWeiToWei(big.NewInt(totalMissedRewardsCl))
//ret.MissedRewards.ProposerRewards.El = utils.GWeiToEther(big.NewInt(totalMissedRewardsEl))

ret.Rewards.El, ret.Apr.El, ret.Rewards.Cl, ret.Apr.Cl, err = d.getElClAPR(ctx, dashboardId, groupId, hours)
if err != nil {
Expand Down

0 comments on commit 7faa26a

Please sign in to comment.