diff --git a/tests/phase0/block_processing/test_process_attestation.py b/tests/phase0/block_processing/test_process_attestation.py index ca6933ce7..1e8ee4488 100644 --- a/tests/phase0/block_processing/test_process_attestation.py +++ b/tests/phase0/block_processing/test_process_attestation.py @@ -7,7 +7,6 @@ from build.phase0.state_transition import ( state_transition, ) from build.phase0.spec import ( - ZERO_HASH, get_current_epoch, process_attestation, slot_to_epoch, @@ -102,7 +101,7 @@ def test_bad_source_root(state): attestation = get_valid_attestation(state) state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY - attestation.data.source_root = b'\x42'*32 + attestation.data.source_root = b'\x42' * 32 pre_state, post_state = run_attestation_processing(state, attestation, False) @@ -113,7 +112,7 @@ def test_non_zero_crosslink_data_root(state): attestation = get_valid_attestation(state) state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY - attestation.data.crosslink_data_root = b'\x42'*32 + attestation.data.crosslink_data_root = b'\x42' * 32 pre_state, post_state = run_attestation_processing(state, attestation, False) diff --git a/tests/phase0/block_processing/test_process_attester_slashing.py b/tests/phase0/block_processing/test_process_attester_slashing.py index 06f214c4b..cf58ee244 100644 --- a/tests/phase0/block_processing/test_process_attester_slashing.py +++ b/tests/phase0/block_processing/test_process_attester_slashing.py @@ -31,7 +31,6 @@ def run_attester_slashing_processing(state, attester_slashing, valid=True): slashed_index = attester_slashing.attestation_1.custody_bit_0_indices[0] slashed_validator = post_state.validator_registry[slashed_index] - assert not slashed_validator.initiated_exit assert slashed_validator.slashed assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH diff --git a/tests/phase0/block_processing/test_process_block_header.py b/tests/phase0/block_processing/test_process_block_header.py index 4981b656c..508a70b19 100644 --- a/tests/phase0/block_processing/test_process_block_header.py +++ b/tests/phase0/block_processing/test_process_block_header.py @@ -54,7 +54,7 @@ def test_invalid_slot(state): def test_invalid_previous_block_root(state): block = build_empty_block_for_next_slot(state) - block.previous_block_root = b'\12'*32 # invalid prev root + block.previous_block_root = b'\12' * 32 # invalid prev root pre_state, post_state = run_block_header_processing(state, block, valid=False) return pre_state, block, None diff --git a/tests/phase0/block_processing/test_process_proposer_slashing.py b/tests/phase0/block_processing/test_process_proposer_slashing.py index 467d2164b..317829518 100644 --- a/tests/phase0/block_processing/test_process_proposer_slashing.py +++ b/tests/phase0/block_processing/test_process_proposer_slashing.py @@ -30,7 +30,6 @@ def run_proposer_slashing_processing(state, proposer_slashing, valid=True): process_proposer_slashing(post_state, proposer_slashing) slashed_validator = post_state.validator_registry[proposer_slashing.proposer_index] - assert not slashed_validator.initiated_exit assert slashed_validator.slashed assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH diff --git a/tests/phase0/block_processing/test_voluntary_exit.py b/tests/phase0/block_processing/test_voluntary_exit.py index 6adc81464..7627f1f0b 100644 --- a/tests/phase0/block_processing/test_voluntary_exit.py +++ b/tests/phase0/block_processing/test_voluntary_exit.py @@ -47,8 +47,8 @@ def test_success(state): # process_voluntary_exit(post_state, voluntary_exit) - assert not pre_state.validator_registry[validator_index].initiated_exit - assert post_state.validator_registry[validator_index].initiated_exit + assert pre_state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + assert post_state.validator_registry[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH return pre_state, voluntary_exit, post_state @@ -111,37 +111,6 @@ def test_validator_already_exited(state): return pre_state, voluntary_exit, None -def test_validator_already_initiated_exit(state): - pre_state = deepcopy(state) - # - # setup pre_state - # - # move state forward PERSISTENT_COMMITTEE_PERIOD epochs to allow validator able to exit - pre_state.slot += spec.PERSISTENT_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - - current_epoch = get_current_epoch(pre_state) - validator_index = get_active_validator_indices(pre_state.validator_registry, current_epoch)[0] - privkey = pubkey_to_privkey[pre_state.validator_registry[validator_index].pubkey] - - # but validator already has initiated exit - pre_state.validator_registry[validator_index].initiated_exit = True - - # - # build voluntary exit - # - voluntary_exit = build_voluntary_exit( - pre_state, - current_epoch, - validator_index, - privkey, - ) - - with pytest.raises(AssertionError): - process_voluntary_exit(pre_state, voluntary_exit) - - return pre_state, voluntary_exit, None - - def test_validator_not_active_long_enough(state): pre_state = deepcopy(state) # @@ -151,9 +120,6 @@ def test_validator_not_active_long_enough(state): validator_index = get_active_validator_indices(pre_state.validator_registry, current_epoch)[0] privkey = pubkey_to_privkey[pre_state.validator_registry[validator_index].pubkey] - # but validator already has initiated exit - pre_state.validator_registry[validator_index].initiated_exit = True - # # build voluntary exit # diff --git a/tests/phase0/helpers.py b/tests/phase0/helpers.py index 33f394def..e60c7c64c 100644 --- a/tests/phase0/helpers.py +++ b/tests/phase0/helpers.py @@ -25,7 +25,6 @@ from build.phase0.spec import ( get_attestation_participants, get_block_root, get_crosslink_committee_for_attestation, - get_crosslink_committees_at_slot, get_current_epoch, get_domain, get_empty_block, @@ -249,7 +248,7 @@ def get_valid_proposer_slashing(state): def get_valid_attester_slashing(state): attestation_1 = get_valid_attestation(state) attestation_2 = deepcopy(attestation_1) - attestation_2.data.target_root = b'\x01'*32 + attestation_2.data.target_root = b'\x01' * 32 return AttesterSlashing( attestation_1=convert_to_indexed(state, attestation_1), diff --git a/tests/phase0/test_sanity.py b/tests/phase0/test_sanity.py index 90825242f..a2ce8928b 100644 --- a/tests/phase0/test_sanity.py +++ b/tests/phase0/test_sanity.py @@ -128,11 +128,9 @@ def test_proposer_slashing(state): block.body.proposer_slashings.append(proposer_slashing) state_transition(test_state, block) - assert not state.validator_registry[validator_index].initiated_exit assert not state.validator_registry[validator_index].slashed slashed_validator = test_state.validator_registry[validator_index] - assert not slashed_validator.initiated_exit assert slashed_validator.slashed assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH @@ -154,11 +152,9 @@ def test_attester_slashing(state): block.body.attester_slashings.append(attester_slashing) state_transition(test_state, block) - assert not state.validator_registry[validator_index].initiated_exit assert not state.validator_registry[validator_index].slashed slashed_validator = test_state.validator_registry[validator_index] - assert not slashed_validator.initiated_exit assert slashed_validator.slashed assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH @@ -316,9 +312,7 @@ def test_voluntary_exit(state): initiate_exit_block.body.voluntary_exits.append(voluntary_exit) state_transition(post_state, initiate_exit_block) - assert not pre_state.validator_registry[validator_index].initiated_exit - assert post_state.validator_registry[validator_index].initiated_exit - assert post_state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + assert post_state.validator_registry[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH # # Process within epoch transition @@ -350,8 +344,6 @@ def test_no_exit_churn_too_long_since_change(state): pre_state.validator_registry_update_epoch = ( get_current_epoch(pre_state) - spec.LATEST_SLASHED_EXIT_LENGTH ) - # set validator to have previously initiated exit - pre_state.validator_registry[validator_index].initiated_exit = True post_state = deepcopy(pre_state) @@ -362,8 +354,10 @@ def test_no_exit_churn_too_long_since_change(state): block.slot += spec.SLOTS_PER_EPOCH state_transition(post_state, block) - assert post_state.validator_registry_update_epoch == get_current_epoch(post_state) - 1 + assert post_state.validator_registry[validator_index].activation_eligibility_epoch == spec.FAR_FUTURE_EPOCH assert post_state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + assert post_state.exit_queue_filled == pre_state.exit_queue_filled + assert post_state.exit_epoch == pre_state.exit_epoch return pre_state, [block], post_state @@ -419,7 +413,7 @@ def test_transfer(state): return pre_state, [block], post_state -def test_ejection(state): +def test_balance_driven_status_transitions(state): pre_state = deepcopy(state) current_epoch = get_current_epoch(pre_state) @@ -438,7 +432,7 @@ def test_ejection(state): block.slot += spec.SLOTS_PER_EPOCH state_transition(post_state, block) - assert post_state.validator_registry[validator_index].initiated_exit == True + assert post_state.validator_registry[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH return pre_state, [block], post_state diff --git a/utils/phase0/state_transition.py b/utils/phase0/state_transition.py index 2c420014f..3a3601ddb 100644 --- a/utils/phase0/state_transition.py +++ b/utils/phase0/state_transition.py @@ -94,10 +94,9 @@ def process_epoch_transition(state: BeaconState) -> None: spec.process_crosslinks(state) spec.maybe_reset_eth1_period(state) spec.apply_rewards(state) - spec.process_ejections(state) + spec.process_balance_driven_status_transitions(state) spec.update_registry(state) spec.process_slashings(state) - spec.process_exit_queue(state) spec.finish_epoch_update(state)