Skip to content

Commit c5cc449

Browse files
Add justified epoch to notification (#28)
* Add justified epoch to notification * mention epoch in noti
1 parent d39143d commit c5cc449

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

internal/adapters/notifier/notifier.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (n *Notifier) sendNotification(payload NotificationPayload) error {
105105
}
106106

107107
// SendValidatorLivenessNot sends a notification when one or more validators go offline or online.
108-
func (n *Notifier) SendValidatorLivenessNot(validators []domain.ValidatorIndex, live bool) error {
108+
func (n *Notifier) SendValidatorLivenessNot(validators []domain.ValidatorIndex, epoch domain.Epoch, live bool) error {
109109
var title, body string
110110
var priority Priority
111111
var status Status
@@ -121,13 +121,13 @@ func (n *Notifier) SendValidatorLivenessNot(validators []domain.ValidatorIndex,
121121
}
122122
if live {
123123
title = fmt.Sprintf("All validators back online (%d)", len(validators))
124-
body = fmt.Sprintf("✅ All validators are back online and atesting on %s (%d).", n.Network, len(validators))
124+
body = fmt.Sprintf("✅ All validators are back online and atesting at epoch %d on %s (%d).", epoch, n.Network, len(validators))
125125
priority = Low
126126
status = Resolved
127127
isBanner = false
128128
} else {
129129
title = fmt.Sprintf("Validator(s) Offline: %s", indexesToString(validators, true))
130-
body = fmt.Sprintf("❌ Validator(s) %s are not attesting on %s.", indexesToString(validators, true), n.Network)
130+
body = fmt.Sprintf("❌ Validator(s) %s are not attesting at epoch %d on %s.", indexesToString(validators, true), epoch, n.Network)
131131
priority = High
132132
status = Triggered
133133
isBanner = true
@@ -147,9 +147,9 @@ func (n *Notifier) SendValidatorLivenessNot(validators []domain.ValidatorIndex,
147147
}
148148

149149
// SendValidatorsSlashedNot sends a notification when one or more validators are slashed.
150-
func (n *Notifier) SendValidatorsSlashedNot(validators []domain.ValidatorIndex) error {
150+
func (n *Notifier) SendValidatorsSlashedNot(validators []domain.ValidatorIndex, epoch domain.Epoch) error {
151151
title := fmt.Sprintf("Validator(s) Slashed: %s", indexesToString(validators, true))
152-
body := fmt.Sprintf("🚨 Validator(s) %s have been slashed on %s! Immediate attention required.", indexesToString(validators, true), n.Network)
152+
body := fmt.Sprintf("🚨 Validator(s) %s have been slashed at epoch %d on %s! Immediate attention required.", indexesToString(validators, true), epoch, n.Network)
153153
priority := Critical
154154
status := Triggered
155155
isBanner := true
@@ -174,7 +174,7 @@ func (n *Notifier) SendValidatorsSlashedNot(validators []domain.ValidatorIndex)
174174
}
175175

176176
// SendBlockProposalNot sends a notification when a block is proposed or missed by one or more validators.
177-
func (n *Notifier) SendBlockProposalNot(validators []domain.ValidatorIndex, epoch int, proposed bool) error {
177+
func (n *Notifier) SendBlockProposalNot(validators []domain.ValidatorIndex, epoch domain.Epoch, proposed bool) error {
178178
var title, body string
179179
var priority Priority
180180
var status Status = Triggered

internal/application/ports/notifier.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package ports
33
import "github.com/dappnode/validator-tracker/internal/application/domain"
44

55
type NotifierPort interface {
6-
SendValidatorLivenessNot(validators []domain.ValidatorIndex, live bool) error
7-
SendValidatorsSlashedNot(validators []domain.ValidatorIndex) error
8-
SendBlockProposalNot(validators []domain.ValidatorIndex, epoch int, proposed bool) error
6+
SendValidatorLivenessNot(validators []domain.ValidatorIndex, epoch domain.Epoch, live bool) error
7+
SendValidatorsSlashedNot(validators []domain.ValidatorIndex, epoch domain.Epoch) error
8+
SendBlockProposalNot(validators []domain.ValidatorIndex, epoch domain.Epoch, proposed bool) error
99
}

internal/application/services/dutieschecker_service.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (a *DutiesChecker) performChecks(ctx context.Context, justifiedEpoch domain
9999
if len(offline) > 0 && a.PreviouslyAllLive {
100100
if notificationsEnabled[domain.Notifications.Liveness] {
101101
logger.Debug("Sending notification for validators going offline: %v", offline)
102-
if err := a.Notifier.SendValidatorLivenessNot(offline, false); err != nil {
102+
if err := a.Notifier.SendValidatorLivenessNot(offline, justifiedEpoch, false); err != nil {
103103
logger.Warn("Error sending validator liveness notification: %v", err)
104104
}
105105
}
@@ -111,7 +111,7 @@ func (a *DutiesChecker) performChecks(ctx context.Context, justifiedEpoch domain
111111
if allLive && a.PreviouslyOffline {
112112
if notificationsEnabled[domain.Notifications.Liveness] {
113113
logger.Debug("Sending notification for all validators back online: %v", indices)
114-
if err := a.Notifier.SendValidatorLivenessNot(indices, true); err != nil {
114+
if err := a.Notifier.SendValidatorLivenessNot(indices, justifiedEpoch, true); err != nil {
115115
logger.Warn("Error sending validator liveness notification: %v", err)
116116
}
117117
}
@@ -126,12 +126,12 @@ func (a *DutiesChecker) performChecks(ctx context.Context, justifiedEpoch domain
126126
return err
127127
}
128128
if len(proposed) > 0 && notificationsEnabled[domain.Notifications.Proposal] {
129-
if err := a.Notifier.SendBlockProposalNot(proposed, int(justifiedEpoch), true); err != nil {
129+
if err := a.Notifier.SendBlockProposalNot(proposed, justifiedEpoch, true); err != nil {
130130
logger.Warn("Error sending block proposal notification: %v", err)
131131
}
132132
}
133133
if len(missed) > 0 && notificationsEnabled[domain.Notifications.Proposal] {
134-
if err := a.Notifier.SendBlockProposalNot(missed, int(justifiedEpoch), false); err != nil {
134+
if err := a.Notifier.SendBlockProposalNot(missed, justifiedEpoch, false); err != nil {
135135
logger.Warn("Error sending block proposal notification: %v", err)
136136
}
137137
}
@@ -153,7 +153,7 @@ func (a *DutiesChecker) performChecks(ctx context.Context, justifiedEpoch domain
153153
}
154154

155155
if len(toNotify) > 0 && notificationsEnabled[domain.Notifications.Slashed] {
156-
if err := a.Notifier.SendValidatorsSlashedNot(toNotify); err != nil {
156+
if err := a.Notifier.SendValidatorsSlashedNot(toNotify, justifiedEpoch); err != nil {
157157
logger.Warn("Error sending validator slashed notification: %v", err)
158158
}
159159
}

0 commit comments

Comments
 (0)