Skip to content

Commit

Permalink
Don't timeout if offline or bootstrapping before genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
It's me, CI committed Oct 11, 2023
1 parent 57f3e00 commit f9c8dcc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
64 changes: 36 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,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
Expand All @@ -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 ;
Expand Down Expand Up @@ -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
Expand All @@ -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 ()
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

0 comments on commit f9c8dcc

Please sign in to comment.