Daemon: await_bootstrapped_node now retries on Connection_failed

This allows the baker/endorser/accuser to wait a litlle bit for the
node to initialize itself and to open its RPC port.

By default, the deamon retries 6 times with a total waiting time
around 20 seconds, before to fail.
This commit is contained in:
Grégoire Henry 2019-03-05 17:29:09 +01:00 committed by Grégoire
parent 32a1d2647c
commit b7c2546e5b
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2
2 changed files with 26 additions and 2 deletions

View File

@ -23,10 +23,32 @@
(* *)
(*****************************************************************************)
let rec retry (cctxt: #Proto_alpha.full) ~delay ~tries f x =
f x >>= function
| Ok _ as r -> Lwt.return r
| Error (RPC_client.Request_failed
{ error = Connection_failed _ ; _ } :: _) as err
when tries > 0 -> begin
cctxt#message
"Connection refused, retrying in %.2f seconds..."
delay >>= fun () ->
Lwt.pick
[ (Lwt_unix.sleep delay >|= fun () -> `Continue) ;
(Lwt_exit.termination_thread >|= fun _ -> `Killed) ;
] >>= function
| `Killed ->
Lwt.return err
| `Continue ->
retry cctxt ~delay:(delay *. 1.5) ~tries:(tries - 1) f x
end
| Error _ as err ->
Lwt.return err
let await_bootstrapped_node (cctxt: #Proto_alpha.full) =
(* Waiting for the node to be synchronized *)
cctxt#message "Waiting for the node to be synchronized with its \
peers..." >>= fun () ->
retry cctxt ~tries:5 ~delay:1.
Shell_services.Monitor.bootstrapped cctxt >>=? fun _ ->
cctxt#message "Node synchronized." >>= fun () ->
return_unit

View File

@ -9,6 +9,7 @@
tezos-client-alpha
tezos-client-commands
tezos-storage
tezos-rpc-http
tezos-rpc)
(library_flags (:standard -linkall))
(modules (:standard \
@ -22,7 +23,8 @@
-open Tezos_client_alpha
-open Tezos_client_commands
-open Tezos_storage
-open Tezos_rpc)))
-open Tezos_rpc
-open Tezos_rpc_http)))
(library
(name tezos_baking_alpha_commands)