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

Use sparse ledger for staged ledger diff application #14547

Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add allocate_index helper function
mrmr1993 committed Nov 6, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 88a05a49fd9c68d0b076b02aa9b81405ed1c2437
1 change: 1 addition & 0 deletions src/lib/mina_base/sparse_ledger_base.ml
Original file line number Diff line number Diff line change
@@ -152,6 +152,7 @@ M.
, get_exn
, path_exn
, set_exn
, allocate_index
, find_index
, find_index_exn
, add_path
2 changes: 2 additions & 0 deletions src/lib/mina_base/sparse_ledger_base.mli
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@ val set_exn : t -> int -> Account.t -> t
val path_exn :
t -> int -> [ `Left of Ledger_hash.t | `Right of Ledger_hash.t ] list

val allocate_index : t -> Account_id.t -> int * t

val find_index : t -> Account_id.t -> int option

val find_index_exn : t -> Account_id.t -> int
12 changes: 12 additions & 0 deletions src/lib/sparse_ledger_lib/sparse_ledger.ml
Original file line number Diff line number Diff line change
@@ -65,6 +65,8 @@ module type S = sig

val of_hash : depth:int -> current_location:int option -> hash -> t

val allocate_index : t -> account_id -> int * t

val get_exn : t -> int -> account

val path_exn : t -> int -> [ `Left of hash | `Right of hash ] list
@@ -209,6 +211,16 @@ end = struct
(List.map t.indexes ~f:fst)
()

let allocate_index ({ T.current_location; indexes; _ } as t) account_id =
let new_location =
match current_location with None -> 0 | Some x -> x + 1
in
( new_location
, { t with
current_location = Some new_location
; indexes = (account_id, new_location) :: indexes
} )

let get_exn ({ T.tree; depth; _ } as t) idx =
let rec go i tree =
match (i < 0, tree) with