From 7b2ff584e20ad4ba5f6f45067ac04db908b22c85 Mon Sep 17 00:00:00 2001 From: hweawer Date: Tue, 15 Oct 2024 10:08:24 +0200 Subject: [PATCH 1/2] Rename churn limit to exit churn limit --- src/constants.py | 4 ++-- src/modules/ejector/ejector.py | 12 ++++++------ src/utils/validator_state.py | 6 +++--- tests/modules/ejector/test_ejector.py | 24 ++++++++++++------------ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/constants.py b/src/constants.py index e3dc6b67d..0199231b0 100644 --- a/src/constants.py +++ b/src/constants.py @@ -16,8 +16,8 @@ # https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#withdrawal-prefixes ETH1_ADDRESS_WITHDRAWAL_PREFIX = '0x01' # https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#validator-cycle -MIN_PER_EPOCH_CHURN_LIMIT = 2 ** 2 -CHURN_LIMIT_QUOTIENT = 2 ** 16 +MIN_PER_EPOCH_EXIT_CHURN_LIMIT = 2 ** 2 +EXIT_CHURN_LIMIT_QUOTIENT = 2 ** 16 # https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#time-parameters SLOTS_PER_HISTORICAL_ROOT = 8192 diff --git a/src/modules/ejector/ejector.py b/src/modules/ejector/ejector.py index 7fc0f9119..1efc485e5 100644 --- a/src/modules/ejector/ejector.py +++ b/src/modules/ejector/ejector.py @@ -243,9 +243,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) @@ -299,11 +299,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 = len([ diff --git a/src/utils/validator_state.py b/src/utils/validator_state.py index 56449f290..37527ffc3 100644 --- a/src/utils/validator_state.py +++ b/src/utils/validator_state.py @@ -7,8 +7,8 @@ FAR_FUTURE_EPOCH, EFFECTIVE_BALANCE_INCREMENT, MAX_SEED_LOOKAHEAD, - MIN_PER_EPOCH_CHURN_LIMIT, - CHURN_LIMIT_QUOTIENT, + MIN_PER_EPOCH_EXIT_CHURN_LIMIT, + EXIT_CHURN_LIMIT_QUOTIENT, ) from src.providers.consensus.types import Validator from src.types import EpochNumber, Gwei @@ -113,4 +113,4 @@ def compute_activation_exit_epoch(ref_epoch: EpochNumber): def compute_exit_churn_limit(active_validators_count: int): - return max(MIN_PER_EPOCH_CHURN_LIMIT, active_validators_count // CHURN_LIMIT_QUOTIENT) + return max(MIN_PER_EPOCH_EXIT_CHURN_LIMIT, active_validators_count // EXIT_CHURN_LIMIT_QUOTIENT) diff --git a/tests/modules/ejector/test_ejector.py b/tests/modules/ejector/test_ejector.py index 0b80ba7e9..9b271fdfd 100644 --- a/tests/modules/ejector/test_ejector.py +++ b/tests/modules/ejector/test_ejector.py @@ -225,7 +225,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" @@ -338,7 +338,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: @@ -352,15 +352,15 @@ 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) - assert result == constants.MIN_PER_EPOCH_CHURN_LIMIT, "Unexpected churn limit" + result = ejector._get_exit_churn_limit(ref_blockstamp) + assert result == constants.MIN_PER_EPOCH_EXIT_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, @@ -368,13 +368,13 @@ def test_get_churn_limit_validators_less_than_min_churn( ) -> 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, @@ -382,11 +382,11 @@ def test_get_churn_limit_basic( ) -> None: with monkeypatch.context() as m: 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) + m.setattr(validator_state, "MIN_PER_EPOCH_EXIT_CHURN_LIMIT", 0) + m.setattr(validator_state, "EXIT_CHURN_LIMIT_QUOTIENT", 2) + 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) From caaf5b38a99d8cf8338bd6a014e551ded201ab92 Mon Sep 17 00:00:00 2001 From: hweawer Date: Thu, 28 Nov 2024 16:45:16 +0100 Subject: [PATCH 2/2] Return envs --- src/constants.py | 4 ++-- src/utils/validator_state.py | 6 +++--- tests/modules/ejector/test_ejector.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/constants.py b/src/constants.py index 0199231b0..e3dc6b67d 100644 --- a/src/constants.py +++ b/src/constants.py @@ -16,8 +16,8 @@ # https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#withdrawal-prefixes ETH1_ADDRESS_WITHDRAWAL_PREFIX = '0x01' # https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#validator-cycle -MIN_PER_EPOCH_EXIT_CHURN_LIMIT = 2 ** 2 -EXIT_CHURN_LIMIT_QUOTIENT = 2 ** 16 +MIN_PER_EPOCH_CHURN_LIMIT = 2 ** 2 +CHURN_LIMIT_QUOTIENT = 2 ** 16 # https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#time-parameters SLOTS_PER_HISTORICAL_ROOT = 8192 diff --git a/src/utils/validator_state.py b/src/utils/validator_state.py index 37527ffc3..56449f290 100644 --- a/src/utils/validator_state.py +++ b/src/utils/validator_state.py @@ -7,8 +7,8 @@ FAR_FUTURE_EPOCH, EFFECTIVE_BALANCE_INCREMENT, MAX_SEED_LOOKAHEAD, - MIN_PER_EPOCH_EXIT_CHURN_LIMIT, - EXIT_CHURN_LIMIT_QUOTIENT, + MIN_PER_EPOCH_CHURN_LIMIT, + CHURN_LIMIT_QUOTIENT, ) from src.providers.consensus.types import Validator from src.types import EpochNumber, Gwei @@ -113,4 +113,4 @@ def compute_activation_exit_epoch(ref_epoch: EpochNumber): def compute_exit_churn_limit(active_validators_count: int): - return max(MIN_PER_EPOCH_EXIT_CHURN_LIMIT, active_validators_count // EXIT_CHURN_LIMIT_QUOTIENT) + return max(MIN_PER_EPOCH_CHURN_LIMIT, active_validators_count // CHURN_LIMIT_QUOTIENT) diff --git a/tests/modules/ejector/test_ejector.py b/tests/modules/ejector/test_ejector.py index 9b271fdfd..bea8da3c0 100644 --- a/tests/modules/ejector/test_ejector.py +++ b/tests/modules/ejector/test_ejector.py @@ -355,7 +355,7 @@ def mock_is_active_validator(self, monkeypatch: pytest.MonkeyPatch) -> Iterable: 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_exit_churn_limit(ref_blockstamp) - assert result == constants.MIN_PER_EPOCH_EXIT_CHURN_LIMIT, "Unexpected churn limit" + 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 @@ -382,8 +382,8 @@ def test_get_exit_churn_limit_basic( ) -> None: with monkeypatch.context() as m: ejector.w3.cc.get_validators = Mock(return_value=[1] * 99) - m.setattr(validator_state, "MIN_PER_EPOCH_EXIT_CHURN_LIMIT", 0) - m.setattr(validator_state, "EXIT_CHURN_LIMIT_QUOTIENT", 2) + m.setattr(validator_state, "MIN_PER_EPOCH_CHURN_LIMIT", 0) + m.setattr(validator_state, "CHURN_LIMIT_QUOTIENT", 2) result = ejector._get_exit_churn_limit(ref_blockstamp) assert result == 49, "Unexpected churn limit" ejector._get_exit_churn_limit(ref_blockstamp)