Alpha/Client: add --mempool to command bake for <delegate>.

This commit is contained in:
Grégoire Henry 2018-08-08 16:34:32 +02:00
parent bb82702fd6
commit 2f6896a6f3
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2
6 changed files with 31 additions and 10 deletions

View File

@ -400,6 +400,8 @@ module Make(Proto : PROTO)(Next_proto : PROTO) : sig
module Mempool : sig module Mempool : sig
val encoding: Mempool.t Data_encoding.t
val pending_operations: val pending_operations:
('a, 'b) RPC_path.t -> ('a, 'b) RPC_path.t ->
([ `GET ], 'a, ([ `GET ], 'a,

View File

@ -291,11 +291,19 @@ let ops_of_mempool (ops : Alpha_block_services.Mempool.t) =
List.rev_map (fun (_, op) -> op) ops.applied List.rev_map (fun (_, op) -> op) ops.applied
) )
let unopt_operations cctxt chain = function let unopt_operations cctxt chain mempool = function
| None -> | None -> begin
Alpha_block_services.Mempool.pending_operations cctxt ~chain () >>=? fun mpool -> match mempool with
let ops = ops_of_mempool mpool in | None ->
return ops 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 -> | Some operations ->
return operations return operations
@ -379,11 +387,12 @@ let forge_block cctxt ?(chain = `Main) block
?(sort = best_effort) ?(sort = best_effort)
?(fee_threshold = Tez.zero) ?(fee_threshold = Tez.zero)
?timestamp ?timestamp
?mempool
~priority ~priority
?seed_nonce_hash ~src_sk () = ?seed_nonce_hash ~src_sk () =
(* making the arguments usable *) (* 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) -> decode_priority cctxt chain block priority >>=? fun (priority, minimal_timestamp) ->
unopt_timestamp timestamp minimal_timestamp >>=? fun timestamp -> unopt_timestamp timestamp minimal_timestamp >>=? fun timestamp ->

View File

@ -61,6 +61,7 @@ val forge_block:
?sort:bool -> ?sort:bool ->
?fee_threshold:Tez.t -> ?fee_threshold:Tez.t ->
?timestamp:Time.t -> ?timestamp:Time.t ->
?mempool:string ->
priority:[`Set of int | `Auto of (public_key_hash * int option)] -> priority:[`Set of int | `Auto of (public_key_hash * int option)] ->
?seed_nonce_hash:Nonce_hash.t -> ?seed_nonce_hash:Nonce_hash.t ->
src_sk:Client_keys.sk_uri -> src_sk:Client_keys.sk_uri ->

View File

@ -29,7 +29,7 @@ open Alpha_context
let bake_block (cctxt : #Proto_alpha.full) let bake_block (cctxt : #Proto_alpha.full)
?(chain = `Main) block ?(chain = `Main) block
?fee_threshold ?fee_threshold
?force ?max_priority ?(minimal_timestamp=false) ?force ?max_priority ?(minimal_timestamp=false) ?mempool
?src_sk ?src_pk delegate = ?src_sk ?src_pk delegate =
begin begin
match src_sk with match src_sk with
@ -59,6 +59,7 @@ let bake_block (cctxt : #Proto_alpha.full)
?fee_threshold ?fee_threshold
?force ?force
?seed_nonce_hash ~src_sk block ?seed_nonce_hash ~src_sk block
?mempool
~priority:(`Auto (delegate, max_priority)) () >>=? fun block_hash -> ~priority:(`Auto (delegate, max_priority)) () >>=? fun block_hash ->
let src_pkh = Signature.Public_key.hash src_pk in let src_pkh = Signature.Public_key.hash src_pk in
Client_baking_forge.State.record cctxt src_pkh level.level >>=? fun () -> Client_baking_forge.State.record cctxt src_pkh level.level >>=? fun () ->

View File

@ -35,6 +35,7 @@ val bake_block:
?force:bool -> ?force:bool ->
?max_priority: int -> ?max_priority: int ->
?minimal_timestamp: bool -> ?minimal_timestamp: bool ->
?mempool: string ->
?src_sk:Client_keys.sk_uri -> ?src_sk:Client_keys.sk_uri ->
?src_pk:Signature.public_key -> ?src_pk:Signature.public_key ->
public_key_hash -> public_key_hash ->

View File

@ -37,18 +37,25 @@ let directory_parameter =
else else
return p) 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 delegate_commands () =
let open Clic in let open Clic in
[ [
command ~group ~desc: "Forge and inject block using the delegate rights." 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" ] (prefixes [ "bake"; "for" ]
@@ Client_keys.Public_key_hash.source_param @@ Client_keys.Public_key_hash.source_param
~name:"baker" ~desc: "name of the delegate owning the baking right" ~name:"baker" ~desc: "name of the delegate owning the baking right"
@@ stop) @@ 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 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." command ~group ~desc: "Forge and inject a seed-nonce revelation operation."
no_options no_options
(prefixes [ "reveal"; "nonce"; "for" ] (prefixes [ "reveal"; "nonce"; "for" ]