@@ -25,8 +25,8 @@ use task_executor::ShutdownReason;
2525use tokio:: sync:: mpsc;
2626use tokio:: time:: Sleep ;
2727use types:: {
28- ChainSpec , EthSpec , ForkContext , ForkName , RelativeEpoch , Slot , SubnetId ,
29- SyncCommitteeSubscription , SyncSubnetId , Unsigned , ValidatorSubscription ,
28+ ChainSpec , EthSpec , ForkContext , RelativeEpoch , Slot , SubnetId , SyncCommitteeSubscription ,
29+ SyncSubnetId , Unsigned , ValidatorSubscription ,
3030} ;
3131
3232mod tests;
@@ -281,32 +281,34 @@ impl<T: BeaconChainTypes> NetworkService<T> {
281281 pub fn required_gossip_fork_digests ( & self ) -> Vec < [ u8 ; 4 ] > {
282282 let fork_context = & self . fork_context ;
283283 let spec = & self . beacon_chain . spec ;
284- match fork_context. current_fork ( ) {
285- ForkName :: Base => {
286- // If we are SUBSCRIBE_DELAY_SLOTS before the fork slot, subscribe only to Base,
287- // else subscribe to Base and Altair.
288- let current_slot = self . beacon_chain . slot ( ) . unwrap_or ( spec. genesis_slot ) ;
289- match spec. next_fork_epoch :: < T :: EthSpec > ( current_slot) {
290- Some ( ( _, fork_epoch) ) => {
291- if current_slot. saturating_add ( Slot :: new ( SUBSCRIBE_DELAY_SLOTS ) )
292- >= fork_epoch. start_slot ( T :: EthSpec :: slots_per_epoch ( ) )
293- {
294- fork_context. all_fork_digests ( )
295- } else {
296- vec ! [ fork_context. genesis_context_bytes( ) ]
297- }
298- }
299- None => vec ! [ fork_context. genesis_context_bytes( ) ] ,
300- }
284+ let current_slot = self . beacon_chain . slot ( ) . unwrap_or ( spec. genesis_slot ) ;
285+ let current_fork = fork_context. current_fork ( ) ;
286+
287+ let mut result = vec ! [ fork_context
288+ . to_context_bytes( current_fork)
289+ . unwrap_or_else( || {
290+ panic!(
291+ "{} fork bytes should exist as it's initialized in ForkContext" ,
292+ current_fork
293+ )
294+ } ) ] ;
295+
296+ if let Some ( ( next_fork, fork_epoch) ) = spec. next_fork_epoch :: < T :: EthSpec > ( current_slot) {
297+ if current_slot. saturating_add ( Slot :: new ( SUBSCRIBE_DELAY_SLOTS ) )
298+ >= fork_epoch. start_slot ( T :: EthSpec :: slots_per_epoch ( ) )
299+ {
300+ let next_fork_context_bytes =
301+ fork_context. to_context_bytes ( next_fork) . unwrap_or_else ( || {
302+ panic ! (
303+ "context bytes should exist as spec.next_fork_epoch({}) returned Some({})" ,
304+ current_slot, next_fork
305+ )
306+ } ) ;
307+ result. push ( next_fork_context_bytes) ;
301308 }
302- ForkName :: Altair => vec ! [ fork_context
303- . to_context_bytes( ForkName :: Altair )
304- . expect( "Altair fork bytes should exist as it's initialized in ForkContext" ) ] ,
305- // TODO: check this.. what even is this?
306- ForkName :: Merge => vec ! [ fork_context
307- . to_context_bytes( ForkName :: Merge )
308- . expect( "Merge fork bytes should exist as it's initialized in ForkContext" ) ] ,
309309 }
310+
311+ result
310312 }
311313}
312314
0 commit comments