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