Skip to content

Commit

Permalink
Revert "Merge pull request #14285 from MinaProtocol/sventimir/fix-for…
Browse files Browse the repository at this point in the history
…k-generation-develop"

This reverts commit ab24cde, reversing
changes made to 79c6253.
  • Loading branch information
nholland94 committed Jan 2, 2024
1 parent 7a2751f commit afae4c9
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 377 deletions.
1 change: 0 additions & 1 deletion src/lib/mina_graphql/dune
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
graphql_lib
block_time
currency
merkle_ledger
mina_lib
mina_commands
mina_state
Expand Down
116 changes: 52 additions & 64 deletions src/lib/mina_graphql/mina_graphql.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,15 @@ module Queries = struct
|> Runtime_config.to_yojson |> Yojson.Safe.to_basic )

let fork_config =
let rec map_results ~f = function
| [] ->
Result.return []
| r :: rs ->
let open Result.Let_syntax in
let%bind r' = f r in
let%map rs = map_results ~f rs in
r' :: rs
in
field "fork_config"
~doc:
"The runtime configuration for a blockchain fork intended to be a \
Expand All @@ -2305,80 +2314,59 @@ module Queries = struct
`Assoc [ ("error", `String "Daemon is bootstrapping") ]
| `Active best_tip -> (
let block = Transition_frontier.Breadcrumb.(block best_tip) in
let blockchain_length = Mina_block.blockchain_length block in
let global_slot =
Mina_block.consensus_state block
|> Consensus.Data.Consensus_state.curr_global_slot
Mina_block.blockchain_length block |> Unsigned.UInt32.to_int
in
let staged_ledger =
let accounts_or_error =
Transition_frontier.Breadcrumb.staged_ledger best_tip
|> Staged_ledger.ledger
|> Ledger.foldi ~init:[] ~f:(fun _ accum act -> act :: accum)
|> map_results
~f:Runtime_config.Json_layout.Accounts.Single.of_account
in
let protocol_state =
Transition_frontier.Breadcrumb.protocol_state best_tip
in
let consensus =
Mina_state.Protocol_state.consensus_state protocol_state
in
let staking_epoch =
Consensus.Proof_of_stake.Data.Consensus_state.staking_epoch_data
consensus
in
let next_epoch =
Consensus.Proof_of_stake.Data.Consensus_state.next_epoch_data
consensus
in
let staking_epoch_seed =
Mina_base.Epoch_seed.to_base58_check
staking_epoch.Mina_base.Epoch_data.Poly.seed
in
let next_epoch_seed =
Mina_base.Epoch_seed.to_base58_check
next_epoch.Mina_base.Epoch_data.Poly.seed
in
let runtime_config = Mina_lib.runtime_config mina in
match
let open Result.Let_syntax in
let%bind staking_ledger =
match Mina_lib.staking_ledger mina with
| None ->
Error "Staking ledger is not initialized."
| Some (Genesis_epoch_ledger l) ->
Ok (Ledger.Any_ledger.cast (module Ledger) l)
| Some (Ledger_db l) ->
Ok (Ledger.Any_ledger.cast (module Ledger.Db) l)
in
assert (
Mina_base.Ledger_hash.equal
(Ledger.Any_ledger.M.merkle_root staking_ledger)
staking_epoch.ledger.hash ) ;
let%bind next_epoch_ledger =
match Mina_lib.next_epoch_ledger mina with
| None ->
Error "Next epoch ledger is not initialized."
| Some `Notfinalized ->
Ok None
| Some (`Finalized (Genesis_epoch_ledger l)) ->
Ok (Some (Ledger.Any_ledger.cast (module Ledger) l))
| Some (`Finalized (Ledger_db l)) ->
Ok (Some (Ledger.Any_ledger.cast (module Ledger.Db) l))
in
let protocol_state_hash =
Transition_frontier.Breadcrumb.state_hash best_tip
in
Option.iter next_epoch_ledger ~f:(fun ledger ->
assert (
Mina_base.Ledger_hash.equal
(Ledger.Any_ledger.M.merkle_root ledger)
next_epoch.ledger.hash ) ) ;
Runtime_config.make_fork_config ~staged_ledger ~global_slot
~staking_ledger ~staking_epoch_seed ~next_epoch_ledger
~next_epoch_seed ~blockchain_length ~protocol_state_hash
runtime_config
with
match accounts_or_error with
| Error e ->
`Assoc [ ("error", `String e) ]
| Ok new_config ->
| Ok accounts ->
let runtime_config = Mina_lib.runtime_config mina in
let ledger = Option.value_exn runtime_config.ledger in
let previous_length =
let open Option.Let_syntax in
let%bind proof = runtime_config.proof in
let%map fork = proof.fork in
fork.previous_length + global_slot
in
let fork =
Runtime_config.Fork_config.
{ previous_state_hash =
State_hash.to_base58_check
protocol_state.previous_state_hash
; previous_length =
Option.value ~default:global_slot previous_length
; genesis_slot = global_slot
}
in
let update =
Runtime_config.make
(* add_genesis_winner must be set to false, because this
config effectively creates a continuation of the current
blockchain state and therefore the genesis ledger already
contains the winner of the previous block. No need to
artificially add it. In fact, it wouldn't work at all,
because the new node would try to create this account at
startup, even though it already exists, leading to an error.*)
~ledger:
{ ledger with
base = Accounts accounts
; add_genesis_winner = Some false
}
~proof:(Runtime_config.Proof_keys.make ~fork ())
()
in
let new_config = Runtime_config.combine runtime_config update in
Runtime_config.to_yojson new_config |> Yojson.Safe.to_basic ) )

let thread_graph =
Expand Down
5 changes: 1 addition & 4 deletions src/lib/runtime_config/dune
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@
data_hash_lib
kimchi_backend.pasta
kimchi_backend.pasta.basic
merkle_ledger
mina_base
mina_base.import
mina_ledger
mina_numbers
signature_lib
snark_params
unsigned_extended
pickles
pickles.backend
pickles_types
with_hash
signature_lib
staged_ledger
)
(instrumentation (backend bisect_ppx))
(preprocess (pps ppx_custom_printf ppx_sexp_conv ppx_let ppx_deriving_yojson
Expand Down
Loading

0 comments on commit afae4c9

Please sign in to comment.