Skip to content

Commit 08c34e6

Browse files
authored
Merge pull request #17879 from MinaProtocol/georgeee/add-sw-internal-trace-logs
Add additional SW internal trace logging
2 parents 6fc2083 + 4dfb7e7 commit 08c34e6

File tree

8 files changed

+80
-16
lines changed

8 files changed

+80
-16
lines changed

src/lib/transaction_witness/transaction_witness.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ type t =
171171
; status : Mina_base.Transaction_status.t
172172
; block_global_slot : Mina_numbers.Global_slot_since_genesis.t
173173
}
174-
[@@deriving sexp_of, to_yojson]
174+
[@@deriving fields, sexp_of, to_yojson]
175175

176176
let read_all_proofs_from_disk
177177
{ transaction

src/lib/transaction_witness/transaction_witness.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type t =
108108
; status : Mina_base.Transaction_status.t
109109
; block_global_slot : Mina_numbers.Global_slot_since_genesis.t
110110
}
111-
[@@deriving sexp_of, to_yojson]
111+
[@@deriving fields, sexp_of, to_yojson]
112112

113113
val read_all_proofs_from_disk : t -> Stable.Latest.t
114114

src/lib/work_selector/inputs.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@ open Core_kernel
22
open Currency
33

44
module Test_inputs = struct
5-
module Transaction_witness = Int
5+
module Transaction_witness = struct
6+
type t = Int.t
7+
8+
let transaction = Fn.id
9+
end
10+
611
module Ledger_hash = Int
712
module Sparse_ledger = Int
8-
module Transaction = Int
13+
14+
module Transaction = struct
15+
type t = Int.t
16+
17+
let yojson_summary t = `Int t
18+
end
19+
920
module Ledger_proof_statement = Fee
1021

1122
module Transaction_protocol_state = struct

src/lib/work_selector/intf.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ module type Inputs_intf = sig
2020

2121
module Transaction : sig
2222
type t
23+
24+
val yojson_summary : t -> Yojson.Safe.t
2325
end
2426

2527
module Transaction_witness : sig
2628
type t
29+
30+
val transaction : t -> Transaction.t
2731
end
2832

2933
module Ledger_proof : sig
@@ -117,7 +121,8 @@ module type Lib_intf = sig
117121

118122
(** [mark_scheduled t work] Mark [work] as scheduled in [t] *)
119123
val mark_scheduled :
120-
t
124+
logger:Logger.t
125+
-> t
121126
-> ( Transaction_witness.t
122127
, Ledger_proof.Cached.t )
123128
Snark_work_lib.Work.Single.Spec.t

src/lib/work_selector/random.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
open Core_kernel
22

33
module Make (Lib : Intf.Lib_intf) = struct
4-
let work ~snark_pool ~fee ~logger:_ (state : Lib.State.t) =
4+
let work ~snark_pool ~fee ~logger (state : Lib.State.t) =
55
match Lib.State.all_unscheduled_expensive_works ~snark_pool ~fee state with
66
| [] ->
77
None
88
| expensive_work ->
99
let i = Random.int (List.length expensive_work) in
1010
let x = List.nth_exn expensive_work i in
11-
Lib.State.mark_scheduled state x ;
11+
Lib.State.mark_scheduled ~logger state x ;
1212
Some x
1313
end
1414

src/lib/work_selector/random_offset.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ module Make (Lib : Intf.Lib_intf) = struct
4242
List.nth_exn expensive_work !offset
4343
end
4444

45-
let work ~snark_pool ~fee ~logger:_ (state : Lib.State.t) =
45+
let work ~snark_pool ~fee ~logger (state : Lib.State.t) =
4646
match Lib.State.all_unscheduled_expensive_works ~snark_pool ~fee state with
4747
| [] ->
4848
None
4949
| expensive_work ->
5050
Offset.update ~new_length:(List.length expensive_work) ;
5151
let x = Offset.get_nth expensive_work in
52-
Lib.State.mark_scheduled state x ;
52+
Lib.State.mark_scheduled ~logger state x ;
5353
Some x
5454
end
5555

src/lib/work_selector/sequence.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module Make (Lib : Intf.Lib_intf) = struct
2-
let work ~snark_pool ~fee ~logger:_ (state : Lib.State.t) =
2+
let work ~snark_pool ~fee ~logger (state : Lib.State.t) =
33
match Lib.State.all_unscheduled_expensive_works ~snark_pool ~fee state with
44
| [] ->
55
None
66
| x :: _ ->
7-
Lib.State.mark_scheduled state x ;
7+
Lib.State.mark_scheduled ~logger state x ;
88
Some x
99
end
1010

src/lib/work_selector/work_lib.ml

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ module Make (Inputs : Intf.Inputs_intf) = struct
66
module Inputs = Inputs
77
module Work_spec = Snark_work_lib.Work.Single.Spec
88

9+
let yojson_summary t =
10+
let f = function
11+
| Work_spec.Merge _ ->
12+
`String "merge"
13+
| Transition (_, witness) ->
14+
Inputs.Transaction.yojson_summary
15+
(Inputs.Transaction_witness.transaction witness)
16+
in
17+
`List (One_or_two.map ~f t |> One_or_two.to_list)
18+
919
module State = struct
1020
module Job_key = struct
1121
module T = struct
@@ -71,11 +81,44 @@ module Make (Inputs : Intf.Inputs_intf) = struct
7181
( Time.diff end_time start_time
7282
|> Time.Span.to_ms ) )
7383
] ;
84+
let old_available_jobs = t.available_jobs in
85+
let old_job_keys =
86+
List.map ~f:Job_key.of_job old_available_jobs
87+
|> Job_key.Set.of_list
88+
in
7489
t.available_jobs <- new_available_jobs ;
7590
let new_job_keys =
76-
List.map ~f:Job_key.of_job t.available_jobs
91+
List.map ~f:Job_key.of_job new_available_jobs
7792
|> Job_key.Set.of_list
7893
in
94+
let removed_job_keys =
95+
Job_key.Set.diff old_job_keys new_job_keys
96+
in
97+
let added_job_keys =
98+
Job_key.Set.diff new_job_keys old_job_keys
99+
in
100+
List.iter old_available_jobs ~f:(fun job ->
101+
if
102+
Job_key.Set.mem removed_job_keys
103+
(Job_key.of_job job)
104+
then
105+
[%log internal] "Snark_work_removed"
106+
~metadata:
107+
[ ( "work_ids"
108+
, Transaction_snark_work.Statement
109+
.compact_json @@ Job_key.of_job job )
110+
; ("txs", yojson_summary job)
111+
] ) ;
112+
List.iter new_available_jobs ~f:(fun job ->
113+
if Job_key.Set.mem added_job_keys (Job_key.of_job job)
114+
then
115+
[%log internal] "Snark_work_added"
116+
~metadata:
117+
[ ( "work_ids"
118+
, Transaction_snark_work.Statement
119+
.compact_json @@ Job_key.of_job job )
120+
; ("txs", yojson_summary job)
121+
] ) ;
79122
t.jobs_scheduled <-
80123
Job_key.Set.inter t.jobs_scheduled new_job_keys ) ;
81124
Deferred.unit )
@@ -84,10 +127,15 @@ module Make (Inputs : Intf.Inputs_intf) = struct
84127
|> Deferred.don't_wait_for ;
85128
t
86129

87-
let mark_scheduled t x =
88-
t.jobs_scheduled <-
89-
Job_key.Set.add t.jobs_scheduled
90-
(One_or_two.map ~f:Work_spec.statement x)
130+
let mark_scheduled ~logger t job =
131+
let statement = One_or_two.map ~f:Work_spec.statement job in
132+
(* Log to internal trace all of the newly available jobs. *)
133+
[%log internal] "Snark_work_scheduled"
134+
~metadata:
135+
[ ("work_ids", Transaction_snark_work.Statement.compact_json statement)
136+
; ("txs", yojson_summary job)
137+
] ;
138+
t.jobs_scheduled <- Job_key.Set.add t.jobs_scheduled statement
91139

92140
let does_not_have_better_fee ~snark_pool ~fee
93141
(statements : Inputs.Transaction_snark_work.Statement.t) : bool =

0 commit comments

Comments
 (0)