Client/genesis: option to set the timestamp of the activation block.

This commit is contained in:
Benjamin Canou 2017-03-06 15:54:05 +01:00 committed by Grégoire Henry
parent ccfdaa6bd0
commit 3b483811f5
2 changed files with 16 additions and 6 deletions

View File

@ -25,9 +25,9 @@ let forge_block
Services.Forge.block block
((net_id, pred, timestamp, fitness), command)
let mine cctxt block command fitness seckey =
let mine cctxt ?timestamp block command fitness seckey =
Client_blocks.get_block_info cctxt block >>= fun bi ->
forge_block cctxt block bi.net command fitness >>= fun blk ->
forge_block cctxt ?timestamp block bi.net command fitness >>= fun blk ->
let signed_blk = Environment.Ed25519.Signature.append seckey blk in
Client_node_rpcs.inject_block cctxt ~wait:true signed_blk >>=? fun hash ->
cctxt.answer "Injected %a" Block_hash.pp_short hash >>= fun () ->
@ -41,9 +41,14 @@ let handle_error cctxt = function
cctxt.Client_commands.error "%s" "cannot continue"
let commands () =
let timestamp = ref None in
let args =
[ "-timestamp",
Arg.String (fun t -> timestamp := Some (Time.of_notation_exn t)),
"Set the timestamp of the block (and initial time of the chain)" ] in
let open Cli_entries in
[
command ~desc: "Activate a protocol" begin
command ~args ~desc: "Activate a protocol" begin
prefixes [ "activate" ; "protocol" ] @@
param ~name:"version" ~desc:"Protocol version (b58check)"
(fun _ p -> Lwt.return @@ Protocol_hash.of_b58check p) @@
@ -57,12 +62,14 @@ let commands () =
stop
end
(fun hash fitness seckey cctxt ->
let timestamp = !timestamp in
let block = Client_config.block () in
let fitness =
Client_embedded_proto_alpha.Fitness_repr.from_int64 fitness in
mine cctxt block (Activate hash) fitness seckey >>= handle_error cctxt)
mine cctxt ?timestamp block (Activate hash) fitness seckey >>=
handle_error cctxt)
;
command ~desc: "Fork a test protocol" begin
command ~args ~desc: "Fork a test protocol" begin
prefixes [ "fork" ; "test" ; "protocol" ] @@
param ~name:"version" ~desc:"Protocol version (b58check)"
(fun _ p -> Lwt.return (Protocol_hash.of_b58check p)) @@
@ -77,10 +84,12 @@ let commands () =
stop
end
(fun hash fitness seckey cctxt ->
let timestamp = !timestamp in
let block = Client_config.block () in
let fitness =
Client_embedded_proto_alpha.Fitness_repr.from_int64 fitness in
mine cctxt block (Activate_testnet hash) fitness seckey >>= handle_error cctxt) ;
mine cctxt ?timestamp block (Activate_testnet hash) fitness seckey >>=
handle_error cctxt) ;
]
let () =

View File

@ -9,6 +9,7 @@
val mine:
Client_commands.context ->
?timestamp: Time.t ->
Client_node_rpcs.Blocks.block ->
Data.Command.t ->
Fitness.fitness ->