@@ -250,7 +250,7 @@ pub struct CustodyContext<E: EthSpec> {
250250 validator_registrations : RwLock < ValidatorRegistrations > ,
251251 /// Stores an immutable, ordered list of all custody columns as determined by the node's NodeID
252252 /// on startup.
253- all_custody_columns_ordered : OnceLock < Box < [ ColumnIndex ] > > ,
253+ all_custody_columns_ordered : Vec < ColumnIndex > ,
254254 _phantom_data : PhantomData < E > ,
255255}
256256
@@ -259,15 +259,22 @@ impl<E: EthSpec> CustodyContext<E> {
259259 /// exists.
260260 ///
261261 /// The `node_custody_type` value is based on current cli parameters.
262- pub fn new ( node_custody_type : NodeCustodyType , spec : & ChainSpec ) -> Self {
262+ pub fn new (
263+ node_custody_type : NodeCustodyType ,
264+ all_custody_groups_ordered : Vec < CustodyIndex > ,
265+ spec : & ChainSpec ,
266+ ) -> Self {
263267 let cgc_override = node_custody_type. get_custody_count_override ( spec) ;
264268 // If there's no override, we initialise `validator_custody_count` to 0. This has been the
265269 // existing behaviour and we maintain this for now to avoid a semantic schema change until
266270 // a later release.
271+ // FIXME: remove unwrap
272+ let all_custody_columns_ordered =
273+ Self :: compute_ordered_data_columns ( all_custody_groups_ordered, spec) . unwrap ( ) ;
267274 Self {
268275 validator_custody_count : AtomicU64 :: new ( cgc_override. unwrap_or ( 0 ) ) ,
269276 validator_registrations : RwLock :: new ( ValidatorRegistrations :: new ( cgc_override) ) ,
270- all_custody_columns_ordered : OnceLock :: new ( ) ,
277+ all_custody_columns_ordered,
271278 _phantom_data : PhantomData ,
272279 }
273280 }
@@ -290,6 +297,7 @@ impl<E: EthSpec> CustodyContext<E> {
290297 ssz_context : CustodyContextSsz ,
291298 node_custody_type : NodeCustodyType ,
292299 head_epoch : Epoch ,
300+ all_custody_groups_ordered : Vec < CustodyIndex > ,
293301 spec : & ChainSpec ,
294302 ) -> ( Self , Option < CustodyCountChanged > ) {
295303 let CustodyContextSsz {
@@ -347,6 +355,10 @@ impl<E: EthSpec> CustodyContext<E> {
347355 }
348356 }
349357
358+ // FIXME: remove unwrap
359+ let all_custody_columns_ordered =
360+ Self :: compute_ordered_data_columns ( all_custody_groups_ordered, spec) . unwrap ( ) ;
361+
350362 let custody_context = CustodyContext {
351363 validator_custody_count : AtomicU64 :: new ( validator_custody_at_head) ,
352364 validator_registrations : RwLock :: new ( ValidatorRegistrations {
@@ -355,7 +367,7 @@ impl<E: EthSpec> CustodyContext<E> {
355367 . into_iter ( )
356368 . collect ( ) ,
357369 } ) ,
358- all_custody_columns_ordered : OnceLock :: new ( ) ,
370+ all_custody_columns_ordered,
359371 _phantom_data : PhantomData ,
360372 } ;
361373
@@ -370,22 +382,17 @@ impl<E: EthSpec> CustodyContext<E> {
370382 ///
371383 /// # Returns
372384 /// Ok(()) if initialization succeeds, Err with description string if it fails
373- pub fn init_ordered_data_columns_from_custody_groups (
374- & self ,
385+ fn compute_ordered_data_columns (
375386 all_custody_groups_ordered : Vec < CustodyIndex > ,
376387 spec : & ChainSpec ,
377- ) -> Result < ( ) , String > {
388+ ) -> Result < Vec < ColumnIndex > , String > {
378389 let mut ordered_custody_columns = vec ! [ ] ;
379390 for custody_index in all_custody_groups_ordered {
380391 let columns = compute_columns_for_custody_group :: < E > ( custody_index, spec)
381392 . map_err ( |e| format ! ( "Failed to compute columns for custody group {e:?}" ) ) ?;
382393 ordered_custody_columns. extend ( columns) ;
383394 }
384- self . all_custody_columns_ordered
385- . set ( ordered_custody_columns. into_boxed_slice ( ) )
386- . map_err ( |_| {
387- "Failed to initialise CustodyContext with computed custody columns" . to_string ( )
388- } )
395+ Ok ( ordered_custody_columns)
389396 }
390397
391398 /// Register a new validator index and updates the list of validators if required.
@@ -497,11 +504,7 @@ impl<E: EthSpec> CustodyContext<E> {
497504 /// A slice of ordered column indices that should be sampled for this epoch based on the node's custody configuration
498505 pub fn sampling_columns_for_epoch ( & self , epoch : Epoch , spec : & ChainSpec ) -> & [ ColumnIndex ] {
499506 let num_of_columns_to_sample = self . num_of_data_columns_to_sample ( epoch, spec) ;
500- let all_columns_ordered = self
501- . all_custody_columns_ordered
502- . get ( )
503- . expect ( "all_custody_columns_ordered should be initialized" ) ;
504- & all_columns_ordered[ ..num_of_columns_to_sample]
507+ & self . all_custody_columns_ordered [ ..num_of_columns_to_sample]
505508 }
506509
507510 /// Returns the ordered list of column indices that the node is assigned to custody
@@ -528,12 +531,7 @@ impl<E: EthSpec> CustodyContext<E> {
528531 self . custody_group_count_at_head ( spec) as usize
529532 } ;
530533
531- let all_columns_ordered = self
532- . all_custody_columns_ordered
533- . get ( )
534- . expect ( "all_custody_columns_ordered should be initialized" ) ;
535-
536- & all_columns_ordered[ ..custody_group_count]
534+ & self . all_custody_columns_ordered [ ..custody_group_count]
537535 }
538536
539537 /// The node has completed backfill for this epoch. Update the internal records so the function
0 commit comments