Skip to content

Commit

Permalink
feat(notification): prepare group online offline notification features
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbitfly committed Oct 2, 2024
1 parent ae17848 commit 8d9c801
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions backend/pkg/commons/types/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const (
ValidatorGotSlashedEventName EventName = "validator_got_slashed"
ValidatorDidSlashEventName EventName = "validator_did_slash"
ValidatorIsOfflineEventName EventName = "validator_is_offline"
ValidatorGroupIsOfflineEventName EventName = "validator_group_is_offline"
ValidatorReceivedWithdrawalEventName EventName = "validator_withdrawal"
NetworkLivenessIncreasedEventName EventName = "network_liveness_increased"
EthClientUpdateEventName EventName = "eth_client_update"
Expand Down
12 changes: 6 additions & 6 deletions backend/pkg/notification/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func collectBlockProposalNotifications(notificationsByUserID types.Notifications
// collectAttestationAndOfflineValidatorNotifications collects notifications for missed attestations and offline validators
func collectAttestationAndOfflineValidatorNotifications(notificationsByUserID types.NotificationsPerUserId, epoch uint64, validatorDashboardConfig *types.ValidatorDashboardConfig) error {
// Retrieve subscriptions for missed attestations
subMap, err := GetSubsForEventFilter(types.ValidatorMissedAttestationEventName, "", nil, nil, validatorDashboardConfig)
subMapAttestationMissed, err := GetSubsForEventFilter(types.ValidatorMissedAttestationEventName, "", nil, nil, validatorDashboardConfig)
if err != nil {
return fmt.Errorf("error getting subscriptions for missted attestations %w", err)
}
Expand Down Expand Up @@ -547,7 +547,7 @@ func collectAttestationAndOfflineValidatorNotifications(notificationsByUserID ty
if !participated {
pubkey, err := GetPubkeyForIndex(uint64(validatorIndex))
if err == nil {
if currentEpoch != types.Epoch(epoch) || subMap[hex.EncodeToString(pubkey)] == nil {
if currentEpoch != types.Epoch(epoch) || subMapAttestationMissed[hex.EncodeToString(pubkey)] == nil {
continue
}

Expand All @@ -568,7 +568,7 @@ func collectAttestationAndOfflineValidatorNotifications(notificationsByUserID ty

// process missed attestation events
for _, event := range events {
subscribers, ok := subMap[hex.EncodeToString(event.EventFilter)]
subscribers, ok := subMapAttestationMissed[hex.EncodeToString(event.EventFilter)]
if !ok {
return fmt.Errorf("error event returned that does not exist: %x", event.EventFilter)
}
Expand Down Expand Up @@ -681,14 +681,14 @@ func collectAttestationAndOfflineValidatorNotifications(notificationsByUserID ty
return fmt.Errorf("retrieved more than %v online validators notifications: %v, exiting", onlineValidatorsLimit, len(onlineValidators))
}

subMap, err = GetSubsForEventFilter(types.ValidatorIsOfflineEventName, "", nil, nil, validatorDashboardConfig)
subMapOnlineOffline, err := GetSubsForEventFilter(types.ValidatorIsOfflineEventName, "", nil, nil, validatorDashboardConfig)
if err != nil {
return fmt.Errorf("failed to get subs for %v: %v", types.ValidatorIsOfflineEventName, err)
}

for _, validator := range offlineValidators {
t := hex.EncodeToString(validator.Pubkey)
subs := subMap[t]
subs := subMapOnlineOffline[t]
for _, sub := range subs {
if sub.UserID == nil || sub.ID == nil {
return fmt.Errorf("error expected userId and subId to be defined but got user: %v, sub: %v", sub.UserID, sub.ID)
Expand Down Expand Up @@ -719,7 +719,7 @@ func collectAttestationAndOfflineValidatorNotifications(notificationsByUserID ty

for _, validator := range onlineValidators {
t := hex.EncodeToString(validator.Pubkey)
subs := subMap[t]
subs := subMapOnlineOffline[t]
for _, sub := range subs {
if sub.UserID == nil || sub.ID == nil {
return fmt.Errorf("error expected userId and subId to be defined but got user: %v, sub: %v", sub.UserID, sub.ID)
Expand Down
50 changes: 50 additions & 0 deletions backend/pkg/notification/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,56 @@ func (n *validatorIsOfflineNotification) GetLegacyTitle() string {
}
}

type validatorGroupIsOfflineNotification struct {

Check failure on line 201 in backend/pkg/notification/types.go

View workflow job for this annotation

GitHub Actions / lint

type `validatorGroupIsOfflineNotification` is unused (unused)
types.NotificationBaseImpl

IsOffline bool
}

func (n *validatorGroupIsOfflineNotification) GetEntitiyId() string {

Check failure on line 207 in backend/pkg/notification/types.go

View workflow job for this annotation

GitHub Actions / lint

func `(*validatorGroupIsOfflineNotification).GetEntitiyId` is unused (unused)
return fmt.Sprintf("%s - %s", n.GetDashboardName(), n.GetDashboardGroupName())
}

// Overwrite specific methods
func (n *validatorGroupIsOfflineNotification) GetInfo(format types.NotificationFormat) string {

Check failure on line 212 in backend/pkg/notification/types.go

View workflow job for this annotation

GitHub Actions / lint

func `(*validatorGroupIsOfflineNotification).GetInfo` is unused (unused)
epoch := ""
if n.IsOffline {
epoch = formatEpochLink(format, n.LatestState)
} else {
epoch = formatEpochLink(format, n.Epoch)
}

if n.IsOffline {
return fmt.Sprintf(`Group %s is offline since epoch %s.`, n.DashboardGroupName, epoch)
} else {
return fmt.Sprintf(`Group %s is back online since epoch %v.`, n.DashboardGroupName, epoch)
}
}

func (n *validatorGroupIsOfflineNotification) GetTitle() string {

Check failure on line 227 in backend/pkg/notification/types.go

View workflow job for this annotation

GitHub Actions / lint

func `(*validatorGroupIsOfflineNotification).GetTitle` is unused (unused)
if n.IsOffline {
return "Group is offline"
} else {
return "Group is back online"
}
}

func (n *validatorGroupIsOfflineNotification) GetLegacyInfo() string {

Check failure on line 235 in backend/pkg/notification/types.go

View workflow job for this annotation

GitHub Actions / lint

func `(*validatorGroupIsOfflineNotification).GetLegacyInfo` is unused (unused)
if n.IsOffline {
return fmt.Sprintf(`Group %s is offline since epoch %s.`, n.DashboardGroupName, n.LatestState)
} else {
return fmt.Sprintf(`Group %s is back online since epoch %v.`, n.DashboardGroupName, n.Epoch)
}
}

func (n *validatorGroupIsOfflineNotification) GetLegacyTitle() string {

Check failure on line 243 in backend/pkg/notification/types.go

View workflow job for this annotation

GitHub Actions / lint

func `(*validatorGroupIsOfflineNotification).GetLegacyTitle` is unused (unused)
if n.IsOffline {
return "Group is offline"
} else {
return "Group is back online"
}
}

type validatorAttestationNotification struct {
types.NotificationBaseImpl

Expand Down

0 comments on commit 8d9c801

Please sign in to comment.