Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
vgorkavenko committed May 2, 2023
1 parent 7d240ef commit 9276e88
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/handlers/slashing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import logging
from dataclasses import dataclass
from enum import Enum
from itertools import groupby
from typing import Optional, Literal

from unsync import unsync
Expand All @@ -10,6 +8,7 @@
from src.handlers.handler import WatcherHandler
from src.metrics.prometheus.duration_meter import duration_meter
from src.providers.consensus.typings import BlockDetailsResponse
from src.variables import NETWORK_NAME, ADDITIONAL_ALERTMANAGER_LABELS

logger = logging.getLogger()

Expand Down Expand Up @@ -82,7 +81,7 @@ def _send_alerts(self, watcher, head: BlockDetailsResponse, slashings: list[Slas
unknown_slashings = [s for s in slashings if s.owner == 'unknown']
other_slashings = [s for s in slashings if s.owner == 'other']
if lido_slashings:
summary = f'🚨🚨🚨 Lido {len(list(lido_slashings))} validators slashed! 🚨🚨🚨'
summary = f'🚨🚨🚨 {len(list(lido_slashings))} Lido validators were slashed! 🚨🚨🚨'
description = ''
by_operator = {}
for slashing in lido_slashings:
Expand All @@ -93,59 +92,65 @@ def _send_alerts(self, watcher, head: BlockDetailsResponse, slashings: list[Slas
for slashing in operator_slashing:
by_duty.setdefault(slashing.duty, []).append(slashing)
for duty, duty_group in by_duty.items():
description += f' {duty.capitalize()}s: '
description += f' Violated duty: {duty} | Validators: '
description += (
"["
+ ', '.join(
[
f'[{slashing.index}](http://beaconcha.in/validator/{slashing.index})'
f'[{slashing.index}](http://{NETWORK_NAME}.beaconcha.in/validator/{slashing.index})'
for slashing in duty_group
]
)
+ "]"
)
description += f'\n\nslot: [{head.message.slot}](https://beaconcha.in/slot/{head.message.slot})'
description += (
f'\n\nslot: [{head.message.slot}](https://{NETWORK_NAME}.beaconcha.in/slot/{head.message.slot})'
)
alert = SlashingAlert(name="HeadWatcherLidoSlashing", severity="critical")
watcher.alertmanager.send_alerts([alert.build_body(summary, description)])
if unknown_slashings:
summary = f'🚨 Unknown {len(list(unknown_slashings))} validators slashed!'
summary = f'🚨 {len(list(unknown_slashings))} unknown validators were slashed!'
description = ''
by_duty = {}
for slashing in other_slashings:
by_duty.setdefault(slashing.duty, []).append(slashing)
for duty, duty_group in by_duty.items():
description += f' {duty.capitalize()}s: '
description += f' Violated duty: {duty} | Validators: '
description += (
"["
+ ', '.join(
[
f'[{slashing.index}](http://beaconcha.in/validator/{slashing.index})'
f'[{slashing.index}](http://{NETWORK_NAME}.beaconcha.in/validator/{slashing.index})'
for slashing in duty_group
]
)
+ "]"
)
description += f'\n\nslot: [{head.message.slot}](https://beaconcha.in/slot/{head.message.slot})'
description += (
f'\n\nslot: [{head.message.slot}](https://{NETWORK_NAME}.beaconcha.in/slot/{head.message.slot})'
)
alert = SlashingAlert(name="HeadWatcherUnknownSlashing", severity="critical")
watcher.alertmanager.send_alerts([alert.build_body(summary, description)])
if other_slashings:
summary = f'ℹ️ Other {len(list(other_slashings))} validators slashed'
summary = f'ℹ️ {len(list(other_slashings))} other validators were slashed'
description = ''
by_duty = {}
for slashing in other_slashings:
by_duty.setdefault(slashing.duty, []).append(slashing)
for duty, duty_group in by_duty.items():
description += f' {duty.capitalize()}s: '
description += f' Violated duty: {duty} | Validators: '
description += (
"["
+ ', '.join(
[
f'[{slashing.index}](http://beaconcha.in/validator/{slashing.index})'
f'[{slashing.index}](http://{NETWORK_NAME}.beaconcha.in/validator/{slashing.index})'
for slashing in duty_group
]
)
+ "]"
)
description += f'\n\nslot: [{head.message.slot}](https://beaconcha.in/slot/{head.message.slot})'
description += (
f'\n\nslot: [{head.message.slot}](https://{NETWORK_NAME}.beaconcha.in/slot/{head.message.slot})'
)
alert = SlashingAlert(name="HeadWatcherOtherSlashing", severity="info")
watcher.alertmanager.send_alerts([alert.build_body(summary, description)])

0 comments on commit 9276e88

Please sign in to comment.