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

libp2p restarts if env variable is set #6847

Merged
merged 1 commit into from
Nov 24, 2020
Merged
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
45 changes: 24 additions & 21 deletions src/lib/gossip_net/libp2p.ml
Original file line number Diff line number Diff line change
Expand Up @@ -385,27 +385,30 @@ module Make (Rpc_intf : Coda_base.Rpc_intf.Rpc_interface_intf) :
let rec on_libp2p_create res =
net2_ref :=
Deferred.map res ~f:(fun (n, _, _, _) ->
let restart_after =
let plus_or_minus initial ~delta =
initial +. (Random.float (2. *. delta) -. delta)
in
let base_time =
Option.value_map ~f:Float.of_string
(Sys.getenv "MINA_LIBP2P_HELPER_RESTART_INTERVAL_BASE")
~default:7.
in
let delta =
Option.value_map ~f:Float.of_string
(Sys.getenv "MINA_LIBP2P_HELPER_RESTART_INTERVAL_DELTA")
~default:2.5
|> Float.min (base_time /. 2.)
in
Time.Span.(of_min (base_time |> plus_or_minus ~delta))
in
upon (after restart_after) (fun () ->
don't_wait_for
(let%bind () = Coda_net2.shutdown n in
on_unexpected_termination ()) ) ;
( match
Sys.getenv "MINA_LIBP2P_HELPER_RESTART_INTERVAL_BASE"
with
| Some base_time ->
let restart_after =
let plus_or_minus initial ~delta =
initial +. (Random.float (2. *. delta) -. delta)
in
let base_time = Float.of_string base_time in
let delta =
Option.value_map ~f:Float.of_string
(Sys.getenv
"MINA_LIBP2P_HELPER_RESTART_INTERVAL_DELTA")
~default:2.5
|> Float.min (base_time /. 2.)
in
Time.Span.(of_min (base_time |> plus_or_minus ~delta))
in
upon (after restart_after) (fun () ->
don't_wait_for
(let%bind () = Coda_net2.shutdown n in
on_unexpected_termination ()) )
| None ->
() ) ;
n ) ;
subscription_ref := Deferred.map res ~f:(fun (_, s, _, _) -> s) ;
upon res (fun (_, _, m, me) ->
Expand Down