Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization: More memory-efficient scan state and staged ledger hashing #14524

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions src/lib/parallel_scan/parallel_scan.ml
Original file line number Diff line number Diff line change
Expand Up @@ -941,39 +941,46 @@ module State = struct
match job with Job.Merge a -> f_merge a | Base d -> f_base d )
in
Mina_stdlib.Nonempty_list.iter trees ~f:(fun tree ->
let w_to_string { Weight.base = b; merge = m } =
Int.to_string b ^ Int.to_string m
let add_weight_to_hash { Weight.base = b; merge = m } =
add_string @@ Int.to_string b ;
add_string @@ Int.to_string m
in
let add_weight_pair_to_hash (w1, w2) =
add_weight_to_hash w1 ; add_weight_to_hash w2
in
let w_to_string' (w1, w2) = w_to_string w1 ^ w_to_string w2 in
let f_merge = function
| w, Merge.Job.Empty ->
add_string (w_to_string' w ^ "Empty")
add_weight_pair_to_hash w ; add_string "Empty"
| w, Merge.Job.Full { left; right; status; seq_no } ->
add_string
( w_to_string' w ^ "Full" ^ Int.to_string seq_no
^ Job_status.to_string status ) ;
add_weight_pair_to_hash w ;
add_string "Full" ;
add_string @@ Int.to_string seq_no ;
add_string @@ Job_status.to_string status ;
add_string (f_merge left) ;
add_string (f_merge right)
| w, Merge.Job.Part j ->
add_string (w_to_string' w ^ "Part") ;
add_weight_pair_to_hash w ;
add_string "Part" ;
add_string (f_merge j)
in
let f_base = function
| w, Base.Job.Empty ->
add_string (w_to_string w ^ "Empty")
add_weight_to_hash w ; add_string "Empty"
| w, Base.Job.Full { job; status; seq_no } ->
add_string
( w_to_string w ^ "Full" ^ Int.to_string seq_no
^ Job_status.to_string status ) ;
add_weight_to_hash w ;
add_string "Full" ;
add_string @@ Int.to_string seq_no ;
add_string @@ Job_status.to_string status ;
add_string (f_base job)
in
tree_hash tree f_merge f_base )
in
let acc_string =
Option.value_map acc ~default:"None" ~f:(fun (a, d_lst) ->
f_merge a ^ List.fold ~init:"" d_lst ~f:(fun acc d -> acc ^ f_base d) )
in
add_string acc_string ;
( match acc with
| Some (a, d_lst) ->
add_string (f_merge a) ;
List.iter d_lst ~f:(fun d -> add_string (f_base d))
| None ->
add_string "None" ) ;
add_string (Int.to_string curr_job_seq_no) ;
add_string (Int.to_string max_base_jobs) ;
add_string (Int.to_string delay) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,19 @@ module Stable = struct
t.previous_incomplete_zkapp_updates
in
let incomplete_updates =
List.fold ~init:"" previous_incomplete_zkapp_updates ~f:(fun acc t ->
acc
^ Binable.to_string (module Transaction_with_witness.Stable.V2) t )
|> Digestif.SHA256.digest_string
List.fold ~init:(Digestif.SHA256.init ())
previous_incomplete_zkapp_updates ~f:(fun h t ->
Digestif.SHA256.feed_string h
@@ Binable.to_string (module Transaction_with_witness.Stable.V2) t )
|> Digestif.SHA256.get
in
let continue_in_next_tree =
Digestif.SHA256.digest_string (Bool.to_string continue_in_next_tree)
in
Staged_ledger_hash.Aux_hash.of_sha256
Digestif.SHA256.(
digest_string
( to_raw_string state_hash
^ to_raw_string incomplete_updates
^ to_raw_string continue_in_next_tree ))
[ state_hash; incomplete_updates; continue_in_next_tree ]
|> List.fold ~init:(Digestif.SHA256.init ()) ~f:(fun h t ->
Digestif.SHA256.feed_string h (Digestif.SHA256.to_raw_string t) )
|> Digestif.SHA256.get |> Staged_ledger_hash.Aux_hash.of_sha256
end
end]

Expand Down