Skip to content

Commit 77db665

Browse files
authored
Merge pull request #17781 from MinaProtocol/cjjdespres/fork-config-of-hashes
Add runtime config method for hard fork config
2 parents 7690daf + 7225559 commit 77db665

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/lib/runtime_config/runtime_config.ml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,8 @@ module Accounts = struct
833833
Result.bind ~f:of_json_layout (Json_layout.Accounts.of_yojson json)
834834
end
835835

836+
(** Parameters for protocol constants that specify the genesis ledger used by
837+
the network *)
836838
module Ledger = struct
837839
type base =
838840
| Named of string (** One of the named ledgers in [Genesis_ledger] *)
@@ -1186,6 +1188,8 @@ module Proof_keys = struct
11861188
}
11871189
end
11881190

1191+
(** Parameters for protocol constants that specify slot spans, and relate slot
1192+
spans to system times *)
11891193
module Genesis = struct
11901194
type t = Json_layout.Genesis.t =
11911195
{ k : int option (* the depth of finality constant (in slots) *)
@@ -1349,6 +1353,8 @@ module Daemon = struct
13491353
}
13501354
end
13511355

1356+
(** Parameters for protocol constants that specify the genesis epoch ledger
1357+
snapshots used by the network *)
13521358
module Epoch_data = struct
13531359
module Data = struct
13541360
type t = { ledger : Ledger.t; seed : string }
@@ -1573,6 +1579,17 @@ let ledger_of_accounts accounts =
15731579
; add_genesis_winner = Some false
15741580
}
15751581

1582+
let ledger_of_hashes ~root_hash ~s3_data_hash () =
1583+
Ledger.
1584+
{ base = Hash
1585+
; num_accounts = None
1586+
; balances = []
1587+
; hash = Some root_hash
1588+
; s3_data_hash = Some s3_data_hash
1589+
; name = None
1590+
; add_genesis_winner = Some false
1591+
}
1592+
15761593
let make_fork_config ~staged_ledger ~global_slot_since_genesis ~state_hash
15771594
~blockchain_length ~staking_ledger ~staking_epoch_seed ~next_epoch_ledger
15781595
~next_epoch_seed =
@@ -1649,3 +1666,49 @@ let slot_tx_end, slot_chain_end =
16491666
t.daemon >>= get_runtime >>| Mina_numbers.Global_slot_since_hard_fork.of_int
16501667
in
16511668
(f (fun d -> d.slot_tx_end), f (fun d -> d.slot_chain_end))
1669+
1670+
(** This method creates a runtime daemon config for a hard fork, containing the
1671+
data that can't necessarily be computed in advance of the hard fork. This
1672+
ends up being data that's computed based on the last block produced before
1673+
the transaction stop slot. The only exception is the
1674+
[genesis_state_timestamp]; this value will be known in advance if the hard
1675+
fork automation MIP is accepted, but it is convenient to include this
1676+
parameter in the config for testing purposes. That way, the output of
1677+
[make_automatic_fork_config] will set the same fields as the config created
1678+
by the legacy hard fork config generation procedure. *)
1679+
let make_automatic_fork_config ~genesis_state_timestamp ~genesis_ledger_config
1680+
~global_slot_since_genesis ~state_hash ~blockchain_length
1681+
~staking_ledger_config ~staking_epoch_seed ~next_epoch_ledger_config
1682+
~next_epoch_seed =
1683+
let genesis =
1684+
Genesis.
1685+
{ genesis_state_timestamp = Some genesis_state_timestamp
1686+
; k = None
1687+
; delta = None
1688+
; slots_per_epoch = None
1689+
; slots_per_sub_window = None
1690+
; grace_period_slots = None
1691+
}
1692+
in
1693+
let global_slot_since_genesis =
1694+
Mina_numbers.Global_slot_since_genesis.to_int global_slot_since_genesis
1695+
in
1696+
let blockchain_length = Unsigned.UInt32.to_int blockchain_length in
1697+
let fork =
1698+
Fork_config.
1699+
{ state_hash = Mina_base.State_hash.to_base58_check state_hash
1700+
; blockchain_length
1701+
; global_slot_since_genesis
1702+
}
1703+
in
1704+
let epoch_data =
1705+
let open Epoch_data in
1706+
let open Data in
1707+
{ staking = { ledger = staking_ledger_config; seed = staking_epoch_seed }
1708+
; next =
1709+
Option.map next_epoch_ledger_config ~f:(fun config ->
1710+
{ ledger = config; seed = next_epoch_seed } )
1711+
}
1712+
in
1713+
make ~genesis ~epoch_data ~ledger:genesis_ledger_config
1714+
~proof:(Proof_keys.make ~fork ()) ()

0 commit comments

Comments
 (0)