Skip to content

Commit

Permalink
Merge pull request #1113 from gobitfly/staging
Browse files Browse the repository at this point in the history
merge staging->main
  • Loading branch information
guybrush authored Nov 11, 2024
2 parents 29bcaa6 + bbb5e35 commit 15233d3
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 84 deletions.
61 changes: 23 additions & 38 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,16 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
notificationDetails := t.NotificationValidatorDashboardDetail{
ValidatorOffline: []uint64{},
ProposalMissed: []t.IndexSlots{},
ProposalDone: []t.IndexBlocks{},
UpcomingProposals: []t.IndexSlots{},
ProposalSuccess: []t.IndexBlocks{},
ProposalUpcoming: []t.IndexSlots{},
Slashed: []uint64{},
SyncCommittee: []uint64{},
Sync: []uint64{},
AttestationMissed: []t.IndexEpoch{},
Withdrawal: []t.NotificationEventWithdrawal{},
ValidatorOfflineReminder: []uint64{},
ValidatorBackOnline: []t.NotificationEventValidatorBackOnline{},
MinimumCollateralReached: []t.Address{},
MaximumCollateralReached: []t.Address{},
ValidatorOnline: []t.NotificationEventValidatorBackOnline{},
MinCollateral: []t.Address{},
MaxCollateral: []t.Address{},
}

