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=[],
)
activation_queue = []
pre_activation_queue = []
below_minimum = []
for index, validator in enumerate(post.validators):
if validator.activation_epoch == FAR_FUTURE_EPOCH:
if validator.activation_eligibility_epoch != FAR_FUTURE_EPOCH:
activation_queue.append(index)
else:
if validator.effective_balance >= MIN_ACTIVATION_BALANCE:
pre_activation_queue.append(index)
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:
# add validators that are not yet active to pending balance deposits
pre_activation = sorted([
index for index, validator in enumerate(post.validators)
if validator.activation_epoch == FAR_FUTURE_EPOCH
], key=lambda index: (
post.validators[index].activation_eligibility_epoch,
post.validators[index].effective_balance < MIN_ACTIVATION_BALANCE,
index
))
for index in pre_activation:
queue_entire_balance_and_reset_validator(post, ValidatorIndex(index))
# Ensure early adopters of compounding credentials go through the activation churn