add test for queue efficiency
This commit is contained in:
parent
d126162ca8
commit
e4d710590a
|
@ -1311,7 +1311,7 @@ def process_registry_updates(state: BeaconState) -> None:
|
|||
if is_active_validator(validator, get_current_epoch(state)) and validator.effective_balance <= EJECTION_BALANCE:
|
||||
initiate_validator_exit(state, ValidatorIndex(index))
|
||||
|
||||
# Queue validators eligible for activation and not yet dequeued for activation prior
|
||||
# Queue validators eligible for activation and not yet dequeued for activation
|
||||
activation_queue = sorted([
|
||||
index for index, validator in enumerate(state.validators)
|
||||
if validator.activation_eligibility_epoch != FAR_FUTURE_EPOCH
|
||||
|
|
|
@ -63,6 +63,34 @@ def test_activation_queue_sorting(spec, state):
|
|||
assert state.validators[churn_limit - 2].activation_epoch != spec.FAR_FUTURE_EPOCH
|
||||
|
||||
|
||||
@with_all_phases
|
||||
@spec_state_test
|
||||
def test_activation_queue_efficiency(spec, state):
|
||||
churn_limit = spec.get_validator_churn_limit(state)
|
||||
mock_activations = churn_limit * 2
|
||||
|
||||
epoch = spec.get_current_epoch(state)
|
||||
for i in range(mock_activations):
|
||||
mock_deposit(spec, state, i)
|
||||
state.validators[i].activation_eligibility_epoch = epoch + 1
|
||||
|
||||
# Run first registry update. Do not yield test vectors
|
||||
for _ in run_process_registry_updates(spec, state):
|
||||
pass
|
||||
|
||||
# Half should churn in first run of registry update
|
||||
for i in range(mock_activations):
|
||||
if i < mock_activations // 2:
|
||||
assert state.validators[i].activation_epoch < spec.FAR_FUTURE_EPOCH
|
||||
else:
|
||||
assert state.validators[i].activation_epoch == spec.FAR_FUTURE_EPOCH
|
||||
|
||||
# Second half should churn in second run of registry update
|
||||
yield from run_process_registry_updates(spec, state)
|
||||
for i in range(mock_activations):
|
||||
assert state.validators[i].activation_epoch < spec.FAR_FUTURE_EPOCH
|
||||
|
||||
|
||||
@with_all_phases
|
||||
@spec_state_test
|
||||
def test_ejection(spec, state):
|
||||
|
|
Loading…
Reference in New Issue