2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2018-02-06 00:17:03 +04:00
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
open Logging.Client.Denunciation
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let create cctxt endorsement_stream =
|
2016-09-08 21:13:10 +04:00
|
|
|
let last_get_endorsement = ref None in
|
|
|
|
let get_endorsement () =
|
|
|
|
match !last_get_endorsement with
|
|
|
|
| None ->
|
|
|
|
let t = Lwt_stream.get endorsement_stream in
|
|
|
|
last_get_endorsement := Some t ;
|
|
|
|
t
|
|
|
|
| Some t -> t in
|
|
|
|
let rec worker_loop () =
|
|
|
|
(* let timeout = compute_timeout state in *)
|
|
|
|
Lwt.choose [
|
|
|
|
(* (timeout >|= fun () -> `Timeout) ; *)
|
|
|
|
(get_endorsement () >|= fun e -> `Endorsement e) ;
|
|
|
|
] >>= function
|
2017-04-05 01:35:41 +04:00
|
|
|
| `Endorsement (None | Some (Error _)) ->
|
2016-09-08 21:13:10 +04:00
|
|
|
Lwt.return_unit
|
2017-04-05 01:35:41 +04:00
|
|
|
| `Endorsement (Some (Ok e)) ->
|
2016-09-08 21:13:10 +04:00
|
|
|
last_get_endorsement := None ;
|
2016-12-03 16:05:02 +04:00
|
|
|
Client_keys.Public_key_hash.name cctxt
|
2017-11-01 15:07:33 +04:00
|
|
|
e.Client_baking_operations.source >>= function
|
2017-04-05 03:02:10 +04:00
|
|
|
| Ok source ->
|
|
|
|
lwt_debug
|
|
|
|
"Discovered endorsement for block %a by %s (slot @[<h>%a@])"
|
|
|
|
Block_hash.pp_short e.block
|
|
|
|
source
|
|
|
|
Format.(pp_print_list pp_print_int) e.slots >>= fun () ->
|
|
|
|
worker_loop ()
|
|
|
|
| Error _ ->
|
|
|
|
(* TODO log *)
|
|
|
|
worker_loop ()
|
|
|
|
in
|
2016-09-08 21:13:10 +04:00
|
|
|
lwt_log_info "Starting denunciation daemon" >>= fun () ->
|
|
|
|
worker_loop ()
|