Fixed bug in previous version

Validators cannot simply be "popped out" of the list because it's super-important for validator indices to be immutable.

Instead, the validator stays until a new run of `add_validator` swaps it out.
This commit is contained in:
vbuterin 2018-11-09 15:31:50 -05:00 committed by GitHub
parent 20358f8d18
commit f7a8eb5a3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 8 deletions

View File

@ -616,9 +616,9 @@ This routine should be run for every validator that is inducted as part of a log
First, a helper function: First, a helper function:
```python ```python
def min_empty_validator(validators: List[ValidatorRecord]): def min_empty_validator(validators: List[ValidatorRecord], current_slot: int):
for i, v in enumerate(validators): for i, v in enumerate(validators):
if v.status == WITHDRAWN: if v.status == WITHDRAWN and v.exit_slot <= current_slot - DELETION_PERIOD:
return i return i
return None return None
``` ```
@ -866,8 +866,7 @@ def change_validators(validators: List[ValidatorRecord], current_slot) -> None:
) )
# Separate loop to withdraw validators that have been logged out for long enough, and # Separate loop to withdraw validators that have been logged out for long enough, and
# calculate their penalties if they were slashed # calculate their penalties if they were slashed
i = 0 for i in range(len(validators)):
while i < len(validators):
if validators[i].status in (PENDING_WITHDRAW, PENALIZED) and current_slot >= validators[i].exit_slot + WITHDRAWAL_PERIOD: if validators[i].status in (PENDING_WITHDRAW, PENALIZED) and current_slot >= validators[i].exit_slot + WITHDRAWAL_PERIOD:
if validators[i].status == PENALIZED: if validators[i].status == PENALIZED:
validators[i].balance -= validators[i].balance * min(total_penalties * 3, total_balance) // total_balance validators[i].balance -= validators[i].balance * min(total_penalties * 3, total_balance) // total_balance
@ -877,10 +876,6 @@ def change_validators(validators: List[ValidatorRecord], current_slot) -> None:
withdraw_amount = validators[i].balance withdraw_amount = validators[i].balance
... ...
# STUB: withdraw to shard chain # STUB: withdraw to shard chain
if validators[i].status == WITHDRAWN and current_slot >= validators[i].exit_slot + DELETION_PERIOD:
validators.pop(i)
else:
i += 1
``` ```