Skip to content

Commit 6a7b23f

Browse files
committed
Add hard fork config dump and command
1 parent a555043 commit 6a7b23f

File tree

8 files changed

+410
-25
lines changed

8 files changed

+410
-25
lines changed

src/app/cli/src/init/client.ml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,28 @@ let test_genesis_creation =
23122312
Cli_lib.Exceptions.handle_nicely
23132313
Test_genesis_creation.time_genesis_creation )
23142314

2315+
let test_generate_hardfork_config =
2316+
let open Command.Param in
2317+
let hardfork_config_dir_flag =
2318+
flag "--hardfork-config-dir"
2319+
~doc:"DIR Directory to generate hardfork configuration" (required string)
2320+
in
2321+
Command.async ~summary:"Generate reference hardfork configuration"
2322+
(Cli_lib.Background_daemon.rpc_init hardfork_config_dir_flag
2323+
~f:(fun port directory_name ->
2324+
match%bind
2325+
Daemon_rpcs.Client.dispatch_join_errors
2326+
Daemon_rpcs.Generate_hardfork_config.rpc directory_name port
2327+
with
2328+
| Error e ->
2329+
eprintf "Failed to request hardfork config generation: %s\n"
2330+
(Error.to_string_hum e) ;
2331+
exit 17
2332+
| Ok () ->
2333+
printf "Hardfork configuration successfully requested in %s\n"
2334+
directory_name ;
2335+
exit 0 ) )
2336+
23152337
let test_ledger_application =
23162338
Command.async ~summary:"Test ledger application"
23172339
(let%map_open.Command privkey_path = Cli_lib.Flag.privkey_read_path
@@ -2535,7 +2557,9 @@ let advanced ~itn_features =
25352557
; ("print-signature-kind", signature_kind)
25362558
; ( "test"
25372559
, Command.group ~summary:"Testing-only commands"
2538-
[ ("create-genesis", test_genesis_creation) ] )
2560+
[ ("create-genesis", test_genesis_creation)
2561+
; ("generate-hardfork-config", test_generate_hardfork_config)
2562+
] )
25392563
]
25402564
in
25412565
let cmds =

src/app/cli/src/init/mina_run.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,23 @@ let setup_local_server ?(client_trustlist = []) ?rest_server_port
369369
; implement Daemon_rpcs.Get_object_lifetime_statistics.rpc (fun () () ->
370370
return
371371
(Yojson.Safe.pretty_to_string @@ Allocation_functor.Table.dump ()) )
372+
; implement Daemon_rpcs.Generate_hardfork_config.rpc
373+
(fun () directory_name ->
374+
let dump () =
375+
let%map result =
376+
Mina_lib.Hardfork_config.dump_reference_config
377+
~breadcrumb_spec:`Stop_slot ~directory_name mina
378+
in
379+
match result with
380+
| Error e ->
381+
[%log warn]
382+
!"Failed to generate hardfork config: %s"
383+
(Error.to_string_hum e)
384+
| Ok _ ->
385+
()
386+
in
387+
don't_wait_for (dump ()) ;
388+
return (Ok ()) )
372389
; implement Daemon_rpcs.Submit_internal_log.rpc
373390
(fun () { timestamp; message; metadata; process } ->
374391
let metadata =

src/lib/daemon_rpcs/daemon_rpcs.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,13 @@ module Get_object_lifetime_statistics = struct
346346
Rpc.Rpc.create ~name:"Get_object_lifetime_statistics" ~version:0 ~bin_query
347347
~bin_response
348348
end
349+
350+
module Generate_hardfork_config = struct
351+
type query = string [@@deriving bin_io_unversioned]
352+
353+
type response = unit Or_error.t [@@deriving bin_io_unversioned]
354+
355+
let rpc : (query, response) Rpc.Rpc.t =
356+
Rpc.Rpc.create ~name:"Generate_hardfork_config" ~version:0 ~bin_query
357+
~bin_response
358+
end

src/lib/mina_graphql/mina_graphql.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,7 @@ module Queries = struct
26172617
; staking_epoch_seed
26182618
; next_epoch_seed
26192619
; blockchain_length
2620+
; block_timestamp = _
26202621
} =
26212622
Mina_lib.Hardfork_config.prepare_inputs ~breadcrumb_spec mina
26222623
in

src/lib/mina_ledger/root.ml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -215,26 +215,24 @@ struct
215215
; backing_2 = Config.backing_of_config config
216216
} )
217217

218-
let create_component_checkpoints t ~directory_name =
219-
let stable_db, unstable_db_opt =
220-
match t with
221-
| Stable_db db ->
222-
(db, None)
223-
| Converting_db db ->
224-
( Converting_ledger.primary_ledger db
225-
, Some (Converting_ledger.converting_ledger db) )
226-
in
227-
let config = Converting_ledger.Config.with_primary ~directory_name in
228-
let stable_checkpoint =
229-
Stable_db.create_checkpoint stable_db
230-
~directory_name:config.primary_directory ()
231-
in
232-
let unstable_checkpoint =
233-
Option.map unstable_db_opt ~f:(fun unstable_db ->
234-
Unstable_db.create_checkpoint unstable_db
235-
~directory_name:config.converting_directory () )
236-
in
237-
(stable_checkpoint, unstable_checkpoint)
218+
let create_stable_checkpoint t ~directory_name =
219+
match t with
220+
| Stable_db db ->
221+
Stable_db.create_checkpoint db ~directory_name ()
222+
| Converting_db db ->
223+
Stable_db.create_checkpoint
224+
(Converting_ledger.primary_ledger db)
225+
~directory_name ()
226+
227+
let create_migrated_checkpoint t ~directory_name =
228+
match t with
229+
| Stable_db _db ->
230+
None
231+
| Converting_db db ->
232+
Some
233+
(Migrated_db.create_checkpoint
234+
(Converting_ledger.converting_ledger db)
235+
~directory_name () )
238236

239237
let as_unmasked t =
240238
match t with

src/lib/mina_ledger/root.mli

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ module Make
130130
(** Make a checkpoint of the root ledger *)
131131
val make_checkpoint : t -> config:Config.t -> unit
132132

133-
(** Make a checkpoint of the existing components of the root ledger and return
134-
new ledgers backed by those separate components *)
135-
val create_component_checkpoints :
136-
t -> directory_name:string -> Stable_db.t * Unstable_db.t option
133+
val create_stable_checkpoint : t -> directory_name:string -> Stable_db.t
134+
135+
val create_migrated_checkpoint :
136+
t -> directory_name:string -> Migrated_db.t option
137137

138138
(** View the root ledger as an unmasked [Any_ledger] so it can be used by code
139139
that does not need to know how the root is implemented *)

0 commit comments

Comments
 (0)