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

[Do note merge] pass cache proof db #16417

Draft
wants to merge 2 commits into
base: dkijania/use_lmdb_cache_in_mina
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ;
~wallets_disk_location:(conf_dir ^/ "wallets")
~persistent_root_location:(conf_dir ^/ "root")
~persistent_frontier_location:(conf_dir ^/ "frontier")
~cache_proof_db_location:((conf_dir ^/ "proof_cache.db"))
~epoch_ledger_location ~snark_work_fee ~time_controller
~block_production_keypairs ~monitor ~consensus_local_state
~is_archive_rocksdb ~work_reassignment_wait
Expand Down
2 changes: 1 addition & 1 deletion src/app/cli/src/init/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ let hash_ledger =
fun () ->
let open Deferred.Let_syntax in
let%bind constraint_constants =
let logger = Logger.create () in
let logger = Logger.null () in
let%map conf =
Runtime_config.Constants.load_constants ~logger config_files
in
Expand Down
23 changes: 13 additions & 10 deletions src/lib/block_producer/block_producer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module type CONTEXT = sig
val zkapp_cmd_limit : int option ref

val vrf_poll_interval : Time.Span.t

end

type Structured_log_events.t += Block_produced
Expand Down Expand Up @@ -170,7 +171,7 @@ let generate_next_state ~commit_id ~zkapp_cmd_limit ~constraint_constants
~previous_protocol_state ~time_controller ~staged_ledger ~transactions
~get_completed_work ~logger ~(block_data : Consensus.Data.Block_data.t)
~winner_pk ~scheduled_time ~log_block_creation ~block_reward_threshold
~zkapp_cmd_limit_hardcap ~slot_tx_end ~slot_chain_end =
~zkapp_cmd_limit_hardcap ~slot_tx_end ~slot_chain_end ~cache_proof_db =
let open Interruptible.Let_syntax in
let global_slot_since_hard_fork =
Consensus.Data.Block_data.global_slot block_data
Expand Down Expand Up @@ -344,7 +345,7 @@ let generate_next_state ~commit_id ~zkapp_cmd_limit ~constraint_constants
let opt_ledger_proof_statement =
Option.map ledger_proof_opt ~f:(fun (proof, _) ->
Ledger_proof.statement
@@ Ledger_proof.Cache_tag.unwrap proof )
@@ Ledger_proof.Cache_tag.unwrap proof cache_proof_db)
in
let ledger_proof_statement =
match ledger_proof_opt with
Expand Down Expand Up @@ -414,7 +415,7 @@ let generate_next_state ~commit_id ~zkapp_cmd_limit ~constraint_constants
~staged_ledger_diff:(Staged_ledger_diff.forget diff)
~ledger_proof:
(Option.map ledger_proof_opt ~f:(fun (proof, _) ->
Ledger_proof.Cache_tag.unwrap proof ) ) )
Ledger_proof.Cache_tag.unwrap proof cache_proof_db) ) )
in
let witness =
{ Pending_coinbase_witness.pending_coinbases =
Expand Down Expand Up @@ -701,6 +702,7 @@ let produce ~genesis_breadcrumb ~context:(module Context : CONTEXT) ~prover
~verifier ~trust_system ~get_completed_work ~transaction_resource_pool
~frontier_reader ~time_controller ~transition_writer ~log_block_creation
~block_reward_threshold ~block_produced_bvar ~slot_tx_end ~slot_chain_end
~cache_proof_db
~net ~zkapp_cmd_limit_hardcap ivar
(scheduled_time, block_data, winner_pubkey) =
let open Context in
Expand Down Expand Up @@ -798,7 +800,7 @@ let produce ~genesis_breadcrumb ~context:(module Context : CONTEXT) ~prover
~transactions ~get_completed_work ~logger ~log_block_creation
~winner_pk:winner_pubkey ~block_reward_threshold
~zkapp_cmd_limit:!zkapp_cmd_limit ~zkapp_cmd_limit_hardcap
~slot_tx_end ~slot_chain_end
~slot_tx_end ~slot_chain_end ~cache_proof_db
in
[%log internal] "Generate_next_state_done" ;
match next_state_opt with
Expand Down Expand Up @@ -932,10 +934,11 @@ let produce ~genesis_breadcrumb ~context:(module Context : CONTEXT) ~prover
"Build breadcrumb on produced block" (fun () ->
Breadcrumb.build ~logger ~precomputed_values ~verifier
~get_completed_work:(Fn.const None) ~trust_system
~parent:crumb ~transition
~parent:crumb
~transition
~sender:None (* Consider skipping `All here *)
~skip_staged_ledger_verification:`Proofs
~transition_receipt_time () )
~transition_receipt_time ~cache_proof_db () )
|> Deferred.Result.map_error ~f:(function
| `Invalid_staged_ledger_diff e ->
`Invalid_staged_ledger_diff (e, staged_ledger_diff)
Expand Down Expand Up @@ -1224,7 +1227,7 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier
~time_controller ~consensus_local_state ~coinbase_receiver ~frontier_reader
~transition_writer ~set_next_producer_timing ~log_block_creation
~block_reward_threshold ~block_produced_bvar ~vrf_evaluation_state ~net
~zkapp_cmd_limit_hardcap =
~zkapp_cmd_limit_hardcap ~cache_proof_db =
let open Context in
O1trace.sync_thread "produce_blocks" (fun () ->
let genesis_breadcrumb =
Expand All @@ -1243,7 +1246,7 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier
~transaction_resource_pool ~frontier_reader ~time_controller
~transition_writer ~log_block_creation ~block_reward_threshold
~block_produced_bvar ~slot_tx_end ~slot_chain_end ~net
~zkapp_cmd_limit_hardcap
~zkapp_cmd_limit_hardcap ~cache_proof_db
in
let module Breadcrumb = Transition_frontier.Breadcrumb in
let production_supervisor = Singleton_supervisor.create ~task:produce in
Expand Down Expand Up @@ -1372,7 +1375,7 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier
: unit Block_time.Timeout.t ) )

let run_precomputed ~context:(module Context : CONTEXT) ~verifier ~trust_system
~time_controller ~frontier_reader ~transition_writer ~precomputed_blocks =
~time_controller ~frontier_reader ~transition_writer ~precomputed_blocks ~cache_proof_db =
let open Context in
let rejected_blocks_logger =
Logger.create ~id:Logger.Logger_id.rejected_blocks ()
Expand Down Expand Up @@ -1499,7 +1502,7 @@ let run_precomputed ~context:(module Context : CONTEXT) ~verifier ~trust_system
~get_completed_work:(Fn.const None) ~trust_system
~parent:crumb ~transition ~sender:None
~skip_staged_ledger_verification:`Proofs
~transition_receipt_time ()
~transition_receipt_time ~cache_proof_db ()
|> Deferred.Result.map_error ~f:(function
| `Invalid_staged_ledger_diff e ->
`Invalid_staged_ledger_diff (e, staged_ledger_diff)
Expand Down
13 changes: 8 additions & 5 deletions src/lib/bootstrap_controller/bootstrap_controller.ml
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ let external_transition_compare ~context:(module Context : CONTEXT) =
*)
let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
~consensus_local_state ~transition_reader ~preferred_peers ~persistent_root
~persistent_frontier ~initial_root_transition ~catchup_mode =
~persistent_frontier ~initial_root_transition ~catchup_mode ~cache_proof_db =
let open Context in
O1trace.thread "bootstrap" (fun () ->
let rec loop previous_cycles =
Expand Down Expand Up @@ -627,7 +627,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
Transition_frontier.load
~context:(module Consensus_context)
~retry_with_fresh_db:false ~verifier ~consensus_local_state
~persistent_root ~persistent_frontier ~catchup_mode ()
~persistent_root ~persistent_frontier ~catchup_mode ~cache_proof_db ()
>>| function
| Ok frontier ->
frontier
Expand Down Expand Up @@ -886,7 +886,7 @@ let%test_module "Bootstrap_controller tests" =
(E.Set.of_list saved_transitions)
~expect:(E.Set.of_list expected_transitions) )

let run_bootstrap ~timeout_duration ~my_net ~transition_reader =
let run_bootstrap ~timeout_duration ~my_net ~transition_reader ~cache_proof_db=
let open Fake_network in
let time_controller = Block_time.Controller.basic ~logger in
let persistent_root =
Expand All @@ -909,7 +909,7 @@ let%test_module "Bootstrap_controller tests" =
~trust_system ~verifier ~network:my_net.network ~preferred_peers:[]
~consensus_local_state:my_net.state.consensus_local_state
~transition_reader ~persistent_root ~persistent_frontier
~catchup_mode:`Normal ~initial_root_transition )
~catchup_mode:`Normal ~initial_root_transition ~cache_proof_db)

let assert_transitions_increasingly_sorted ~root
(incoming_transitions : Transition_cache.element list) =
Expand Down Expand Up @@ -941,7 +941,9 @@ let%test_module "Bootstrap_controller tests" =
: Mina_block.Header.t )

let%test_unit "sync with one node after receiving a transition" =

Quickcheck.test ~trials:1

Fake_network.Generator.(
gen ~precomputed_values ~verifier ~max_frontier_length
~use_super_catchup:false
Expand All @@ -950,6 +952,7 @@ let%test_module "Bootstrap_controller tests" =
~frontier_branch_size:((max_frontier_length * 2) + 2)
])
~f:(fun fake_network ->
let cache_proof_db = Ledger_proof.Cache_tag.For_tests.random () in
let [ my_net; peer_net ] = fake_network.peer_networks in
let transition_reader, transition_writer =
Pipe_lib.Strict_pipe.create ~name:(__MODULE__ ^ __LOC__)
Expand All @@ -971,7 +974,7 @@ let%test_module "Bootstrap_controller tests" =
Async.Thread_safe.block_on_async_exn (fun () ->
run_bootstrap
~timeout_duration:(Block_time.Span.of_ms 30_000L)
~my_net ~transition_reader )
~my_net ~transition_reader ~cache_proof_db)
in
assert_transitions_increasingly_sorted
~root:(Transition_frontier.root new_frontier)
Expand Down
1 change: 1 addition & 0 deletions src/lib/bootstrap_controller/bootstrap_controller.mli
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ val run :
-> persistent_frontier:Transition_frontier.Persistent_frontier.t
-> initial_root_transition:Mina_block.Validated.t
-> catchup_mode:[ `Normal | `Super ]
-> cache_proof_db:Ledger_proof.Cache_tag.Cache.t
-> (Transition_frontier.t * Transition_cache.element list) Deferred.t
6 changes: 3 additions & 3 deletions src/lib/ledger_catchup/ledger_catchup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ end

let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
~frontier ~catchup_job_reader ~catchup_breadcrumbs_writer
~unprocessed_transition_cache : unit =
~unprocessed_transition_cache ~cache_proof_db : unit =
match Transition_frontier.catchup_state frontier with
| Hash _ ->
Normal_catchup.run
~context:(module Context)
~trust_system ~verifier ~network ~frontier ~catchup_job_reader
~catchup_breadcrumbs_writer ~unprocessed_transition_cache
~catchup_breadcrumbs_writer ~unprocessed_transition_cache ~cache_proof_db
| Full _ ->
Super_catchup.run
~context:(module Context)
~trust_system ~verifier ~network ~frontier ~catchup_job_reader
~catchup_breadcrumbs_writer ~unprocessed_transition_cache
~catchup_breadcrumbs_writer ~unprocessed_transition_cache ~cache_proof_db
1 change: 1 addition & 0 deletions src/lib/ledger_catchup/ledger_catchup.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ val run :
Strict_pipe.Writer.t
-> unprocessed_transition_cache:
Transition_handler.Unprocessed_transition_cache.t
-> cache_proof_db:Ledger_proof.Cache_tag.Cache.t
-> unit
29 changes: 16 additions & 13 deletions src/lib/ledger_catchup/normal_catchup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ let download_transitions ~target_hash ~logger ~trust_system ~network

let verify_transitions_and_build_breadcrumbs ~context:(module Context : CONTEXT)
~trust_system ~verifier ~frontier ~unprocessed_transition_cache ~transitions
~target_hash ~subtrees =
~target_hash ~subtrees ~cache_proof_db =
let open Context in
let open Deferred.Or_error.Let_syntax in
let verification_start_time = Core.Time.now () in
Expand Down Expand Up @@ -610,7 +610,7 @@ let verify_transitions_and_build_breadcrumbs ~context:(module Context : CONTEXT)
let open Deferred.Let_syntax in
match%bind
Transition_handler.Breadcrumb_builder.build_subtrees_of_breadcrumbs ~logger
~precomputed_values ~verifier ~trust_system ~frontier ~initial_hash
~precomputed_values ~verifier ~trust_system ~frontier ~initial_hash ~cache_proof_db
trees_of_transitions
with
| Ok result ->
Expand Down Expand Up @@ -659,7 +659,7 @@ let garbage_collect_subtrees ~logger ~subtrees =

let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
~frontier ~catchup_job_reader ~catchup_breadcrumbs_writer
~unprocessed_transition_cache : unit =
~unprocessed_transition_cache ~cache_proof_db : unit =
let open Context in
let hash_tree =
match Transition_frontier.catchup_state frontier with
Expand Down Expand Up @@ -828,7 +828,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
verify_transitions_and_build_breadcrumbs
~context:(module Context)
~trust_system ~verifier ~frontier ~unprocessed_transition_cache
~transitions ~target_hash ~subtrees
~transitions ~target_hash ~subtrees ~cache_proof_db
with
| Ok trees_of_breadcrumbs ->
[%log trace]
Expand Down Expand Up @@ -965,7 +965,7 @@ let%test_module "Ledger_catchup tests" =
Strict_pipe.Reader.t
}

let run_catchup ~network ~frontier =
let run_catchup ~network ~frontier ~cache_proof_db =
let catchup_job_reader, catchup_job_writer =
Strict_pipe.create ~name:(__MODULE__ ^ __LOC__)
(Buffered (`Capacity 10, `Overflow Crash))
Expand All @@ -981,14 +981,14 @@ let%test_module "Ledger_catchup tests" =
run
~context:(module Context)
~verifier ~trust_system ~network ~frontier ~catchup_breadcrumbs_writer
~catchup_job_reader ~unprocessed_transition_cache ;
~catchup_job_reader ~unprocessed_transition_cache ~cache_proof_db;
{ cache = unprocessed_transition_cache
; job_writer = catchup_job_writer
; breadcrumbs_reader = catchup_breadcrumbs_reader
}

let run_catchup_with_target ~network ~frontier ~target_breadcrumb =
let test = run_catchup ~network ~frontier in
let run_catchup_with_target ~network ~frontier ~target_breadcrumb ~cache_proof_db=
let test = run_catchup ~network ~frontier ~cache_proof_db in
let parent_hash =
Transition_frontier.Breadcrumb.parent_hash target_breadcrumb
in
Expand All @@ -1000,12 +1000,12 @@ let%test_module "Ledger_catchup tests" =
(parent_hash, [ Rose_tree.T ((target_transition, None), []) ]) ;
(`Test test, `Cached_transition target_transition)

let test_successful_catchup ~my_net ~target_best_tip_path =
let test_successful_catchup ~my_net ~target_best_tip_path ~cache_proof_db =
let open Fake_network in
let target_breadcrumb = List.last_exn target_best_tip_path in
let `Test { breadcrumbs_reader; _ }, _ =
run_catchup_with_target ~network:my_net.network
~frontier:my_net.state.frontier ~target_breadcrumb
~frontier:my_net.state.frontier ~target_breadcrumb ~cache_proof_db
in
(* TODO: expose Strict_pipe.read *)
let%map cached_catchup_breadcrumbs =
Expand Down Expand Up @@ -1044,6 +1044,7 @@ let%test_module "Ledger_catchup tests" =

