From 28abac0fb9dd1be05ec497e32e3ffce67d37db3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Wed, 13 Jun 2018 11:32:22 +0800 Subject: [PATCH] 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. --- src/proto_alpha/lib_delegate/client_baking_endorsement.ml | 6 +++--- src/proto_alpha/lib_delegate/client_baking_endorsement.mli | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_delegate/client_baking_endorsement.ml b/src/proto_alpha/lib_delegate/client_baking_endorsement.ml index ed295515b..c74fbd2ef 100644 --- a/src/proto_alpha/lib_delegate/client_baking_endorsement.ml +++ b/src/proto_alpha/lib_delegate/client_baking_endorsement.ml @@ -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 _) -> diff --git a/src/proto_alpha/lib_delegate/client_baking_endorsement.mli b/src/proto_alpha/lib_delegate/client_baking_endorsement.mli index 52eb8721b..519347e84 100644 --- a/src/proto_alpha/lib_delegate/client_baking_endorsement.mli +++ b/src/proto_alpha/lib_delegate/client_baking_endorsement.mli @@ -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