Skip to content

Commit

Permalink
Merge pull request #424 from lidofinance/fix/develop_hotfix
Browse files Browse the repository at this point in the history
Fix/develop hotfix
  • Loading branch information
infloop authored Mar 18, 2024
2 parents 74265f4 + f71e71f commit 9146bf5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM python:3.11-slim as base
FROM python:3.11.6-slim as base

RUN apt-get update && apt-get install -y --no-install-recommends -qq \
gcc=4:10.2.1-1 \
libffi-dev=3.3-6 \
g++=4:10.2.1-1 \
curl=7.74.0-1.3+deb11u7 \
gcc=4:12.2.0-3 \
libffi-dev=3.4.4-1 \
g++=4:12.2.0-3 \
curl=7.88.1-10+deb12u5 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
5 changes: 5 additions & 0 deletions src/services/bunker_cases/abnormal_cl_rebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def is_abnormal_cl_rebase(
logger.info({"msg": "Checking abnormal CL rebase"})

normal_report_cl_rebase = self._calculate_lido_normal_cl_rebase(blockstamp)

# If there were no cl balance, no need to check changes
if normal_report_cl_rebase == 0:
return False

diff_current_with_normal = 1 - current_report_cl_rebase / normal_report_cl_rebase

if diff_current_with_normal > self.b_conf.normalized_cl_reward_mistake_rate:
Expand Down
6 changes: 6 additions & 0 deletions src/utils/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def decorator(func: Callable[..., Sequence]) -> Callable[..., list[T]]:
def wrapper_decorator(*args, **kwargs):
list_of_elements = func(*args, **kwargs)

if not isinstance(list_of_elements, list) and not isinstance(list_of_elements, tuple):
raise DecodeToDataclassException(f'Type {type(list_of_elements)} is not supported.')

if not list_of_elements:
return list_of_elements

if isinstance(list_of_elements[0], dict):
return list(map(lambda x: _dataclass_factory(**x), list_of_elements))

Expand Down
31 changes: 22 additions & 9 deletions tests/modules/accounting/bunker/test_bunker_abnormal_cl_rebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,23 @@ def simple_validators(

@pytest.mark.unit
@pytest.mark.parametrize(
("blockstamp", "frame_cl_rebase", "nearest_epoch_distance", "far_epoch_distance", "expected_is_abnormal"),
(
"blockstamp",
"frame_cl_rebase",
"nearest_epoch_distance",
"far_epoch_distance",
"expected_is_abnormal",
"lido_validators_exist",
),
[
(simple_ref_blockstamp(40), 378585832, 0, 0, False), # < mistake rate
(simple_ref_blockstamp(40), 378585831.6, 0, 0, False), # == mistake rate and no check specific rebase
(simple_ref_blockstamp(40), 378585830, 10, 20, False), # > mistake rate but specific rebase is positive
(simple_ref_blockstamp(40), 378585830, 10, 10, False), # > mistake rate but specific rebase is positive
(simple_ref_blockstamp(40), 378585830, 0, 0, True), # > mistake rate and no check specific rebase
(simple_ref_blockstamp(20), 126195276, 10, 20, True), # > mistake rate and specific rebase is negative
(simple_ref_blockstamp(20), 126195276, 10, 10, True), # > mistake rate and specific rebase is negative
(simple_ref_blockstamp(40), 378585832, 0, 0, False, True), # < mistake rate
(simple_ref_blockstamp(40), 378585831.6, 0, 0, False, True), # == mistake rate and no check specific rebase
(simple_ref_blockstamp(40), 378585830, 10, 20, False, True), # > mistake rate but specific rebase is positive
(simple_ref_blockstamp(40), 378585830, 10, 10, False, True), # > mistake rate but specific rebase is positive
(simple_ref_blockstamp(40), 378585830, 0, 0, True, True), # > mistake rate and no check specific rebase
(simple_ref_blockstamp(20), 126195276, 10, 20, True, True), # > mistake rate and specific rebase is negative
(simple_ref_blockstamp(20), 126195276, 10, 10, True, True), # > mistake rate and specific rebase is negative
(simple_ref_blockstamp(20), 126195276, 10, 10, False, False), # > mistake rate and specific rebase is negative
],
)
def test_is_abnormal_cl_rebase(
Expand All @@ -59,9 +67,14 @@ def test_is_abnormal_cl_rebase(
nearest_epoch_distance,
far_epoch_distance,
expected_is_abnormal,
lido_validators_exist,
):
all_validators = abnormal_case.w3.cc.get_validators(blockstamp)
lido_validators = abnormal_case.w3.cc.get_validators(blockstamp)[3:6]

lido_validators = []
if lido_validators_exist:
lido_validators = abnormal_case.w3.cc.get_validators(blockstamp)[3:6]

abnormal_case.b_conf = BunkerConfig(
normalized_cl_reward_per_epoch=64,
normalized_cl_reward_mistake_rate=0.1,
Expand Down
19 changes: 18 additions & 1 deletion tests/utils/test_dataclass.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, is_dataclass
from typing import Any
from typing import Any, Iterable

import pytest

Expand Down Expand Up @@ -83,6 +83,23 @@ def get_cars_with_already_as_cars() -> list[Car]:
get_cars_with_already_as_cars()


def test_list_of_dataclasses_empty():
@list_of_dataclasses(Car)
def get_no_cars() -> list[Car]:
return []

assert get_no_cars() == []


def test_list_of_dataclasses_generator():
@list_of_dataclasses(Car)
def get_iterable_cars() -> Iterable:
return range(10)

with pytest.raises(DecodeToDataclassException):
get_iterable_cars()


def test_list_of_dataclasses_with_mixed_types():
@list_of_dataclasses(Car)
def get_cars_inconsistent() -> list[Any]:
Expand Down

0 comments on commit 9146bf5

Please sign in to comment.