2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-04-05 01:35:41 +04:00
|
|
|
open Client_commands
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-05-08 23:35:29 +04:00
|
|
|
let mine_block cctxt block
|
2017-11-01 15:07:33 +04:00
|
|
|
?force ?max_priority ?(free_baking=false) ?src_sk delegate =
|
2016-09-08 21:13:10 +04:00
|
|
|
begin
|
|
|
|
match src_sk with
|
|
|
|
| None ->
|
2016-12-03 16:05:02 +04:00
|
|
|
Client_keys.get_key cctxt delegate >>=? fun (_, _, src_sk) ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return src_sk
|
|
|
|
| Some sk -> return sk
|
|
|
|
end >>=? fun src_sk ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Context.level cctxt.rpc_config block >>=? fun level ->
|
2016-09-08 21:13:10 +04:00
|
|
|
let level = Raw_level.succ level.level in
|
2017-11-01 15:07:33 +04:00
|
|
|
let seed_nonce = Client_baking_forge.generate_seed_nonce () in
|
2017-04-27 03:01:05 +04:00
|
|
|
let seed_nonce_hash = Nonce.hash seed_nonce in
|
2017-11-01 15:07:33 +04:00
|
|
|
Client_baking_forge.forge_block cctxt.rpc_config
|
2016-09-08 21:13:10 +04:00
|
|
|
~timestamp:(Time.now ())
|
2017-03-08 21:47:01 +04:00
|
|
|
?force
|
2017-04-27 03:01:05 +04:00
|
|
|
~seed_nonce_hash ~src_sk block
|
2017-11-01 15:07:33 +04:00
|
|
|
~priority:(`Auto (delegate, max_priority, free_baking)) () >>=? fun block_hash ->
|
|
|
|
Client_baking_forge.State.record_block cctxt level block_hash seed_nonce
|
2016-09-08 21:13:10 +04:00
|
|
|
|> trace_exn (Failure "Error while recording block") >>=? fun () ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "Injected block %a" Block_hash.pp_short block_hash >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return ()
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let endorse_block cctxt ?force ?max_priority delegate =
|
|
|
|
Client_keys.get_key cctxt delegate >>=? fun (_src_name, src_pk, src_sk) ->
|
2017-11-01 15:07:33 +04:00
|
|
|
Client_baking_endorsement.forge_endorsement cctxt
|
2017-03-15 04:17:20 +04:00
|
|
|
cctxt.config.block ?force ?max_priority ~src_sk src_pk >>=? fun oph ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.answer "Operation successfully injected in the node." >>= fun () ->
|
|
|
|
cctxt.answer "Operation hash is '%a'." Operation_hash.pp oph >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return ()
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let get_predecessor_cycle cctxt cycle =
|
2016-09-08 21:13:10 +04:00
|
|
|
match Cycle.pred cycle with
|
|
|
|
| None ->
|
|
|
|
if Cycle.(cycle = root) then
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.Client_commands.error "No predecessor for the first cycle"
|
2016-09-08 21:13:10 +04:00
|
|
|
else
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.error
|
2016-09-08 21:13:10 +04:00
|
|
|
"Cannot compute the predecessor of cycle %a"
|
|
|
|
Cycle.pp cycle
|
|
|
|
| Some cycle -> Lwt.return cycle
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let do_reveal cctxt ?force block blocks =
|
2016-09-08 21:13:10 +04:00
|
|
|
let nonces = List.map snd blocks in
|
2017-11-01 15:07:33 +04:00
|
|
|
Client_baking_revelation.forge_seed_nonce_revelation cctxt
|
2016-09-08 21:13:10 +04:00
|
|
|
block ?force nonces >>=? fun () ->
|
2016-12-03 16:05:02 +04:00
|
|
|
Client_proto_nonces.dels cctxt (List.map fst blocks) >>=? fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return ()
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let reveal_block_nonces cctxt ?force block_hashes =
|
2016-09-08 21:13:10 +04:00
|
|
|
Lwt_list.filter_map_p
|
|
|
|
(fun hash ->
|
|
|
|
Lwt.catch
|
|
|
|
(fun () ->
|
2017-11-01 15:07:33 +04:00
|
|
|
Client_baking_blocks.info cctxt.rpc_config (`Hash hash) >>= function
|
2016-09-08 21:13:10 +04:00
|
|
|
| Ok bi -> Lwt.return (Some bi)
|
|
|
|
| Error _ ->
|
|
|
|
Lwt.fail Not_found)
|
|
|
|
(fun _ ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.warning
|
2016-11-22 20:28:25 +04:00
|
|
|
"Cannot find block %a in the chain. (ignoring)@."
|
|
|
|
Block_hash.pp_short hash >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
Lwt.return_none))
|
|
|
|
block_hashes >>= fun block_infos ->
|
2017-11-01 15:07:33 +04:00
|
|
|
filter_map_s (fun (bi : Client_baking_blocks.block_info) ->
|
2016-12-03 16:05:02 +04:00
|
|
|
Client_proto_nonces.find cctxt bi.hash >>= function
|
2016-09-08 21:13:10 +04:00
|
|
|
| None ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.warning "Cannot find nonces for block %a (ignoring)@."
|
2016-11-22 20:28:25 +04:00
|
|
|
Block_hash.pp_short bi.hash >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return None
|
|
|
|
| Some nonce ->
|
|
|
|
return (Some (bi.hash, (bi.level.level, nonce))))
|
|
|
|
block_infos >>=? fun blocks ->
|
2017-03-15 04:17:20 +04:00
|
|
|
do_reveal cctxt ?force cctxt.config.block blocks
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let reveal_nonces cctxt ?force () =
|
2017-09-22 19:36:43 +04:00
|
|
|
let block = Client_rpcs.last_mined_block cctxt.config.block in
|
2017-11-01 15:07:33 +04:00
|
|
|
Client_baking_forge.get_unrevealed_nonces
|
2017-09-22 19:36:43 +04:00
|
|
|
cctxt ?force block >>=? fun nonces ->
|
2017-03-15 04:17:20 +04:00
|
|
|
do_reveal cctxt ?force cctxt.config.block nonces
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
open Client_proto_args
|
|
|
|
|
2017-11-01 15:07:33 +04:00
|
|
|
let run_daemon cctxt max_priority endorsement_delay delegates ~endorsement ~baking ~denunciation =
|
|
|
|
Client_baking_daemon.run cctxt
|
2017-09-19 13:31:35 +04:00
|
|
|
?max_priority
|
|
|
|
~delay:endorsement_delay
|
2016-09-21 18:22:43 +04:00
|
|
|
~min_date:((Time.add (Time.now ()) (Int64.neg 1800L)))
|
2017-11-01 15:07:33 +04:00
|
|
|
~endorsement ~baking ~denunciation
|
2016-09-08 21:13:10 +04:00
|
|
|
(List.map snd delegates)
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let group =
|
|
|
|
{ Cli_entries.name = "delegate" ;
|
|
|
|
title = "Commands related to delegate operations." }
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
let commands () =
|
|
|
|
let open Cli_entries in
|
|
|
|
[
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "Launch a daemon that handles delegate operations."
|
2017-09-19 13:31:35 +04:00
|
|
|
(args5 max_priority_arg endorsement_delay_arg
|
2017-11-13 19:34:00 +04:00
|
|
|
Daemon.baking_switch Daemon.endorsement_switch Daemon.denunciation_switch)
|
2016-09-08 21:13:10 +04:00
|
|
|
(prefixes [ "launch" ; "daemon" ]
|
2017-09-19 13:31:35 +04:00
|
|
|
@@ seq_of_param Client_keys.Public_key_hash.alias_param)
|
2017-11-01 15:07:33 +04:00
|
|
|
(fun (max_priority, endorsement_delay, baking, endorsement, denunciation) delegates cctxt ->
|
|
|
|
let (endorsement, baking, denunciation) =
|
|
|
|
if (not endorsement) && (not baking) && (not denunciation)
|
2017-09-19 13:31:35 +04:00
|
|
|
then (true, true, true)
|
2017-11-01 15:07:33 +04:00
|
|
|
else (endorsement, baking, denunciation) in
|
|
|
|
run_daemon cctxt max_priority endorsement_delay ~endorsement ~baking ~denunciation delegates) ;
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "Forge and inject an endorsement operation"
|
2017-09-19 13:31:35 +04:00
|
|
|
(args2 force_switch max_priority_arg)
|
2016-09-08 21:13:10 +04:00
|
|
|
(prefixes [ "endorse"; "for" ]
|
|
|
|
@@ Client_keys.Public_key_hash.alias_param
|
2017-11-06 17:12:19 +04:00
|
|
|
~name:"baker" ~desc: "name of the delegate owning the endorsement right"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ stop)
|
2017-09-19 13:31:35 +04:00
|
|
|
(fun (force, max_priority) (_, delegate) cctxt ->
|
2016-12-03 16:05:02 +04:00
|
|
|
endorse_block cctxt
|
2017-09-19 13:31:35 +04:00
|
|
|
~force ?max_priority delegate) ;
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "Forge and inject block using the delegate rights"
|
2017-11-01 15:07:33 +04:00
|
|
|
(args3 max_priority_arg force_switch free_baking_switch)
|
2016-09-08 21:13:10 +04:00
|
|
|
(prefixes [ "mine"; "for" ]
|
|
|
|
@@ Client_keys.Public_key_hash.alias_param
|
2017-11-06 17:12:19 +04:00
|
|
|
~name:"baker" ~desc: "name of the delegate owning the baking right"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ stop)
|
2017-11-01 15:07:33 +04:00
|
|
|
(fun (max_priority, force, free_baking) (_, delegate) cctxt ->
|
2017-03-15 04:17:20 +04:00
|
|
|
mine_block cctxt cctxt.config.block
|
2017-11-01 15:07:33 +04:00
|
|
|
~force ?max_priority ~free_baking delegate) ;
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "Forge and inject a seed-nonce revelation operation"
|
2017-09-19 13:31:35 +04:00
|
|
|
(args1 force_switch)
|
2016-09-08 21:13:10 +04:00
|
|
|
(prefixes [ "reveal"; "nonce"; "for" ]
|
2017-09-19 13:31:35 +04:00
|
|
|
@@ seq_of_param Block_hash.param)
|
|
|
|
(fun force block_hashes cctxt ->
|
2016-12-03 16:05:02 +04:00
|
|
|
reveal_block_nonces cctxt
|
2017-09-19 13:31:35 +04:00
|
|
|
~force block_hashes) ;
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "Forge and inject redemption operations"
|
2017-09-19 13:31:35 +04:00
|
|
|
(args1 force_switch)
|
2016-09-08 21:13:10 +04:00
|
|
|
(prefixes [ "reveal"; "nonces" ]
|
|
|
|
@@ stop)
|
2017-09-19 13:31:35 +04:00
|
|
|
(fun force cctxt ->
|
|
|
|
reveal_nonces cctxt ~force ()) ;
|
2016-09-08 21:13:10 +04:00
|
|
|
]
|
|
|
|
|
|
|
|
let () =
|
2016-12-03 16:05:02 +04:00
|
|
|
Client_commands.register Client_proto_main.protocol @@
|
2016-09-08 21:13:10 +04:00
|
|
|
commands ()
|