Skip to content

Commit eff2f2a

Browse files
committed
Merge branch 'sventimir/fix-fork-config-generation' into sventimir/fix-fork-config-generation-berkeley
2 parents 57f3e00 + a8c6f2b commit eff2f2a

File tree

4 files changed

+368
-141
lines changed

4 files changed

+368
-141
lines changed

src/lib/mina_graphql/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
graphql_lib
6161
block_time
6262
currency
63+
merkle_ledger
6364
mina_lib
6465
mina_commands
6566
mina_state

src/lib/mina_graphql/mina_graphql.ml

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,15 +2293,6 @@ module Queries = struct
22932293
|> Runtime_config.to_yojson |> Yojson.Safe.to_basic )
22942294

22952295
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
23052296
field "fork_config"
23062297
~doc:
23072298
"The runtime configuration for a blockchain fork intended to be a \
@@ -2314,59 +2305,69 @@ module Queries = struct
23142305
`Assoc [ ("error", `String "Daemon is bootstrapping") ]
23152306
| `Active best_tip -> (
23162307
let block = Transition_frontier.Breadcrumb.(block best_tip) in
2308+
let blockchain_length = Mina_block.blockchain_length block in
23172309
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
23192312
in
2320-
let accounts_or_error =
2313+
let staged_ledger =
23212314
Transition_frontier.Breadcrumb.staged_ledger best_tip
23222315
|> 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
23262316
in
23272317
let protocol_state =
23282318
Transition_frontier.Breadcrumb.protocol_state best_tip
23292319
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
23312368
| Error e ->
23322369
`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 ->
23702371
Runtime_config.to_yojson new_config |> Yojson.Safe.to_basic ) )
23712372

23722373
let thread_graph =

src/lib/runtime_config/dune

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616
data_hash_lib
1717
kimchi_backend.pasta
1818
kimchi_backend.pasta.basic
19+
merkle_ledger
1920
mina_base
2021
mina_base.import
22+
mina_ledger
2123
mina_numbers
22-
signature_lib
2324
ppx_dhall_type
2425
snark_params
2526
unsigned_extended
2627
pickles
2728
pickles.backend
2829
pickles_types
2930
with_hash
31+
signature_lib
32+
staged_ledger
3033
)
3134
(instrumentation (backend bisect_ppx))
3235
(preprocess (pps ppx_custom_printf ppx_sexp_conv ppx_let ppx_deriving_yojson

0 commit comments

Comments
 (0)