Skip to content

Commit

Permalink
CR: rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
remoterami committed Dec 5, 2024
1 parent 2719699 commit dab22b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 34 deletions.
17 changes: 9 additions & 8 deletions backend/pkg/api/data_access/vdb_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
37 changes: 11 additions & 26 deletions backend/pkg/api/data_access/vdb_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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])
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1331,42 +1329,28 @@ 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 {
rpFactor = d.getRocketPoolOperatorFactor(rpValidator)
}
}

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)
current.SyncRewards = utils.GWeiToWei(big.NewInt(entry.SyncRewards)).Mul(rpFactor)
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
Expand Down Expand Up @@ -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"
}
Expand Down

0 comments on commit dab22b7

Please sign in to comment.