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

Follow up on comments from #16093 #16384

Open
wants to merge 6 commits into
base: compatible
Choose a base branch
from
Open
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
35 changes: 20 additions & 15 deletions src/lib/genesis_ledger_helper/genesis_ledger_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -679,19 +679,23 @@ module Genesis_proof = struct
~genesis_epoch_data ~constraint_constants ~consensus_constants
~genesis_body_reference
in
{ Genesis_proof.Inputs.runtime_config
; constraint_constants
; proof_level
; compile_config
; blockchain_proof_system_id
; genesis_ledger = ledger
; genesis_epoch_data
; consensus_constants
; protocol_state_with_hashes
; constraint_system_digests = None
; genesis_constants
; genesis_body_reference
}
let inputs =
{ Genesis_proof.Inputs.runtime_config
; constraint_constants
; proof_level
; compile_config
; blockchain_proof_system_id
; genesis_ledger = ledger
; genesis_epoch_data
; consensus_constants
; protocol_state_with_hashes
; constraint_system_digests = None
; genesis_constants
; genesis_body_reference
}
in
let%map.Or_error () = Genesis_proof.valid_inputs inputs in
inputs

let generate (inputs : Genesis_proof.Inputs.t) =
match inputs.proof_level with
Expand Down Expand Up @@ -808,7 +812,7 @@ module Config_loader : Config_loader_intf = struct
in
[%log info] "Loaded genesis ledger from $ledger_file"
~metadata:[ ("ledger_file", `String ledger_file) ] ;
let%map genesis_epoch_data, genesis_epoch_data_config =
let%bind genesis_epoch_data, genesis_epoch_data_config =
Epoch_data.load ~proof_level ~genesis_dir ~logger ~constraint_constants
config.epoch_data
in
Expand All @@ -821,10 +825,11 @@ module Config_loader : Config_loader_intf = struct
let c2 = Runtime_config.of_constants constants in
(* This should give us the entire configuration object, including the implied constants *)
let runtime_config = Runtime_config.combine c1 c2 in
let proof_inputs =
let%map proof_inputs =
Genesis_proof.generate_inputs ~runtime_config ~proof_level
~ledger:genesis_ledger ~constraint_constants ~genesis_constants
~compile_config ~blockchain_proof_system_id:None ~genesis_epoch_data
|> Deferred.return
in
(proof_inputs, runtime_config)

Expand Down
14 changes: 14 additions & 0 deletions src/lib/genesis_proof/genesis_proof.ml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ let create_values_no_proof (t : Inputs.t) =
; proof_data = None
}

let valid_inputs (t : Inputs.t) =
let validate_depth ~label =
Option.value_map ~default:(Ok ()) ~f:(fun v ->
if v > 0 then Ok ()
else Or_error.errorf "Invalid value configured for %s" label )
in
Option.value_map ~default:(Ok ()) t.runtime_config.daemon ~f:(fun v ->
Or_error.combine_errors_unit
[ validate_depth ~label:"sync_ledger_default_subtree_depth"
v.sync_ledger_default_subtree_depth
; validate_depth ~label:"sync_ledger_max_subtree_depth"
v.sync_ledger_max_subtree_depth
] )

let to_inputs (t : t) : Inputs.t =
{ runtime_config = t.runtime_config
; constraint_constants = t.constraint_constants
Expand Down
4 changes: 4 additions & 0 deletions src/lib/node_config/node_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ include Node_config_version
[%%inject
"sync_ledger_default_subtree_depth", sync_ledger_default_subtree_depth]

let () =
assert (sync_ledger_default_subtree_depth > 0) ;
assert (sync_ledger_max_subtree_depth > 0)

[%%ifndef scan_state_transaction_capacity_log_2]

let scan_state_transaction_capacity_log_2 : int option = None
Expand Down
10 changes: 6 additions & 4 deletions src/lib/syncable_ledger/syncable_ledger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ end = struct

type query = Addr.t Query.t

(* Provides addresses at an specific depth from this address *)
(* Provides addresses at a specific depth from this address *)
let intermediate_range ledger_depth addr i =
Array.init (1 lsl i) ~f:(fun idx ->
Addr.extend_exn ~ledger_depth addr ~num_bits:i (Int64.of_int idx) )
Expand Down Expand Up @@ -555,10 +555,12 @@ end = struct
let open (val t.context) in
let len = Array.length nodes in
let is_power = Int.is_pow2 len in
let is_more_than_two = len >= 2 in
let is_equal_or_more_than_two = len >= 2 in
let subtree_depth = Int.ceil_log2 len in
let less_than_requested = subtree_depth <= requested_depth in
let valid_length = is_power && is_more_than_two && less_than_requested in
let equal_or_less_than_requested = subtree_depth <= requested_depth in
let valid_length =
is_power && is_equal_or_more_than_two && equal_or_less_than_requested
in
if valid_length then
let ledger_depth = MT.depth t.tree in
let expected =
Expand Down
23 changes: 13 additions & 10 deletions src/lib/syncable_ledger/test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,21 @@ module Make_test_edge_cases (Input : Input_intf) = struct
let%bind answ_or_error =
Sync_responder.answer_query sr (Envelope.Incoming.local query)
in
match check_answer query answ_or_error with
| `Answer answ ->
let write_response answ =
Linear_pipe.write aw
(root_hash, query, Envelope.Incoming.local answ)
in
match (check_answer query answ_or_error, query) with
| `Answer answ, What_contents _ ->
let%bind () =
if match query with What_contents _ -> true | _ -> false then
Clock_ns.after
(Time_ns.Span.randomize (Time_ns.Span.of_ms 0.2)
~percent:(Percent.of_percentage 20.) )
else Deferred.unit
Clock_ns.after
(Time_ns.Span.randomize (Time_ns.Span.of_ms 0.2)
~percent:(Percent.of_percentage 20.) )
in
Linear_pipe.write aw
(root_hash, query, Envelope.Incoming.local answ)
| `Failure_as_expected ->
write_response answ
| `Answer answ, _ ->
write_response answ
| `Failure_as_expected, _ ->
Ivar.fill got_failure_ivar true ;
Deferred.unit ) ) ;
Async.Thread_safe.block_on_async_exn (fun () ->
Expand Down