Skip to content

Commit

Permalink
Remove duplicated proof loading from verifier process
Browse files Browse the repository at this point in the history
  • Loading branch information
dkijania committed Oct 10, 2024
1 parent 6df5977 commit 081b26d
Show file tree
Hide file tree
Showing 27 changed files with 162 additions and 102 deletions.
2 changes: 2 additions & 0 deletions opam.export
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ roots: [
"js_of_ocaml-toplevel.4.0.0"
"lmdb.1.0"
"menhir.20210419"
"memtrace_viewer.0.16.0"
"merlin.4.5-414"
"ocaml-base-compiler.4.14.0"
"ocamlformat.0.20.1"
Expand Down Expand Up @@ -153,6 +154,7 @@ installed: [
"merlin.4.5-414"
"merlin-extend.0.6.1"
"mew.0.1.0"
"memtrace.0.2.3"
"mew_vi.0.5.0"
"minicli.5.0.2"
"mirage-crypto-ec.0.11.0"
Expand Down
6 changes: 4 additions & 2 deletions src/app/archive/lib/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ let%test_module "Archive node unit tests" =

let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests" ()
~verification_key )

module Genesis_ledger = (val Genesis_ledger.for_unit_tests)

Expand Down
11 changes: 9 additions & 2 deletions src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1881,10 +1881,17 @@ let internal_commands logger =
| Error err ->
failwithf "Could not parse JSON: %s" err () ) )
in




let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
let%bind verifier =
Verifier.create ~commit_id:Mina_version.commit_id ~logger
~proof_level ~constraint_constants ~pids:(Pid.Table.create ())
~conf_dir:(Some conf_dir) ()
~proof_level ~pids:(Pid.Table.create ())
~conf_dir:(Some conf_dir)
~verification_key
()
in
let%bind result =
let cap lst =
Expand Down
7 changes: 6 additions & 1 deletion src/app/cli/src/init/transaction_snark_profiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ let run ~genesis_constants ~constraint_constants ~proof_level
?min_num_updates ~max_num_updates () )
in
Parallel.init_master () ;


let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
let open Async.Deferred.Let_syntax in
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~commit_id:Mina_version.commit_id ~logger ~proof_level
~constraint_constants ~conf_dir:None
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~verification_key
() )
in
let rec go n =
Expand Down
7 changes: 5 additions & 2 deletions src/lib/bootstrap_controller/bootstrap_controller.ml
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,15 @@ let%test_module "Bootstrap_controller tests" =
let compile_config = compile_config
end


let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests"
~verification_key () )

module Genesis_ledger = (val precomputed_values.genesis_ledger)

Expand Down
6 changes: 4 additions & 2 deletions src/lib/ledger_catchup/normal_catchup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -892,10 +892,12 @@ let%test_module "Ledger_catchup tests" =

let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests"
~verification_key () )

module Context = struct
let logger = logger
Expand Down
6 changes: 4 additions & 2 deletions src/lib/ledger_catchup/super_catchup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1439,10 +1439,12 @@ let%test_module "Ledger_catchup tests" =

let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests"
~verification_key () )

module Context = struct
let logger = logger
Expand Down
7 changes: 3 additions & 4 deletions src/lib/mina_lib/mina_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1562,15 +1562,14 @@ let create ~commit_id ?wallets (config : Config.t) =
~metadata:[ ("exn", Error_json.error_to_yojson err) ] ) )
(fun () ->
O1trace.thread "manage_verifier_subprocess" (fun () ->
let%bind verifier =
let%bind verification_key = Prover.get_blockchain_verification_key prover >>| Or_error.ok_exn in
let%bind verifier =
Verifier.create ~commit_id ~logger:config.logger
~enable_internal_tracing:
(Internal_tracing.is_enabled ())
~internal_trace_filename:"verifier-internal-trace.jsonl"
~proof_level:config.precomputed_values.proof_level
~constraint_constants:
config.precomputed_values.constraint_constants
~pids:config.pids ~conf_dir:(Some config.conf_dir) ()
~pids:config.pids ~conf_dir:(Some config.conf_dir) ~verification_key ()
in
let%map () = set_itn_data (module Verifier) verifier in
verifier ) )
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mina_lib/tests/tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ let%test_module "Epoch ledger sync tests" =
let make_verifier (module Context : CONTEXT) =
let open Context in
Verifier.create ~logger ~proof_level:precomputed_values.proof_level
~constraint_constants:precomputed_values.constraint_constants ~pids
~pids
~conf_dir:(Some (make_dirname "verifier"))
~commit_id:"not specified for unit tests" ()