let%test_unit "can catchup to a peer within [k/2,k]" =
[%log info] "running catchup to peer" ;
let cache_proof_db = Ledger_proof.Cache_tag.For_tests.random () in
Quickcheck.test ~trials:5
Fake_network.Generator.(
let open Quickcheck.Generator.Let_syntax in
Expand All @@ -1065,10 +1066,11 @@ let%test_module "Ledger_catchup tests" =
(best_tip peer_net.state.frontier))
in
Thread_safe.block_on_async_exn (fun () ->
test_successful_catchup ~my_net ~target_best_tip_path ) )
test_successful_catchup ~my_net ~target_best_tip_path ~cache_proof_db) )

let%test_unit "catchup succeeds even if the parent transition is already \
in the frontier" =
let cache_proof_db = Ledger_proof.Cache_tag.For_tests.random () in
Quickcheck.test ~trials:1
Fake_network.Generator.(
gen ~precomputed_values ~verifier ~max_frontier_length
Expand All @@ -1081,9 +1083,10 @@ let%test_module "Ledger_catchup tests" =
[ Transition_frontier.best_tip peer_net.state.frontier ]
in
Thread_safe.block_on_async_exn (fun () ->
test_successful_catchup ~my_net ~target_best_tip_path ) )
test_successful_catchup ~my_net ~target_best_tip_path ~cache_proof_db ) )

let%test_unit "catchup fails if one of the parent transitions fail" =
let cache_proof_db = Ledger_proof.Cache_tag.For_tests.random () in
Quickcheck.test ~trials:1
Fake_network.Generator.(
gen ~precomputed_values ~verifier ~max_frontier_length
Expand Down Expand Up @@ -1114,7 +1117,7 @@ let%test_module "Ledger_catchup tests" =
Thread_safe.block_on_async_exn (fun () ->
let `Test { cache; _ }, `Cached_transition cached_transition =
run_catchup_with_target ~network:my_net.network
~frontier:my_net.state.frontier ~target_breadcrumb
~frontier:my_net.state.frontier ~target_breadcrumb ~cache_proof_db
in
let cached_failing_transition =
Transition_handler.Unprocessed_transition_cache.register_exn
Expand Down
Loading