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

Withdrawal queue -> exit queue #850

Merged
merged 34 commits into from
Apr 14, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1aaa003
Withdrawal queue -> exit queue
vbuterin Mar 28, 2019
deb0e32
Fixes to make Justin happy
vbuterin Mar 28, 2019
aa4bbcc
Bugfix
hwwhww Mar 28, 2019
9c4e034
Merge branch 'dev' into vbuterin-patch-13
hwwhww Mar 29, 2019
a2dae9a
Fix after merging
hwwhww Mar 29, 2019
15498f2
Fixed exit epoch conditional
vbuterin Mar 31, 2019
2529cb1
Update 0_beacon-chain.md
JustinDrake Apr 3, 2019
169579c
Update 0_beacon-chain.md
JustinDrake Apr 6, 2019
7f0a93f
Update 0_beacon-chain.md
JustinDrake Apr 6, 2019
63412d9
Update 0_beacon-chain.md
JustinDrake Apr 6, 2019
5ea5746
Fix `get_genesis_beacon_state` and minor refactoring
hwwhww Apr 6, 2019
8958cf8
Merge branch 'dev' into vbuterin-patch-13
hwwhww Apr 6, 2019
ebba3f5
Fix typo
hwwhww Apr 6, 2019
00872e0
Updated tests
hwwhww Apr 6, 2019
47464f2
Update 0_beacon-chain.md
JustinDrake Apr 6, 2019
4630b13
Fix/Remove pointless assertion
hwwhww Apr 7, 2019
846e2d6
Remove `force_registry_change_at_next_epoch`
hwwhww Apr 7, 2019
cc2d005
Merge branch 'dev' into vbuterin-patch-13
vbuterin Apr 13, 2019
f7c5b0a
set activation_eligibility_epoch during process_deposit
djrtwo Apr 13, 2019
3700440
add exit queue test
djrtwo Apr 13, 2019
bade9ff
enhance exit queue test
djrtwo Apr 13, 2019
f85e7ac
Added churn limit logic
vbuterin Apr 14, 2019
0d64483
Update 0_beacon-chain.md
JustinDrake Apr 14, 2019
d01fb80
Update 0_beacon-chain.md
JustinDrake Apr 14, 2019
15bb967
Update 0_beacon-chain.md
JustinDrake Apr 14, 2019
7705ecf
Update 0_beacon-chain.md
JustinDrake Apr 14, 2019
da4a143
fix test
djrtwo Apr 14, 2019
229af3d
Update 0_beacon-chain.md
JustinDrake Apr 14, 2019
0b77012
Update 0_beacon-chain.md
JustinDrake Apr 14, 2019
06807cf
fix tests and off by one error
djrtwo Apr 14, 2019
704ea7c
Merge branch 'vbuterin-patch-13' of github.com:ethereum/eth2.0-specs …
djrtwo Apr 14, 2019
0908ffa
Update 0_beacon-chain.md
JustinDrake Apr 14, 2019
875b2ba
Update 0_beacon-chain.md
JustinDrake Apr 14, 2019
3394368
Update 0_beacon-chain.md
JustinDrake Apr 14, 2019
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
222 changes: 75 additions & 147 deletions specs/core/0_beacon-chain.md

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions tests/phase0/block_processing/test_process_attestation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
state_transition,
)
from build.phase0.spec import (
ZERO_HASH,
get_current_epoch,
process_attestation,
slot_to_epoch,
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/phase0/block_processing/test_process_block_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 2 additions & 36 deletions tests/phase0/block_processing/test_voluntary_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
#
Expand All @@ -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
#
Expand Down
11 changes: 1 addition & 10 deletions tests/phase0/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
get_attestation_participants,
get_block_root,
get_crosslink_committee_for_attestation,
get_crosslink_committees_at_slot,
get_current_epoch,
get_domain,
get_empty_block,
Expand Down Expand Up @@ -96,14 +95,6 @@ def create_genesis_state(num_validators, deposit_data_leaves=None):
)


def force_registry_change_at_next_epoch(state):
# artificially trigger registry update at next epoch transition
state.finalized_epoch = get_current_epoch(state) - 1
for crosslink in state.latest_crosslinks:
crosslink.epoch = state.finalized_epoch
state.validator_registry_update_epoch = state.finalized_epoch - 1


def build_empty_block_for_next_slot(state):
empty_block = get_empty_block()
empty_block.slot = state.slot + 1
Expand Down Expand Up @@ -249,7 +240,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),
Expand Down
26 changes: 5 additions & 21 deletions tests/phase0/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from tests.phase0.helpers import (
build_deposit_data,
build_empty_block_for_next_slot,
force_registry_change_at_next_epoch,
get_valid_attestation,
get_valid_attester_slashing,
get_valid_proposer_slashing,
Expand Down Expand Up @@ -128,11 +127,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
Expand All @@ -154,11 +151,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
Expand Down Expand Up @@ -289,8 +284,6 @@ def test_voluntary_exit(state):

# move state forward PERSISTENT_COMMITTEE_PERIOD epochs to allow for exit
pre_state.slot += spec.PERSISTENT_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
# artificially trigger registry update at next epoch transition
force_registry_change_at_next_epoch(pre_state)

post_state = deepcopy(pre_state)

Expand All @@ -316,9 +309,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
Expand All @@ -344,14 +335,6 @@ def test_no_exit_churn_too_long_since_change(state):
#
# move state forward PERSISTENT_COMMITTEE_PERIOD epochs to allow for exit
pre_state.slot += spec.PERSISTENT_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
# artificially trigger registry update at next epoch transition
force_registry_change_at_next_epoch(pre_state)
# make epochs since registry update greater than LATEST_SLASHED_EXIT_LENGTH
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)

Expand All @@ -362,8 +345,9 @@ 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].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

Expand Down Expand Up @@ -419,7 +403,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)
Expand All @@ -438,7 +422,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

Expand Down
3 changes: 1 addition & 2 deletions utils/phase0/state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down