Skip to content

Commit 2bbce00

Browse files
authored
Merge pull request #14328 from MinaProtocol/feature/no-offline-bootstrap-timeouts-before-genesis
2 parents 2825f09 + 94ddfbf commit 2bbce00

File tree

2 files changed

+43
-31
lines changed

2 files changed

+43
-31
lines changed

src/lib/mina_lib/mina_lib.ml

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@ let create_sync_status_observer ~logger ~is_seed ~demo_mode ~net
462462
let open Mina_incremental.Status in
463463
let restart_delay = Time.Span.of_min 5. in
464464
let offline_shutdown_delay = Time.Span.of_min 25. in
465+
let after_genesis =
466+
let genesis_timestamp =
467+
Genesis_constants.(
468+
genesis_timestamp_of_string genesis_state_timestamp_string)
469+
in
470+
fun () -> Time.(( >= ) (now ())) genesis_timestamp
471+
in
465472
let incremental_status =
466473
map4 online_status_incr transition_frontier_and_catchup_signal_incr
467474
first_connection_incr first_message_incr
@@ -471,29 +478,31 @@ let create_sync_status_observer ~logger ~is_seed ~demo_mode ~net
471478
else
472479
match online_status with
473480
| `Offline ->
474-
( match !next_helper_restart with
475-
| None ->
476-
next_helper_restart :=
477-
Some
478-
(Async.Clock.Event.run_after restart_delay
479-
(fun () ->
480-
[%log info]
481-
"Offline for too long; restarting libp2p_helper" ;
482-
Mina_networking.restart_helper net ;
483-
next_helper_restart := None ;
484-
match !offline_shutdown with
485-
| None ->
486-
offline_shutdown :=
487-
Some
488-
(Async.Clock.Event.run_after
489-
offline_shutdown_delay
490-
(fun () -> raise Offline_shutdown)
491-
() )
492-
| Some _ ->
493-
() )
494-
() )
495-
| Some _ ->
496-
() ) ;
481+
(* nothing to do if offline before genesis *)
482+
( if after_genesis () then
483+
match !next_helper_restart with
484+
| None ->
485+
next_helper_restart :=
486+
Some
487+
(Async.Clock.Event.run_after restart_delay
488+
(fun () ->
489+
[%log info]
490+
"Offline for too long; restarting libp2p_helper" ;
491+
Mina_networking.restart_helper net ;
492+
next_helper_restart := None ;
493+
match !offline_shutdown with
494+
| None ->
495+
offline_shutdown :=
496+
Some
497+
(Async.Clock.Event.run_after
498+
offline_shutdown_delay
499+
(fun () -> raise Offline_shutdown)
500+
() )
501+
| Some _ ->
502+
() )
503+
() )
504+
| Some _ ->
505+
() ) ;
497506
let is_empty = function `Empty -> true | _ -> false in
498507
if is_empty first_connection then (
499508
[%str_log info] Connecting ;
@@ -572,10 +581,12 @@ let create_sync_status_observer ~logger ~is_seed ~demo_mode ~net
572581
| Some _ ->
573582
()
574583
| None ->
575-
bootstrap_timeout :=
576-
Some
577-
(Timeout.create () bootstrap_timeout_duration
578-
~f:log_bootstrap_error_and_restart )
584+
(* don't check bootstrap timeout before genesis *)
585+
if after_genesis () then
586+
bootstrap_timeout :=
587+
Some
588+
(Timeout.create () bootstrap_timeout_duration
589+
~f:log_bootstrap_error_and_restart )
579590
in
580591
let stop_bootstrap_timeout () =
581592
match !bootstrap_timeout with
@@ -585,7 +596,7 @@ let create_sync_status_observer ~logger ~is_seed ~demo_mode ~net
585596
| None ->
586597
()
587598
in
588-
let handle_status_change sync_status =
599+
let handle_status_change (sync_status : Sync_status.t) =
589600
( match sync_status with
590601
| `Offline ->
591602
start_offline_timeout ()

src/lib/sync_status/sync_status.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
open Core_kernel
22

3-
(** Sync_status represent states interacting with peers in the coda protocol.
3+
(** Sync_status represent states interacting with peers in the Mina protocol.
44
When the protocol is starting, the node should be in the CONNECT state
55
trying to connect to a peer. Once it connects to a peer, the node should be
66
in the LISTENING state waiting for peers to send a message to them. When
77
the node receives a constant flow of messages, its state should be SYNCED.
88
However, when the node is bootstrapping, its state is BOOTSTRAPPING. If it
9-
hasn’t received messages for some time
10-
(Mina_compile_config.inactivity_secs), then it is OFFLINE. *)
9+
hasn’t received messages for some time (see [Mina_lib.offline_time]), then
10+
it is OFFLINE.
11+
*)
1112
let to_string = function
1213
| `Connecting ->
1314
"Connecting"

0 commit comments

Comments
 (0)