Skip to content

Commit

Permalink
fix the order in the location list
Browse files Browse the repository at this point in the history
  • Loading branch information
deepthiskumar authored and georgeee committed Dec 1, 2023
1 parent 717ff96 commit 9c89cca
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/lib/mina_ledger/sparse_ledger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ module GS = Global_state
let of_ledger_root ledger =
of_root ~depth:(Ledger.depth ledger) (Ledger.merkle_root ledger)

(*** [iterate_n ~f init n] returns [[f init, f (f init), ..]] of size [n] *)
let iterate_n ~f =
let rec impl prev = function
| 0 ->
[]
| n ->
let r = f prev in
r :: impl r (n - 1)
in
impl

let of_ledger_subset_exn (oledger : Ledger.t) keys =
let locations = Ledger.location_of_account_batch oledger keys in
let non_empty_locations = List.filter_map locations ~f:snd in
Expand All @@ -27,11 +38,8 @@ let of_ledger_subset_exn (oledger : Ledger.t) keys =
~default:(Ledger.Location.Account empty_address)
(Ledger.last_filled oledger)
in
let loc = ref first_loc in
first_loc
:: List.init (num_new_accounts - 1) ~f:(fun _ ->
loc := next_location_exn !loc ;
!loc )
:: iterate_n ~f:next_location_exn first_loc (num_new_accounts - 1)
in
let merkle_paths =
Ledger.merkle_path_batch oledger (empty_locations @ non_empty_locations)
Expand Down

0 comments on commit 9c89cca

Please sign in to comment.