Skip to content

Commit

Permalink
Merge pull request #515 from lidofinance/fix-defaultdict-access
Browse files Browse the repository at this point in the history
fix: defaultdict access dont raise KeyError
  • Loading branch information
F4ever authored Sep 9, 2024
2 parents dbd4a62 + 339438c commit 13366d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/modules/csm/csm.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,18 @@ def calculate_distribution(
continue

for v in validators:
try:
aggr = self.state.data[ValidatorIndex(int(v.index))]
except KeyError:
aggr = self.state.data.get(ValidatorIndex(int(v.index)))

if aggr is None:
# It's possible that the validator is not assigned to any duty, hence it's performance
# is not presented in the aggregates (e.g. exited, pending for activation etc).
continue
else:
if v.validator.slashed is True:
# It means that validator was active during the frame and got slashed and didn't meet the exit
# epoch, so we should not count such validator for operator's share.
log.operators[no_id].validators[v.index].slashed = True
continue

if v.validator.slashed is True:
# It means that validator was active during the frame and got slashed and didn't meet the exit
# epoch, so we should not count such validator for operator's share.
log.operators[no_id].validators[v.index].slashed = True
continue

if aggr.perf > threshold:
# Count of assigned attestations used as a metrics of time
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/csm/test_csm_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_calculate_distribution(module: CSOracle, csm: CSM):
NodeOperatorId(4),
NodeOperatorId(5),
NodeOperatorId(6),
NodeOperatorId(7),
# NodeOperatorId(7), # Missing in state
NodeOperatorId(8),
NodeOperatorId(9),
)
Expand Down

0 comments on commit 13366d5

Please sign in to comment.