Skip to content

Commit 75efd4f

Browse files
committed
Simplify pre-activation sorting
1 parent ff687ed commit 75efd4f

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

consensus/state_processing/src/upgrade/electra.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use bls::Signature;
2+
use itertools::Itertools;
23
use safe_arith::SafeArith;
34
use std::mem;
45
use types::{
@@ -39,23 +40,13 @@ pub fn upgrade_to_electra<E: EthSpec>(
3940

4041
// Add validators that are not yet active to pending balance deposits
4142
let validators = post.validators().clone();
42-
let mut pre_activation = validators
43+
let pre_activation = validators
4344
.iter()
4445
.enumerate()
4546
.filter(|(_, validator)| validator.activation_epoch == spec.far_future_epoch)
47+
.sorted_by_key(|(index, validator)| (validator.activation_eligibility_epoch, *index))
4648
.collect::<Vec<_>>();
4749

48-
// Sort the indices by activation_eligibility_epoch and then by index
49-
pre_activation.sort_by(|(index_a, val_a), (index_b, val_b)| {
50-
if val_a.activation_eligibility_epoch == val_b.activation_eligibility_epoch {
51-
index_a.cmp(index_b)
52-
} else {
53-
val_a
54-
.activation_eligibility_epoch
55-
.cmp(&val_b.activation_eligibility_epoch)
56-
}
57-
});
58-
5950
// Process validators to queue entire balance and reset them
6051
for (index, _) in pre_activation {
6152
let balance = post

0 commit comments

Comments
 (0)