Simplify Sorting Logic

This commit is contained in:
Mark Mackey 2024-04-10 11:20:42 -05:00
parent 397c2beeb8
commit 21262499d7
1 changed files with 10 additions and 15 deletions

View File

@ -128,21 +128,16 @@ def upgrade_to_eip7251(pre: deneb.BeaconState) -> BeaconState:
pending_consolidations=[], pending_consolidations=[],
) )
activation_queue = [] # add validators that are not yet active to pending balance deposits
pre_activation_queue = [] pre_activation = sorted([
below_minimum = [] index for index, validator in enumerate(post.validators)
for index, validator in enumerate(post.validators): if validator.activation_epoch == FAR_FUTURE_EPOCH
if validator.activation_epoch == FAR_FUTURE_EPOCH: ], key=lambda index: (
if validator.activation_eligibility_epoch != FAR_FUTURE_EPOCH: post.validators[index].activation_eligibility_epoch,
activation_queue.append(index) post.validators[index].effective_balance < MIN_ACTIVATION_BALANCE,
else: index
if validator.effective_balance >= MIN_ACTIVATION_BALANCE: ))
pre_activation_queue.append(index) for index in pre_activation:
else:
below_minimum.append(index)
activation_queue.sort(key=lambda index: (post.validators[index].activation_eligibility_epoch, index))
for index in activation_queue + pre_activation_queue + below_minimum:
queue_entire_balance_and_reset_validator(post, ValidatorIndex(index)) queue_entire_balance_and_reset_validator(post, ValidatorIndex(index))
# Ensure early adopters of compounding credentials go through the activation churn # Ensure early adopters of compounding credentials go through the activation churn