Skip to content

Commit 6334d61

Browse files
authored
Merge pull request #565 from lidofinance/fix-first-report-with-frame-before-enact
fix: do not fail on missing digests for stucks
2 parents 6f1969c + 0cc6ca8 commit 6334d61

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM python:3.12.4-slim as base
33
RUN apt-get update && apt-get install -y --no-install-recommends -qq \
44
libffi-dev=3.4.4-1 \
55
g++=4:12.2.0-3 \
6-
curl=7.88.1-10+deb12u7 \
6+
curl=7.88.1-10+deb12u8 \
77
&& apt-get clean \
88
&& rm -rf /var/lib/apt/lists/*
99

src/modules/csm/csm.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,13 @@ def stuck_operators(self, blockstamp: ReferenceBlockStamp) -> set[NodeOperatorId
308308
blockstamp.slot_number,
309309
)
310310
)
311-
digests = self.w3.lido_validators.get_lido_node_operators_by_modules(l_blockstamp).get(self.module_id)
312-
if digests is None:
313-
raise InconsistentData(f"No Node Operators digests found for {self.module_id=}")
314-
stuck.update(no.id for no in digests if no.stuck_validators_count > 0)
311+
312+
nos_by_module = self.w3.lido_validators.get_lido_node_operators_by_modules(l_blockstamp)
313+
if self.module_id in nos_by_module:
314+
stuck.update(no.id for no in nos_by_module[self.module_id] if no.stuck_validators_count > 0)
315+
else:
316+
logger.warning("No CSM digest at blockstamp=%s, module was not added yet?", l_blockstamp)
317+
315318
stuck.update(
316319
self.w3.csm.get_operators_with_stucks_in_range(
317320
l_blockstamp.block_hash,

tests/modules/csm/test_csm_module.py

+50-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from src.providers.ipfs import CIDv0, CID
1717
from src.types import EpochNumber, NodeOperatorId, SlotNumber, StakingModuleId, ValidatorIndex
1818
from src.web3py.extensions.csm import CSM
19-
from tests.factory.blockstamp import ReferenceBlockStampFactory
19+
from tests.factory.blockstamp import BlockStampFactory, ReferenceBlockStampFactory
2020
from tests.factory.configs import ChainConfigFactory, FrameConfigFactory
2121

2222

@@ -83,6 +83,55 @@ def test_stuck_operators(module: CSOracle, csm: CSM):
8383
assert stuck == {NodeOperatorId(2), NodeOperatorId(4), NodeOperatorId(5), NodeOperatorId(6), NodeOperatorId(1337)}
8484

8585

86+
def test_stuck_operators_left_border_before_enact(module: CSOracle, csm: CSM, caplog: pytest.LogCaptureFixture):
87+
module.module = Mock() # type: ignore
88+
module.module_id = StakingModuleId(3)
89+
module.w3.cc = Mock()
90+
module.w3.lido_validators = Mock()
91+
module.w3.lido_contracts = Mock()
92+
module.w3.lido_validators.get_lido_node_operators_by_modules = Mock(
93+
return_value={
94+
1: {
95+
type('NodeOperator', (object,), {'id': 0, 'stuck_validators_count': 0})(),
96+
type('NodeOperator', (object,), {'id': 1, 'stuck_validators_count': 0})(),
97+
type('NodeOperator', (object,), {'id': 2, 'stuck_validators_count': 1})(),
98+
type('NodeOperator', (object,), {'id': 3, 'stuck_validators_count': 0})(),
99+
type('NodeOperator', (object,), {'id': 4, 'stuck_validators_count': 100500})(),
100+
type('NodeOperator', (object,), {'id': 5, 'stuck_validators_count': 100})(),
101+
type('NodeOperator', (object,), {'id': 6, 'stuck_validators_count': 0})(),
102+
},
103+
2: {},
104+
}
105+
)
106+
107+
module.w3.csm.get_operators_with_stucks_in_range = Mock(
108+
return_value=[
109+
NodeOperatorId(2),
110+
NodeOperatorId(4),
111+
NodeOperatorId(6),
112+
]
113+
)
114+
115+
module.current_frame_range = Mock(return_value=(69, 100))
116+
module.converter = Mock()
117+
module.converter.get_epoch_first_slot = Mock(return_value=lambda epoch: epoch * 32)
118+
119+
l_blockstamp = BlockStampFactory.build()
120+
blockstamp = BlockStampFactory.build()
121+
122+
with patch('src.modules.csm.csm.build_blockstamp', return_value=l_blockstamp):
123+
with patch('src.modules.csm.csm.get_next_non_missed_slot', return_value=Mock()):
124+
stuck = module.stuck_operators(blockstamp=blockstamp)
125+
126+
assert stuck == {
127+
NodeOperatorId(2),
128+
NodeOperatorId(4),
129+
NodeOperatorId(6),
130+
}
131+
132+
assert caplog.messages[0].startswith("No CSM digest at blockstamp")
133+
134+
86135
def test_calculate_distribution(module: CSOracle, csm: CSM):
87136
csm.fee_distributor.shares_to_distribute = Mock(return_value=10_000)
88137
csm.oracle.perf_leeway_bp = Mock(return_value=500)

0 commit comments

Comments
 (0)