@@ -30,6 +30,7 @@ use logging::crit;
3030use operation_pool:: { OperationPool , PersistedOperationPool } ;
3131use parking_lot:: { Mutex , RwLock } ;
3232use proto_array:: { DisallowedReOrgOffsets , ReOrgThreshold } ;
33+ use rand:: RngCore ;
3334use rayon:: prelude:: * ;
3435use slasher:: Slasher ;
3536use slot_clock:: { SlotClock , TestingSlotClock } ;
@@ -105,6 +106,7 @@ pub struct BeaconChainBuilder<T: BeaconChainTypes> {
105106 task_executor : Option < TaskExecutor > ,
106107 validator_monitor_config : Option < ValidatorMonitorConfig > ,
107108 import_all_data_columns : bool ,
109+ rng : Option < Box < dyn RngCore + Send > > ,
108110}
109111
110112impl < TSlotClock , TEth1Backend , E , THotStore , TColdStore >
@@ -145,6 +147,7 @@ where
145147 task_executor : None ,
146148 validator_monitor_config : None ,
147149 import_all_data_columns : false ,
150+ rng : None ,
148151 }
149152 }
150153
@@ -691,6 +694,14 @@ where
691694 self
692695 }
693696
697+ /// Sets the `rng` field.
698+ ///
699+ /// Currently used for shuffling column sidecars in block publishing.
700+ pub fn rng ( mut self , rng : Box < dyn RngCore + Send > ) -> Self {
701+ self . rng = Some ( rng) ;
702+ self
703+ }
704+
694705 /// Consumes `self`, returning a `BeaconChain` if all required parameters have been supplied.
695706 ///
696707 /// An error will be returned at runtime if all required parameters have not been configured.
@@ -716,6 +727,7 @@ where
716727 . genesis_state_root
717728 . ok_or ( "Cannot build without a genesis state root" ) ?;
718729 let validator_monitor_config = self . validator_monitor_config . unwrap_or_default ( ) ;
730+ let rng = self . rng . ok_or ( "Cannot build without an RNG" ) ?;
719731 let beacon_proposer_cache: Arc < Mutex < BeaconProposerCache > > = <_ >:: default ( ) ;
720732
721733 let mut validator_monitor =
@@ -979,6 +991,7 @@ where
979991 . map_err ( |e| format ! ( "Error initializing DataAvailabilityChecker: {:?}" , e) ) ?,
980992 ) ,
981993 kzg : self . kzg . clone ( ) ,
994+ rng : Arc :: new ( Mutex :: new ( rng) ) ,
982995 } ;
983996
984997 let head = beacon_chain. head_snapshot ( ) ;
@@ -1184,6 +1197,8 @@ mod test {
11841197 use genesis:: {
11851198 generate_deterministic_keypairs, interop_genesis_state, DEFAULT_ETH1_BLOCK_HASH ,
11861199 } ;
1200+ use rand:: rngs:: StdRng ;
1201+ use rand:: SeedableRng ;
11871202 use ssz:: Encode ;
11881203 use std:: time:: Duration ;
11891204 use store:: config:: StoreConfig ;
@@ -1230,6 +1245,7 @@ mod test {
12301245 . testing_slot_clock ( Duration :: from_secs ( 1 ) )
12311246 . expect ( "should configure testing slot clock" )
12321247 . shutdown_sender ( shutdown_tx)
1248+ . rng ( Box :: new ( StdRng :: seed_from_u64 ( 42 ) ) )
12331249 . build ( )
12341250 . expect ( "should build" ) ;
12351251
0 commit comments