var searchIndices []uint64
Expand Down Expand Up @@ -554,7 +554,7 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
if searchEnabled && !searchIndexSet[curNotification.ValidatorIndex] {
continue
}
notificationDetails.UpcomingProposals = append(notificationDetails.UpcomingProposals, t.IndexSlots{Index: curNotification.ValidatorIndex, Slots: []uint64{curNotification.Slot}})
notificationDetails.ProposalUpcoming = append(notificationDetails.ProposalUpcoming, t.IndexSlots{Index: curNotification.ValidatorIndex, Slots: []uint64{curNotification.Slot}})
case types.ValidatorGotSlashedEventName:
curNotification, ok := notification.(*n.ValidatorGotSlashedNotification)
if !ok {
Expand Down Expand Up @@ -583,7 +583,7 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
if searchEnabled && !searchIndexSet[curNotification.ValidatorIndex] {
continue
}
notificationDetails.ValidatorBackOnline = append(notificationDetails.ValidatorBackOnline, t.NotificationEventValidatorBackOnline{Index: curNotification.ValidatorIndex, EpochCount: curNotification.Epoch})
notificationDetails.ValidatorOnline = append(notificationDetails.ValidatorOnline, t.NotificationEventValidatorBackOnline{Index: curNotification.ValidatorIndex, EpochCount: curNotification.Epoch})
case types.ValidatorReceivedWithdrawalEventName:
curNotification, ok := notification.(*n.ValidatorWithdrawalNotification)
if !ok {
Expand Down Expand Up @@ -630,9 +630,9 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
addr := t.Address{Hash: t.Hash(nodeAddress), IsContract: true}
addressMapping[nodeAddress] = &addr
if notification.GetEventName() == types.RocketpoolCollateralMinReachedEventName {
notificationDetails.MinimumCollateralReached = append(notificationDetails.MinimumCollateralReached, addr)
notificationDetails.MinCollateral = append(notificationDetails.MinCollateral, addr)
} else {
notificationDetails.MaximumCollateralReached = append(notificationDetails.MaximumCollateralReached, addr)
notificationDetails.MaxCollateral = append(notificationDetails.MaxCollateral, addr)
}
case types.SyncCommitteeSoonEventName:
curNotification, ok := notification.(*n.SyncCommitteeSoonNotification)
Expand All @@ -642,7 +642,7 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
if searchEnabled && !searchIndexSet[curNotification.ValidatorIndex] {
continue
}
notificationDetails.SyncCommittee = append(notificationDetails.SyncCommittee, curNotification.ValidatorIndex)
notificationDetails.Sync = append(notificationDetails.Sync, curNotification.ValidatorIndex)
default:
log.Debugf("Unhandled notification type: %s", notification.GetEventName())
}
Expand All @@ -652,10 +652,10 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
// fill proposals
for validatorIndex, proposalInfo := range proposalsInfo {
if len(proposalInfo.Proposed) > 0 {
notificationDetails.ProposalDone = append(notificationDetails.ProposalDone, t.IndexBlocks{Index: validatorIndex, Blocks: proposalInfo.Proposed})
notificationDetails.ProposalSuccess = append(notificationDetails.ProposalSuccess, t.IndexBlocks{Index: validatorIndex, Blocks: proposalInfo.Proposed})
}
if len(proposalInfo.Scheduled) > 0 {
notificationDetails.UpcomingProposals = append(notificationDetails.UpcomingProposals, t.IndexSlots{Index: validatorIndex, Slots: proposalInfo.Scheduled})
notificationDetails.ProposalUpcoming = append(notificationDetails.ProposalUpcoming, t.IndexSlots{Index: validatorIndex, Slots: proposalInfo.Scheduled})
}
if len(proposalInfo.Missed) > 0 {
notificationDetails.ProposalMissed = append(notificationDetails.ProposalMissed, t.IndexSlots{Index: validatorIndex, Slots: proposalInfo.Missed})
Expand All @@ -674,14 +674,14 @@ func (d *DataAccessService) GetValidatorDashboardNotificationDetails(ctx context
for i, contractStatus := range contractStatusRequests {
contractStatusPerAddress["0x"+contractStatus.Address] = i
}
for i := range notificationDetails.MinimumCollateralReached {
if address, ok := addressMapping[string(notificationDetails.MinimumCollateralReached[i].Hash)]; ok {
notificationDetails.MinimumCollateralReached[i] = *address
for i := range notificationDetails.MinCollateral {
if address, ok := addressMapping[string(notificationDetails.MinCollateral[i].Hash)]; ok {
notificationDetails.MinCollateral[i] = *address
}
}
for i := range notificationDetails.MaximumCollateralReached {
if address, ok := addressMapping[string(notificationDetails.MaximumCollateralReached[i].Hash)]; ok {
notificationDetails.MaximumCollateralReached[i] = *address
for i := range notificationDetails.MaxCollateral {
if address, ok := addressMapping[string(notificationDetails.MaxCollateral[i].Hash)]; ok {
notificationDetails.MaxCollateral[i] = *address
}
}
for i := range notificationDetails.Withdrawal {
Expand Down Expand Up @@ -777,24 +777,12 @@ func (d *DataAccessService) GetMachineNotifications(ctx context.Context, userId
// Calculate the result
cursorData := notificationHistory
for _, notification := range notificationHistory {
resultEntry := t.NotificationMachinesTableRow{
result = append(result, t.NotificationMachinesTableRow{
MachineName: notification.MachineName,
Threshold: notification.EventThreshold,
EventType: string(notification.EventType),
Timestamp: notification.Ts.Unix(),
}
switch notification.EventType {
case types.MonitoringMachineOfflineEventName:
resultEntry.EventType = "offline"
case types.MonitoringMachineDiskAlmostFullEventName:
resultEntry.EventType = "storage"
case types.MonitoringMachineCpuLoadEventName:
resultEntry.EventType = "cpu"
case types.MonitoringMachineMemoryUsageEventName:
resultEntry.EventType = "memory"
default:
return nil, nil, fmt.Errorf("invalid event name for machine notification: %v", notification.EventType)
}
result = append(result, resultEntry)
})
}

// -------------------------------------
Expand Down Expand Up @@ -996,19 +984,16 @@ func (d *DataAccessService) GetNetworkNotifications(ctx context.Context, userId
resultEntry := t.NotificationNetworksTableRow{
ChainId: notification.Network,
Timestamp: notification.Ts.Unix(),
EventType: string(notification.EventType),
}
switch notification.EventType {
case types.NetworkGasAboveThresholdEventName:
resultEntry.EventType = "gas_above"
resultEntry.Threshold = decimal.NewFromFloat(notification.EventThreshold).Mul(decimal.NewFromInt(params.GWei))
case types.NetworkGasBelowThresholdEventName:
resultEntry.EventType = "gas_below"
resultEntry.Threshold = decimal.NewFromFloat(notification.EventThreshold).Mul(decimal.NewFromInt(params.GWei))
case types.NetworkParticipationRateThresholdEventName:
resultEntry.EventType = "participation_rate"
resultEntry.Threshold = decimal.NewFromFloat(notification.EventThreshold)
case types.RocketpoolNewClaimRoundStartedEventName:
resultEntry.EventType = "new_reward_round"
default:
return nil, nil, fmt.Errorf("invalid event name for network notification: %v", notification.EventType)
}
Expand Down
4 changes: 4 additions & 0 deletions backend/pkg/api/data_access/vdb_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func (d *DataAccessService) GetValidatorDashboardBlocks(ctx context.Context, das
),
)

if dashboardId.Validators == nil {
blocksDs = blocksDs.Where(goqu.L("(blocks.proposer IN (SELECT validator_index FROM users_val_dashboards_validators WHERE dashboard_id = ?))", dashboardId.Id))
}

// 2. Selects
groupIdQ := goqu.C("group_id").(exp.Aliaseable)
if dashboardId.Validators != nil {
Expand Down
6 changes: 3 additions & 3 deletions backend/pkg/api/enums/notifications_enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (c NotificationMachinesColumn) ToExpr() OrderableSortable {
case NotificationMachineEventType:
return goqu.C("event_type")
case NotificationMachineTimestamp:
return goqu.C("epoch")
return goqu.C("ts")
default:
return nil
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func (c NotificationClientsColumn) ToExpr() OrderableSortable {
case NotificationClientName:
return goqu.C("client")
case NotificationClientTimestamp:
return goqu.C("epoch")
return goqu.C("ts")
default:
return nil
}
Expand Down Expand Up @@ -256,7 +256,7 @@ func (NotificationNetworksColumn) NewFromString(s string) NotificationNetworksCo
func (c NotificationNetworksColumn) ToExpr() OrderableSortable {
switch c {
case NotificationNetworkTimestamp:
return goqu.C("epoch")
return goqu.C("ts")
case NotificationNetworkNetwork:
return goqu.C("network")
case NotificationNetworkEventType:
Expand Down
11 changes: 2 additions & 9 deletions backend/pkg/api/types/data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/gobitfly/beaconchain/pkg/api/enums"
t "github.com/gobitfly/beaconchain/pkg/commons/types"
"github.com/gobitfly/beaconchain/pkg/consapi/types"
"github.com/gobitfly/beaconchain/pkg/monitoring/constants"
"github.com/shopspring/decimal"
Expand Down Expand Up @@ -139,20 +140,12 @@ type NotificationClientsCursor struct {
Ts time.Time
}

type NotificationRocketPoolsCursor struct {
GenericCursor

NodeAddress []byte
EventType string
Epoch uint64
}

type NotificationNetworksCursor struct {
GenericCursor

Network uint64
Ts time.Time
EventType string
EventType t.EventName
}

type UserCredentialInfo struct {
Expand Down
16 changes: 8 additions & 8 deletions backend/pkg/api/types/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ type NotificationEventWithdrawal struct {
type NotificationValidatorDashboardDetail struct {
DashboardName string `db:"dashboard_name" json:"dashboard_name"`
GroupName string `db:"group_name" json:"group_name"`
ValidatorOffline []uint64 `json:"validator_offline"` // validator indices
ValidatorOffline []uint64 `json:"validator_offline"` // validator indices
ValidatorOfflineReminder []uint64 `json:"validator_offline_reminder"` // validator indices; TODO not filled yet
ValidatorOnline []NotificationEventValidatorBackOnline `json:"validator_online"`
GroupEfficiencyBelow float64 `json:"group_efficiency_below,omitempty"` // fill with the `group_efficiency_below` threshold if event is present
ProposalMissed []IndexSlots `json:"proposal_missed"`
ProposalDone []IndexBlocks `json:"proposal_done"`
UpcomingProposals []IndexSlots `json:"upcoming_proposals"`
ProposalSuccess []IndexBlocks `json:"proposal_success"`
ProposalUpcoming []IndexSlots `json:"proposal_upcoming"`
Slashed []uint64 `json:"slashed"` // validator indices
SyncCommittee []uint64 `json:"sync_committee"` // validator indices
Sync []uint64 `json:"sync"` // validator indices
AttestationMissed []IndexEpoch `json:"attestation_missed"` // index (epoch)
Withdrawal []NotificationEventWithdrawal `json:"withdrawal"`
ValidatorOfflineReminder []uint64 `json:"validator_offline_reminder"` // validator indices; TODO not filled yet
ValidatorBackOnline []NotificationEventValidatorBackOnline `json:"validator_back_online"`
MinimumCollateralReached []Address `json:"min_collateral_reached"` // node addresses
MaximumCollateralReached []Address `json:"max_collateral_reached"` // node addresses
MinCollateral []Address `json:"min_collateral"` // node addresses
MaxCollateral []Address `json:"max_collateral"` // node addresses
}

type InternalGetUserNotificationsValidatorDashboardResponse ApiDataResponse[NotificationValidatorDashboardDetail]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function isSearchResultRestricted(result: ResultSuggestion): boolean {
case ResultType.ValidatorsByPubkey:
return false
default:
return isPublic.value || !user.value?.premium_perks?.ad_free
return isPublic.value || !user.value?.premium_perks?.bulk_adding
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.proposal_done?.length"
:items="details?.proposal_done"
v-if="details?.proposal_success?.length"
:items="details?.proposal_success"
:info-copy="$t('notifications.dashboards.dialog.entity.proposal_done')"
>
<template #headingIcon>
Expand All @@ -140,7 +140,7 @@ const formatValueWei = (value: string) => {
/>
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.proposal_done') }} ({{ details?.proposal_done?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.proposal_done') }} ({{ details?.proposal_success?.length ?? 0 }})
</template>
<template #item="{ item: proposalDone }">
<BcLink
Expand Down Expand Up @@ -182,15 +182,15 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.sync_committee?.length"
:items="details?.sync_committee"
v-if="details?.sync?.length"
:items="details?.sync"
:info-copy="$t('notifications.dashboards.dialog.entity.sync_committee')"
>
<template #headingIcon>
<FontAwesomeIcon :icon="faArrowsRotate" class="notifications-dashboard-dialog-entity__icon__green" />
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.sync_committee') }} ({{ details?.sync_committee?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.sync_committee') }} ({{ details?.sync?.length ?? 0 }})
</template>
<template #item="{ item: syncCommitteIndex }">
<BcLink
Expand Down Expand Up @@ -256,8 +256,8 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.validator_back_online?.length"
:items="details?.validator_back_online"
v-if="details?.validator_online?.length"
:items="details?.validator_online"
:info-copy="$t('notifications.dashboards.dialog.entity.validator_back_online')"
>
<template #headingIcon>
Expand All @@ -267,7 +267,7 @@ const formatValueWei = (value: string) => {
/>
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.validator_back_online') }} ({{ details?.validator_back_online?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.validator_back_online') }} ({{ details?.validator_online?.length ?? 0 }})
</template>
<template #item="{ item: validator }">
<BcLink
Expand Down Expand Up @@ -328,8 +328,8 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.upcoming_proposals?.length"
:items="details?.upcoming_proposals"
v-if="details?.proposal_upcoming?.length"
:items="details?.proposal_upcoming"
:info-copy="$t('notifications.dashboards.dialog.entity.upcoming_proposal')"
>
<template #headingIcon>
Expand All @@ -339,7 +339,7 @@ const formatValueWei = (value: string) => {
/>
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.upcoming_proposal') }} ({{ details?.upcoming_proposals?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.upcoming_proposal') }} ({{ details?.proposal_upcoming?.length ?? 0 }})
</template>
<template #item="{ item: upcomingProposal }">
<BcLink
Expand All @@ -361,8 +361,8 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.min_collateral_reached?.length"
:items="details?.min_collateral_reached"
v-if="details?.min_collateral?.length"
:items="details?.min_collateral"
:info-copy="$t('notifications.dashboards.dialog.entity.min_collateral')"
>
<template #headingIcon>
Expand All @@ -372,7 +372,7 @@ const formatValueWei = (value: string) => {
/>
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.min_collateral') }} ({{ details?.min_collateral_reached?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.min_collateral') }} ({{ details?.min_collateral?.length ?? 0 }})
</template>
<template #item="{ item: minCollateral }">
<BcFormatHash
Expand All @@ -387,8 +387,8 @@ const formatValueWei = (value: string) => {
</template>
</BcAccordion>
<BcAccordion
v-if="details?.max_collateral_reached?.length"
:items="details?.max_collateral_reached"
v-if="details?.max_collateral?.length"
:items="details?.max_collateral"
:info-copy="$t('notifications.dashboards.dialog.entity.max_collateral')"
>
<template #headingIcon>
Expand All @@ -398,7 +398,7 @@ const formatValueWei = (value: string) => {
/>
</template>
<template #heading>
{{ $t('notifications.dashboards.dialog.entity.max_collateral') }} ({{ details?.max_collateral_reached?.length ?? 0 }})
{{ $t('notifications.dashboards.dialog.entity.max_collateral') }} ({{ details?.max_collateral?.length ?? 0 }})
</template>
<template #item="{ item: maxCollateral }">
<BcFormatHash
Expand Down
14 changes: 7 additions & 7 deletions frontend/types/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ export interface NotificationValidatorDashboardDetail {
dashboard_name: string;
group_name: string;
validator_offline: number /* uint64 */[]; // validator indices
validator_offline_reminder: number /* uint64 */[]; // validator indices; TODO not filled yet
validator_online: NotificationEventValidatorBackOnline[];
group_efficiency_below?: number /* float64 */; // fill with the `group_efficiency_below` threshold if event is present
proposal_missed: IndexSlots[];
proposal_done: IndexBlocks[];
upcoming_proposals: IndexSlots[];
proposal_success: IndexBlocks[];
proposal_upcoming: IndexSlots[];
slashed: number /* uint64 */[]; // validator indices
sync_committee: number /* uint64 */[]; // validator indices
sync: number /* uint64 */[]; // validator indices
attestation_missed: IndexEpoch[]; // index (epoch)
withdrawal: NotificationEventWithdrawal[];
validator_offline_reminder: number /* uint64 */[]; // validator indices; TODO not filled yet
validator_back_online: NotificationEventValidatorBackOnline[];
min_collateral_reached: Address[]; // node addresses
max_collateral_reached: Address[]; // node addresses
min_collateral: Address[]; // node addresses
max_collateral: Address[]; // node addresses
}
export type InternalGetUserNotificationsValidatorDashboardResponse = ApiDataResponse<NotificationValidatorDashboardDetail>;
export interface NotificationEventExecution {
Expand Down

0 comments on commit 15233d3

Please sign in to comment.