From f7a8eb5a3e6be6ad8bb497d3e0b5f0995aa85cee Mon Sep 17 00:00:00 2001 From: vbuterin Date: Fri, 9 Nov 2018 15:31:50 -0500 Subject: [PATCH] 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. --- specs/beacon-chain.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 42455f2a6..b68c98d42 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -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 ```