Bunch of fixes

This commit is contained in:
vbuterin 2019-01-01 22:37:43 -06:00 committed by GitHub
parent fdb1b6775d
commit 2105614059
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -200,6 +200,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
| `SEED_LOOKAHEAD` | `2**6` (= 64) | slots | 6.4 minutes | | `SEED_LOOKAHEAD` | `2**6` (= 64) | slots | 6.4 minutes |
| `ENTRY_EXIT_DELAY` | `2**8` (= 256) | slots | 25.6 minutes | | `ENTRY_EXIT_DELAY` | `2**8` (= 256) | slots | 25.6 minutes |
| `POW_RECEIPT_ROOT_VOTING_PERIOD` | `2**10` (= 1,024) | slots | ~1.7 hours | | `POW_RECEIPT_ROOT_VOTING_PERIOD` | `2**10` (= 1,024) | slots | ~1.7 hours |
| `MIN_VALIDATOR_WITHDRAWAL_TIME` | `2**14` (= 16,384) | slots | ~27 hours |
### Reward and penalty quotients ### Reward and penalty quotients
@ -875,6 +876,10 @@ def get_shuffling(seed: Hash32,
""" """
Shuffles ``validators`` into shard committees using ``seed`` as entropy. Shuffles ``validators`` into shard committees using ``seed`` as entropy.
""" """
# Normalizes slot to start of epoch boundary
slot -= slot % EPOCH_LENGTH
active_validator_indices = get_active_validator_indices(validators, slot) active_validator_indices = get_active_validator_indices(validators, slot)
committees_per_slot = max( committees_per_slot = max(
@ -1725,8 +1730,8 @@ def process_penalties_and_exits(state: BeaconState) -> None:
# The total effective balance of active validators # The total effective balance of active validators
total_balance = sum([get_effective_balance(state, i) for i in active_validator_indices]) total_balance = sum([get_effective_balance(state, i) for i in active_validator_indices])
for i, validator in enumerate(validators): for index, validator in enumerate(state.validator_registry):
if (state.slot // EPOCH_LENGTH) - (validator.penalized_slot // EPOCH_LENGTH) == LATEST_PENALIZED_EXIT_LENGTH // 2: if (state.slot // EPOCH_LENGTH) == (validator.penalized_slot // EPOCH_LENGTH) + LATEST_PENALIZED_EXIT_LENGTH // 2:
e = (state.slot // EPOCH_LENGTH) % LATEST_PENALIZED_EXIT_LENGTH e = (state.slot // EPOCH_LENGTH) % LATEST_PENALIZED_EXIT_LENGTH
total_at_start = state.latest_penalized_exit_balances[(e + 1) % LATEST_PENALIZED_EXIT_LENGTH] total_at_start = state.latest_penalized_exit_balances[(e + 1) % LATEST_PENALIZED_EXIT_LENGTH]
total_at_end = state.latest_penalized_exit_balances[e] total_at_end = state.latest_penalized_exit_balances[e]
@ -1742,15 +1747,12 @@ def process_penalties_and_exits(state: BeaconState) -> None:
else: else:
return state.slot >= validator.exit_slot + MIN_VALIDATOR_WITHDRAWAL_TIME return state.slot >= validator.exit_slot + MIN_VALIDATOR_WITHDRAWAL_TIME
all_indices = list(range(len(state.validator_registry)))
eligible_indices = filter(eligible, all_indices) eligible_indices = filter(eligible, all_indices)
sorted_indices = sorted(eligible_indices, filter=lambda index: state.validator_registry[index].exit_count) sorted_indices = sorted(eligible_indices, filter=lambda index: state.validator_registry[index].exit_count)
withdrawn_so_far = 0 withdrawn_so_far = 0
for index in sorted_indices: for index in sorted_indices:
validator = state.validator_registry[index] validator = state.validator_registry[index]
if validator.penalized_slot <= state.slot:
# TODO: calculate and apply penalties for slashed validators
penalty = 1
state.validator_balances[index] -= penalty
prepare_validator_for_withdrawal(state, index) prepare_validator_for_withdrawal(state, index)
withdrawn_so_far += 1 withdrawn_so_far += 1
if withdrawn_so_far >= MAX_WITHDRAWALS_PER_EPOCH: if withdrawn_so_far >= MAX_WITHDRAWALS_PER_EPOCH: