Alpha/endorser: bugfix

The `max_past` parameter, supposed to stop endorsing of blocks that are
too old, compared absolute times rather than relative times.
Specifically, it would check whether the block timestamp or the current
time was more recent than 110 seconds after epoch.

The new version checks whether the difference between the block
timestamp and the current time is greater than 110seconds.
This commit is contained in:
Raphaël Proust 2018-06-13 11:32:22 +08:00 committed by Grégoire Henry
parent ac06ccf935
commit 28abac0fb9
2 changed files with 4 additions and 4 deletions

View File

@ -187,7 +187,7 @@ let endorse_for cctxt = function
name
Operation_hash.pp_short oph >>= return
let prepare_endorsement (cctxt : #Proto_alpha.full) ~(max_past:Time.t) state bi =
let prepare_endorsement (cctxt : #Proto_alpha.full) ~(max_past:int64) state bi =
let may_endorse (block: Client_baking_blocks.block_info) delegate time =
Client_keys.Public_key_hash.name cctxt delegate >>=? fun name ->
lwt_log_info "May endorse block %a for %s"
@ -217,7 +217,7 @@ let prepare_endorsement (cctxt : #Proto_alpha.full) ~(max_past:Time.t) state bi
if Time.compare bi.timestamp (Time.now ()) > 0 then
lwt_log_info "Ignore block %a: forged in the future"
Block_hash.pp_short bi.hash >>= return
else if Time.(min (now ()) bi.timestamp > max_past) then
else if Time.diff (Time.now ()) bi.timestamp > max_past then
lwt_log_info "Ignore block %a: forged too far the past"
Block_hash.pp_short bi.hash >>= return
else
@ -264,7 +264,7 @@ let check_error f =
errs >>= fun () ->
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=110L) ~delay contracts (block_stream : Client_baking_blocks.block_info tzresult Lwt_stream.t) =
lwt_log_info "Starting endorsement daemon" >>= fun () ->
Lwt_stream.get block_stream >>= function
| None | Some (Error _) ->

View File

@ -22,7 +22,7 @@ val forge_endorsement:
val create :
#Proto_alpha.full ->
?max_past:Time.t ->
?max_past:int64 (* number of seconds *) ->
delay:int ->
public_key_hash list ->
Client_baking_blocks.block_info tzresult Lwt_stream.t -> unit Lwt.t