Skip to content

Commit 4d49ac7

Browse files
authored
Merge pull request #17809 from MinaProtocol/lyh/bootstrap-controller-move-time-span-to-mina-stdlib
move time span related fns from bootstrap controller -> stdlib
2 parents 527c3f5 + 64a93e0 commit 4d49ac7

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

src/lib/bootstrap_controller/bootstrap_controller.ml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
open Core
33
open Async
44
open Mina_base
5-
module Ledger = Mina_ledger.Ledger
6-
module Sync_ledger = Mina_ledger.Sync_ledger
75
open Mina_state
86
open Pipe_lib.Strict_pipe
97
open Network_peer
8+
open Mina_stdlib
9+
module Ledger = Mina_ledger.Ledger
10+
module Sync_ledger = Mina_ledger.Sync_ledger
1011
module Transition_cache = Transition_cache
1112

1213
module type CONTEXT = sig
@@ -36,27 +37,14 @@ type t =
3637
; mutable num_of_root_snarked_ledger_retargeted : int
3738
}
3839

39-
type time = Time.Span.t
40-
41-
let time_to_yojson span =
42-
`String (Printf.sprintf "%f seconds" (Time.Span.to_sec span))
43-
44-
type opt_time = time option
45-
46-
let opt_time_to_yojson = function
47-
| Some time ->
48-
time_to_yojson time
49-
| None ->
50-
`Null
51-
5240
(** An auxiliary data structure for collecting various metrics for bootstrap controller. *)
5341
type bootstrap_cycle_stats =
5442
{ cycle_result : string
55-
; sync_ledger_time : time
56-
; staged_ledger_data_download_time : time
57-
; staged_ledger_construction_time : opt_time
43+
; sync_ledger_time : Time.Span.t
44+
; staged_ledger_data_download_time : Time.Span.t
45+
; staged_ledger_construction_time : Time.Span.t option
5846
; local_state_sync_required : bool
59-
; local_state_sync_time : opt_time
47+
; local_state_sync_time : Time.Span.t option
6048
}
6149
[@@deriving to_yojson]
6250

@@ -695,7 +683,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
695683
in
696684
[%log info] "Bootstrap completed in $time_elapsed: $bootstrap_stats"
697685
~metadata:
698-
[ ("time_elapsed", time_to_yojson time_elapsed)
686+
[ ("time_elapsed", Time.Span.to_yojson_hum time_elapsed)
699687
; ( "bootstrap_stats"
700688
, `List (List.map ~f:bootstrap_cycle_stats_to_yojson cycles) )
701689
] ;

src/lib/bootstrap_controller/bootstrap_controller.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Structured_log_events.t += Bootstrap_complete [@@deriving register_event]
2323
it would return a transition frontier with the root breadcrumb and a list
2424
of transitions collected during bootstrap.
2525
26-
Bootstrap controller would do the following steps to contrust the
26+
Bootstrap controller would do the following steps to construct the
2727
transition frontier:
2828
1. Download the root snarked_ledger.
2929
2. Download the scan state and pending coinbases.

src/lib/mina_stdlib/time.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Core_kernel
2+
include Core_kernel.Time
23

34
module Span = struct
45
[%%versioned
@@ -10,6 +11,9 @@ module Span = struct
1011
*)
1112
type t = Core_kernel.Time.Stable.Span.V3.t [@@deriving sexp]
1213

14+
let to_yojson_hum span =
15+
`String (Printf.sprintf "%f seconds" (Time.Span.to_sec span))
16+
1317
let to_yojson span = `Float (Time.Span.to_sec span)
1418

1519
let of_yojson = function
@@ -22,7 +26,7 @@ module Span = struct
2226
end
2327
end]
2428

25-
[%%define_locally Stable.Latest.(to_yojson, of_yojson)]
29+
[%%define_locally Stable.Latest.(to_yojson_hum, to_yojson, of_yojson)]
2630

2731
include Core_kernel.Time.Span
2832
end

0 commit comments

Comments
 (0)