From fdc6bf6b447acecf49b2fc696d53898fb529e00e Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Mon, 18 Jun 2018 22:42:40 +0200 Subject: [PATCH] Baker, Endorser, exit on lost connection to node --- .../lib_delegate/client_baking_endorsement.ml | 11 ++++++----- src/proto_alpha/lib_delegate/client_baking_forge.ml | 13 ++++--------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/proto_alpha/lib_delegate/client_baking_endorsement.ml b/src/proto_alpha/lib_delegate/client_baking_endorsement.ml index 796135397..27a4bd0ee 100644 --- a/src/proto_alpha/lib_delegate/client_baking_endorsement.ml +++ b/src/proto_alpha/lib_delegate/client_baking_endorsement.ml @@ -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) diff --git a/src/proto_alpha/lib_delegate/client_baking_forge.ml b/src/proto_alpha/lib_delegate/client_baking_forge.ml index 6111317c3..2c00e3a96 100644 --- a/src/proto_alpha/lib_delegate/client_baking_forge.ml +++ b/src/proto_alpha/lib_delegate/client_baking_forge.ml @@ -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)