Skip to content

Commit

Permalink
Simplify pre-activation sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Dec 16, 2024
1 parent ff687ed commit 75efd4f
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions consensus/state_processing/src/upgrade/electra.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bls::Signature;
use itertools::Itertools;
use safe_arith::SafeArith;
use std::mem;
use types::{
Expand Down Expand Up @@ -39,23 +40,13 @@ pub fn upgrade_to_electra<E: EthSpec>(

// Add validators that are not yet active to pending balance deposits
let validators = post.validators().clone();
let mut pre_activation = validators
let pre_activation = validators
.iter()
.enumerate()
.filter(|(_, validator)| validator.activation_epoch == spec.far_future_epoch)
.sorted_by_key(|(index, validator)| (validator.activation_eligibility_epoch, *index))
.collect::<Vec<_>>();

// Sort the indices by activation_eligibility_epoch and then by index
pre_activation.sort_by(|(index_a, val_a), (index_b, val_b)| {
if val_a.activation_eligibility_epoch == val_b.activation_eligibility_epoch {
index_a.cmp(index_b)
} else {
val_a
.activation_eligibility_epoch
.cmp(&val_b.activation_eligibility_epoch)
}
});

// Process validators to queue entire balance and reset them
for (index, _) in pre_activation {
let balance = post
Expand Down

0 comments on commit 75efd4f

Please sign in to comment.