From 2f6896a6f33ee7ef58a011a96a9cba1cb2c4e391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Wed, 8 Aug 2018 16:34:32 +0200 Subject: [PATCH] Alpha/Client: add `--mempool` to command `bake for `. --- src/lib_shell_services/block_services.mli | 2 ++ .../lib_delegate/client_baking_forge.ml | 21 +++++++++++++------ .../lib_delegate/client_baking_forge.mli | 1 + .../lib_delegate/client_baking_lib.ml | 3 ++- .../lib_delegate/client_baking_lib.mli | 1 + .../lib_delegate/delegate_commands.ml | 13 +++++++++--- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/lib_shell_services/block_services.mli b/src/lib_shell_services/block_services.mli index 2ff20beb9..b965d7f84 100644 --- a/src/lib_shell_services/block_services.mli +++ b/src/lib_shell_services/block_services.mli @@ -400,6 +400,8 @@ module Make(Proto : PROTO)(Next_proto : PROTO) : sig module Mempool : sig + val encoding: Mempool.t Data_encoding.t + val pending_operations: ('a, 'b) RPC_path.t -> ([ `GET ], 'a, diff --git a/src/proto_alpha/lib_delegate/client_baking_forge.ml b/src/proto_alpha/lib_delegate/client_baking_forge.ml index cbf16f07e..9397d32bd 100644 --- a/src/proto_alpha/lib_delegate/client_baking_forge.ml +++ b/src/proto_alpha/lib_delegate/client_baking_forge.ml @@ -291,11 +291,19 @@ let ops_of_mempool (ops : Alpha_block_services.Mempool.t) = List.rev_map (fun (_, op) -> op) ops.applied ) -let unopt_operations cctxt chain = function - | None -> - Alpha_block_services.Mempool.pending_operations cctxt ~chain () >>=? fun mpool -> - let ops = ops_of_mempool mpool in - return ops +let unopt_operations cctxt chain mempool = function + | None -> begin + match mempool with + | None -> + Alpha_block_services.Mempool.pending_operations cctxt ~chain () >>=? fun mpool -> + let ops = ops_of_mempool mpool in + return ops + | Some file -> + Tezos_stdlib_unix.Lwt_utils_unix.Json.read_file file >>=? fun json -> + let mpool = Data_encoding.Json.destruct Alpha_block_services.S.Mempool.encoding json in + let ops = ops_of_mempool mpool in + return ops +end | Some operations -> return operations @@ -379,11 +387,12 @@ let forge_block cctxt ?(chain = `Main) block ?(sort = best_effort) ?(fee_threshold = Tez.zero) ?timestamp + ?mempool ~priority ?seed_nonce_hash ~src_sk () = (* making the arguments usable *) - unopt_operations cctxt chain operations >>=? fun operations_arg -> + unopt_operations cctxt chain mempool operations >>=? fun operations_arg -> decode_priority cctxt chain block priority >>=? fun (priority, minimal_timestamp) -> unopt_timestamp timestamp minimal_timestamp >>=? fun timestamp -> diff --git a/src/proto_alpha/lib_delegate/client_baking_forge.mli b/src/proto_alpha/lib_delegate/client_baking_forge.mli index c4906df94..45d83e3e4 100644 --- a/src/proto_alpha/lib_delegate/client_baking_forge.mli +++ b/src/proto_alpha/lib_delegate/client_baking_forge.mli @@ -61,6 +61,7 @@ val forge_block: ?sort:bool -> ?fee_threshold:Tez.t -> ?timestamp:Time.t -> + ?mempool:string -> priority:[`Set of int | `Auto of (public_key_hash * int option)] -> ?seed_nonce_hash:Nonce_hash.t -> src_sk:Client_keys.sk_uri -> diff --git a/src/proto_alpha/lib_delegate/client_baking_lib.ml b/src/proto_alpha/lib_delegate/client_baking_lib.ml index bfecdf65d..a385821e9 100644 --- a/src/proto_alpha/lib_delegate/client_baking_lib.ml +++ b/src/proto_alpha/lib_delegate/client_baking_lib.ml @@ -29,7 +29,7 @@ open Alpha_context let bake_block (cctxt : #Proto_alpha.full) ?(chain = `Main) block ?fee_threshold - ?force ?max_priority ?(minimal_timestamp=false) + ?force ?max_priority ?(minimal_timestamp=false) ?mempool ?src_sk ?src_pk delegate = begin match src_sk with @@ -59,6 +59,7 @@ let bake_block (cctxt : #Proto_alpha.full) ?fee_threshold ?force ?seed_nonce_hash ~src_sk block + ?mempool ~priority:(`Auto (delegate, max_priority)) () >>=? fun block_hash -> let src_pkh = Signature.Public_key.hash src_pk in Client_baking_forge.State.record cctxt src_pkh level.level >>=? fun () -> diff --git a/src/proto_alpha/lib_delegate/client_baking_lib.mli b/src/proto_alpha/lib_delegate/client_baking_lib.mli index d338f27c2..ef37261d3 100644 --- a/src/proto_alpha/lib_delegate/client_baking_lib.mli +++ b/src/proto_alpha/lib_delegate/client_baking_lib.mli @@ -35,6 +35,7 @@ val bake_block: ?force:bool -> ?max_priority: int -> ?minimal_timestamp: bool -> + ?mempool: string -> ?src_sk:Client_keys.sk_uri -> ?src_pk:Signature.public_key -> public_key_hash -> diff --git a/src/proto_alpha/lib_delegate/delegate_commands.ml b/src/proto_alpha/lib_delegate/delegate_commands.ml index 257b941a8..c88dcaf03 100644 --- a/src/proto_alpha/lib_delegate/delegate_commands.ml +++ b/src/proto_alpha/lib_delegate/delegate_commands.ml @@ -37,18 +37,25 @@ let directory_parameter = else return p) +let mempool_arg = + Clic.arg + ~long:"mempool" + ~placeholder:"file" + ~doc:"When used the client will read the mempool in the provided file instead of querying the node through an RPC (useful for debugging only)." + string_parameter + let delegate_commands () = let open Clic in [ command ~group ~desc: "Forge and inject block using the delegate rights." - (args4 max_priority_arg fee_threshold_arg force_switch minimal_timestamp_switch) + (args5 max_priority_arg fee_threshold_arg force_switch minimal_timestamp_switch mempool_arg) (prefixes [ "bake"; "for" ] @@ Client_keys.Public_key_hash.source_param ~name:"baker" ~desc: "name of the delegate owning the baking right" @@ stop) - (fun (max_priority, fee_threshold, force, minimal_timestamp) delegate cctxt -> + (fun (max_priority, fee_threshold, force, minimal_timestamp, mempool) delegate cctxt -> bake_block cctxt cctxt#block - ?fee_threshold ~force ?max_priority ~minimal_timestamp delegate) ; + ?fee_threshold ~force ?max_priority ~minimal_timestamp ?mempool delegate) ; command ~group ~desc: "Forge and inject a seed-nonce revelation operation." no_options (prefixes [ "reveal"; "nonce"; "for" ]