diff --git a/src/proto_alpha/bin_baker/main_baker_alpha.ml b/src/proto_alpha/bin_baker/main_baker_alpha.ml index 99340dd7b..4e91c4ba5 100644 --- a/src/proto_alpha/bin_baker/main_baker_alpha.ml +++ b/src/proto_alpha/bin_baker/main_baker_alpha.ml @@ -11,6 +11,6 @@ let select_commands _ _ = return (List.map (Clic.map_command (new Proto_alpha.wrap_full)) - (Client_baking_commands.commands ())) + (Delegate_commands.commands ())) let () = Client_main_run.run select_commands diff --git a/src/proto_alpha/lib_baking/client_baking_daemon.ml b/src/proto_alpha/lib_baking/client_baking_daemon.ml deleted file mode 100644 index dfbafc777..000000000 --- a/src/proto_alpha/lib_baking/client_baking_daemon.ml +++ /dev/null @@ -1,53 +0,0 @@ -(**************************************************************************) -(* *) -(* Copyright (c) 2014 - 2018. *) -(* Dynamic Ledger Solutions, Inc. *) -(* *) -(* All rights reserved. No warranty, explicit or implicit, provided. *) -(* *) -(**************************************************************************) - -let run (cctxt : #Proto_alpha.full) ?max_priority ~delay delegates ~endorsement ~denunciation ~baking = - begin - match delegates with - | [] -> - Tezos_signer_backends.Encrypted.decrypt_all cctxt - | _ :: _ -> - iter_s - (fun k -> - Client_keys.get_key cctxt k >>=? fun (_, _, sk_uri) -> - Client_keys.neuterize sk_uri >>=? fun _ -> - return ()) - delegates - end >>=? fun () -> - (* TODO really detach... *) - let endorsement = - if endorsement then - Client_baking_blocks.monitor_heads cctxt `Main >>=? fun block_stream -> - Client_baking_endorsement.create cctxt ~delay delegates block_stream >>= fun () -> - return () - else - return () - in - let denunciation = - if denunciation then - Client_baking_operations.monitor_endorsement - cctxt >>=? fun endorsement_stream -> - Client_baking_denunciation.create cctxt endorsement_stream >>= fun () -> - return () - else - return () - in - let forge = - if baking then begin - Client_baking_blocks.monitor_heads - cctxt `Main >>=? fun block_stream -> - Client_baking_forge.create cctxt - ?max_priority delegates block_stream >>=? fun () -> - return () - end else - return () - in - denunciation >>=? fun () -> - endorsement >>=? fun () -> - forge diff --git a/src/proto_alpha/lib_baking/client_baking_lib.ml b/src/proto_alpha/lib_baking/client_baking_lib.ml index 8803bc265..cce69e4fc 100644 --- a/src/proto_alpha/lib_baking/client_baking_lib.ml +++ b/src/proto_alpha/lib_baking/client_baking_lib.ml @@ -98,13 +98,35 @@ let reveal_block_nonces (cctxt : #Proto_alpha.full) block_hashes = do_reveal cctxt cctxt#block blocks let reveal_nonces cctxt () = + let block = Block_services.last_baked_block cctxt#block in Client_baking_forge.get_unrevealed_nonces cctxt cctxt#block >>=? fun nonces -> do_reveal cctxt cctxt#block nonces let run_daemon cctxt ?max_priority ~endorsement_delay delegates ~endorsement ~baking ~denunciation = - Client_baking_daemon.run cctxt - ?max_priority - ~delay:endorsement_delay - ~endorsement ~baking ~denunciation - delegates + let endorser = + if endorsement then + Client_daemon.Endorser.run cctxt + ~delay:endorsement_delay + ~min_date:((Time.add (Time.now ()) (Int64.neg 1800L))) + (List.map snd delegates) >>=? fun () -> return () + else return () + in + let baker = + if baking then + Client_daemon.Baker.run cctxt + ?max_priority + ~min_date:((Time.add (Time.now ()) (Int64.neg 1800L))) + (List.map snd delegates) >>=? fun () -> return () + else return () + in + let accuser = + if denunciation then + Client_daemon.Accuser.run cctxt >>=? fun () -> return () + else + return () + in + endorser >>=? fun () -> + baker >>=? fun () -> + accuser >>=? fun () -> + return () diff --git a/src/proto_alpha/lib_baking/client_daemon.ml b/src/proto_alpha/lib_baking/client_daemon.ml new file mode 100644 index 000000000..ff89d7915 --- /dev/null +++ b/src/proto_alpha/lib_baking/client_daemon.ml @@ -0,0 +1,41 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2018. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +module Endorser = struct + + let run (cctxt : #Proto_alpha.full) ~delay ?min_date delegates = + Client_baking_blocks.monitor + cctxt ?min_date ~min_heads:1 () >>=? fun block_stream -> + Client_baking_endorsement.create cctxt ~delay delegates block_stream >>= fun () -> + return () + +end + +module Accuser = struct + + let run (cctxt : #Proto_alpha.full) = + Client_baking_operations.monitor_endorsement + cctxt >>=? fun endorsement_stream -> + Client_baking_denunciation.create cctxt endorsement_stream >>= fun () -> + return () + +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 diff --git a/src/proto_alpha/lib_baking/client_baking_daemon.mli b/src/proto_alpha/lib_baking/client_daemon.mli similarity index 62% rename from src/proto_alpha/lib_baking/client_baking_daemon.mli rename to src/proto_alpha/lib_baking/client_daemon.mli index db798d8ca..8a782eabc 100644 --- a/src/proto_alpha/lib_baking/client_baking_daemon.mli +++ b/src/proto_alpha/lib_baking/client_daemon.mli @@ -10,11 +10,23 @@ open Proto_alpha open Alpha_context -val run: - #Proto_alpha.full -> - ?max_priority: int -> - delay: int -> - public_key_hash list -> - endorsement:bool -> - denunciation:bool -> - baking:bool -> unit tzresult Lwt.t +module Endorser : sig + val run: + #Proto_alpha.full -> + delay: int -> + ?min_date: Time.t -> + public_key_hash list -> unit tzresult Lwt.t +end + +module Baker : sig + val run: + #Proto_alpha.full -> + ?max_priority: int -> + ?min_date: Time.t -> + public_key_hash list -> unit tzresult Lwt.t +end + +module Accuser : sig + val run: + #Proto_alpha.full -> unit tzresult Lwt.t +end diff --git a/src/proto_alpha/lib_baking/client_baking_commands.ml b/src/proto_alpha/lib_baking/delegate_commands.ml similarity index 71% rename from src/proto_alpha/lib_baking/client_baking_commands.ml rename to src/proto_alpha/lib_baking/delegate_commands.ml index 309d77d27..760900989 100644 --- a/src/proto_alpha/lib_baking/client_baking_commands.ml +++ b/src/proto_alpha/lib_baking/delegate_commands.ml @@ -11,7 +11,7 @@ open Client_proto_args open Client_baking_lib let group = - { Clic.name = "delegate" ; + { Cli_entries.name = "delegate" ; title = "Commands related to delegate operations." } let commands () = @@ -21,14 +21,31 @@ let commands () = (args5 max_priority_arg endorsement_delay_arg Daemon.baking_switch Daemon.endorsement_switch Daemon.denunciation_switch) (prefixes [ "launch" ; "daemon" ] - @@ seq_of_param Client_keys.Public_key_hash.source_param) - (fun (max_priority, endorsement_delay, baking, endorsement, denunciation) delegates cctxt -> - let (endorsement, baking, denunciation) = - if (not endorsement) && (not baking) && (not denunciation) - then (true, true, true) - else (endorsement, baking, denunciation) in - iter_s (fun d -> Client_keys.get_key cctxt d >>|? fun _ -> ()) delegates >>=? fun () -> - run_daemon cctxt ?max_priority ~endorsement_delay ~endorsement ~baking ~denunciation delegates) ; + @@ seq_of_param Client_keys.Public_key_hash.alias_param) + (fun max_priority delegates cctxt -> + Client_daemon.Baker.run cctxt + ?max_priority + ~min_date:((Time.add (Time.now ()) (Int64.neg 1800L))) + (List.map snd delegates) + ) ; + + command ~group ~desc: "Launch the accuser daemon" + no_options + (prefixes [ "launch" ; "accuser" ] + @@ stop) + (fun () cctxt -> Client_daemon.Accuser.run cctxt) ; + + command ~group ~desc: "Launch the endorser daemon" + (args1 endorsement_delay_arg ) + (prefixes [ "launch" ; "endorser" ] + @@ seq_of_param Client_keys.Public_key_hash.alias_param) + (fun endorsement_delay delegates cctxt -> + Client_daemon.Endorser.run cctxt + ~delay:endorsement_delay + ~min_date:((Time.add (Time.now ()) (Int64.neg 1800L))) + (List.map snd delegates) + ) ; + command ~group ~desc: "Forge and inject an endorsement operation." no_options (prefixes [ "endorse"; "for" ] diff --git a/src/proto_alpha/lib_baking/client_baking_commands.mli b/src/proto_alpha/lib_baking/delegate_commands.mli similarity index 100% rename from src/proto_alpha/lib_baking/client_baking_commands.mli rename to src/proto_alpha/lib_baking/delegate_commands.mli diff --git a/src/proto_alpha/lib_baking/client_baking_commands_registration.ml b/src/proto_alpha/lib_baking/delegate_commands_registration.ml similarity index 95% rename from src/proto_alpha/lib_baking/client_baking_commands_registration.ml rename to src/proto_alpha/lib_baking/delegate_commands_registration.ml index b0c89238a..0f7397525 100644 --- a/src/proto_alpha/lib_baking/client_baking_commands_registration.ml +++ b/src/proto_alpha/lib_baking/delegate_commands_registration.ml @@ -10,4 +10,4 @@ let () = Client_commands.register Proto_alpha.hash @@ List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@ - Client_baking_commands.commands () + Delegate_commands.commands () diff --git a/src/proto_alpha/lib_baking/jbuild b/src/proto_alpha/lib_baking/jbuild index d1034e5fc..96e3b319c 100644 --- a/src/proto_alpha/lib_baking/jbuild +++ b/src/proto_alpha/lib_baking/jbuild @@ -12,7 +12,9 @@ tezos-client-commands tezos-rpc)) (library_flags (:standard -linkall)) - (modules (:standard \ client_baking_commands client_baking_commands_registration)) + (modules (:standard \ + delegate_commands + delegate_commands_registration)) (flags (:standard -w -9+27-30-32-40@8 -safe-string -open Tezos_base__TzPervasives @@ -34,7 +36,7 @@ tezos-client-commands tezos-baking-alpha)) (library_flags (:standard -linkall)) - (modules (client_baking_commands)) + (modules (delegate_commands)) (flags (:standard -w -9+27-30-32-40@8 -safe-string -open Tezos_base__TzPervasives @@ -59,7 +61,7 @@ tezos-baking-alpha-commands tezos-rpc)) (library_flags (:standard -linkall)) - (modules (client_baking_commands_registration)) + (modules (delegate_commands_registration)) (flags (:standard -w -9+27-30-32-40@8 -safe-string -open Tezos_base__TzPervasives