Baker: re-add endorsement delay
This commit is contained in:
parent
c98fba3eef
commit
f63b96dbd8
@ -144,7 +144,7 @@ let forge_endorsement (cctxt : #Proto_alpha.full)
|
|||||||
|
|
||||||
type state = {
|
type state = {
|
||||||
delegates: public_key_hash list ;
|
delegates: public_key_hash list ;
|
||||||
delay: int64;
|
delay: int64 ;
|
||||||
mutable to_endorse : endorsement option
|
mutable to_endorse : endorsement option
|
||||||
}
|
}
|
||||||
and endorsement = {
|
and endorsement = {
|
||||||
@ -155,16 +155,7 @@ and endorsement = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let create_state delegates delay =
|
let create_state delegates delay =
|
||||||
{ delegates ;
|
{ delegates ; delay ; to_endorse=None }
|
||||||
delay ;
|
|
||||||
to_endorse = None ;
|
|
||||||
}
|
|
||||||
|
|
||||||
let rec insert ({time} as e) = function
|
|
||||||
| [] -> [e]
|
|
||||||
| ({time = time'} :: _) as l when Time.compare time time' < 0 ->
|
|
||||||
e :: l
|
|
||||||
| e' :: l -> e' :: insert e l
|
|
||||||
|
|
||||||
let get_delegates cctxt state =
|
let get_delegates cctxt state =
|
||||||
match state.delegates with
|
match state.delegates with
|
||||||
@ -231,7 +222,6 @@ let prepare_endorsement (cctxt : #Proto_alpha.full) ~(max_past:Time.t) state bis
|
|||||||
lwt_log_info "Ignore block %a: forged too far the past"
|
lwt_log_info "Ignore block %a: forged too far the past"
|
||||||
Block_hash.pp_short bi.hash >>= return
|
Block_hash.pp_short bi.hash >>= return
|
||||||
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
|
) bis
|
||||||
@ -257,6 +247,26 @@ let check_error f =
|
|||||||
errs >>= fun () ->
|
errs >>= fun () ->
|
||||||
Lwt.return_unit
|
Lwt.return_unit
|
||||||
|
|
||||||
|
let compute_timeout state =
|
||||||
|
match state.to_endorse with
|
||||||
|
| None -> Lwt_utils.never_ending
|
||||||
|
| Some {time} ->
|
||||||
|
let delay = (Time.diff time (Time.now ())) in
|
||||||
|
if delay <= 0L then
|
||||||
|
Lwt.return_unit
|
||||||
|
else
|
||||||
|
Lwt_unix.sleep (Int64.to_float delay)
|
||||||
|
|
||||||
|
let check_error f =
|
||||||
|
f >>= function
|
||||||
|
| Ok () -> Lwt.return_unit
|
||||||
|
| Error errs ->
|
||||||
|
lwt_log_error "Error while endorsing:@\n%a"
|
||||||
|
pp_print_error
|
||||||
|
errs >>= fun () ->
|
||||||
|
Lwt.return_unit
|
||||||
|
|
||||||
|
|
||||||
let create (cctxt : #Proto_alpha.full) ?(max_past=(Time.of_seconds 110L)) ~delay contracts block_stream =
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user