@@ -2293,15 +2293,6 @@ module Queries = struct
2293
2293
|> Runtime_config. to_yojson |> Yojson.Safe. to_basic )
2294
2294
2295
2295
let fork_config =
2296
- let rec map_results ~f = function
2297
- | [] ->
2298
- Result. return []
2299
- | r :: rs ->
2300
- let open Result.Let_syntax in
2301
- let % bind r' = f r in
2302
- let % map rs = map_results ~f rs in
2303
- r' :: rs
2304
- in
2305
2296
field " fork_config"
2306
2297
~doc:
2307
2298
" The runtime configuration for a blockchain fork intended to be a \
@@ -2314,59 +2305,69 @@ module Queries = struct
2314
2305
`Assoc [ (" error" , `String " Daemon is bootstrapping" ) ]
2315
2306
| `Active best_tip -> (
2316
2307
let block = Transition_frontier.Breadcrumb. (block best_tip) in
2308
+ let blockchain_length = Mina_block. blockchain_length block in
2317
2309
let global_slot =
2318
- Mina_block. blockchain_length block |> Unsigned.UInt32. to_int
2310
+ Mina_block. consensus_state block
2311
+ |> Consensus.Data.Consensus_state. curr_global_slot
2319
2312
in
2320
- let accounts_or_error =
2313
+ let staged_ledger =
2321
2314
Transition_frontier.Breadcrumb. staged_ledger best_tip
2322
2315
|> Staged_ledger. ledger
2323
- |> Ledger. foldi ~init: [] ~f: (fun _ accum act -> act :: accum)
2324
- |> map_results
2325
- ~f: Runtime_config.Json_layout.Accounts.Single. of_account
2326
2316
in
2327
2317
let protocol_state =
2328
2318
Transition_frontier.Breadcrumb. protocol_state best_tip
2329
2319
in
2330
- match accounts_or_error with
2320
+ let consensus =
2321
+ Mina_state.Protocol_state. consensus_state protocol_state
2322
+ in
2323
+ let staking_epoch =
2324
+ Consensus.Proof_of_stake.Data.Consensus_state. staking_epoch_data
2325
+ consensus
2326
+ in
2327
+ let next_epoch =
2328
+ Consensus.Proof_of_stake.Data.Consensus_state. next_epoch_data
2329
+ consensus
2330
+ in
2331
+ let staking_epoch_seed =
2332
+ Mina_base.Epoch_seed. to_base58_check
2333
+ staking_epoch.Mina_base.Epoch_data.Poly. seed
2334
+ in
2335
+ let next_epoch_seed =
2336
+ Mina_base.Epoch_seed. to_base58_check
2337
+ next_epoch.Mina_base.Epoch_data.Poly. seed
2338
+ in
2339
+ let runtime_config = Mina_lib. runtime_config mina in
2340
+ match
2341
+ let open Result.Let_syntax in
2342
+ let % bind staking_ledger =
2343
+ match Mina_lib. staking_ledger mina with
2344
+ | None ->
2345
+ Error " Staking ledger is not initialized."
2346
+ | Some (Genesis_epoch_ledger l ) ->
2347
+ Ok (Ledger.Any_ledger. cast (module Ledger ) l)
2348
+ | Some (Ledger_db l ) ->
2349
+ Ok (Ledger.Any_ledger. cast (module Ledger. Db ) l)
2350
+ in
2351
+ let % bind next_epoch_ledger =
2352
+ match Mina_lib. next_epoch_ledger mina with
2353
+ | None ->
2354
+ Error " Next epoch ledger is not initialized."
2355
+ | Some `Notfinalized ->
2356
+ Ok None
2357
+ | Some (`Finalized (Genesis_epoch_ledger l )) ->
2358
+ Ok (Some (Ledger.Any_ledger. cast (module Ledger ) l))
2359
+ | Some (`Finalized (Ledger_db l )) ->
2360
+ Ok (Some (Ledger.Any_ledger. cast (module Ledger. Db ) l))
2361
+ in
2362
+ Runtime_config. make_fork_config ~staged_ledger ~global_slot
2363
+ ~staking_ledger ~staking_epoch_seed ~next_epoch_ledger
2364
+ ~next_epoch_seed ~blockchain_length
2365
+ ~protocol_state_hash: protocol_state.previous_state_hash
2366
+ runtime_config
2367
+ with
2331
2368
| Error e ->
2332
2369
`Assoc [ (" error" , `String e) ]
2333
- | Ok accounts ->
2334
- let runtime_config = Mina_lib. runtime_config mina in
2335
- let ledger = Option. value_exn runtime_config.ledger in
2336
- let previous_length =
2337
- let open Option.Let_syntax in
2338
- let % bind proof = runtime_config.proof in
2339
- let % map fork = proof.fork in
2340
- fork.previous_length + global_slot
2341
- in
2342
- let fork =
2343
- Runtime_config.Fork_config.
2344
- { previous_state_hash =
2345
- State_hash. to_base58_check
2346
- protocol_state.previous_state_hash
2347
- ; previous_length =
2348
- Option. value ~default: global_slot previous_length
2349
- ; genesis_slot = global_slot
2350
- }
2351
- in
2352
- let update =
2353
- Runtime_config. make
2354
- (* add_genesis_winner must be set to false, because this
2355
- config effectively creates a continuation of the current
2356
- blockchain state and therefore the genesis ledger already
2357
- contains the winner of the previous block. No need to
2358
- artificially add it. In fact, it wouldn't work at all,
2359
- because the new node would try to create this account at
2360
- startup, even though it already exists, leading to an error.*)
2361
- ~ledger:
2362
- { ledger with
2363
- base = Accounts accounts
2364
- ; add_genesis_winner = Some false
2365
- }
2366
- ~proof: (Runtime_config.Proof_keys. make ~fork () )
2367
- ()
2368
- in
2369
- let new_config = Runtime_config. combine runtime_config update in
2370
+ | Ok new_config ->
2370
2371
Runtime_config. to_yojson new_config |> Yojson.Safe. to_basic ) )
2371
2372
2372
2373
let thread_graph =
0 commit comments