diff --git a/cmd/main.go b/cmd/main.go index 55b93c9..3a30cd7 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -32,6 +32,9 @@ func main() { } } + // Initialize network-specific notification correlation IDs + domain.InitNotifications(cfg.Network) + // Initialize adapters dappmanager := dappmanager.NewDappManagerAdapter(cfg.DappmanagerUrl, cfg.SignerDnpName) notifier := notifier.NewNotifier( diff --git a/internal/adapters/dappmanager/dappmanager.go b/internal/adapters/dappmanager/dappmanager.go index 693dc9a..598edb9 100644 --- a/internal/adapters/dappmanager/dappmanager.go +++ b/internal/adapters/dappmanager/dappmanager.go @@ -53,11 +53,11 @@ func (d *DappManagerAdapter) GetNotificationsEnabled(ctx context.Context) (domai return nil, fmt.Errorf("failed to get notifications from signer manifest: %w", err) } - // Build a set of valid correlation IDs from domain.ValidatorNotification + // Build a set of valid correlation IDs from domain.Notifications validCorrelationIDs := map[string]struct{}{ - string(domain.ValidatorLiveness): {}, - string(domain.ValidatorSlashed): {}, - string(domain.BlockProposal): {}, + string(domain.Notifications.Liveness): {}, + string(domain.Notifications.Slashed): {}, + string(domain.Notifications.Proposal): {}, } notifications := make(domain.ValidatorNotificationsEnabled) diff --git a/internal/adapters/notifier/notifier.go b/internal/adapters/notifier/notifier.go index 9188327..19ca85b 100644 --- a/internal/adapters/notifier/notifier.go +++ b/internal/adapters/notifier/notifier.go @@ -111,7 +111,7 @@ func (n *Notifier) SendValidatorLivenessNot(validators []domain.ValidatorIndex, var priority Priority var status Status var isBanner bool - correlationId := string(domain.ValidatorLiveness) + correlationId := string(domain.Notifications.Liveness) var callToAction *CallToAction beaconchaUrl := n.buildBeaconchaURL(validators) if beaconchaUrl != "" { @@ -122,13 +122,13 @@ func (n *Notifier) SendValidatorLivenessNot(validators []domain.ValidatorIndex, } if live { title = fmt.Sprintf("All validators back online (%d)", len(validators)) - body = fmt.Sprintf("✅ All validators are back online on %s (%d).", n.Network, len(validators)) + body = fmt.Sprintf("✅ All validators are back online and atesting on %s (%d).", n.Network, len(validators)) priority = Info status = Resolved isBanner = false } else { title = fmt.Sprintf("Validator(s) Offline: %s", indexesToString(validators)) - body = fmt.Sprintf("❌ Validator(s) %s are offline on %s.", indexesToString(validators), n.Network) + body = fmt.Sprintf("❌ Validator(s) %s are not attesting on %s.", indexesToString(validators), n.Network) priority = High status = Triggered isBanner = true @@ -154,7 +154,7 @@ func (n *Notifier) SendValidatorsSlashedNot(validators []domain.ValidatorIndex) priority := Critical status := Triggered isBanner := true - correlationId := string(domain.ValidatorSlashed) + correlationId := string(domain.Notifications.Slashed) callToAction := &CallToAction{ Title: "Remove validators", URL: n.BrainUrl, @@ -180,7 +180,7 @@ func (n *Notifier) SendBlockProposalNot(validators []domain.ValidatorIndex, epoc var priority Priority var status Status = Triggered isBanner := true - correlationId := string(domain.BlockProposal) + correlationId := string(domain.Notifications.Proposal) beaconchaUrl := n.buildBeaconchaURL(validators) var callToAction *CallToAction if beaconchaUrl != "" { diff --git a/internal/application/domain/notification.go b/internal/application/domain/notification.go index a46710b..08783f6 100644 --- a/internal/application/domain/notification.go +++ b/internal/application/domain/notification.go @@ -2,11 +2,20 @@ package domain type ValidatorNotificationsEnabled map[ValidatorNotification]bool -// create a enum with the validator notifications type ValidatorNotification string -const ( - ValidatorLiveness ValidatorNotification = "validator-liveness" // online/offline - ValidatorSlashed ValidatorNotification = "validator-slashed" - BlockProposal ValidatorNotification = "block-proposal" -) +type validatorNotifications struct { + Liveness ValidatorNotification + Slashed ValidatorNotification + Proposal ValidatorNotification +} + +var Notifications validatorNotifications + +func InitNotifications(network string) { + Notifications = validatorNotifications{ + Liveness: ValidatorNotification(network + "-validator-liveness"), + Slashed: ValidatorNotification(network + "-validator-slashed"), + Proposal: ValidatorNotification(network + "-block-proposal"), + } +} diff --git a/internal/application/services/dutieschecker_service.go b/internal/application/services/dutieschecker_service.go index 1970a6e..713ddf2 100644 --- a/internal/application/services/dutieschecker_service.go +++ b/internal/application/services/dutieschecker_service.go @@ -92,7 +92,7 @@ func (a *DutiesChecker) performChecks(ctx context.Context, justifiedEpoch domain // Check for the first condition: 1 or more validators offline when all were previously live if len(offline) > 0 && a.PreviouslyAllLive { - if notificationsEnabled[domain.ValidatorLiveness] { + if notificationsEnabled[domain.Notifications.Liveness] { logger.Debug("Sending notification for validators going offline: %v", offline) if err := a.Notifier.SendValidatorLivenessNot(offline, false); err != nil { logger.Warn("Error sending validator liveness notification: %v", err) @@ -104,7 +104,7 @@ func (a *DutiesChecker) performChecks(ctx context.Context, justifiedEpoch domain // Check for the second condition: all validators online after 1 or more were offline if allLive && a.PreviouslyOffline { - if notificationsEnabled[domain.ValidatorLiveness] { + if notificationsEnabled[domain.Notifications.Liveness] { logger.Debug("Sending notification for all validators back online: %v", indices) if err := a.Notifier.SendValidatorLivenessNot(indices, true); err != nil { logger.Warn("Error sending validator liveness notification: %v", err) @@ -120,12 +120,12 @@ func (a *DutiesChecker) performChecks(ctx context.Context, justifiedEpoch domain logger.Error("Error checking block proposals: %v", err) return err } - if len(proposed) > 0 && notificationsEnabled[domain.BlockProposal] { + if len(proposed) > 0 && notificationsEnabled[domain.Notifications.Proposal] { if err := a.Notifier.SendBlockProposalNot(proposed, int(justifiedEpoch), true); err != nil { logger.Warn("Error sending block proposal notification: %v", err) } } - if len(missed) > 0 && notificationsEnabled[domain.BlockProposal] { + if len(missed) > 0 && notificationsEnabled[domain.Notifications.Proposal] { if err := a.Notifier.SendBlockProposalNot(missed, int(justifiedEpoch), false); err != nil { logger.Warn("Error sending block proposal notification: %v", err) } @@ -147,7 +147,7 @@ func (a *DutiesChecker) performChecks(ctx context.Context, justifiedEpoch domain } } - if len(toNotify) > 0 && notificationsEnabled[domain.ValidatorSlashed] { + if len(toNotify) > 0 && notificationsEnabled[domain.Notifications.Slashed] { if err := a.Notifier.SendValidatorsSlashedNot(toNotify); err != nil { logger.Warn("Error sending validator slashed notification: %v", err) }