Expand Down
7 changes: 5 additions & 2 deletions src/lib/network_pool/batcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,13 @@ module Snark_pool = struct
let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests"
~verification_key
() )
let gen_proofs =
let open Quickcheck.Generator.Let_syntax in
Expand Down
6 changes: 4 additions & 2 deletions src/lib/network_pool/snark_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,12 @@ let%test_module "random set test" =

let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests"
~verification_key () )

module Mock_snark_pool =
Make (Mocks.Base_ledger) (Mocks.Staged_ledger) (Mocks.Transition_frontier)
Expand Down
6 changes: 4 additions & 2 deletions src/lib/network_pool/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ let%test_module "network pool test" =

let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests" ()
~verification_key )

module Mock_snark_pool =
Snark_pool.Make (Mocks.Base_ledger) (Mocks.Staged_ledger)
Expand Down
11 changes: 8 additions & 3 deletions src/lib/network_pool/transaction_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1667,10 +1667,13 @@ let%test_module _ =

let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests" ()
~verification_key
)

let `VK vk, `Prover prover =
Transaction_snark.For_tests.create_trivial_snapp ~constraint_constants ()
Expand Down Expand Up @@ -3084,11 +3087,13 @@ let%test_module _ =
let%test "account update with a different network id that uses proof \
authorization would be rejected" =
Thread_safe.block_on_async_exn (fun () ->
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
let%bind verifier_full =
Verifier.create ~logger ~proof_level:Full ~constraint_constants
Verifier.create ~logger ~proof_level:Full
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" ()
~verification_key
in
let%bind test =
setup_test ~verifier:verifier_full
Expand Down
3 changes: 3 additions & 0 deletions src/lib/prover/intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ module type S = sig
sets the process kind for the Itn logger to "prover"
*)
val set_itn_logger_data : t -> daemon_port:int -> unit Deferred.Or_error.t

val get_blockchain_verification_key :
t -> Pickles.Verification_key.t Deferred.Or_error.t
end
26 changes: 25 additions & 1 deletion src/lib/prover/prover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ module Worker_state = struct
val toggle_internal_tracing : bool -> unit

val set_itn_logger_data : daemon_port:int -> unit

val get_blockchain_verification_key :
unit -> Pickles.Verification_key.t Deferred.t
end

(* bin_io required by rpc_parallel *)
Expand Down Expand Up @@ -103,7 +106,6 @@ module Worker_state = struct
Pickles.Cache_handle.generate_or_load B.cache_handle
|> Promise.to_deferred
in

( module struct
module T = T
module B = B
Expand Down Expand Up @@ -161,6 +163,9 @@ module Worker_state = struct

let set_itn_logger_data ~daemon_port =
Itn_logger.set_data ~process_kind:"prover" ~daemon_port

let get_blockchain_verification_key () =
Lazy.force B.Proof.verification_key
end : S )
| Check ->
Deferred.return
Expand Down Expand Up @@ -202,6 +207,9 @@ module Worker_state = struct
let toggle_internal_tracing _ = ()

let set_itn_logger_data ~daemon_port:_ = ()

let get_blockchain_verification_key () =
Deferred.return (Lazy.force Pickles.Verification_key.dummy)
end : S )
| No_check ->
Deferred.return
Expand All @@ -221,6 +229,9 @@ module Worker_state = struct
let toggle_internal_tracing _ = ()

let set_itn_logger_data ~daemon_port:_ = ()

let get_blockchain_verification_key () =
Deferred.return (Lazy.force Pickles.Verification_key.dummy)
end : S )

