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

off by one error for eth1 data voting #992

Merged
merged 2 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ def process_final_updates(state: BeaconState) -> None:
current_epoch = get_current_epoch(state)
next_epoch = current_epoch + 1
# Reset eth1 data votes
if state.slot % SLOTS_PER_ETH1_VOTING_PERIOD == 0:
if (state.slot + 1) % SLOTS_PER_ETH1_VOTING_PERIOD == 0:
state.eth1_data_votes = []
# Update effective balances with hysteresis
for index, validator in enumerate(state.validator_registry):
Expand Down
47 changes: 34 additions & 13 deletions test_libs/pyspec/tests/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,15 @@ def test_transfer(state):


def test_balance_driven_status_transitions(state):
pre_state = deepcopy(state)

current_epoch = get_current_epoch(pre_state)
validator_index = get_active_validator_indices(pre_state, current_epoch)[-1]
current_epoch = get_current_epoch(state)
validator_index = get_active_validator_indices(state, current_epoch)[-1]

assert pre_state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH
assert state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH

# set validator balance to below ejection threshold
pre_state.validator_registry[validator_index].effective_balance = spec.EJECTION_BALANCE
state.validator_registry[validator_index].effective_balance = spec.EJECTION_BALANCE

post_state = deepcopy(pre_state)
post_state = deepcopy(state)
#
# trigger epoch transition
#
Expand All @@ -396,21 +394,44 @@ def test_balance_driven_status_transitions(state):

assert post_state.validator_registry[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH

return pre_state, [block], post_state
return state, [block], post_state


def test_historical_batch(state):
pre_state = deepcopy(state)
pre_state.slot += spec.SLOTS_PER_HISTORICAL_ROOT - (pre_state.slot % spec.SLOTS_PER_HISTORICAL_ROOT) - 1
state.slot += spec.SLOTS_PER_HISTORICAL_ROOT - (state.slot % spec.SLOTS_PER_HISTORICAL_ROOT) - 1

post_state = deepcopy(pre_state)
post_state = deepcopy(state)

block = build_empty_block_for_next_slot(post_state)

state_transition(post_state, block)

assert post_state.slot == block.slot
assert get_current_epoch(post_state) % (spec.SLOTS_PER_HISTORICAL_ROOT // spec.SLOTS_PER_EPOCH) == 0
assert len(post_state.historical_roots) == len(pre_state.historical_roots) + 1
assert len(post_state.historical_roots) == len(state.historical_roots) + 1

return pre_state, [block], post_state
return state, [block], post_state


def test_eth1_data_votes(state):
post_state = deepcopy(state)

expected_votes = 0
assert len(state.eth1_data_votes) == expected_votes

blocks = []
for _ in range(spec.SLOTS_PER_ETH1_VOTING_PERIOD - 1):
block = build_empty_block_for_next_slot(post_state)
state_transition(post_state, block)
expected_votes += 1
assert len(post_state.eth1_data_votes) == expected_votes
blocks.append(block)

block = build_empty_block_for_next_slot(post_state)
state_transition(post_state, block)
blocks.append(block)

assert post_state.slot % spec.SLOTS_PER_ETH1_VOTING_PERIOD == 0
assert len(post_state.eth1_data_votes) == 1

return state, blocks, post_state