From f9c8dcc383d92799bb799f855bafa4f019df9116 Mon Sep 17 00:00:00 2001 From: "It's me, CI" Date: Wed, 11 Oct 2023 12:42:40 -0700 Subject: [PATCH] Don't timeout if offline or bootstrapping before genesis --- src/lib/mina_lib/mina_lib.ml | 64 +++++++++++++++++------------- src/lib/sync_status/sync_status.ml | 7 ++-- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/lib/mina_lib/mina_lib.ml b/src/lib/mina_lib/mina_lib.ml index 415a2e4c2a6..849091690d3 100644 --- a/src/lib/mina_lib/mina_lib.ml +++ b/src/lib/mina_lib/mina_lib.ml @@ -462,6 +462,10 @@ let create_sync_status_observer ~logger ~is_seed ~demo_mode ~net let open Mina_incremental.Status in let restart_delay = Time.Span.of_min 5. in let offline_shutdown_delay = Time.Span.of_min 25. in + let genesis_timestamp = + Genesis_constants.( + genesis_timestamp_of_string genesis_state_timestamp_string) + in let incremental_status = map4 online_status_incr transition_frontier_and_catchup_signal_incr first_connection_incr first_message_incr @@ -471,29 +475,31 @@ let create_sync_status_observer ~logger ~is_seed ~demo_mode ~net else match online_status with | `Offline -> - ( match !next_helper_restart with - | None -> - next_helper_restart := - Some - (Async.Clock.Event.run_after restart_delay - (fun () -> - [%log info] - "Offline for too long; restarting libp2p_helper" ; - Mina_networking.restart_helper net ; - next_helper_restart := None ; - match !offline_shutdown with - | None -> - offline_shutdown := - Some - (Async.Clock.Event.run_after - offline_shutdown_delay - (fun () -> raise Offline_shutdown) - () ) - | Some _ -> - () ) - () ) - | Some _ -> - () ) ; + (* nothing to do if offline before genesis *) + ( if Time.(( >= ) (now ())) genesis_timestamp then + match !next_helper_restart with + | None -> + next_helper_restart := + Some + (Async.Clock.Event.run_after restart_delay + (fun () -> + [%log info] + "Offline for too long; restarting libp2p_helper" ; + Mina_networking.restart_helper net ; + next_helper_restart := None ; + match !offline_shutdown with + | None -> + offline_shutdown := + Some + (Async.Clock.Event.run_after + offline_shutdown_delay + (fun () -> raise Offline_shutdown) + () ) + | Some _ -> + () ) + () ) + | Some _ -> + () ) ; let is_empty = function `Empty -> true | _ -> false in if is_empty first_connection then ( [%str_log info] Connecting ; @@ -572,10 +578,12 @@ let create_sync_status_observer ~logger ~is_seed ~demo_mode ~net | Some _ -> () | None -> - bootstrap_timeout := - Some - (Timeout.create () bootstrap_timeout_duration - ~f:log_bootstrap_error_and_restart ) + (* don't check bootstrap timeout before genesis *) + if Time.(( >= ) (now ())) genesis_timestamp then + bootstrap_timeout := + Some + (Timeout.create () bootstrap_timeout_duration + ~f:log_bootstrap_error_and_restart ) in let stop_bootstrap_timeout () = match !bootstrap_timeout with @@ -585,7 +593,7 @@ let create_sync_status_observer ~logger ~is_seed ~demo_mode ~net | None -> () in - let handle_status_change sync_status = + let handle_status_change (sync_status : Sync_status.t) = ( match sync_status with | `Offline -> start_offline_timeout () diff --git a/src/lib/sync_status/sync_status.ml b/src/lib/sync_status/sync_status.ml index fdb5d923994..77b78092366 100644 --- a/src/lib/sync_status/sync_status.ml +++ b/src/lib/sync_status/sync_status.ml @@ -1,13 +1,14 @@ open Core_kernel -(** Sync_status represent states interacting with peers in the coda protocol. +(** Sync_status represent states interacting with peers in the Mina protocol. When the protocol is starting, the node should be in the CONNECT state trying to connect to a peer. Once it connects to a peer, the node should be in the LISTENING state waiting for peers to send a message to them. When the node receives a constant flow of messages, its state should be SYNCED. However, when the node is bootstrapping, its state is BOOTSTRAPPING. If it - hasn’t received messages for some time - (Mina_compile_config.inactivity_secs), then it is OFFLINE. *) + hasn’t received messages for some time (see [Mina_lib.offline_time]), then + it is OFFLINE. +*) let to_string = function | `Connecting -> "Connecting"