Client: add option for forcing free mining.

This commit is contained in:
Grégoire Henry 2017-05-08 21:35:29 +02:00
parent 3b38720fb6
commit 68f9851bce
6 changed files with 22 additions and 8 deletions

View File

@ -105,15 +105,21 @@ let forge_block cctxt block
cctxt block ~prio () >>=? fun time -> cctxt block ~prio () >>=? fun time ->
return (prio, time) return (prio, time)
end end
| `Auto (src_pkh, max_priority) -> | `Auto (src_pkh, max_priority, free_mining) ->
Client_proto_rpcs.Helpers.Rights.mining_rights_for_delegate cctxt Client_proto_rpcs.Helpers.Rights.mining_rights_for_delegate cctxt
?max_priority ?max_priority
~first_level:level ~first_level:level
~last_level:level ~last_level:level
block src_pkh () >>=? fun possibilities -> block src_pkh () >>=? fun possibilities ->
try try
begin
if free_mining then
Client_proto_rpcs.Constants.first_free_mining_slot cctxt block
else
return 0
end >>=? fun min_prio ->
let _, prio, time = let _, prio, time =
List.find (fun (l,_,_) -> l = level) possibilities in List.find (fun (l,p,_) -> l = level && p >= min_prio) possibilities in
return (prio, time) return (prio, time)
with Not_found -> with Not_found ->
Error_monad.failwith "No slot found at level %a" Raw_level.pp level Error_monad.failwith "No slot found at level %a" Raw_level.pp level

View File

@ -38,7 +38,7 @@ val forge_block:
?best_effort:bool -> ?best_effort:bool ->
?sort:bool -> ?sort:bool ->
?timestamp:Time.t -> ?timestamp:Time.t ->
priority:[`Set of int | `Auto of (public_key_hash * int option)] -> priority:[`Set of int | `Auto of (public_key_hash * int option * bool)] ->
seed_nonce:Nonce.t -> seed_nonce:Nonce.t ->
src_sk:secret_key -> src_sk:secret_key ->
unit -> unit ->
@ -54,7 +54,7 @@ val forge_block:
* Mining priority: If [`Auto] is used, it will be computed from * Mining priority: If [`Auto] is used, it will be computed from
the public key hash of the specified contract, optionally capped the public key hash of the specified contract, optionally capped
to a maximum value. to a maximum value, and optionnaly restricting for free mining slot.
* Timestamp: If [?timestamp] is set, and is compatible with the * Timestamp: If [?timestamp] is set, and is compatible with the
computed mining priority, it will be used. Otherwise, it will be computed mining priority, it will be used. Otherwise, it will be

View File

@ -11,7 +11,8 @@ open Cli_entries
open Client_commands open Client_commands
open Client_proto_contracts open Client_proto_contracts
let mine_block cctxt block ?force ?max_priority ?src_sk delegate = let mine_block cctxt block
?force ?max_priority ?(free_mining=false) ?src_sk delegate =
begin begin
match src_sk with match src_sk with
| None -> | None ->
@ -26,7 +27,7 @@ let mine_block cctxt block ?force ?max_priority ?src_sk delegate =
~timestamp:(Time.now ()) ~timestamp:(Time.now ())
?force ?force
~seed_nonce ~src_sk block ~seed_nonce ~src_sk block
~priority:(`Auto (delegate, max_priority)) () >>=? fun block_hash -> ~priority:(`Auto (delegate, max_priority, free_mining)) () >>=? fun block_hash ->
Client_mining_forge.State.record_block cctxt level block_hash seed_nonce Client_mining_forge.State.record_block cctxt level block_hash seed_nonce
|> trace_exn (Failure "Error while recording block") >>=? fun () -> |> trace_exn (Failure "Error while recording block") >>=? fun () ->
cctxt.message "Injected block %a" Block_hash.pp_short block_hash >>= fun () -> cctxt.message "Injected block %a" Block_hash.pp_short block_hash >>= fun () ->
@ -122,14 +123,14 @@ let commands () =
endorse_block cctxt endorse_block cctxt
~force:!force ?max_priority:!max_priority delegate) ; ~force:!force ?max_priority:!max_priority delegate) ;
command ~group ~desc: "Forge and inject block using the delegate rights" command ~group ~desc: "Forge and inject block using the delegate rights"
~args: [ max_priority_arg ; force_arg ] ~args: [ max_priority_arg ; force_arg ; free_mining_arg ]
(prefixes [ "mine"; "for" ] (prefixes [ "mine"; "for" ]
@@ Client_keys.Public_key_hash.alias_param @@ Client_keys.Public_key_hash.alias_param
~name:"miner" ~desc: "name of the delegate owning the mining right" ~name:"miner" ~desc: "name of the delegate owning the mining right"
@@ stop) @@ stop)
(fun (_, delegate) cctxt -> (fun (_, delegate) cctxt ->
mine_block cctxt cctxt.config.block mine_block cctxt cctxt.config.block
~force:!force ?max_priority:!max_priority delegate) ; ~force:!force ?max_priority:!max_priority ~free_mining:!free_mining delegate) ;
command ~group ~desc: "Forge and inject a seed-nonce revelation operation" command ~group ~desc: "Forge and inject a seed-nonce revelation operation"
~args: [ force_arg ] ~args: [ force_arg ]
(prefixes [ "reveal"; "nonce"; "for" ] (prefixes [ "reveal"; "nonce"; "for" ]

View File

@ -12,6 +12,7 @@ val mine_block:
Client_proto_rpcs.block -> Client_proto_rpcs.block ->
?force:bool -> ?force:bool ->
?max_priority: int -> ?max_priority: int ->
?free_mining: bool ->
?src_sk:secret_key -> ?src_sk:secret_key ->
public_key_hash -> public_key_hash ->
unit tzresult Lwt.t unit tzresult Lwt.t

View File

@ -97,6 +97,10 @@ let max_priority_arg =
with _ -> raise (Arg.Bad "invalid priority in -max-priority")), with _ -> raise (Arg.Bad "invalid priority in -max-priority")),
"Set the max_priority used when looking for mining slot." "Set the max_priority used when looking for mining slot."
let free_mining = ref false
let free_mining_arg =
"-free-mining", Arg.Set free_mining, "Only consider free mining slots."
let endorsement_delay = ref 15 let endorsement_delay = ref 15
let endorsement_delay_arg = let endorsement_delay_arg =
"-endorsement-delay", "-endorsement-delay",

View File

@ -17,6 +17,7 @@ val delegate_arg: string * Arg.spec * string
val delegatable_args: (string * Arg.spec * string) list val delegatable_args: (string * Arg.spec * string) list
val spendable_args: (string * Arg.spec * string) list val spendable_args: (string * Arg.spec * string) list
val max_priority_arg: string * Arg.spec * string val max_priority_arg: string * Arg.spec * string
val free_mining_arg: string * Arg.spec * string
val force_arg: string * Arg.spec * string val force_arg: string * Arg.spec * string
val endorsement_delay_arg: string * Arg.spec * string val endorsement_delay_arg: string * Arg.spec * string
@ -35,6 +36,7 @@ val fee: Tez.t ref
val init: string ref val init: string ref
val arg: string option ref val arg: string option ref
val max_priority: int option ref val max_priority: int option ref
val free_mining: bool ref
val endorsement_delay: int ref val endorsement_delay: int ref
module Daemon : sig module Daemon : sig