Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't timeout if offline or bootstrapping before genesis #14328

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 39 additions & 28 deletions src/lib/mina_lib/mina_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ 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 after_genesis =
let genesis_timestamp =
Genesis_constants.(
genesis_timestamp_of_string genesis_state_timestamp_string)
in
fun () -> Time.(( >= ) (now ())) genesis_timestamp
in
let incremental_status =
map4 online_status_incr transition_frontier_and_catchup_signal_incr
first_connection_incr first_message_incr
Expand All @@ -471,29 +478,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 after_genesis () 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 ;
Expand Down Expand Up @@ -572,10 +581,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 after_genesis () then
bootstrap_timeout :=
Some
(Timeout.create () bootstrap_timeout_duration
~f:log_bootstrap_error_and_restart )
in
let stop_bootstrap_timeout () =
match !bootstrap_timeout with
Expand All @@ -585,7 +596,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 ()
Expand Down
7 changes: 4 additions & 3 deletions src/lib/sync_status/sync_status.ml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down