diff --git a/scripts/hardfork/build-and-test.sh b/scripts/hardfork/build-and-test.sh index cb399bf2e1d3..37f12f99f156 100755 --- a/scripts/hardfork/build-and-test.sh +++ b/scripts/hardfork/build-and-test.sh @@ -77,10 +77,10 @@ if [[ ! -L compatible-devnet ]]; then fi git submodule sync --recursive git submodule update --init --recursive - git apply "$SCRIPT_DIR"/localnet-patches/compatible-{1,2}.patch + git apply "$SCRIPT_DIR"/localnet-patches/compatible.patch nix "${NIX_OPTS[@]}" build "$compatible_build?submodules=1#devnet" --out-link "$INIT_DIR/compatible-devnet" nix "${NIX_OPTS[@]}" build "$compatible_build?submodules=1#devnet.genesis" --out-link "$INIT_DIR/compatible-devnet" - git apply -R "$SCRIPT_DIR"/localnet-patches/compatible-{1,2}.patch + git apply -R "$SCRIPT_DIR"/localnet-patches/compatible.patch if [[ $# == 0 ]]; then cd - rm -Rf "$compatible_build" diff --git a/scripts/hardfork/localnet-patches/compatible-2.patch b/scripts/hardfork/localnet-patches/compatible-2.patch deleted file mode 100644 index 23f446d2ca53..000000000000 --- a/scripts/hardfork/localnet-patches/compatible-2.patch +++ /dev/null @@ -1,269 +0,0 @@ -From 0ae23d96a5c5ef4d2826ddad7d80fb02c843ec86 Mon Sep 17 00:00:00 2001 -From: georgeee -Date: Thu, 29 Feb 2024 12:37:58 +0100 -Subject: [PATCH] Port runtime_genesis_ledger from Berkeley (without SHA3 hash) - ---- - nix/ocaml.nix | 5 +- - src/app/runtime_genesis_ledger/dune | 12 +- - .../runtime_genesis_ledger.ml | 174 ++++++++++++++---- - 3 files changed, 149 insertions(+), 42 deletions(-) - -diff --git a/nix/ocaml.nix b/nix/ocaml.nix -index ebdd36800d..dbcc62d399 100644 ---- a/nix/ocaml.nix -+++ b/nix/ocaml.nix -@@ -182,9 +182,10 @@ let - src/app/rosetta/rosetta_testnet_signatures.exe \ - src/app/rosetta/rosetta_mainnet_signatures.exe \ - src/app/generate_keypair/generate_keypair.exe \ -+ src/app/runtime_genesis_ledger/runtime_genesis_ledger.exe \ - src/lib/mina_base/sample_keypairs.json \ - -j$NIX_BUILD_CORES -- dune exec src/app/runtime_genesis_ledger/runtime_genesis_ledger.exe -- --genesis-dir _build/coda_cache_dir -+ # dune exec src/app/runtime_genesis_ledger/runtime_genesis_ledger.exe -- --genesis-dir _build/coda_cache_dir - dune build @doc || true - ''; - -@@ -193,7 +194,7 @@ let - - installPhase = '' - mkdir -p $out/bin $sample/share/mina $out/share/doc $generate_keypair/bin $mainnet/bin $testnet/bin $genesis/bin $genesis/var/lib/coda $batch_txn_tool/bin -- mv _build/coda_cache_dir/genesis* $genesis/var/lib/coda -+ # mv _build/coda_cache_dir/genesis* $genesis/var/lib/coda - pushd _build/default - cp src/app/cli/src/mina.exe $out/bin/mina - cp src/app/logproc/logproc.exe $out/bin/logproc -diff --git a/src/app/runtime_genesis_ledger/dune b/src/app/runtime_genesis_ledger/dune -index 2dd27537d5..c989d10cfe 100644 ---- a/src/app/runtime_genesis_ledger/dune -+++ b/src/app/runtime_genesis_ledger/dune -@@ -7,6 +7,7 @@ - core_kernel - async_kernel - async -+ async_unix - core - result - async.async_command -@@ -17,14 +18,9 @@ - logger - cache_dir - mina_base -+ precomputed_values -+ coda_genesis_ledger - ) - (preprocessor_deps ../../config.mlh) - (instrumentation (backend bisect_ppx)) -- (preprocess (pps ppx_version ppx_let ppx_optcomp ppx_deriving_yojson))) -- --(rule -- (targets genesis_filename.txt) -- (deps -- (:< gen/gen.exe)) -- (action -- (run %{<}))) -+ (preprocess (pps ppx_jane ppx_version ppx_let ppx_deriving_yojson ppx_coda))) -diff --git a/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml b/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml -index efa8d49f93..1032d3a852 100644 ---- a/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml -+++ b/src/app/runtime_genesis_ledger/runtime_genesis_ledger.ml -@@ -2,53 +2,163 @@ open Core - open Async - open Mina_base - --type t = Ledger.t -- --let main ~config_file ~genesis_dir ~proof_level () = -- let%bind config = -- match config_file with -- | Some config_file -> ( -- let%map config_json = -- Deferred.Or_error.ok_exn -- @@ Genesis_ledger_helper.load_config_json config_file -- in -- match Runtime_config.of_yojson config_json with -- | Ok config -> -- config -- | Error err -> -- failwithf "Could not parse configuration: %s" err () ) -- | None -> -- return Runtime_config.default -- in -- Deferred.Or_error.ok_exn @@ Deferred.Or_error.ignore_m -- @@ Genesis_ledger_helper.init_from_config_file ?genesis_dir -- ~logger:(Logger.create ()) ~proof_level config -+module Hashes = struct -+ type t = { hash : string } [@@deriving to_yojson] -+end -+ -+module Hash_json = struct -+ type epoch_data = { staking : Hashes.t; next : Hashes.t } -+ [@@deriving to_yojson] -+ -+ type t = { ledger : Hashes.t; epoch_data : epoch_data } [@@deriving to_yojson] -+end -+ -+let ledger_depth = -+ Genesis_constants.Constraint_constants.compiled -+ .ledger_depth -+ -+let logger = Logger.create () -+ -+let load_ledger (accounts : Runtime_config.Accounts.t) = -+ let accounts = -+ List.map accounts ~f:(fun account -> -+ (None, Runtime_config.Accounts.Single.to_account account) ) -+ in -+ let packed = -+ Genesis_ledger_helper.Ledger.packed_genesis_ledger_of_accounts -+ ~depth:ledger_depth -+ (lazy accounts) -+ in -+ Lazy.force (Genesis_ledger.Packed.t packed) -+ -+let generate_ledger_tarball ~genesis_dir ~ledger_name_prefix ledger = -+ let%map tar_path = -+ Deferred.Or_error.ok_exn -+ @@ Genesis_ledger_helper.Ledger.generate_tar ~genesis_dir ~logger -+ ~ledger_name_prefix ledger -+ in -+ [%log info] "Generated ledger tar at %s" tar_path ; -+ let hash = -+ Mina_base.Ledger_hash.to_base58_check -+ @@ Ledger.merkle_root ledger -+ in -+ { Hashes.hash } -+ -+let generate_hash_json ~genesis_dir ledger staking_ledger next_ledger = -+ let%bind ledger_hashes = -+ generate_ledger_tarball ~ledger_name_prefix:"genesis_ledger" ~genesis_dir -+ ledger -+ in -+ let%bind staking = -+ generate_ledger_tarball ~ledger_name_prefix:"epoch_ledger" ~genesis_dir -+ staking_ledger -+ in -+ let%map next = -+ generate_ledger_tarball ~ledger_name_prefix:"epoch_ledger" ~genesis_dir -+ next_ledger -+ in -+ { Hash_json.ledger = ledger_hashes; epoch_data = { staking; next } } -+ -+let is_dirty_proof = function -+ | Runtime_config.Proof_keys. -+ { level = None -+ ; sub_windows_per_window = None -+ ; ledger_depth = None -+ ; work_delay = None -+ ; block_window_duration_ms = None -+ ; transaction_capacity = None -+ ; coinbase_amount = None -+ ; supercharged_coinbase_factor = None -+ ; account_creation_fee = None -+ ; fork = _ -+ } -> -+ false -+ | _ -> -+ true -+ -+let extract_accounts_exn = function -+ | { Runtime_config.Ledger.base = Accounts accounts -+ ; num_accounts = None -+ ; balances = [] -+ (* ; add_genesis_winner = Some false *) -+ ; _ -+ } -> -+ accounts -+ | _ -> -+ failwith "Wrong ledger supplied" -+ -+let load_config_exn config_file = -+ let%map config_json = -+ Deferred.Or_error.ok_exn -+ @@ Genesis_ledger_helper.load_config_json config_file -+ in -+ let config = -+ Runtime_config.of_yojson config_json -+ |> Result.map_error ~f:(fun err -> -+ Failure ("Could not parse configuration: " ^ err) ) -+ |> Result.ok_exn -+ in -+ if -+ Option.( -+ is_some config.daemon || is_some config.genesis -+ || Option.value_map ~default:false ~f:is_dirty_proof config.proof) -+ then failwith "Runtime config has unexpected fields" ; -+ let ledger = Option.value_exn ~message:"No ledger provided" config.ledger in -+ let staking_ledger = -+ let%map.Option { staking; _ } = config.epoch_data in -+ staking.ledger -+ in -+ let next_ledger = -+ let%bind.Option { next; _ } = config.epoch_data in -+ let%map.Option { ledger; _ } = next in -+ ledger -+ in -+ ( extract_accounts_exn ledger -+ , Option.map ~f:extract_accounts_exn staking_ledger -+ , Option.map ~f:extract_accounts_exn next_ledger ) -+ -+let main ~config_file ~genesis_dir ~hash_output_file () = -+ let%bind accounts, staking_accounts_opt, next_accounts_opt = -+ load_config_exn config_file -+ in -+ let ledger = load_ledger accounts in -+ let staking_ledger = -+ Option.value_map ~default:ledger ~f:load_ledger staking_accounts_opt -+ in -+ let next_ledger = -+ Option.value_map ~default:staking_ledger ~f:load_ledger next_accounts_opt -+ in -+ let%bind hash_json = -+ generate_hash_json ~genesis_dir ledger staking_ledger next_ledger -+ in -+ Async.Writer.save hash_output_file -+ ~contents:(Yojson.Safe.to_string (Hash_json.to_yojson hash_json)) - - let () = - Command.run - (Command.async - ~summary: - "Generate the genesis ledger and genesis proof for a given \ -- configuration file, or for the compile-time configuration if none \ -- is provided" -+ configuration file, or for the compile-time configuration if none is \ -+ provided" - Command.( - let open Let_syntax in - let open Command.Param in - let%map config_file = - flag "--config-file" ~doc:"PATH path to the JSON configuration file" -- (optional string) -+ (required string) - and genesis_dir = - flag "--genesis-dir" - ~doc: - (sprintf - "Dir where the genesis ledger and genesis proof is to be \ - saved (default: %s)" -- Cache_dir.autogen_path) -- (optional string) -- and proof_level = -- flag "--proof-level" -- (optional -- (Arg_type.create Genesis_constants.Proof_level.of_string)) -- ~doc:"full|check|none" -+ Cache_dir.autogen_path ) -+ (required string) -+ and hash_output_file = -+ flag "--hash-output-file" (required string) -+ ~doc: -+ "PATH path to the file where the hashes of the ledgers are to \ -+ be saved" - in -- main ~config_file ~genesis_dir ~proof_level)) -+ main ~config_file ~genesis_dir ~hash_output_file) ) --- -2.18.1 - diff --git a/scripts/hardfork/localnet-patches/compatible-1.patch b/scripts/hardfork/localnet-patches/compatible.patch similarity index 100% rename from scripts/hardfork/localnet-patches/compatible-1.patch rename to scripts/hardfork/localnet-patches/compatible.patch