|
1 | 1 | use std::{collections::HashMap, sync::Arc}; |
2 | 2 |
|
3 | | -use derivative::Derivative; |
4 | 3 | use once_cell::sync::OnceCell; |
5 | 4 |
|
6 | 5 | use crate::phase0::primitives::{Epoch, Slot, ValidatorIndex}; |
7 | 6 |
|
8 | | -/// Equivalence function for `ptc_positions` that ignores trailing `None` entries. |
9 | | -/// Will be used in tests. |
10 | | -fn compare_ptc_positions(xs: &Vec<Option<usize>>, ys: &Vec<Option<usize>>) -> bool { |
11 | | - use std::cmp::Ordering; |
12 | | - |
13 | | - let (shorter, longer) = match xs.len().cmp(&ys.len()) { |
14 | | - Ordering::Equal => { |
15 | | - return xs == ys; |
16 | | - } |
17 | | - Ordering::Less => (xs, ys), |
18 | | - Ordering::Greater => (ys, xs), |
19 | | - }; |
20 | | - |
21 | | - shorter == &longer[..shorter.len()] |
22 | | - && longer[shorter.len()..].iter().all(|new| new.is_none()) |
23 | | -} |
24 | | - |
25 | | -/// Equivalence function for `multiple_positions` HashMap. |
26 | | -fn compare_multiple_positions( |
27 | | - xs: &HashMap<ValidatorIndex, Vec<(Slot, usize)>>, |
28 | | - ys: &HashMap<ValidatorIndex, Vec<(Slot, usize)>>, |
29 | | -) -> bool { |
30 | | - xs == ys |
31 | | -} |
32 | | - |
33 | 7 | /// Cache for Payload Timeliness Committee (PTC) assignments for an entire epoch. |
34 | 8 | /// |
35 | 9 | /// Uses a hybrid storage approach: |
36 | 10 | /// - Most validators have few occurrences: stored in flat Vec |
37 | 11 | /// - Validators with multiple occurrences: stored in HashMap |
38 | | -#[derive(Clone, Debug, Derivative)] |
39 | | -#[derivative(PartialEq)] |
| 12 | +#[derive(Clone, Debug)] |
40 | 13 | pub struct PTCCache { |
41 | 14 | /// The epoch this cache was initialized for |
42 | 15 | pub initialized_epoch: Option<Epoch>, |
43 | 16 | /// Flat shuffling for all slots in epoch |
44 | 17 | pub ptc_shuffling: Vec<ValidatorIndex>, |
45 | 18 | /// Reverse index for single occurrences: validator_index → first position |
46 | | - #[derivative(PartialEq(compare_with = "compare_ptc_positions"))] |
47 | 19 | pub ptc_positions: Vec<Option<usize>>, |
48 | 20 | /// HashMap for validators with multiple occurrences |
49 | | - #[derivative(PartialEq(compare_with = "compare_multiple_positions"))] |
50 | 21 | pub multiple_positions: HashMap<ValidatorIndex, Vec<(Slot, usize)>>, |
51 | 22 | /// PTC size per slot |
52 | 23 | pub ptc_size: usize, |
|
0 commit comments