Baker, Endorser, exit on lost connection to node

This commit is contained in:
Benjamin Canou 2018-06-18 22:42:40 +02:00 committed by Grégoire Henry
parent ce926e575a
commit fdc6bf6b44
2 changed files with 10 additions and 14 deletions

View File

@ -238,7 +238,6 @@ let create
block_stream
bi =
lwt_log_info "Preparing endorsement daemon" >>= fun () ->
(* statefulness setup *)
let last_get_block = ref None in
let get_block () =
@ -256,12 +255,14 @@ let create
let timeout = compute_timeout state in
Lwt.choose [ (timeout >|= fun () -> `Timeout) ;
(get_block () >|= fun b -> `Hash b) ] >>= function
| `Hash (None | Some (Error _)) ->
Lwt.cancel timeout;
| `Hash None ->
last_get_block := None;
lwt_log_error "Connection to node lost, exiting." >>= fun () ->
exit 1
| `Hash (Some (Error _)) ->
last_get_block := None;
Lwt.return_unit
| `Hash (Some (Ok bi)) ->
Lwt.cancel timeout;
last_get_block := None;
check_error @@ prepare_endorsement cctxt ~max_past state bi
| `Timeout ->
@ -290,6 +291,6 @@ let create
contracts
(block_stream: Client_baking_blocks.block_info tzresult Lwt_stream.t) =
Client_baking_scheduling.wait_for_first_block
~info:cctxt#message
~info:lwt_log_info
block_stream
(create cctxt ~max_past ~delay contracts block_stream)

View File

@ -746,7 +746,7 @@ let create
(block_stream: Client_baking_blocks.block_info tzresult Lwt_stream.t)
(bi: Client_baking_blocks.block_info) =
cctxt#message "Setting up before the baker can start." >>= fun () ->
lwt_log_info "Setting up before the baker can start." >>= fun () ->
Shell_services.Blocks.hash cctxt ~block:`Genesis () >>=? fun genesis_hash ->
(* statefulness *)
@ -774,33 +774,28 @@ let create
(* event matching *)
| `Hash (None | Some (Error _)) ->
(* return to restart *)
Lwt.cancel timeout ;
last_get_block := None ;
Lwt.return_unit
lwt_log_error "Connection to node lost, exiting." >>= fun () ->
exit 1
| `Hash (Some (Ok bi)) -> begin
(* new block: cancel everything and bake on the new head *)
Lwt.cancel timeout ;
last_get_block := None ;
lwt_debug
"Discoverered block: %a"
Block_hash.pp_short bi.Client_baking_blocks.hash >>= fun () ->
check_error @@ insert_block cctxt ?max_priority state bi
end
| `Timeout ->
(* main event: it's baking time *)
lwt_debug "Waking up for baking..." >>= fun () ->
(* core functionality *)
check_error @@ bake cctxt state
end >>= fun () ->
(* and restart *)
worker_loop () in
(* ignition *)
lwt_log_info "Starting baking daemon" >>= fun () ->
cctxt#message "Starting the baker" >>= fun () ->
worker_loop ()
(* Wrapper around previous [create] function that handles the case of
@ -812,6 +807,6 @@ let create
(delegates: public_key_hash list)
(block_stream: Client_baking_blocks.block_info tzresult Lwt_stream.t) =
Client_baking_scheduling.wait_for_first_block
~info:cctxt#message
~info:lwt_log_info
block_stream
(create cctxt ?max_priority ~context_path delegates block_stream)