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

BIDS-2559 Sync committe notification text is unreadable #2755

Closed
wants to merge 4 commits into from
Closed
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
97 changes: 84 additions & 13 deletions services/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
// the epochs_notified sql table is used to keep track of already notified epochs
// before collecting notifications several db consistency checks are done
func notificationCollector() {

for {
latestFinalizedEpoch := LatestFinalizedEpoch()

Expand Down Expand Up @@ -628,6 +629,7 @@ func sendPushNotifications(useDB *sqlx.DB) error {
}

func queueEmailNotifications(notificationsByUserID map[uint64]map[types.EventName][]types.Notification, useDB *sqlx.DB) error {

userIDs := []uint64{}
for userID := range notificationsByUserID {
userIDs = append(userIDs, userID)
Expand Down Expand Up @@ -658,19 +660,25 @@ func queueEmailNotifications(notificationsByUserID map[uint64]map[types.EventNam
subject := ""
notificationTitlesMap := make(map[string]bool)
notificationTitles := []string{}

for event, ns := range userNotifications {
if len(msg.Body) > 0 {
msg.Body += "<br>"
}
event_title := event

if event == types.TaxReportEventName {
event_title = "income_history"
}

msg.Body += template.HTML(fmt.Sprintf("%s<br>====<br><br>", types.EventLabel[event_title]))
unsubURL := "https://" + utils.Config.Frontend.SiteDomain + "/notifications/unsubscribe"

for i, n := range ns {

// Find all unique notification titles for the subject
title := n.GetTitle()

if _, ok := notificationTitlesMap[title]; !ok {
notificationTitlesMap[title] = true
notificationTitles = append(notificationTitles, title)
Expand Down Expand Up @@ -727,7 +735,24 @@ func queueEmailNotifications(notificationsByUserID map[uint64]map[types.EventNam
unsubURL += "&hash=" + html.EscapeString(unsubHash)
}
msg.UnSubURL = template.HTML(fmt.Sprintf(`<a style="color: white" onMouseOver="this.style.color='#F5B498'" onMouseOut="this.style.color='#FFFFFF'" href="%v">Unsubscribe</a>`, unsubURL))
msg.Body += template.HTML(fmt.Sprintf("%s<br>", n.GetInfo(true)))

if event == types.SyncCommitteeSoon && len(ns) > 1 {
extras := n.GetExtras()
if extras != nil {
if i == 0 {
msg.Body += template.HTML(fmt.Sprintf("Your validators %s, ", extras[0]))
} else if i == len(ns)-1 {
msg.Body += template.HTML(fmt.Sprintf("and %s have been elected to be part of the next sync committee. The additional duties start at epoch %s, which is in %s and will last for about a day until epoch %s.<br>", extras[0], extras[1], extras[2], extras[3]))
} else {
msg.Body += template.HTML(fmt.Sprintf("%s, ", extras[0]))
}
} else {
logger.Errorf("error getting extras for sync committee soon notification")
}
} else {
msg.Body += template.HTML(fmt.Sprintf("%s<br>", n.GetInfo(true)))
}

if att := n.GetEmailAttachment(); att != nil {
attachments = append(attachments, *att)
}
Expand Down Expand Up @@ -1348,6 +1373,10 @@ func (n *validatorProposalNotification) GetInfoMarkdown() string {
return generalPart
}

func (n *validatorProposalNotification) GetExtras() []string {
return nil
}

func collectAttestationAndOfflineValidatorNotifications(notificationsByUserID map[uint64]map[types.EventName][]types.Notification, status uint64, epoch uint64) error {
_, subMap, err := db.GetSubsForEventFilter(types.ValidatorMissedAttestationEventName)
if err != nil {
Expand Down Expand Up @@ -1713,6 +1742,10 @@ func (n *validatorIsOfflineNotification) GetInfoMarkdown() string {
}
}

func (n *validatorIsOfflineNotification) GetExtras() []string {
return nil
}

type validatorAttestationNotification struct {
SubscriptionID uint64
ValidatorIndex uint64
Expand Down Expand Up @@ -1797,6 +1830,10 @@ func (n *validatorAttestationNotification) GetInfoMarkdown() string {
return generalPart
}

func (n *validatorAttestationNotification) GetExtras() []string {
return nil
}

type validatorGotSlashedNotification struct {
SubscriptionID uint64
ValidatorIndex uint64
Expand Down Expand Up @@ -1855,6 +1892,10 @@ func (n *validatorGotSlashedNotification) GetInfoMarkdown() string {
return generalPart
}

func (n *validatorGotSlashedNotification) GetExtras() []string {
return nil
}

func collectValidatorGotSlashedNotifications(notificationsByUserID map[uint64]map[types.EventName][]types.Notification, epoch uint64) error {
dbResult, err := db.GetValidatorsGotSlashed(epoch)
if err != nil {
Expand Down Expand Up @@ -1976,6 +2017,10 @@ func (n *validatorWithdrawalNotification) GetInfoMarkdown() string {
return generalPart
}

func (n *validatorWithdrawalNotification) GetExtras() []string {
return nil
}

// collectWithdrawalNotifications collects all notifications validator withdrawals
func collectWithdrawalNotifications(notificationsByUserID map[uint64]map[types.EventName][]types.Notification, epoch uint64) error {

Expand Down Expand Up @@ -2141,6 +2186,10 @@ func (n *ethClientNotification) GetInfoMarkdown() string {
return generalPart
}

func (n *ethClientNotification) GetExtras() []string {
return nil
}

func collectEthClientNotifications(notificationsByUserID map[uint64]map[types.EventName][]types.Notification, eventName types.EventName) error {
updatedClients := ethclients.GetUpdatedClients() //only check if there are new updates
for _, client := range updatedClients {
Expand Down Expand Up @@ -2449,6 +2498,10 @@ func (n *monitorMachineNotification) GetInfo(includeUrl bool) string {
return ""
}

func (n *monitorMachineNotification) GetExtras() []string {
return nil
}

func (n *monitorMachineNotification) GetTitle() string {
switch n.EventName {
case types.MonitoringMachineDiskAlmostFullEventName:
Expand Down Expand Up @@ -2557,6 +2610,10 @@ func (n *taxReportNotification) GetInfoMarkdown() string {
return n.GetInfo(false)
}

func (n *taxReportNotification) GetExtras() []string {
return nil
}

func collectTaxReportNotificationNotifications(notificationsByUserID map[uint64]map[types.EventName][]types.Notification, eventName types.EventName) error {
lastStatsDay, err := LatestExportedStatisticDay()

Expand Down Expand Up @@ -2720,6 +2777,10 @@ func collectNetworkNotifications(notificationsByUserID map[uint64]map[types.Even
return nil
}

func (n *networkNotification) GetExtras() []string {
return nil
}

type rocketpoolNotification struct {
SubscriptionID uint64
UserID uint64
Expand Down Expand Up @@ -2758,6 +2819,7 @@ func (n *rocketpoolNotification) GetEventName() types.EventName {
}

func (n *rocketpoolNotification) GetInfo(includeUrl bool) string {

switch n.EventName {
case types.RocketpoolCommissionThresholdEventName:
return fmt.Sprintf(`The current RPL commission rate of %v has reached your configured threshold.`, n.ExtraData)
Expand All @@ -2768,25 +2830,34 @@ func (n *rocketpoolNotification) GetInfo(includeUrl bool) string {
case types.RocketpoolCollateralMinReached:
return fmt.Sprintf(`Your RPL collateral has reached your configured threshold at %v%%.`, n.ExtraData)
case types.SyncCommitteeSoon:
extras := strings.Split(n.ExtraData, "|")
if len(extras) != 3 {
logger.Errorf("Invalid number of arguments passed to sync committee extra data. Notification will not be sent until code is corrected.")
extras := n.GetExtras()
if extras == nil {
return ""
}
var inTime time.Duration
syncStartEpoch, err := strconv.ParseUint(extras[1], 10, 64)
if err != nil {
inTime = time.Duration(utils.Day)
} else {
inTime = time.Until(utils.EpochToTime(syncStartEpoch))
}

return fmt.Sprintf(`Your validator %v has been elected to be part of the next sync committee. The additional duties start at epoch %v, which is in %s and will last for about a day until epoch %v.`, extras[0], extras[1], inTime.Round(time.Second), extras[2])
return fmt.Sprintf(`Your validator %s has been elected to be part of the next sync committee. The additional duties start at epoch %s, which is in %s and will last for about a day until epoch %s.`, extras[0], extras[1], extras[2], extras[3])
}

return ""
}

func (n *rocketpoolNotification) GetExtras() []string {
Eisei24 marked this conversation as resolved.
Show resolved Hide resolved
extras := strings.Split(n.ExtraData, "|")

if len(extras) != 3 {
logger.Errorf("Invalid number of arguments passed to sync committee extra data. Notification will not be sent until code is corrected.")
return nil
}
var inTime time.Duration
syncStartEpoch, err := strconv.ParseUint(extras[1], 10, 64)
if err != nil {
inTime = time.Duration(utils.Day)
} else {
inTime = time.Until(utils.EpochToTime(syncStartEpoch))
}

return []string{extras[0], extras[1], inTime.Round(time.Second).String(), extras[2]}
}

func (n *rocketpoolNotification) GetTitle() string {
switch n.EventName {
case types.RocketpoolCommissionThresholdEventName:
Expand Down
1 change: 1 addition & 0 deletions types/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ type Notification interface {
GetEventName() EventName
GetEpoch() uint64
GetInfo(includeUrl bool) string
GetExtras() []string
GetTitle() string
GetEventFilter() string
GetEmailAttachment() *EmailAttachment
Expand Down
Loading