Skip to content

Commit

Permalink
fix: do not add 32 ether validators to withdrawable
Browse files Browse the repository at this point in the history
  • Loading branch information
madlabman committed Dec 20, 2024
1 parent 41e6a6f commit 1437532
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
11 changes: 1 addition & 10 deletions src/modules/ejector/ejector.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def _get_sweep_delay_in_epochs(self, blockstamp: ReferenceBlockStamp) -> int:
# duration. Roughly every 512 requests adds one more epoch to sweep duration in the current state.
# On the other side, to consider pending withdrawals it is necessary to fetch the beacon state and query the
# EIP-7002 predeployed contract, which adds complexity with limited improvement for predictions.
total_withdrawable_validators = len(self._get_expected_withdrawable_validators(blockstamp))
total_withdrawable_validators = len(self._get_withdrawable_validators(blockstamp))
logger.info({'msg': 'Calculate total withdrawable validators.', 'value': total_withdrawable_validators})
slots_to_sweep = math.ceil(total_withdrawable_validators / MAX_WITHDRAWALS_PER_PAYLOAD)
full_sweep_in_epochs = math.ceil(slots_to_sweep / chain_config.slots_per_epoch)
Expand All @@ -307,15 +307,6 @@ def _get_withdrawable_validators(self, blockstamp: ReferenceBlockStamp) -> list[
if is_partially_withdrawable_validator(v) or is_fully_withdrawable_validator(v, blockstamp.ref_epoch)
]

def _get_expected_withdrawable_validators(self, blockstamp: ReferenceBlockStamp) -> list[Validator]:
def is_withdrawing_validator(v: Validator) -> bool:
# We assume a recently swept or appeared validator will get enough balance waiting for the next sweep cycle.
has_enough_balance_to_sweep = int(v.balance) >= get_max_effective_balance(v)
may_be_swept = has_execution_withdrawal_credential(v) and has_enough_balance_to_sweep
return may_be_swept or is_fully_withdrawable_validator(v, blockstamp.ref_epoch)

return [v for v in self.w3.cc.get_validators(blockstamp) if is_withdrawing_validator(v)]

@lru_cache(maxsize=1)
def _get_churn_limit(self, blockstamp: ReferenceBlockStamp) -> int:
total_active_validators = self._get_total_active_validators(blockstamp)
Expand Down
24 changes: 1 addition & 23 deletions tests/modules/ejector/test_ejector.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def test_get_sweep_delay_in_epochs_post_electra(
m.setattr(
ejector_module,
"is_fully_withdrawable_validator",
Mock(return_value=False),
Mock(return_value=True),
)
delay = ejector._get_sweep_delay_in_epochs(Mock(ref_epoch=0))
assert delay == 2, "Unexpected sweep delay in epochs"
Expand Down Expand Up @@ -435,28 +435,6 @@ def test_get_withdrawable_validators(ejector: Ejector, monkeypatch) -> None:
assert [v.index for v in withdrawable] == [2]


@pytest.mark.unit
def test_get_expected_withdrawable_validators(ejector: Ejector, monkeypatch) -> None:
ejector.w3.cc = Mock()
ejector.w3.cc.get_validators = Mock(
return_value=[
LidoValidatorFactory.build_with_balance(Gwei(32 * 10**9), index=1),
LidoValidatorFactory.build_with_balance(Gwei(33 * 10**9), index=2),
LidoValidatorFactory.build_with_balance(Gwei(31 * 10**9), index=3),
],
)

with monkeypatch.context() as m:
m.setattr(
ejector_module,
"is_fully_withdrawable_validator",
Mock(return_value=False),
)
withdrawable = ejector._get_expected_withdrawable_validators(Mock())

assert [v.index for v in withdrawable] == [1, 2]


@pytest.mark.usefixtures("contracts")
def test_get_total_balance(ejector: Ejector, blockstamp: BlockStamp) -> None:
ejector.w3.lido_contracts.get_withdrawal_balance = Mock(return_value=3)
Expand Down

0 comments on commit 1437532

Please sign in to comment.