Skip to content

Commit 38f381c

Browse files
committed
Add an option to control stop time randomness
The --stop-time-interval option sets the upper bound on the number of random hours added to the --stop-time of the daemon. It is optional, with default 9 to match the current daemon behaviour. Setting the option to 0 will disable the randomness entirely. This is useful for ensuring that daemons will stop at deterministic intervals.
1 parent 9845659 commit 38f381c

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,14 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee =
547547
were no slots won within an hour after the stop time) (Default: \
548548
%d)"
549549
Cli_lib.Default.stop_time )
550+
and stop_time_interval =
551+
flag "--stop-time-interval" ~aliases:[ "stop-time-interval" ] (optional int)
552+
~doc:
553+
(sprintf
554+
"UPTIME An upper bound (inclusive) on the random number of hours \
555+
added to the stop-time. Setting it to zero disables this \
556+
randomness. (Default: %d)"
557+
Cli_lib.Default.stop_time_interval )
550558
and upload_blocks_to_gcloud =
551559
flag "--upload-blocks-to-gcloud"
552560
~aliases:[ "upload-blocks-to-gcloud" ]
@@ -1289,6 +1297,10 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee =
12891297
or_from_config YJ.Util.to_int_option "stop-time"
12901298
~default:Cli_lib.Default.stop_time stop_time
12911299
in
1300+
let stop_time_interval =
1301+
or_from_config YJ.Util.to_int_option "stop-time-interval"
1302+
~default:Cli_lib.Default.stop_time_interval stop_time_interval
1303+
in
12921304
if enable_tracing then Mina_tracing.start conf_dir |> don't_wait_for ;
12931305
let%bind () =
12941306
if enable_internal_tracing then
@@ -1469,8 +1481,8 @@ Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ;
14691481
~log_precomputed_blocks ~start_filtered_logs
14701482
~upload_blocks_to_gcloud ~block_reward_threshold ~uptime_url
14711483
~uptime_submitter_keypair ~uptime_send_node_commit ~stop_time
1472-
~node_status_url ~graphql_control_port:itn_graphql_port
1473-
~simplified_node_stats
1484+
~stop_time_interval ~node_status_url
1485+
~graphql_control_port:itn_graphql_port ~simplified_node_stats
14741486
~zkapp_cmd_limit:(ref compile_config.zkapp_cmd_limit)
14751487
~itn_features ~compile_config ~hardfork_mode () )
14761488
in

src/lib/cli_lib/default.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ let conf_dir_name = ".mina-config"
1111

1212
let stop_time = 168
1313

14+
let stop_time_interval = 9
15+
1416
let receiver_key_warning =
1517
"Warning: If the key is from a zkApp account, the account's receive \
1618
permission must be None."

src/lib/mina_lib/config.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type t =
6262
; uptime_submitter_keypair : Keypair.t option [@default None]
6363
; uptime_send_node_commit : bool [@default false]
6464
; stop_time : int
65+
; stop_time_interval : int
6566
; file_log_level : Logger.Level.t [@default Logger.Level.Info]
6667
; log_level : Logger.Level.t [@default Logger.Level.Info]
6768
; log_json : bool [@default false]

src/lib/mina_lib/mina_lib.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,12 @@ let check_and_stop_daemon t ~wait =
12291229
`Check_in (Core.Time.Span.scale vrf_poll_interval 2.0) )
12301230

12311231
let stop_long_running_daemon t =
1232-
let wait_mins = (t.config.stop_time * 60) + (Random.int 10 * 60) in
1232+
(* The Random.int upper bound is exclusive *)
1233+
let additional_wait_hours =
1234+
if t.config.stop_time_interval < 1 then 0
1235+
else Random.int (t.config.stop_time_interval + 1)
1236+
in
1237+
let wait_mins = (t.config.stop_time + additional_wait_hours) * 60 in
12331238
[%log' info t.config.logger]
12341239
"Stopping daemon after $wait mins and when there are no blocks to be \
12351240
produced"

0 commit comments

Comments
 (0)