Skip to content

Commit 7024558

Browse files
committed
Fixup Masking_merkle_tree.get_batch
1 parent fc28357 commit 7024558

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

src/lib/merkle_mask/masking_merkle_tree.ml

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,44 @@ module Make (Inputs : Inputs_intf.S) = struct
185185

186186
let get_batch t locations =
187187
assert_is_attached t ;
188-
let found_accounts, leftover_locations =
189-
List.partition_map locations ~f:(fun location ->
190-
match self_find_account t location with
191-
| Some account ->
192-
Either.first (location, Some account)
193-
| None ->
194-
Either.second location )
188+
let locations_with_locations_rev, leftover_locations_rev =
189+
let rec go locations locations_with_locations_rev leftover_locations_rev
190+
=
191+
match locations with
192+
| [] ->
193+
(locations_with_locations_rev, leftover_locations_rev)
194+
| location :: locations -> (
195+
match self_find_account t location with
196+
| None ->
197+
go locations
198+
((location, None) :: locations_with_locations_rev)
199+
(location :: leftover_locations_rev)
200+
| Some account ->
201+
go locations
202+
((location, Some account) :: locations_with_locations_rev)
203+
leftover_locations_rev )
204+
in
205+
go locations [] []
206+
in
207+
let leftover_location_accounts_rev =
208+
Base.get_batch (get_parent t) leftover_locations_rev
209+
in
210+
let rec go locations_with_locations_rev leftover_locations_rev accounts =
211+
match (locations_with_locations_rev, leftover_locations_rev) with
212+
| [], _ ->
213+
accounts
214+
| ( (location, None) :: locations_with_locations_rev
215+
, (_location, account) :: leftover_locations_rev ) ->
216+
go locations_with_locations_rev leftover_locations_rev
217+
((location, account) :: accounts)
218+
| ( (location, Some account) :: locations_with_locations_rev
219+
, leftover_locations_rev ) ->
220+
go locations_with_locations_rev leftover_locations_rev
221+
((location, Some account) :: accounts)
222+
| _ :: _, [] ->
223+
assert false
195224
in
196-
found_accounts @ Base.get_batch (get_parent t) leftover_locations
225+
go locations_with_locations_rev leftover_location_accounts_rev []
197226

198227
(* fixup_merkle_path patches a Merkle path reported by the parent,
199228
overriding with hashes which are stored in the mask *)

0 commit comments

Comments
 (0)