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:
parent
20358f8d18
commit
f7a8eb5a3e
|
@ -616,9 +616,9 @@ This routine should be run for every validator that is inducted as part of a log
|
|||
First, a helper function:
|
||||
|
||||
```python
|
||||
def min_empty_validator(validators: List[ValidatorRecord]):
|
||||
def min_empty_validator(validators: List[ValidatorRecord], current_slot: int):
|
||||
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 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
|
||||
# calculate their penalties if they were slashed
|
||||
i = 0
|
||||
while i < len(validators):
|
||||
for i in range(len(validators)):
|
||||
if validators[i].status in (PENDING_WITHDRAW, PENALIZED) and current_slot >= validators[i].exit_slot + WITHDRAWAL_PERIOD:
|
||||
if validators[i].status == PENALIZED:
|
||||
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
|
||||
...
|
||||
# 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
|
||||
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue