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
14 changes: 8 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ func main() {

// Start the duties checker service in a goroutine
dutiesChecker := &services.DutiesChecker{
Beacon: beacon,
Brain: brain,
Notifier: notifier,
Dappmanager: dappmanager,
PollInterval: 1 * time.Minute,
SlashedNotified: make(map[domain.ValidatorIndex]bool),
Beacon: beacon,
Brain: brain,
Notifier: notifier,
Dappmanager: dappmanager,
PollInterval: 1 * time.Minute,
SlashedNotified: make(map[domain.ValidatorIndex]bool),
PreviouslyAllLive: true, // assume all validators were live at start
PreviouslyOffline: false,
}
wg.Add(1)
go func() {
Expand Down
11 changes: 8 additions & 3 deletions internal/adapters/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func (n *Notifier) SendValidatorLivenessNot(validators []domain.ValidatorIndex,
}
}
if live {
title = fmt.Sprintf("Validator(s) Online: %s", indexesToString(validators))
body = fmt.Sprintf("✅ Validator(s) %s are back online on %s.", indexesToString(validators), n.Network)
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))
priority = Info
status = Resolved
isBanner = false
Expand Down Expand Up @@ -215,7 +215,12 @@ func (n *Notifier) SendBlockProposalNot(validators []domain.ValidatorIndex, epoc
// Helper to join validator indexes as comma-separated string
func indexesToString(indexes []domain.ValidatorIndex) string {
var s []string
for _, idx := range indexes {
max := 10
for i, idx := range indexes {
if i == max {
s = append(s, "...")
break
}
s = append(s, fmt.Sprintf("%d", idx))
}
return strings.Join(s, ",")
Expand Down
25 changes: 18 additions & 7 deletions internal/application/services/dutieschecker_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ type DutiesChecker struct {

PollInterval time.Duration
lastJustifiedEpoch domain.Epoch
lastLivenessState *bool
lastRunHadError bool

SlashedNotified map[domain.ValidatorIndex]bool

// Tracking previous states for notifications
PreviouslyAllLive bool
PreviouslyOffline bool
}

func (a *DutiesChecker) Run(ctx context.Context) {
Expand Down Expand Up @@ -85,26 +88,33 @@ func (a *DutiesChecker) performChecks(ctx context.Context, justifiedEpoch domain

// Debug print: show offline, online, and allLive status
logger.Debug("Liveness check: offline=%v, online=%v, allLive=%v", offline, online, allLive)
logger.Debug("Previously all live: %v, previously offline: %v", a.PreviouslyAllLive, a.PreviouslyOffline)

if len(offline) > 0 && (a.lastLivenessState == nil || *a.lastLivenessState) {
// 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] {
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)
}
}
val := false
a.lastLivenessState = &val
a.PreviouslyAllLive = false
a.PreviouslyOffline = true
}
if allLive && (a.lastLivenessState == nil || !*a.lastLivenessState) {

// Check for the second condition: all validators online after 1 or more were offline
if allLive && a.PreviouslyOffline {
if notificationsEnabled[domain.ValidatorLiveness] {
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)
}
}
val := true
a.lastLivenessState = &val
a.PreviouslyAllLive = true
a.PreviouslyOffline = false
}

// Check block proposals (successful or missed)
proposed, missed, err := a.checkProposals(ctx, justifiedEpoch, indices)
if err != nil {
logger.Error("Error checking block proposals: %v", err)
Expand All @@ -121,6 +131,7 @@ func (a *DutiesChecker) performChecks(ctx context.Context, justifiedEpoch domain
}
}

// Check for slashed validators
slashed, err := a.Beacon.GetSlashedValidators(ctx, indices)
if err != nil {
logger.Error("Error fetching slashed validators: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func LoadConfig() Config {
beaconEndpoint := fmt.Sprintf("http://beacon-chain.%s.dncore.dappnode:3500", network)
web3SignerEndpoint := fmt.Sprintf("http://web3signer.%s.dncore.dappnode:9000", network)
dappmanagerEndpoint := "http://dappmanager.dappnode"
notifierEndpoint := "http://notifier.dappnode:8080"
notifierEndpoint := "http://notifier.notifications.dappnode:8080"
brainEndpoint := fmt.Sprintf("http://brain.web3signer-%s.dappnode", network)

// Allow override via environment variables
Expand Down