Skip to content

Commit 694931e

Browse files
committed
feat: add logging of proposed/missed blocks
1 parent 6ec1ca1 commit 694931e

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

eth_validator_watcher/blocks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def process_block(validators: WatchedValidators, schedule: ProposerSchedule, slo
1414
return
1515

1616
if has_block:
17-
validator.proposed_blocks_total += 1
17+
validator.proposed_blocks.append(slot_id)
1818
else:
19-
validator.missed_blocks_total += 1
19+
validator.missed_blocks.append(slot_id)
2020

2121

2222
def process_finalized_block(validators: WatchedValidators, schedule: ProposerSchedule, slot_id: int, has_block: bool):
@@ -29,9 +29,9 @@ def process_finalized_block(validators: WatchedValidators, schedule: ProposerSch
2929
return
3030

3131
if has_block:
32-
validator.proposed_blocks_finalized_total += 1
32+
validator.proposed_blocks_finalized.append(slot_id)
3333
else:
34-
validator.missed_blocks_finalized_total += 1
34+
validator.missed_blocks_finalized.append(slot_id)
3535

3636

3737
def process_future_blocks(validators: WatchedValidators, schedule: ProposerSchedule, slot_id: int):
@@ -42,4 +42,4 @@ def process_future_blocks(validators: WatchedValidators, schedule: ProposerSched
4242
if validator is None:
4343
continue
4444

45-
validator.future_blocks_proposal += 1
45+
validator.future_blocks_proposal.append(slot_id)

eth_validator_watcher/entrypoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _update_metrics(self, watched_validators: WatchedValidators, epoch: int, slo
100100
# there is a log of entries here, this makes code here a bit
101101
# more complex and entangled.
102102

103-
metrics = compute_validator_metrics(watched_validators.validators())
103+
metrics = compute_validator_metrics(watched_validators.validators(), slot)
104104

105105
for label, m in metrics.items():
106106
for status in Validators.DataItem.StatusEnum:

eth_validator_watcher/metrics.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from prometheus_client import Counter, Gauge
99

10+
from .utils import LABEL_SCOPE_WATCHED
1011
from .watched_validators import WatchedValidator
1112

1213

@@ -77,7 +78,7 @@ class AggregatedMetricsByLabel():
7778
future_blocks: int = 0
7879

7980

80-
def compute_validator_metrics(validators: dict[int, WatchedValidator]) -> dict[str, AggregatedMetricsByLabel]:
81+
def compute_validator_metrics(validators: dict[int, WatchedValidator], slot: int) -> dict[str, AggregatedMetricsByLabel]:
8182
"""Compute the metrics from a list of validators.
8283
8384
Parameters:
@@ -123,12 +124,22 @@ def compute_validator_metrics(validators: dict[int, WatchedValidator]) -> dict[s
123124
m.missed_attestations += int(v.missed_attestation == True)
124125
m.missed_consecutive_attestations += int(v.previous_missed_attestation == True and v.missed_attestation == True)
125126

126-
m.proposed_blocks += v.proposed_blocks_total
127-
m.missed_blocks += v.missed_blocks_total
128-
m.proposed_finalized_blocks += v.proposed_blocks_finalized_total
129-
m.missed_finalized_blocks += v.missed_blocks_finalized_total
130-
131-
m.future_blocks += v.future_blocks_proposal
127+
m.proposed_blocks += len(v.proposed_blocks)
128+
m.missed_blocks += len(v.missed_blocks)
129+
m.proposed_finalized_blocks += len(v.proposed_blocks_finalized)
130+
m.missed_finalized_blocks += len(v.missed_blocks_finalized)
131+
132+
m.future_blocks += len(v.future_blocks_proposal)
133+
134+
if label == LABEL_SCOPE_WATCHED:
135+
for proposed in v.proposed_blocks:
136+
logging.info(f"✨ Validator {v.pubkey} proposed block at head slot={proposed} ✨")
137+
for proposed in v.proposed_blocks_finalized:
138+
logging.info(f"✅ Validator {v.pubkey} proposed block at finalized slot={proposed} ✅")
139+
for miss in v.missed_blocks:
140+
logging.info(f"❗Validator {v.pubkey} missed blocks at head slot={miss} ❗")
141+
for miss in v.missed_blocks_finalized:
142+
logging.info(f"❌ Validator {v.pubkey} missed blocks at finalized slot={miss} ❌")
132143

133144
v.reset_counters()
134145

eth_validator_watcher/watched_validators.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ def __init__(self):
6262

6363
# Counters (incremented continuously) ; implies to use rates()
6464
# on the Prometheus side to have meaningful graphs.
65-
self.missed_blocks_total : int = 0
66-
self.missed_blocks_finalized_total : int = 0
67-
self.proposed_blocks_total : int = 0
68-
self.proposed_blocks_finalized_total : int = 0
69-
self.future_blocks_proposal : int = 0
65+
self.missed_blocks : list = []
66+
self.missed_blocks_finalized : list = []
67+
self.proposed_blocks : list = []
68+
self.proposed_blocks_finalized : list = []
69+
self.future_blocks_proposal : list = []
7070

7171
@property
7272
def pubkey(self) -> str:
@@ -129,11 +129,11 @@ def process_liveness(self, liveness: ValidatorsLivenessResponse.Data):
129129
def reset_counters(self):
130130
"""Reset the counters for the next run.
131131
"""
132-
self.missed_blocks_total = 0
133-
self.missed_blocks_finalized_total = 0
134-
self.proposed_blocks_total = 0
135-
self.proposed_blocks_finalized_total = 0
136-
self.future_blocks_proposal = 0
132+
self.missed_blocks.clear()
133+
self.missed_blocks_finalized.clear()
134+
self.proposed_blocks.clear()
135+
self.proposed_blocks_finalized.clear()
136+
self.future_blocks_proposal.clear()
137137

138138

139139

0 commit comments

Comments
 (0)