Alpha/Baker: better naming for error management
This commit is contained in:
parent
99f3b8446c
commit
3e71d21713
@ -304,7 +304,7 @@ let create
|
|||||||
| `Hash (Some (Ok bi)) ->
|
| `Hash (Some (Ok bi)) ->
|
||||||
Lwt.cancel timeout;
|
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 ->
|
||||||
begin
|
begin
|
||||||
endorse_for cctxt state.to_endorse >>= function
|
endorse_for cctxt state.to_endorse >>= function
|
||||||
|
@ -438,6 +438,8 @@ let get_delegates cctxt state =
|
|||||||
return (List.map (fun (_,pkh,_,_) -> pkh) keys)
|
return (List.map (fun (_,pkh,_,_) -> pkh) keys)
|
||||||
| _ :: _ as delegates -> return delegates
|
| _ :: _ as delegates -> return delegates
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let insert_block
|
let insert_block
|
||||||
(cctxt : #Proto_alpha.full) ?max_priority state (bi: Client_baking_blocks.block_info) =
|
(cctxt : #Proto_alpha.full) ?max_priority state (bi: Client_baking_blocks.block_info) =
|
||||||
begin
|
begin
|
||||||
@ -476,13 +478,6 @@ let pop_baking_slots state =
|
|||||||
state.future_slots <- future_slots ;
|
state.future_slots <- future_slots ;
|
||||||
slots
|
slots
|
||||||
|
|
||||||
let insert_blocks cctxt ?max_priority state bi =
|
|
||||||
insert_block cctxt ?max_priority state bi >>= function
|
|
||||||
| Ok () ->
|
|
||||||
Lwt.return_unit
|
|
||||||
| Error err ->
|
|
||||||
lwt_log_error "Error: %a" pp_print_error err
|
|
||||||
|
|
||||||
let bake_slot
|
let bake_slot
|
||||||
cctxt
|
cctxt
|
||||||
state
|
state
|
||||||
@ -612,6 +607,10 @@ let bake (cctxt : #Proto_alpha.full) state =
|
|||||||
lwt_debug "No valid candidates." >>= fun () ->
|
lwt_debug "No valid candidates." >>= fun () ->
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
|
let check_error p =
|
||||||
|
p >>= function
|
||||||
|
| Ok () -> Lwt.return_unit
|
||||||
|
| Error errs -> lwt_log_error "Error while baking:@\n%a" pp_print_error errs
|
||||||
|
|
||||||
(* [create] starts the main loop of the baker. The loop monitors new blocks and
|
(* [create] starts the main loop of the baker. The loop monitors new blocks and
|
||||||
starts individual baking operations when baking-slots are available to any of
|
starts individual baking operations when baking-slots are available to any of
|
||||||
@ -636,7 +635,7 @@ let create
|
|||||||
t
|
t
|
||||||
| Some t -> t in
|
| Some t -> t in
|
||||||
let state = create_state genesis_hash delegates bi in
|
let state = create_state genesis_hash delegates bi in
|
||||||
insert_blocks cctxt ?max_priority state bi >>= fun () ->
|
check_error @@ insert_block cctxt ?max_priority state bi >>= fun () ->
|
||||||
|
|
||||||
(* main loop *)
|
(* main loop *)
|
||||||
let rec worker_loop () =
|
let rec worker_loop () =
|
||||||
@ -660,18 +659,14 @@ let create
|
|||||||
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 () ->
|
||||||
insert_blocks 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 () ->
|
||||||
begin
|
(* core functionality *)
|
||||||
(* core functionality *)
|
check_error @@ bake cctxt state
|
||||||
bake cctxt state >>= function
|
|
||||||
| Ok () -> Lwt.return_unit
|
|
||||||
| Error errs -> lwt_log_error "Error while baking:@\n%a" pp_print_error errs
|
|
||||||
end
|
|
||||||
|
|
||||||
end >>= fun () ->
|
end >>= fun () ->
|
||||||
(* and restart *)
|
(* and restart *)
|
||||||
|
Loading…
Reference in New Issue
Block a user