Alpha/Denunciator: improve worker loop

- exit on errors
- log errors
This commit is contained in:
Raphaël Proust 2018-06-19 14:03:10 +08:00
parent a220aeb1a7
commit 18f6dab856

View File

@ -18,6 +18,7 @@ let create cctxt endorsement_stream =
last_get_endorsement := Some t ; last_get_endorsement := Some t ;
t t
| Some t -> t in | Some t -> t in
let rec worker_loop () = let rec worker_loop () =
(* let timeout = compute_timeout state in *) (* let timeout = compute_timeout state in *)
Lwt.choose [ Lwt.choose [
@ -25,7 +26,8 @@ let create cctxt endorsement_stream =
(get_endorsement () >|= fun e -> `Endorsement e) ; (get_endorsement () >|= fun e -> `Endorsement e) ;
] >>= function ] >>= function
| `Endorsement (None | Some (Error _)) -> | `Endorsement (None | Some (Error _)) ->
Lwt.return_unit lwt_log_error "Connection to node lost, exiting." >>= fun () ->
exit 1
| `Endorsement (Some (Ok e)) -> | `Endorsement (Some (Ok e)) ->
last_get_endorsement := None ; last_get_endorsement := None ;
Client_keys.Public_key_hash.name cctxt Client_keys.Public_key_hash.name cctxt
@ -37,9 +39,13 @@ let create cctxt endorsement_stream =
source source
Format.(pp_print_list pp_print_int) e.slots >>= fun () -> Format.(pp_print_list pp_print_int) e.slots >>= fun () ->
worker_loop () worker_loop ()
| Error _ -> | Error errs ->
(* TODO log *) lwt_log_error "Error whilst checking the endorsment %a/%a:@\n%a"
Block_hash.pp_short e.block
Format.(pp_print_list pp_print_int) e.slots
pp_print_error errs >>= fun () ->
worker_loop () worker_loop ()
in in
lwt_log_info "Starting denunciation daemon" >>= fun () -> lwt_log_info "Starting denunciation daemon" >>= fun () ->
worker_loop () worker_loop ()