Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename churn limit to exit churn limit #540

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/modules/ejector/ejector.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ def _get_predicted_withdrawable_epoch(
max_exit_epoch_number = activation_exit_epoch
latest_to_exit_validators_count = 0

churn_limit = self._get_churn_limit(blockstamp)
exit_churn_limit = self._get_exit_churn_limit(blockstamp)

epochs_required_to_exit_validators = (validators_to_eject_count + latest_to_exit_validators_count) // churn_limit
epochs_required_to_exit_validators = (validators_to_eject_count + latest_to_exit_validators_count) // exit_churn_limit

return EpochNumber(max_exit_epoch_number + epochs_required_to_exit_validators + MIN_VALIDATOR_WITHDRAWABILITY_DELAY)

Expand Down Expand Up @@ -301,11 +301,11 @@ def _get_total_withdrawable_validators(self, blockstamp: ReferenceBlockStamp) ->
return total_withdrawable_validators

@lru_cache(maxsize=1)
def _get_churn_limit(self, blockstamp: ReferenceBlockStamp) -> int:
def _get_exit_churn_limit(self, blockstamp: ReferenceBlockStamp) -> int:
total_active_validators = self._get_total_active_validators(blockstamp)
churn_limit = compute_exit_churn_limit(total_active_validators)
logger.info({'msg': 'Calculate churn limit.', 'value': churn_limit})
return churn_limit
exit_churn_limit = compute_exit_churn_limit(total_active_validators)
logger.info({'msg': 'Calculate exit churn limit.', 'value': exit_churn_limit})
return exit_churn_limit

def _get_total_active_validators(self, blockstamp: ReferenceBlockStamp) -> int:
total_active_validators = reduce(
Expand Down
18 changes: 9 additions & 9 deletions tests/modules/ejector/test_ejector.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_is_contract_reportable(ejector: Ejector, blockstamp: BlockStamp) -> Non
@pytest.mark.unit
def test_get_predicted_withdrawable_epoch(ejector: Ejector) -> None:
ejector._get_latest_exit_epoch = Mock(return_value=[1, 32])
ejector._get_churn_limit = Mock(return_value=2)
ejector._get_exit_churn_limit = Mock(return_value=2)
ref_blockstamp = ReferenceBlockStampFactory.build(ref_epoch=3546)
result = ejector._get_predicted_withdrawable_epoch(ref_blockstamp, 2)
assert result == 3808, "Unexpected predicted withdrawable epoch"
Expand Down Expand Up @@ -355,7 +355,7 @@ def test_get_total_balance(ejector: Ejector, blockstamp: BlockStamp) -> None:


class TestChurnLimit:
"""_get_churn_limit tests"""
"""_get_exit_churn_limit tests"""

@pytest.fixture(autouse=True)
def mock_is_active_validator(self, monkeypatch: pytest.MonkeyPatch) -> Iterable:
Expand All @@ -369,29 +369,29 @@ def mock_is_active_validator(self, monkeypatch: pytest.MonkeyPatch) -> Iterable:

@pytest.mark.unit
@pytest.mark.usefixtures("consensus_client")
def test_get_churn_limit_no_validators(self, ejector: Ejector, ref_blockstamp: ReferenceBlockStamp) -> None:
def test_get_exit_churn_limit_no_validators(self, ejector: Ejector, ref_blockstamp: ReferenceBlockStamp) -> None:
ejector.w3.cc.get_validators = Mock(return_value=[])
result = ejector._get_churn_limit(ref_blockstamp)
result = ejector._get_exit_churn_limit(ref_blockstamp)
assert result == constants.MIN_PER_EPOCH_CHURN_LIMIT, "Unexpected churn limit"
ejector.w3.cc.get_validators.assert_called_once_with(ref_blockstamp)

@pytest.mark.unit
@pytest.mark.usefixtures("consensus_client")
def test_get_churn_limit_validators_less_than_min_churn(
def test_get_exit_churn_limit_validators_less_than_min_churn(
self,
ejector: Ejector,
ref_blockstamp: ReferenceBlockStamp,
monkeypatch: pytest.MonkeyPatch,
) -> None:
with monkeypatch.context() as m:
ejector.w3.cc.get_validators = Mock(return_value=[1, 1, 0])
result = ejector._get_churn_limit(ref_blockstamp)
result = ejector._get_exit_churn_limit(ref_blockstamp)
assert result == 4, "Unexpected churn limit"
ejector.w3.cc.get_validators.assert_called_once_with(ref_blockstamp)

@pytest.mark.unit
@pytest.mark.usefixtures("consensus_client")
def test_get_churn_limit_basic(
def test_get_exit_churn_limit_basic(
self,
ejector: Ejector,
ref_blockstamp: ReferenceBlockStamp,
Expand All @@ -401,9 +401,9 @@ def test_get_churn_limit_basic(
ejector.w3.cc.get_validators = Mock(return_value=[1] * 99)
m.setattr(validator_state, "MIN_PER_EPOCH_CHURN_LIMIT", 0)
m.setattr(validator_state, "CHURN_LIMIT_QUOTIENT", 2)
result = ejector._get_churn_limit(ref_blockstamp)
result = ejector._get_exit_churn_limit(ref_blockstamp)
assert result == 49, "Unexpected churn limit"
ejector._get_churn_limit(ref_blockstamp)
ejector._get_exit_churn_limit(ref_blockstamp)
ejector.w3.cc.get_validators.assert_called_once_with(ref_blockstamp)


Expand Down
Loading