rebase modifications

This commit is contained in:
Vincent Botbol 2018-06-11 15:51:59 +02:00 committed by Grégoire Henry
parent f63b96dbd8
commit cbcc808abc
3 changed files with 34 additions and 36 deletions

View File

@ -187,7 +187,7 @@ let endorse_for cctxt = function
name name
Operation_hash.pp_short oph >>= return Operation_hash.pp_short oph >>= return
let prepare_endorsement (cctxt : #Proto_alpha.full) ~(max_past:Time.t) state bis = let prepare_endorsement (cctxt : #Proto_alpha.full) ~(max_past:Time.t) state bi =
let may_endorse (block: Client_baking_blocks.block_info) delegate time = let may_endorse (block: Client_baking_blocks.block_info) delegate time =
Client_keys.Public_key_hash.name cctxt delegate >>=? fun name -> Client_keys.Public_key_hash.name cctxt delegate >>=? fun name ->
lwt_log_info "May endorse block %a for %s" lwt_log_info "May endorse block %a for %s"
@ -213,8 +213,7 @@ let prepare_endorsement (cctxt : #Proto_alpha.full) ~(max_past:Time.t) state bis
get_delegates cctxt state >>=? fun delegates -> get_delegates cctxt state >>=? fun delegates ->
iter_p iter_p
(fun delegate -> (fun delegate ->
iter_p let open Client_baking_blocks in
(fun (bi : Client_baking_blocks.block_info) ->
if Time.compare bi.timestamp (Time.now ()) > 0 then if Time.compare bi.timestamp (Time.now ()) > 0 then
lwt_log_info "Ignore block %a: forged in the future" lwt_log_info "Ignore block %a: forged in the future"
Block_hash.pp_short bi.hash >>= return Block_hash.pp_short bi.hash >>= return
@ -224,7 +223,6 @@ let prepare_endorsement (cctxt : #Proto_alpha.full) ~(max_past:Time.t) state bis
else else
let time = Time.(add (now ()) state.delay) in let time = Time.(add (now ()) state.delay) in
may_endorse bi delegate time may_endorse bi delegate time
) bis
) )
delegates delegates
@ -266,13 +264,12 @@ let check_error f =
errs >>= fun () -> errs >>= fun () ->
Lwt.return_unit Lwt.return_unit
let create (cctxt : #Proto_alpha.full) ?(max_past=(Time.of_seconds 110L)) ~delay contracts (block_stream : Client_baking_blocks.block_info tzresult Lwt_stream.t) =
let create (cctxt : #Proto_alpha.full) ?(max_past=(Time.of_seconds 110L)) ~delay contracts block_stream =
lwt_log_info "Starting endorsement daemon" >>= fun () -> lwt_log_info "Starting endorsement daemon" >>= fun () ->
Lwt_stream.get block_stream >>= function Lwt_stream.get block_stream >>= function
| None | Some (Ok []) | Some (Error _) -> | None | Some (Error _) ->
cctxt#error "Can't fetch the current block head." cctxt#error "Can't fetch the current block head."
| Some (Ok initial_heads) -> | Some (Ok head) ->
let last_get_block = ref None in let last_get_block = ref None in
let get_block () = let get_block () =
match !last_get_block with match !last_get_block with
@ -288,13 +285,13 @@ let create (cctxt : #Proto_alpha.full) ?(max_past=(Time.of_seconds 110L)) ~delay
(get_block () >|= fun b -> `Hash b) ] >>= function (get_block () >|= fun b -> `Hash b) ] >>= function
| `Hash (None | Some (Error _)) -> | `Hash (None | Some (Error _)) ->
Lwt.return_unit Lwt.return_unit
| `Hash (Some (Ok bis)) -> | `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 bis) >>= fun () -> check_error (prepare_endorsement cctxt ~max_past state bi) >>= fun () ->
worker_loop () worker_loop ()
| `Timeout -> | `Timeout ->
check_error (endorse_for cctxt state.to_endorse) >>= fun () -> check_error (endorse_for cctxt state.to_endorse) >>= fun () ->
worker_loop () in worker_loop () in
check_error (prepare_endorsement cctxt ~max_past state initial_heads) >>= fun () -> check_error (prepare_endorsement cctxt ~max_past state head) >>= fun () ->
worker_loop () worker_loop ()

View File

@ -25,4 +25,4 @@ val create :
?max_past:Time.t -> ?max_past:Time.t ->
delay:int -> delay:int ->
public_key_hash list -> public_key_hash list ->
Client_baking_blocks.block_info list tzresult Lwt_stream.t -> unit Lwt.t Client_baking_blocks.block_info tzresult Lwt_stream.t -> unit Lwt.t

View File

@ -10,9 +10,23 @@
module Endorser = struct module Endorser = struct
let run (cctxt : #Proto_alpha.full) ~delay ?min_date delegates = let run (cctxt : #Proto_alpha.full) ~delay ?min_date delegates =
Client_baking_blocks.monitor Client_baking_blocks.monitor_heads
cctxt ?min_date ~min_heads:1 () >>=? fun block_stream -> cctxt `Main >>=? fun block_stream ->
Client_baking_endorsement.create cctxt ~delay delegates block_stream >>= fun () -> Client_baking_endorsement.create cctxt ~delay delegates block_stream >>= fun () ->
ignore min_date;
return ()
end
module Baker = struct
let run (cctxt : #Proto_alpha.full) ?max_priority ?min_date delegates =
Client_baking_blocks.monitor_heads
cctxt `Main >>=? fun block_stream ->
Client_baking_forge.create cctxt
?max_priority delegates block_stream >>=? fun () ->
ignore min_date;
return () return ()
end end
@ -26,16 +40,3 @@ module Accuser = struct
return () return ()
end end
module Baker = struct
let run (cctxt : #Proto_alpha.full) ?max_priority ?min_date delegates =
Client_baking_blocks.monitor
cctxt ?min_date ~min_heads:1 () >>=? fun block_stream ->
Client_baking_operations.monitor_endorsement
cctxt >>=? fun endorsement_stream ->
Client_baking_forge.create cctxt
?max_priority delegates block_stream endorsement_stream >>=? fun () ->
return ()
end