Skip to content
Merged
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
3 changes: 3 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions internal/adapters/dappmanager/dappmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/adapters/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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 != "" {
Expand Down
21 changes: 15 additions & 6 deletions internal/application/domain/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
10 changes: 5 additions & 5 deletions internal/application/services/dutieschecker_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down