From dab22b7f8d5b633c3f0e65f3fb115a1d3f8aa1a7 Mon Sep 17 00:00:00 2001 From: remoterami <142154971+remoterami@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:46:19 +0100 Subject: [PATCH] CR: rewards --- backend/pkg/api/data_access/vdb_management.go | 17 +++++---- backend/pkg/api/data_access/vdb_rewards.go | 37 ++++++------------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/backend/pkg/api/data_access/vdb_management.go b/backend/pkg/api/data_access/vdb_management.go index a50ab703f..435756bef 100644 --- a/backend/pkg/api/data_access/vdb_management.go +++ b/backend/pkg/api/data_access/vdb_management.go @@ -374,12 +374,18 @@ func (d *DataAccessService) GetValidatorDashboardOverview(ctx context.Context, d // Balance validatorBalance := utils.GWeiToWei(big.NewInt(int64(metadata.Balance))) effectiveBalance := utils.GWeiToWei(big.NewInt(int64(metadata.EffectiveBalance))) + data.Balances.Effective = data.Balances.Effective.Add(effectiveBalance) - if rpInfos == nil { + handleNonRpDashboard := func() { data.Balances.Total = data.Balances.Total.Add(validatorBalance) - nonRpDashboardId.Validators = append(nonRpDashboardId.Validators, validator) - } else if rpValidator, ok := rpInfos.Minipool[validator]; ok { + } + + if rpInfos == nil { + handleNonRpDashboard() + } else if rpValidator, ok := rpInfos.Minipool[validator]; !ok { + handleNonRpDashboard() + } else { if protocolModes.RocketPool { // Calculate the balance of the operator fullDeposit := rpValidator.UserDepositBalance.Add(rpValidator.NodeDepositBalance) @@ -397,12 +403,7 @@ func (d *DataAccessService) GetValidatorDashboardOverview(ctx context.Context, d data.Balances.Total = data.Balances.Total.Add(validatorBalance) } data.Balances.StakedEth = data.Balances.StakedEth.Add(rpValidator.NodeDepositBalance) - } else { - data.Balances.Total = data.Balances.Total.Add(validatorBalance) - - nonRpDashboardId.Validators = append(nonRpDashboardId.Validators, validator) } - data.Balances.Effective = data.Balances.Effective.Add(effectiveBalance) } // Get the total cl deposits for non-rocketpool validators diff --git a/backend/pkg/api/data_access/vdb_rewards.go b/backend/pkg/api/data_access/vdb_rewards.go index 134143691..ed8e17e15 100644 --- a/backend/pkg/api/data_access/vdb_rewards.go +++ b/backend/pkg/api/data_access/vdb_rewards.go @@ -87,7 +87,7 @@ func (d *DataAccessService) GetValidatorDashboardRewards(ctx context.Context, da } // ------------------------------------------------------------------------------------------------------------------ - // Build the main and EL rewards queries + // Build the main (CL) and EL rewards queries rewardsDs := goqu.Dialect("postgres"). From(goqu.L("validator_dashboard_data_epoch e")). With("validators", goqu.L("(SELECT validator_index as validator_index, group_id FROM users_val_dashboards_validators WHERE dashboard_id = ?)", dashboardId.Id)). @@ -348,7 +348,7 @@ func (d *DataAccessService) GetValidatorDashboardRewards(ctx context.Context, da err = d.clickhouseReader.SelectContext(ctx, &queryResult, query, args...) if err != nil { - return fmt.Errorf("error retrieving rewards data: %v", err) + return fmt.Errorf("error retrieving rewards data: %w", err) } validatorGroupMap := make(map[uint64]int64) @@ -821,9 +821,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex elReward := elRewards[entry.ValidatorIndex].Mul(rpFactor) if rpInfos != nil && protocolModes.RocketPool { if _, ok := rpInfos.Minipool[entry.ValidatorIndex]; ok { - if _, ok := rpInfos.Minipool[entry.ValidatorIndex].SmoothingPoolRewards[epoch]; ok { - elReward = elReward.Add(rpInfos.Minipool[entry.ValidatorIndex].SmoothingPoolRewards[epoch]) - } + elReward = elReward.Add(rpInfos.Minipool[entry.ValidatorIndex].SmoothingPoolRewards[epoch]) } } @@ -973,7 +971,7 @@ func (d *DataAccessService) GetValidatorDashboardRewardsChart(ctx context.Contex err = d.clickhouseReader.SelectContext(ctx, &queryResult, query, args...) if err != nil { - return fmt.Errorf("error retrieving rewards chart data: %v", err) + return fmt.Errorf("error retrieving rewards chart data: %w", err) } validatorGroupMap := make(map[uint64]uint64) @@ -1331,28 +1329,10 @@ func (d *DataAccessService) GetValidatorDashboardDuties(ctx context.Context, das err = d.clickhouseReader.SelectContext(ctx, &queryResult, query, args...) if err != nil { - return fmt.Errorf("error retrieving validator rewards data: %v", err) + return fmt.Errorf("error retrieving validator rewards data: %w", err) } for _, entry := range queryResult { - queryResultAdjusted = append(queryResultAdjusted, QueryResultAdjusted{ - QueryResultBase: QueryResultBase{ - ValidatorIndex: entry.ValidatorIndex, - AttestationsScheduled: entry.AttestationsScheduled, - AttestationsSourceExecuted: entry.AttestationsSourceExecuted, - AttestationsTargetExecuted: entry.AttestationsTargetExecuted, - AttestationsHeadExecuted: entry.AttestationsHeadExecuted, - SyncScheduled: entry.SyncScheduled, - SyncExecuted: entry.SyncExecuted, - Slashed: entry.Slashed, - BlocksSlashingCount: entry.BlocksSlashingCount, - BlocksScheduled: entry.BlocksScheduled, - BlocksProposed: entry.BlocksProposed, - }, - }) - - current := &queryResultAdjusted[len(queryResultAdjusted)-1] - rpFactor := decimal.NewFromInt(1) if rpInfos != nil && protocolModes.RocketPool { if rpValidator, ok := rpInfos.Minipool[entry.ValidatorIndex]; ok { @@ -1360,6 +1340,8 @@ func (d *DataAccessService) GetValidatorDashboardDuties(ctx context.Context, das } } + current := QueryResultAdjusted{QueryResultBase: entry.QueryResultBase} + current.AttestationsSourceReward = utils.GWeiToWei(big.NewInt(entry.AttestationsSourceReward)).Mul(rpFactor) current.AttestationsTargetReward = utils.GWeiToWei(big.NewInt(entry.AttestationsTargetReward)).Mul(rpFactor) current.AttestationsHeadReward = utils.GWeiToWei(big.NewInt(entry.AttestationsHeadReward)).Mul(rpFactor) @@ -1367,6 +1349,8 @@ func (d *DataAccessService) GetValidatorDashboardDuties(ctx context.Context, das current.BlocksClSlasherReward = utils.GWeiToWei(big.NewInt(entry.BlocksClSlasherReward)).Mul(rpFactor) current.BlocksClAttestationsReward = utils.GWeiToWei(big.NewInt(entry.BlocksClAttestationsReward)).Mul(rpFactor) current.BlocksClSyncAggregateReward = utils.GWeiToWei(big.NewInt(entry.BlocksClSyncAggregateReward)).Mul(rpFactor) + + queryResultAdjusted = append(queryResultAdjusted, current) } return nil @@ -1438,8 +1422,9 @@ func (d *DataAccessService) GetValidatorDashboardDuties(ctx context.Context, das if res.Slashed { if res.BlocksSlashingCount > 0 { slashedEvent.Status = "partial" + } else { + slashedEvent.Status = "failed" } - slashedEvent.Status = "failed" } else if res.BlocksSlashingCount > 0 { slashedEvent.Status = "success" }