Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BEDS-1184) return el rewards for guest dashboards #1314

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions backend/pkg/api/data_access/vdb_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ func (d *DataAccessService) GetValidatorDashboardRewards(ctx context.Context, da
Select(
goqu.L("b.epoch"),
goqu.COALESCE(goqu.SUM(goqu.I("value")), 0).As("el_rewards")).
From(goqu.L("users_val_dashboards_validators v")).
From(goqu.I("execution_rewards_finalized").As("b")).
Where(goqu.L("b.epoch >= ?", startEpoch)).
LeftJoin(goqu.I("execution_rewards_finalized").As("b"), goqu.On(goqu.L("v.validator_index = b.proposer"))).
GroupBy(goqu.L("b.epoch"))

if dashboardId.Validators == nil {
rewardsDs = rewardsDs.
InnerJoin(goqu.L("validators v"), goqu.On(goqu.L("e.validator_index = v.validator_index"))).
Where(goqu.L("e.validator_index IN (SELECT validator_index FROM validators)"))
elDs = elDs.
InnerJoin(goqu.I("users_val_dashboards_validators").As("v"), goqu.On(goqu.L("v.validator_index = b.proposer"))).
Where(goqu.L("v.dashboard_id = ?", dashboardId.Id))
if currentCursor.IsValid() {
if currentCursor.IsReverse() {
Expand Down Expand Up @@ -546,10 +546,8 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex
Where(goqu.L("e.epoch_timestamp = fromUnixTimestamp(?)", utils.EpochToTime(epoch).Unix()))

elDs := goqu.Dialect("postgres").
Select(
goqu.COALESCE(goqu.SUM(goqu.I("value")), 0).As("blocks_el_rewards")).
From(goqu.L("users_val_dashboards_validators v")).
LeftJoin(goqu.I("execution_rewards_finalized").As("b"), goqu.On(goqu.L("v.validator_index = b.proposer"))).
Select(goqu.COALESCE(goqu.SUM(goqu.I("value")), 0).As("blocks_el_rewards")).
From(goqu.I("execution_rewards_finalized").As("b")).
Where(goqu.L("b.epoch = ?", epoch))

// handle the case when we have a list of validators
Expand All @@ -559,6 +557,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex
InnerJoin(goqu.L("validators v"), goqu.On(goqu.L("e.validator_index = v.validator_index"))).
Where(goqu.L("e.validator_index IN (SELECT validator_index FROM validators)"))
elDs = elDs.
InnerJoin(goqu.I("users_val_dashboards_validators").As("v"), goqu.On(goqu.L("v.validator_index = b.proposer"))).
Where(goqu.L("v.dashboard_id = ?", dashboardId.Id))
if groupId != t.AllGroups {
rewardsDs = rewardsDs.Where(goqu.L("v.group_id = ?", groupId))
Expand Down Expand Up @@ -659,7 +658,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex
ret.Inactivity.StatusCount.Success++
}

ret.Proposal.Income = ret.Proposal.Income.Add(entry.BlocksClReward.Mul(gWei))
ret.Proposal.Income.Cl = ret.Proposal.Income.Cl.Add(entry.BlocksClReward.Mul(gWei))
ret.Proposal.StatusCount.Success += uint64(entry.BlocksProposed)
ret.Proposal.StatusCount.Failed += uint64(entry.BlocksScheduled) - uint64(entry.BlocksProposed)

Expand All @@ -678,7 +677,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex
ret.ProposalClSlashingIncReward = ret.ProposalClSlashingIncReward.Add(entry.SlasherRewards.Mul(gWei))
}

ret.Proposal.Income = ret.Proposal.Income.Add(elRewards)
ret.Proposal.Income.El = elRewards
ret.ProposalElReward = elRewards

return ret, nil
Expand Down
20 changes: 10 additions & 10 deletions backend/pkg/api/types/validator_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ type VDBRewardsTableRow struct {

type GetValidatorDashboardRewardsResponse ApiPagingResponse[VDBRewardsTableRow]

type VDBGroupRewardsDetails struct {
StatusCount StatusCount `json:"status_count"`
Income decimal.Decimal `json:"income"`
type VDBGroupRewardsDetails[T any] struct {
StatusCount StatusCount `json:"status_count"`
Income T `json:"income"`
}
type VDBGroupRewardsData struct {
AttestationsSource VDBGroupRewardsDetails `json:"attestations_source"`
AttestationsTarget VDBGroupRewardsDetails `json:"attestations_target"`
AttestationsHead VDBGroupRewardsDetails `json:"attestations_head"`
Sync VDBGroupRewardsDetails `json:"sync"`
Slashing VDBGroupRewardsDetails `json:"slashing"`
Inactivity VDBGroupRewardsDetails `json:"inactivity"`
Proposal VDBGroupRewardsDetails `json:"proposal"`
AttestationsSource VDBGroupRewardsDetails[decimal.Decimal] `json:"attestations_source"`
AttestationsTarget VDBGroupRewardsDetails[decimal.Decimal] `json:"attestations_target"`
AttestationsHead VDBGroupRewardsDetails[decimal.Decimal] `json:"attestations_head"`
Sync VDBGroupRewardsDetails[decimal.Decimal] `json:"sync"`
Slashing VDBGroupRewardsDetails[decimal.Decimal] `json:"slashing"`
Inactivity VDBGroupRewardsDetails[decimal.Decimal] `json:"inactivity"`
Proposal VDBGroupRewardsDetails[ClElValue[decimal.Decimal]] `json:"proposal"`

ProposalElReward decimal.Decimal `json:"proposal_el_reward"`
ProposalClAttIncReward decimal.Decimal `json:"proposal_cl_att_inc_reward"`
Expand Down
18 changes: 9 additions & 9 deletions frontend/types/api/validator_dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,18 @@ export interface VDBRewardsTableRow {
reward: ClElValue<string /* decimal.Decimal */>;
}
export type GetValidatorDashboardRewardsResponse = ApiPagingResponse<VDBRewardsTableRow>;
export interface VDBGroupRewardsDetails {
export interface VDBGroupRewardsDetails<T extends any> {
status_count: StatusCount;
income: string /* decimal.Decimal */;
income: T;
}
export interface VDBGroupRewardsData {
attestations_source: VDBGroupRewardsDetails;
attestations_target: VDBGroupRewardsDetails;
attestations_head: VDBGroupRewardsDetails;
sync: VDBGroupRewardsDetails;
slashing: VDBGroupRewardsDetails;
inactivity: VDBGroupRewardsDetails;
proposal: VDBGroupRewardsDetails;
attestations_source: VDBGroupRewardsDetails<string /* decimal.Decimal */>;
attestations_target: VDBGroupRewardsDetails<string /* decimal.Decimal */>;
attestations_head: VDBGroupRewardsDetails<string /* decimal.Decimal */>;
sync: VDBGroupRewardsDetails<string /* decimal.Decimal */>;
slashing: VDBGroupRewardsDetails<string /* decimal.Decimal */>;
inactivity: VDBGroupRewardsDetails<string /* decimal.Decimal */>;
proposal: VDBGroupRewardsDetails<ClElValue<string /* decimal.Decimal */>>;
proposal_el_reward: string /* decimal.Decimal */;
proposal_cl_att_inc_reward: string /* decimal.Decimal */;
proposal_cl_sync_inc_reward: string /* decimal.Decimal */;
Expand Down
Loading