From 7a3edb6961e0d695fd5f85f3e85e98920259f84b Mon Sep 17 00:00:00 2001 From: tersec Date: Wed, 27 Mar 2024 08:18:50 +0000 Subject: [PATCH] more initialize_validator_exit optimization (#6146) --- beacon_chain/spec/beaconstate.nim | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index 279bfb32b..7009a5b04 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -11,13 +11,11 @@ import stew/assign2, json_serialization/std/sets, chronicles, - ../extras, ./datatypes/[phase0, altair, bellatrix], "."/[eth2_merkleization, forks, signatures, validator] from std/algorithm import fill from std/sequtils import anyIt, mapIt, toSeq - from ./datatypes/capella import BeaconState, ExecutionPayloadHeader, Withdrawal export extras, forks, validator, chronicles @@ -104,25 +102,31 @@ func initiate_validator_exit*( # Return if validator already initiated exit let validator = addr state.validators.mitem(index) - var exit_queue_epoch = compute_activation_exit_epoch(get_current_epoch(state)) + var + exit_queue_epoch = compute_activation_exit_epoch(get_current_epoch(state)) + exit_queue_churn: uint64 # Compute max exit epoch for idx in 0.. exit_queue_epoch: exit_queue_epoch = exit_epoch - var exit_queue_churn: uint64 - let validator_churn_limit = get_validator_churn_limit(cfg, state, cache) - for idx in 0..= validator_churn_limit: - inc exit_queue_epoch - break + if exit_queue_churn >= get_validator_churn_limit(cfg, state, cache): + inc exit_queue_epoch # Set validator exit epoch and withdrawable epoch validator.exit_epoch = exit_queue_epoch