|
| 1 | +open Core |
| 2 | +open Currency |
| 3 | +open Genesis_ledger |
| 4 | + |
| 5 | +let ledger_is_prefix ledger1 ledger2 = |
| 6 | + List.is_prefix ledger2 ~prefix:ledger1 |
| 7 | + ~equal:(fun |
| 8 | + ({ account_name = name1; _ } : Test_config.Test_account.t) |
| 9 | + ({ account_name = name2; _ } : Test_config.Test_account.t) |
| 10 | + -> String.equal name1 name2 ) |
| 11 | + |
| 12 | +let create ~(test_config : Test_config.t) ~(genesis_ledger : Genesis_ledger.t) = |
| 13 | + { Runtime_config.daemon = |
| 14 | + Some |
| 15 | + { txpool_max_size = Some test_config.txpool_max_size |
| 16 | + ; peer_list_url = None |
| 17 | + ; zkapp_proof_update_cost = None |
| 18 | + ; zkapp_signed_single_update_cost = None |
| 19 | + ; zkapp_signed_pair_update_cost = None |
| 20 | + ; zkapp_transaction_cost_limit = None |
| 21 | + ; max_event_elements = None |
| 22 | + ; max_action_elements = None |
| 23 | + ; zkapp_cmd_limit_hardcap = None |
| 24 | + ; slot_tx_end = test_config.slot_tx_end |
| 25 | + ; slot_chain_end = test_config.slot_chain_end |
| 26 | + ; hard_fork_genesis_slot_delta = |
| 27 | + test_config.hard_fork_genesis_slot_delta |
| 28 | + ; minimum_user_command_fee = None |
| 29 | + ; network_id = test_config.network_id |
| 30 | + ; sync_ledger_max_subtree_depth = None |
| 31 | + ; sync_ledger_default_subtree_depth = None |
| 32 | + } |
| 33 | + ; genesis = |
| 34 | + Some |
| 35 | + { k = Some test_config.k |
| 36 | + ; delta = Some test_config.delta |
| 37 | + ; slots_per_epoch = Some test_config.slots_per_epoch |
| 38 | + ; slots_per_sub_window = Some test_config.slots_per_sub_window |
| 39 | + ; grace_period_slots = Some test_config.grace_period_slots |
| 40 | + ; genesis_state_timestamp = |
| 41 | + Some Core.Time.(to_string_abs ~zone:Zone.utc (now ())) |
| 42 | + } |
| 43 | + ; proof = |
| 44 | + Some test_config.proof_config (* TODO: prebake ledger and only set hash *) |
| 45 | + ; ledger = |
| 46 | + Some |
| 47 | + { base = |
| 48 | + Accounts |
| 49 | + (List.map genesis_ledger.accounts ~f:(fun (_name, acct) -> acct)) |
| 50 | + ; add_genesis_winner = None |
| 51 | + ; num_accounts = None |
| 52 | + ; balances = [] |
| 53 | + ; hash = None |
| 54 | + ; s3_data_hash = None |
| 55 | + ; name = None |
| 56 | + } |
| 57 | + ; epoch_data = |
| 58 | + (* each staking epoch ledger account must also be a genesis ledger account, though |
| 59 | + the balance may be different; the converse is not necessarily true, since |
| 60 | + an account may have been added after the last epoch ledger was taken |
| 61 | +
|
| 62 | + each staking epoch ledger account must also be in the next epoch ledger, if provided |
| 63 | +
|
| 64 | + if provided, each next_epoch_ledger account must be in the genesis ledger |
| 65 | +
|
| 66 | + in all ledgers, the accounts must be in the same order, so that accounts will |
| 67 | + be in the same leaf order |
| 68 | + *) |
| 69 | + Option.map test_config.epoch_data |
| 70 | + ~f:(fun { staking = staking_ledger; next } -> |
| 71 | + let genesis_winner_account : Runtime_config.Accounts.single = |
| 72 | + Runtime_config.Accounts.Single.of_account |
| 73 | + Mina_state.Consensus_state_hooks.genesis_winner_account |
| 74 | + |> Or_error.ok_exn |
| 75 | + in |
| 76 | + let ledger_of_epoch_accounts |
| 77 | + (epoch_accounts : Test_config.Test_account.t list) = |
| 78 | + let epoch_ledger_accounts = |
| 79 | + List.map epoch_accounts |
| 80 | + ~f:(fun { account_name; balance; timing; permissions; zkapp } -> |
| 81 | + let balance = Balance.of_mina_string_exn balance in |
| 82 | + let timing = runtime_timing_of_timing timing in |
| 83 | + let genesis_account = |
| 84 | + match |
| 85 | + List.Assoc.find genesis_ledger.accounts account_name |
| 86 | + ~equal:String.equal |
| 87 | + with |
| 88 | + | Some acct -> |
| 89 | + acct |
| 90 | + | None -> |
| 91 | + failwithf |
| 92 | + "Epoch ledger account %s not in genesis ledger" |
| 93 | + account_name () |
| 94 | + in |
| 95 | + { genesis_account with |
| 96 | + balance |
| 97 | + ; timing |
| 98 | + ; permissions = |
| 99 | + Option.map |
| 100 | + ~f: |
| 101 | + Runtime_config.Accounts.Single.Permissions |
| 102 | + .of_permissions permissions |
| 103 | + ; zkapp = |
| 104 | + Option.map |
| 105 | + ~f:Runtime_config.Accounts.Single.Zkapp_account.of_zkapp |
| 106 | + zkapp |
| 107 | + } ) |
| 108 | + in |
| 109 | + (* because we run integration tests with Proof_level = Full, the winner account |
| 110 | + gets added to the genesis ledger |
| 111 | + there isn't a corresponding mechanism to add the winner account to epoch |
| 112 | + ledgers, so we add it explicitly here |
| 113 | + `add_genesis_winner` in the record below has no effect, it's ignored in |
| 114 | + Runtime_config.Epoch_data.to_yojson, which is used to create the config file |
| 115 | + *) |
| 116 | + ( { base = Accounts (genesis_winner_account :: epoch_ledger_accounts) |
| 117 | + ; add_genesis_winner = None (* no effect *) |
| 118 | + ; num_accounts = None |
| 119 | + ; balances = [] |
| 120 | + ; hash = None |
| 121 | + ; s3_data_hash = None |
| 122 | + ; name = None |
| 123 | + } |
| 124 | + : Runtime_config.Ledger.t ) |
| 125 | + in |
| 126 | + let staking = |
| 127 | + let ({ epoch_ledger; epoch_seed } : Test_config.Epoch_data.Data.t) = |
| 128 | + staking_ledger |
| 129 | + in |
| 130 | + if not (ledger_is_prefix epoch_ledger test_config.genesis_ledger) |
| 131 | + then failwith "Staking epoch ledger not a prefix of genesis ledger" ; |
| 132 | + let ledger = ledger_of_epoch_accounts epoch_ledger in |
| 133 | + let seed = epoch_seed in |
| 134 | + ({ ledger; seed } : Runtime_config.Epoch_data.Data.t) |
| 135 | + in |
| 136 | + let next = |
| 137 | + Option.map next ~f:(fun { epoch_ledger; epoch_seed } -> |
| 138 | + if |
| 139 | + not |
| 140 | + (ledger_is_prefix staking_ledger.epoch_ledger epoch_ledger) |
| 141 | + then |
| 142 | + failwith |
| 143 | + "Staking epoch ledger not a prefix of next epoch ledger" ; |
| 144 | + if |
| 145 | + not (ledger_is_prefix epoch_ledger test_config.genesis_ledger) |
| 146 | + then failwith "Next epoch ledger not a prefix of genesis ledger" ; |
| 147 | + let ledger = ledger_of_epoch_accounts epoch_ledger in |
| 148 | + let seed = epoch_seed in |
| 149 | + ({ ledger; seed } : Runtime_config.Epoch_data.Data.t) ) |
| 150 | + in |
| 151 | + ({ staking; next } : Runtime_config.Epoch_data.t) ) |
| 152 | + } |
0 commit comments