let get = Fn.id
Expand Down Expand Up @@ -275,6 +286,12 @@ module Functions = struct
let (module M) = Worker_state.get w in
M.set_itn_logger_data ~daemon_port ;
Deferred.unit )

let get_blockchain_verification_key =
create bin_unit [%bin_type_class: Pickles.Verification_key.Stable.Latest.t]
(fun w () ->
let (module M) = Worker_state.get w in
M.get_blockchain_verification_key () )
end

module Worker = struct
Expand All @@ -288,6 +305,8 @@ module Worker = struct
; verify_blockchain : ('w, Blockchain.t, unit Or_error.t) F.t
; toggle_internal_tracing : ('w, bool, unit) F.t
; set_itn_logger_data : ('w, int, unit) F.t
; get_blockchain_verification_key :
('w, unit, Pickles.Verification_key.t) F.t
}

module Worker_state = Worker_state
Expand Down Expand Up @@ -316,6 +335,7 @@ module Worker = struct
; verify_blockchain = f verify_blockchain
; toggle_internal_tracing = f toggle_internal_tracing
; set_itn_logger_data = f set_itn_logger_data
; get_blockchain_verification_key = f get_blockchain_verification_key
}

let init_worker_state
Expand Down Expand Up @@ -566,3 +586,7 @@ let toggle_internal_tracing { connection; _ } enabled =
let set_itn_logger_data { connection; _ } ~daemon_port =
Worker.Connection.run connection ~f:Worker.functions.set_itn_logger_data
~arg:daemon_port

let get_blockchain_verification_key { connection; _ } =
Worker.Connection.run connection
~f:Worker.functions.get_blockchain_verification_key ~arg:()
16 changes: 13 additions & 3 deletions src/lib/staged_ledger/staged_ledger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2389,10 +2389,12 @@ let%test_module "staged ledger tests" =

let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests" ()
~verification_key )

let find_vk ledger =
Zkapp_command.Verifiable.load_vk_from_ledger ~get:(Ledger.get ledger)
Expand Down Expand Up @@ -5187,12 +5189,20 @@ let%test_module "staged ledger tests" =
(Staged_ledger_diff.With_valid_signatures_and_proofs
.commands diff )
= 1 ) ;

let%bind verifier_full =

let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key
~constraint_constants
~proof_level:Full)

in
Verifier.create ~logger ~proof_level:Full
~constraint_constants ~conf_dir:None
~conf_dir:None
~pids:
(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" ()
~verification_key
in
match%map
Sl.apply ~constraint_constants ~global_slot !sl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@ let%test_module "transaction_status" =
let block_window_duration =
Mina_compile_config.For_unit_tests.t.block_window_duration


let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests"
~verification_key () )

let key_gen =
let open Quickcheck.Generator in
Expand Down
7 changes: 5 additions & 2 deletions src/lib/transition_frontier/full_frontier/full_frontier.ml
Original file line number Diff line number Diff line change
Expand Up @@ -962,10 +962,13 @@ module For_tests = struct

let verifier () =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
let open Async.Deferred.Let_syntax in
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None
~pids:(Child_processes.Termination.create_pid_table ())
~commit_id:"not specified for unit tests" () )
~commit_id:"not specified for unit tests" ()
~verification_key )

module Genesis_ledger = (val precomputed_values.genesis_ledger)

Expand Down
5 changes: 3 additions & 2 deletions src/lib/transition_handler/catchup_scheduler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@ let%test_module "Transition_handler.Catchup_scheduler tests" =

let verifier =
Async.Thread_safe.block_on_async_exn (fun () ->
Verifier.create ~logger ~proof_level ~constraint_constants
~conf_dir:None ~pids ~commit_id:"not specified for unit tests" () )
let%bind verification_key = Lazy.force (Verifier.For_test.get_blockchain_verification_key ~constraint_constants ~proof_level) in
Verifier.create ~logger ~proof_level
~conf_dir:None ~pids ~commit_id:"not specified for unit tests" ~verification_key () )

(* cast a breadcrumb into a cached, enveloped, partially validated transition *)
let downcast_breadcrumb breadcrumb =
Expand Down
Loading

0 comments on commit 081b26d

Please sign in to comment.