fix and add tests for activation queue
This commit is contained in:
parent
e117b58ae2
commit
e8d079b366
|
@ -1,4 +1,7 @@
|
||||||
from eth2spec.test.helpers.state import next_epoch
|
from eth2spec.test.helpers.state import (
|
||||||
|
next_epoch,
|
||||||
|
next_epoch_with_attestations,
|
||||||
|
)
|
||||||
from eth2spec.test.context import spec_state_test, with_all_phases
|
from eth2spec.test.context import spec_state_test, with_all_phases
|
||||||
from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import run_epoch_processing_with
|
from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import run_epoch_processing_with
|
||||||
|
|
||||||
|
@ -17,18 +20,71 @@ def mock_deposit(spec, state, index):
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_activation(spec, state):
|
def test_add_to_activation_queue(spec, state):
|
||||||
|
# move past first two irregular epochs wrt finality
|
||||||
|
next_epoch(spec, state)
|
||||||
|
next_epoch(spec, state)
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
mock_deposit(spec, state, index)
|
mock_deposit(spec, state, index)
|
||||||
|
|
||||||
for _ in range(spec.MAX_SEED_LOOKAHEAD + 1):
|
yield from run_process_registry_updates(spec, state)
|
||||||
|
|
||||||
|
# validator moved into queue
|
||||||
|
assert state.validators[index].activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
|
assert state.validators[index].activation_epoch == spec.FAR_FUTURE_EPOCH
|
||||||
|
assert not spec.is_active_validator(state.validators[index], spec.get_current_epoch(state))
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_activation_queue_to_activated_if_finalized(spec, state):
|
||||||
|
# move past first two irregular epochs wrt finality
|
||||||
next_epoch(spec, state)
|
next_epoch(spec, state)
|
||||||
|
next_epoch(spec, state)
|
||||||
|
|
||||||
|
index = 0
|
||||||
|
mock_deposit(spec, state, index)
|
||||||
|
|
||||||
|
# mock validator as having been in queue since before latest finalized
|
||||||
|
state.finalized_checkpoint.epoch = spec.get_current_epoch(state) - 1
|
||||||
|
state.validators[index].activation_eligibility_epoch = state.finalized_checkpoint.epoch - 1
|
||||||
|
|
||||||
|
assert not spec.is_active_validator(state.validators[index], spec.get_current_epoch(state))
|
||||||
|
|
||||||
yield from run_process_registry_updates(spec, state)
|
yield from run_process_registry_updates(spec, state)
|
||||||
|
|
||||||
|
# validator activated for future epoch
|
||||||
assert state.validators[index].activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH
|
assert state.validators[index].activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
assert state.validators[index].activation_epoch != spec.FAR_FUTURE_EPOCH
|
assert state.validators[index].activation_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
assert spec.is_active_validator(state.validators[index], spec.get_current_epoch(state))
|
assert not spec.is_active_validator(state.validators[index], spec.get_current_epoch(state))
|
||||||
|
assert spec.is_active_validator(
|
||||||
|
state.validators[index],
|
||||||
|
spec.compute_activation_exit_epoch(spec.get_current_epoch(state))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_activation_queue_no_activation_no_finality(spec, state):
|
||||||
|
# move past first two irregular epochs wrt finality
|
||||||
|
next_epoch(spec, state)
|
||||||
|
next_epoch(spec, state)
|
||||||
|
|
||||||
|
index = 0
|
||||||
|
mock_deposit(spec, state, index)
|
||||||
|
|
||||||
|
# mock validator as having been in queue only since latest finalized (not before)
|
||||||
|
state.finalized_checkpoint.epoch = spec.get_current_epoch(state) - 1
|
||||||
|
state.validators[index].activation_eligibility_epoch = state.finalized_checkpoint.epoch
|
||||||
|
|
||||||
|
assert not spec.is_active_validator(state.validators[index], spec.get_current_epoch(state))
|
||||||
|
|
||||||
|
yield from run_process_registry_updates(spec, state)
|
||||||
|
|
||||||
|
# validator not activated
|
||||||
|
assert state.validators[index].activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
|
assert state.validators[index].activation_epoch == spec.FAR_FUTURE_EPOCH
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
|
@ -44,6 +100,10 @@ def test_activation_queue_sorting(spec, state):
|
||||||
# give the last priority over the others
|
# give the last priority over the others
|
||||||
state.validators[mock_activations - 1].activation_eligibility_epoch = epoch
|
state.validators[mock_activations - 1].activation_eligibility_epoch = epoch
|
||||||
|
|
||||||
|
# move state forward and finalize to allow for activations
|
||||||
|
state.slot += spec.SLOTS_PER_EPOCH * 3
|
||||||
|
state.finalized_checkpoint.epoch = epoch + 2
|
||||||
|
|
||||||
# make sure we are hitting the churn
|
# make sure we are hitting the churn
|
||||||
churn_limit = spec.get_validator_churn_limit(state)
|
churn_limit = spec.get_validator_churn_limit(state)
|
||||||
assert mock_activations > churn_limit
|
assert mock_activations > churn_limit
|
||||||
|
@ -74,6 +134,10 @@ def test_activation_queue_efficiency(spec, state):
|
||||||
mock_deposit(spec, state, i)
|
mock_deposit(spec, state, i)
|
||||||
state.validators[i].activation_eligibility_epoch = epoch + 1
|
state.validators[i].activation_eligibility_epoch = epoch + 1
|
||||||
|
|
||||||
|
# move state forward and finalize to allow for activations
|
||||||
|
state.slot += spec.SLOTS_PER_EPOCH * 3
|
||||||
|
state.finalized_checkpoint.epoch = epoch + 2
|
||||||
|
|
||||||
# Run first registry update. Do not yield test vectors
|
# Run first registry update. Do not yield test vectors
|
||||||
for _ in run_process_registry_updates(spec, state):
|
for _ in run_process_registry_updates(spec, state):
|
||||||
pass
|
pass
|
||||||
|
@ -101,13 +165,11 @@ def test_ejection(spec, state):
|
||||||
# Mock an ejection
|
# Mock an ejection
|
||||||
state.validators[index].effective_balance = spec.EJECTION_BALANCE
|
state.validators[index].effective_balance = spec.EJECTION_BALANCE
|
||||||
|
|
||||||
for _ in range(spec.MAX_SEED_LOOKAHEAD + 1):
|
|
||||||
next_epoch(spec, state)
|
|
||||||
|
|
||||||
yield from run_process_registry_updates(spec, state)
|
yield from run_process_registry_updates(spec, state)
|
||||||
|
|
||||||
assert state.validators[index].exit_epoch != spec.FAR_FUTURE_EPOCH
|
assert state.validators[index].exit_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
|
assert spec.is_active_validator(state.validators[index], spec.get_current_epoch(state))
|
||||||
assert not spec.is_active_validator(
|
assert not spec.is_active_validator(
|
||||||
state.validators[index],
|
state.validators[index],
|
||||||
spec.get_current_epoch(state),
|
spec.compute_activation_exit_epoch(spec.get_current_epoch(state))
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue