Skip to content

Commit 8de4e2c

Browse files
authored
Merge pull request #17932 from MinaProtocol/cjjdespres/chain-state-dir
Add notion of chain state location to the daemon
2 parents f5d3afd + e2d3eb2 commit 8de4e2c

File tree

6 files changed

+84
-28
lines changed

6 files changed

+84
-28
lines changed

src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,43 @@ let plugin_flag =
4949
times"
5050
else Command.Param.return []
5151

52+
module Chain_state_locations = struct
53+
(** The locations of the chain state in a daemon. These will be computed by
54+
[chain_state_locations] based on the runtime daemon config. By default,
55+
the [chain_state] will be located in the mina config directory and the
56+
other directories will be located in the [chain_state]. *)
57+
type t =
58+
{ chain_state : string (** The top-level chain state directory *)
59+
; mina_net : string (** Mina networking information *)
60+
; trust : string (** P2P trust information *)
61+
; root : string (** The root snarked ledgers *)
62+
; genesis : string (** The genesis ledgers *)
63+
; frontier : string (** The transition frontier *)
64+
; epoch_ledger : string (** The epoch ledger snapshots *)
65+
; proof_cache : string (** The proof cache *)
66+
; zkapp_vk_cache : string (** The zkApp vk cache *)
67+
; snark_pool : string (** The snark pool *)
68+
}
69+
70+
(** Determine the locations of the chain state components based on the daemon
71+
runtime config *)
72+
let of_config ~conf_dir (config : Runtime_config.t) : t =
73+
(* TODO: post hard fork, we should not be ignoring this *)
74+
let _config = config in
75+
let chain_state = conf_dir in
76+
{ chain_state
77+
; mina_net = chain_state ^/ "mina_net2"
78+
; trust = chain_state ^/ "trust"
79+
; root = chain_state ^/ "root"
80+
; genesis = chain_state ^/ "genesis"
81+
; frontier = chain_state ^/ "frontier"
82+
; epoch_ledger = chain_state
83+
; proof_cache = chain_state ^/ "proof_cache"
84+
; zkapp_vk_cache = chain_state ^/ "zkapp_vk_cache"
85+
; snark_pool = chain_state ^/ "snark_pool"
86+
}
87+
end
88+
5289
let load_config_files ~logger ~genesis_constants ~constraint_constants ~conf_dir
5390
~genesis_dir ~cli_proof_level ~proof_level ~genesis_backing_type
5491
config_files =
@@ -98,7 +135,12 @@ let load_config_files ~logger ~genesis_constants ~constraint_constants ~conf_dir
98135
] ;
99136
failwithf "Could not parse configuration file: %s" err () )
100137
in
101-
let genesis_dir = Option.value ~default:(conf_dir ^/ "genesis") genesis_dir in
138+
let chain_state_locations =
139+
Chain_state_locations.of_config ~conf_dir config
140+
in
141+
let genesis_dir =
142+
Option.value ~default:chain_state_locations.genesis genesis_dir
143+
in
102144
let%bind precomputed_values =
103145
match%map
104146
Genesis_ledger_helper.init_from_config_file ~cli_proof_level ~genesis_dir
@@ -138,7 +180,7 @@ let load_config_files ~logger ~genesis_constants ~constraint_constants ~conf_dir
138180
~metadata ;
139181
Error.raise err
140182
in
141-
return (precomputed_values, config_jsons, config)
183+
return (precomputed_values, config_jsons, config, chain_state_locations)
142184

143185
let setup_daemon logger ~itn_features ~default_snark_worker_fee =
144186
let open Command.Let_syntax in
@@ -793,13 +835,15 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee =
793835
let ledger_backing_type =
794836
Mina_lib.Config.ledger_backing ~hardfork_mode
795837
in
796-
let%bind precomputed_values, config_jsons, config =
838+
let%bind ( precomputed_values
839+
, config_jsons
840+
, config
841+
, chain_state_locations ) =
797842
load_config_files ~logger ~conf_dir ~genesis_dir
798843
~proof_level:Genesis_constants.Compiled.proof_level config_files
799844
~genesis_constants ~constraint_constants ~cli_proof_level
800845
~genesis_backing_type:ledger_backing_type
801846
in
802-
803847
constraint_constants.block_window_duration_ms |> Float.of_int
804848
|> Time.Span.of_ms |> Mina_metrics.initialize_all ;
805849

@@ -1133,7 +1177,7 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee =
11331177
Logger.trace logger ~module_:__MODULE__ "Creating %s at %s"
11341178
~location typ
11351179
in
1136-
let trust_dir = conf_dir ^/ "trust" in
1180+
let trust_dir = chain_state_locations.trust in
11371181
let%bind () = Async.Unix.mkdir ~p:() trust_dir in
11381182
let%bind trust_system = Trust_system.create trust_dir in
11391183
trace_database_initialization "trust_system" __LOC__ trust_dir ;
@@ -1151,7 +1195,9 @@ let setup_daemon logger ~itn_features ~default_snark_worker_fee =
11511195
(kp, Public_key.compress kp.Keypair.public_key) )
11521196
|> Option.to_list |> Keypair.And_compressed_pk.Set.of_list
11531197
in
1154-
let epoch_ledger_location = conf_dir ^/ "epoch_ledger" in
1198+
let epoch_ledger_location =
1199+
chain_state_locations.epoch_ledger ^/ "epoch_ledger"
1200+
in
11551201
let module Context = struct
11561202
let logger = logger
11571203

@@ -1286,7 +1332,7 @@ Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ;
12861332
Gossip_net.Libp2p.Config.
12871333
{ timeout = Time.Span.of_sec 3.
12881334
; logger
1289-
; conf_dir
1335+
; mina_net_location = chain_state_locations.mina_net
12901336
; chain_id
12911337
; unsafe_no_trust_ip = false
12921338
; seed_peer_list_url =
@@ -1408,20 +1454,23 @@ Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ;
14081454
; num_threads = snark_worker_parallelism_flag
14091455
}
14101456
~snark_coordinator_key:run_snark_coordinator_flag
1411-
~snark_pool_disk_location:(conf_dir ^/ "snark_pool")
1457+
~snark_pool_disk_location:chain_state_locations.snark_pool
14121458
~wallets_disk_location:(conf_dir ^/ "wallets")
1413-
~persistent_root_location:(conf_dir ^/ "root")
1414-
~persistent_frontier_location:(conf_dir ^/ "frontier")
1415-
~epoch_ledger_location ~snark_work_fee:snark_work_fee_flag
1416-
~time_controller ~block_production_keypairs ~monitor
1417-
~consensus_local_state ~is_archive_rocksdb
1418-
~work_reassignment_wait ~archive_process_location
1419-
~log_block_creation ~precomputed_values ~start_time
1420-
?precomputed_blocks_path ~log_precomputed_blocks
1421-
~start_filtered_logs ~upload_blocks_to_gcloud
1422-
~block_reward_threshold ~uptime_url ~uptime_submitter_keypair
1423-
~uptime_send_node_commit ~stop_time ~node_status_url
1424-
~graphql_control_port:itn_graphql_port ~simplified_node_stats
1459+
~persistent_root_location:chain_state_locations.root
1460+
~persistent_frontier_location:chain_state_locations.frontier
1461+
~epoch_ledger_location
1462+
~proof_cache_location:chain_state_locations.proof_cache
1463+
~zkapp_vk_cache_location:chain_state_locations.zkapp_vk_cache
1464+
~snark_work_fee:snark_work_fee_flag ~time_controller
1465+
~block_production_keypairs ~monitor ~consensus_local_state
1466+
~is_archive_rocksdb ~work_reassignment_wait
1467+
~archive_process_location ~log_block_creation
1468+
~precomputed_values ~start_time ?precomputed_blocks_path
1469+
~log_precomputed_blocks ~start_filtered_logs
1470+
~upload_blocks_to_gcloud ~block_reward_threshold ~uptime_url
1471+
~uptime_submitter_keypair ~uptime_send_node_commit ~stop_time
1472+
~node_status_url ~graphql_control_port:itn_graphql_port
1473+
~simplified_node_stats
14251474
~zkapp_cmd_limit:(ref compile_config.zkapp_cmd_limit)
14261475
~itn_features ~compile_config ~hardfork_mode () )
14271476
in
@@ -1973,7 +2022,10 @@ let internal_commands logger ~itn_features =
19732022
List.map config_files ~f:(fun config_file ->
19742023
(config_file, `Must_exist) )
19752024
in
1976-
let%bind precomputed_values, _config_jsons, _config =
2025+
let%bind ( precomputed_values
2026+
, _config_jsons
2027+
, _config
2028+
, _chain_state_locations ) =
19772029
load_config_files ~logger ~conf_dir ~genesis_dir ~genesis_constants
19782030
~constraint_constants ~proof_level ~cli_proof_level:None
19792031
~genesis_backing_type:Stable_db config_files

src/app/heap_usage/heap_usage.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ let print_heap_usage name v =
1313
words (words * bytes_per_word)
1414

1515
let initialize_proof_cache_db ~logger conf_dir =
16-
let%map res = Proof_cache_tag.create_db ~logger (conf_dir ^/ "proof_cache") in
16+
(* Ad-hoc proof cache location for convenience in this executable *)
17+
let proof_cache_location = conf_dir ^/ "proof_cache" in
18+
let%map res = Proof_cache_tag.create_db ~logger proof_cache_location in
1719
Result.(
1820
map_error ~f:(fun (`Initialization_error e) -> Error.to_exn e) res |> ok_exn)
1921

src/lib/gossip_net/libp2p.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Config = struct
3232
; initial_peers : Mina_net2.Multiaddr.t list
3333
; addrs_and_ports : Node_addrs_and_ports.t
3434
; metrics_port : int option
35-
; conf_dir : string
35+
; mina_net_location : string
3636
; chain_id : string
3737
; logger : Logger.t
3838
; unsafe_no_trust_ip : bool
@@ -246,7 +246,7 @@ module Make (Rpc_interface : RPC_INTERFACE) :
246246
Error.tag err ~tag:"Failed to connect to libp2p_helper process"
247247
|> Error.raise
248248
in
249-
let conf_dir = config.conf_dir ^/ "mina_net2" in
249+
let conf_dir = config.mina_net_location in
250250
let%bind () = Unix.mkdir ~p:() conf_dir in
251251
match%bind
252252
Monitor.try_with ~here:[%here] ~rest:(`Call handle_mina_net2_exception)

src/lib/mina_lib/config.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type t =
3737
; persistent_root_location : string
3838
; persistent_frontier_location : string
3939
; epoch_ledger_location : string
40+
; proof_cache_location : string
41+
; zkapp_vk_cache_location : string
4042
; staged_ledger_transition_backup_capacity : int [@default 10]
4143
; time_controller : Block_time.Controller.t
4244
; snark_work_fee : Currency.Fee.t

src/lib/mina_lib/mina_lib.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,13 +1748,12 @@ let raise_on_initialization_error (`Initialization_error e) =
17481748
Error.raise @@ Error.tag ~tag:"proof cache initialization error" e
17491749

17501750
let initialize_proof_cache_db (config : Config.t) =
1751-
Proof_cache_tag.create_db ~logger:config.logger
1752-
(config.conf_dir ^/ "proof_cache")
1751+
Proof_cache_tag.create_db ~logger:config.logger config.proof_cache_location
17531752
>>| function Error e -> raise_on_initialization_error e | Ok db -> db
17541753

17551754
let initialize_zkapp_vk_cache_db (config : Config.t) =
17561755
Zkapp_vk_cache_tag.create_db ~logger:config.logger
1757-
(config.conf_dir ^/ "zkapp_vk_cache")
1756+
config.zkapp_vk_cache_location
17581757
>>| function Error e -> raise_on_initialization_error e | Ok db -> db
17591758

17601759
let create ~commit_id ?wallets (config : Config.t) =

src/lib/mina_lib/tests/tests.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ let%test_module "Epoch ledger sync tests" =
259259
let creatable_gossip_net =
260260
let chain_id = "dummy_chain_id" in
261261
let conf_dir = make_dirname "libp2p" in
262+
let mina_net_location = Filename.concat conf_dir "mina_net2" in
262263
let seed_peer_list_url = None in
263264
let addrs_and_ports =
264265
let external_ip = Core.Unix.Inet_addr.localhost in
@@ -279,7 +280,7 @@ let%test_module "Epoch ledger sync tests" =
279280
let gossip_net_params : Gossip_net.Libp2p.Config.t =
280281
{ timeout = Time.Span.of_sec 3.
281282
; logger
282-
; conf_dir
283+
; mina_net_location
283284
; chain_id
284285
; unsafe_no_trust_ip = false
285286
; seed_peer_list_url

0 commit comments

Comments
 (0)