-
Notifications
You must be signed in to change notification settings - Fork 583
Make converting ledger sync check more defensive #17819
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
base: compatible
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix crash in ledger sync check that could occur when trying to load ledger | ||
databases that were only partially synced to a network ledger |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -879,10 +879,15 @@ module Make (Inputs : Inputs_intf.S) = struct | |
let addr = Location.to_path_exn location in | ||
Addr.to_int addr | ||
|
||
let get_at_index_exn t index = | ||
let get_at_index t index = | ||
assert_is_attached t ; | ||
let addr = Addr.of_int_exn ~ledger_depth:t.depth index in | ||
get t (Location.Account addr) |> Option.value_exn | ||
get t (Location.Account addr) | ||
|
||
let get_at_index_exn t index = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: add |
||
assert_is_attached t ; | ||
get_at_index t index | ||
|> Option.value_exn ~message:"Expected account at index" ~here:[%here] | ||
|
||
let set_at_index_exn t index account = | ||
assert_is_attached t ; | ||
|
@@ -906,11 +911,17 @@ module Make (Inputs : Inputs_intf.S) = struct | |
let%map.Async.Deferred accts = to_list t in | ||
List.map accts ~f:Account.identifier |> Account_id.Set.of_list | ||
|
||
let iteri t ~f = | ||
let iteri_untrusted t ~f = | ||
assert_is_attached t ; | ||
let num_accounts = num_accounts t in | ||
Sequence.range ~stop:`exclusive 0 num_accounts | ||
|> Sequence.iter ~f:(fun i -> f i (get_at_index_exn t i)) | ||
|> Sequence.iter ~f:(fun i -> f i (get_at_index t i)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do a simple for loop here? It seems more readable than this. I'll have to check the API of sequence to understand if this is written correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let range ?(stride = 1) ?(start = `inclusive) ?(stop = `exclusive) start_v stop_v =
let step =
match stop with
| `inclusive when stride >= 0 ->
fun i -> if i > stop_v then Done else Yield { value = i; state = i + stride }
| `inclusive ->
fun i -> if i < stop_v then Done else Yield { value = i; state = i + stride }
| `exclusive when stride >= 0 ->
fun i -> if i >= stop_v then Done else Yield { value = i; state = i + stride }
| `exclusive ->
fun i -> if i <= stop_v then Done else Yield { value = i; state = i + stride }
in
let init =
match start with
| `inclusive -> start_v
| `exclusive -> start_v + stride
in
unfold_step ~init ~f:step
;; it seems stop being exclusive is the default. Thought I'm looking at Base v0.17.2 |
||
|
||
let iteri t ~f = | ||
iteri_untrusted t ~f:(fun index account_opt -> | ||
f index | ||
(Option.value_exn ~message:"Expected account at index" ~here:[%here] | ||
account_opt ) ) | ||
|
||
let foldi_with_ignored_accounts t ignored_accounts ~init ~f = | ||
assert_is_attached t ; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: use
Option.iter
here