Skip to content

Commit 4dfb7e7

Browse files
committed
Fix Snark_work_requested, add tx constitution info
1 parent f420481 commit 4dfb7e7

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
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: 4 additions & 0 deletions
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

src/lib/work_selector/work_lib.ml

Lines changed: 45 additions & 9 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,19 +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
79-
(* Log to internal trace all of the newly available jobs. *)
80-
Job_key.Set.iter new_job_keys ~f:(fun job_key ->
81-
[%log internal] "Snark_work_requested"
82-
~metadata:
83-
[ ( "work_ids"
84-
, Transaction_snark_work.Statement.compact_json
85-
job_key )
86-
] ) ;
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+
] ) ;
87122
t.jobs_scheduled <-
88123
Job_key.Set.inter t.jobs_scheduled new_job_keys ) ;
89124
Deferred.unit )
@@ -98,6 +133,7 @@ module Make (Inputs : Intf.Inputs_intf) = struct
98133
[%log internal] "Snark_work_scheduled"
99134
~metadata:
100135
[ ("work_ids", Transaction_snark_work.Statement.compact_json statement)
136+
; ("txs", yojson_summary job)
101137
] ;
102138
t.jobs_scheduled <- Job_key.Set.add t.jobs_scheduled statement
103139

0 commit comments

Comments
 (0)