diff --git a/src/client/embedded/alpha/baker/client_mining_forge.ml b/src/client/embedded/alpha/baker/client_mining_forge.ml index 78b182b53..d1fe0b1db 100644 --- a/src/client/embedded/alpha/baker/client_mining_forge.ml +++ b/src/client/embedded/alpha/baker/client_mining_forge.ml @@ -105,15 +105,21 @@ let forge_block cctxt block cctxt block ~prio () >>=? fun time -> return (prio, time) end - | `Auto (src_pkh, max_priority) -> + | `Auto (src_pkh, max_priority, free_mining) -> Client_proto_rpcs.Helpers.Rights.mining_rights_for_delegate cctxt ?max_priority ~first_level:level ~last_level:level block src_pkh () >>=? fun possibilities -> 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 = - List.find (fun (l,_,_) -> l = level) possibilities in + List.find (fun (l,p,_) -> l = level && p >= min_prio) possibilities in return (prio, time) with Not_found -> Error_monad.failwith "No slot found at level %a" Raw_level.pp level diff --git a/src/client/embedded/alpha/baker/client_mining_forge.mli b/src/client/embedded/alpha/baker/client_mining_forge.mli index a82ca9363..9c9ce10db 100644 --- a/src/client/embedded/alpha/baker/client_mining_forge.mli +++ b/src/client/embedded/alpha/baker/client_mining_forge.mli @@ -38,7 +38,7 @@ val forge_block: ?best_effort:bool -> ?sort:bool -> ?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 -> src_sk:secret_key -> unit -> @@ -54,7 +54,7 @@ val forge_block: * Mining priority: If [`Auto] is used, it will be computed from 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 computed mining priority, it will be used. Otherwise, it will be diff --git a/src/client/embedded/alpha/baker/client_mining_main.ml b/src/client/embedded/alpha/baker/client_mining_main.ml index 06e6c84ff..19ac3e2e1 100644 --- a/src/client/embedded/alpha/baker/client_mining_main.ml +++ b/src/client/embedded/alpha/baker/client_mining_main.ml @@ -11,7 +11,8 @@ open Cli_entries open Client_commands 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 match src_sk with | None -> @@ -26,7 +27,7 @@ let mine_block cctxt block ?force ?max_priority ?src_sk delegate = ~timestamp:(Time.now ()) ?force ~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 |> trace_exn (Failure "Error while recording block") >>=? fun () -> cctxt.message "Injected block %a" Block_hash.pp_short block_hash >>= fun () -> @@ -122,14 +123,14 @@ let commands () = endorse_block cctxt ~force:!force ?max_priority:!max_priority delegate) ; 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" ] @@ Client_keys.Public_key_hash.alias_param ~name:"miner" ~desc: "name of the delegate owning the mining right" @@ stop) (fun (_, delegate) cctxt -> 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" ~args: [ force_arg ] (prefixes [ "reveal"; "nonce"; "for" ] diff --git a/src/client/embedded/alpha/baker/client_mining_main.mli b/src/client/embedded/alpha/baker/client_mining_main.mli index 1b0c233e2..ca7d63a5e 100644 --- a/src/client/embedded/alpha/baker/client_mining_main.mli +++ b/src/client/embedded/alpha/baker/client_mining_main.mli @@ -12,6 +12,7 @@ val mine_block: Client_proto_rpcs.block -> ?force:bool -> ?max_priority: int -> + ?free_mining: bool -> ?src_sk:secret_key -> public_key_hash -> unit tzresult Lwt.t diff --git a/src/client/embedded/alpha/client_proto_args.ml b/src/client/embedded/alpha/client_proto_args.ml index db394523c..3f440eaff 100644 --- a/src/client/embedded/alpha/client_proto_args.ml +++ b/src/client/embedded/alpha/client_proto_args.ml @@ -97,6 +97,10 @@ let max_priority_arg = with _ -> raise (Arg.Bad "invalid priority in -max-priority")), "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_arg = "-endorsement-delay", diff --git a/src/client/embedded/alpha/client_proto_args.mli b/src/client/embedded/alpha/client_proto_args.mli index 8e996f295..33ed0a701 100644 --- a/src/client/embedded/alpha/client_proto_args.mli +++ b/src/client/embedded/alpha/client_proto_args.mli @@ -17,6 +17,7 @@ val delegate_arg: string * Arg.spec * string val delegatable_args: (string * Arg.spec * string) list val spendable_args: (string * Arg.spec * string) list val max_priority_arg: string * Arg.spec * string +val free_mining_arg: string * Arg.spec * string val force_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 arg: string option ref val max_priority: int option ref +val free_mining: bool ref val endorsement_delay: int ref module Daemon : sig