@@ -92,6 +92,7 @@ use ream_validator_lean::{
9292use ssz_types:: VariableList ;
9393use tokio:: {
9494 sync:: { broadcast, mpsc} ,
95+ time,
9596 time:: Instant ,
9697} ;
9798use tracing:: { error, info} ;
@@ -316,6 +317,10 @@ pub async fn run_lean_node(config: LeanNodeConfig, executor: ReamExecutor, ream_
316317 ream_rpc_lean:: server:: start ( server_config, lean_chain_reader, network_state) . await
317318 } ) ;
318319
320+ executor. spawn ( async move {
321+ countdown_for_genesis ( ) . await ;
322+ } ) ;
323+
319324 tokio:: select! {
320325 result = chain_future => {
321326 error!( "Chain service has stopped unexpectedly: {result:?}" ) ;
@@ -703,6 +708,40 @@ pub async fn run_generate_private_key(config: GeneratePrivateKeyConfig) {
703708 process:: exit ( 0 ) ;
704709}
705710
711+ // Countdown logs until the genesis timestamp reaches
712+ pub async fn countdown_for_genesis ( ) {
713+ loop {
714+ let now = SystemTime :: now ( )
715+ . duration_since ( UNIX_EPOCH )
716+ . unwrap_or ( Duration :: MAX )
717+ . as_secs ( ) ;
718+ let genesis = lean_network_spec ( ) . genesis_time ;
719+
720+ if now >= genesis {
721+ // Only log the "Genesis reached" message if we are starting within
722+ // a small 2-second window of the actual event.
723+ if now <= genesis + 2 {
724+ info ! ( "Genesis reached! Starting services..." ) ;
725+ }
726+ break ;
727+ }
728+
729+ let remaining = lean_network_spec ( ) . genesis_time . saturating_sub ( now) ;
730+
731+ // Format the remaining time for a cleaner log
732+ let minutes = ( remaining % 3600 ) / 60 ;
733+ let seconds = remaining % 60 ;
734+
735+ info ! (
736+ "Waiting for genesis in {:02}:{:02} seconds" ,
737+ minutes, seconds
738+ ) ;
739+
740+ // Sleep for 1 second before ticking again
741+ time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
742+ }
743+ }
744+
706745#[ cfg( test) ]
707746mod tests {
708747 use std:: time:: Duration ;
0 commit comments