alpha-baker: Rename client_baking -> delegate

This commit is contained in:
Pietro 2018-03-22 18:37:23 +01:00 committed by Grégoire Henry
parent 5a3492ea8b
commit 9d4be9caba
9 changed files with 121 additions and 80 deletions

View File

@ -11,6 +11,6 @@ let select_commands _ _ =
return return
(List.map (List.map
(Clic.map_command (new Proto_alpha.wrap_full)) (Clic.map_command (new Proto_alpha.wrap_full))
(Client_baking_commands.commands ())) (Delegate_commands.commands ()))
let () = Client_main_run.run select_commands let () = Client_main_run.run select_commands

View File

@ -1,53 +0,0 @@
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2018. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* 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

View File

@ -98,13 +98,35 @@ let reveal_block_nonces (cctxt : #Proto_alpha.full) block_hashes =
do_reveal cctxt cctxt#block blocks do_reveal cctxt cctxt#block blocks
let reveal_nonces cctxt () = let reveal_nonces cctxt () =
let block = Block_services.last_baked_block cctxt#block in
Client_baking_forge.get_unrevealed_nonces Client_baking_forge.get_unrevealed_nonces
cctxt cctxt#block >>=? fun nonces -> cctxt cctxt#block >>=? fun nonces ->
do_reveal cctxt cctxt#block nonces do_reveal cctxt cctxt#block nonces
let run_daemon cctxt ?max_priority ~endorsement_delay delegates ~endorsement ~baking ~denunciation = let run_daemon cctxt ?max_priority ~endorsement_delay delegates ~endorsement ~baking ~denunciation =
Client_baking_daemon.run cctxt let endorser =
?max_priority if endorsement then
Client_daemon.Endorser.run cctxt
~delay:endorsement_delay ~delay:endorsement_delay
~endorsement ~baking ~denunciation ~min_date:((Time.add (Time.now ()) (Int64.neg 1800L)))
delegates (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 ()

View File

@ -0,0 +1,41 @@
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2018. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* 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

View File

@ -10,11 +10,23 @@
open Proto_alpha open Proto_alpha
open Alpha_context open Alpha_context
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: val run:
#Proto_alpha.full -> #Proto_alpha.full ->
?max_priority: int -> ?max_priority: int ->
delay: int -> ?min_date: Time.t ->
public_key_hash list -> public_key_hash list -> unit tzresult Lwt.t
endorsement:bool -> end
denunciation:bool ->
baking:bool -> unit tzresult Lwt.t module Accuser : sig
val run:
#Proto_alpha.full -> unit tzresult Lwt.t
end

View File

@ -11,7 +11,7 @@ open Client_proto_args
open Client_baking_lib open Client_baking_lib
let group = let group =
{ Clic.name = "delegate" ; { Cli_entries.name = "delegate" ;
title = "Commands related to delegate operations." } title = "Commands related to delegate operations." }
let commands () = let commands () =
@ -21,14 +21,31 @@ let commands () =
(args5 max_priority_arg endorsement_delay_arg (args5 max_priority_arg endorsement_delay_arg
Daemon.baking_switch Daemon.endorsement_switch Daemon.denunciation_switch) Daemon.baking_switch Daemon.endorsement_switch Daemon.denunciation_switch)
(prefixes [ "launch" ; "daemon" ] (prefixes [ "launch" ; "daemon" ]
@@ seq_of_param Client_keys.Public_key_hash.source_param) @@ seq_of_param Client_keys.Public_key_hash.alias_param)
(fun (max_priority, endorsement_delay, baking, endorsement, denunciation) delegates cctxt -> (fun max_priority delegates cctxt ->
let (endorsement, baking, denunciation) = Client_daemon.Baker.run cctxt
if (not endorsement) && (not baking) && (not denunciation) ?max_priority
then (true, true, true) ~min_date:((Time.add (Time.now ()) (Int64.neg 1800L)))
else (endorsement, baking, denunciation) in (List.map snd delegates)
iter_s (fun d -> Client_keys.get_key cctxt d >>|? fun _ -> ()) delegates >>=? fun () -> ) ;
run_daemon cctxt ?max_priority ~endorsement_delay ~endorsement ~baking ~denunciation 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." command ~group ~desc: "Forge and inject an endorsement operation."
no_options no_options
(prefixes [ "endorse"; "for" ] (prefixes [ "endorse"; "for" ]

View File

@ -10,4 +10,4 @@
let () = let () =
Client_commands.register Proto_alpha.hash @@ Client_commands.register Proto_alpha.hash @@
List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@ List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@
Client_baking_commands.commands () Delegate_commands.commands ()

View File

@ -12,7 +12,9 @@
tezos-client-commands tezos-client-commands
tezos-rpc)) tezos-rpc))
(library_flags (:standard -linkall)) (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 (flags (:standard -w -9+27-30-32-40@8
-safe-string -safe-string
-open Tezos_base__TzPervasives -open Tezos_base__TzPervasives
@ -34,7 +36,7 @@
tezos-client-commands tezos-client-commands
tezos-baking-alpha)) tezos-baking-alpha))
(library_flags (:standard -linkall)) (library_flags (:standard -linkall))
(modules (client_baking_commands)) (modules (delegate_commands))
(flags (:standard -w -9+27-30-32-40@8 (flags (:standard -w -9+27-30-32-40@8
-safe-string -safe-string
-open Tezos_base__TzPervasives -open Tezos_base__TzPervasives
@ -59,7 +61,7 @@
tezos-baking-alpha-commands tezos-baking-alpha-commands
tezos-rpc)) tezos-rpc))
(library_flags (:standard -linkall)) (library_flags (:standard -linkall))
(modules (client_baking_commands_registration)) (modules (delegate_commands_registration))
(flags (:standard -w -9+27-30-32-40@8 (flags (:standard -w -9+27-30-32-40@8
-safe-string -safe-string
-open Tezos_base__TzPervasives -open Tezos_base__TzPervasives