diff --git a/src/config/fork.mlh b/src/config/fork.mlh index 0c8e8dab67e..c09b7b0434c 100644 --- a/src/config/fork.mlh +++ b/src/config/fork.mlh @@ -1,3 +1,3 @@ -[%%undef fork_previous_length] -[%%undef fork_previous_state_hash] -[%%undef fork_previous_global_slot] +[%%undef fork_blockchain_length] +[%%undef fork_state_hash] +[%%undef fork_global_slot_since_genesis] diff --git a/src/config/fork_at_3757.mlh b/src/config/fork_at_3757.mlh index 5ff73e82f57..67d0a579af1 100644 --- a/src/config/fork_at_3757.mlh +++ b/src/config/fork_at_3757.mlh @@ -1,3 +1,3 @@ -[%%define fork_previous_length 3757] -[%%define fork_previous_state_hash "3NKR3QYJ7qwxiGgX39umahgdT8BH5yXBQwQtpYZdvodCXcsndK7f"] -[%%define fork_previous_global_slot 12796] \ No newline at end of file +[%%define fork_blockchain_length 3757] +[%%define fork_state_hash "3NKR3QYJ7qwxiGgX39umahgdT8BH5yXBQwQtpYZdvodCXcsndK7f"] +[%%define fork_global_slot_since_genesis 12796] \ No newline at end of file diff --git a/src/lib/blockchain_snark/blockchain_snark_state.ml b/src/lib/blockchain_snark/blockchain_snark_state.ml index 2b3d0ee0552..8fa03849421 100644 --- a/src/lib/blockchain_snark/blockchain_snark_state.ml +++ b/src/lib/blockchain_snark/blockchain_snark_state.ml @@ -123,7 +123,7 @@ let%snarkydef step ~(logger : Logger.t) in let%bind previous_state_hash = match constraint_constants.fork with - | Some { previous_state_hash = fork_prev; _ } -> + | Some { state_hash = fork_prev; _ } -> State_hash.if_ is_base_case ~then_:(State_hash.var_of_t fork_prev) ~else_:t.previous_state_hash diff --git a/src/lib/consensus/constants.ml b/src/lib/consensus/constants.ml index ce0798073dc..bdf71d7e502 100644 --- a/src/lib/consensus/constants.ml +++ b/src/lib/consensus/constants.ml @@ -240,7 +240,7 @@ let create' (type a b c) slots | Some f -> M.( + ) - (M.constant (Unsigned.UInt32.to_int f.previous_global_slot)) + (M.constant (Unsigned.UInt32.to_int f.global_slot_since_genesis)) slots in let res : (a, b, c) Poly.t = diff --git a/src/lib/consensus/proof_of_stake.ml b/src/lib/consensus/proof_of_stake.ml index fe7a6b0c5be..a30e8dcaa07 100644 --- a/src/lib/consensus/proof_of_stake.ml +++ b/src/lib/consensus/proof_of_stake.ml @@ -2033,10 +2033,10 @@ module Data = struct match constraint_constants.fork with | None -> (Length.zero, Mina_numbers.Global_slot.zero) - | Some { previous_length; previous_global_slot; _ } -> + | Some { blockchain_length; global_slot_since_genesis; _ } -> (*Note: global_slot_since_genesis at fork point is the same as global_slot_since_genesis in the new genesis. This value is used to check transaction validity and existence of locked tokens. For reviewers, should this be incremented by 1 because it's technically a new block? we don't really know how many slots passed since the fork point*) - (previous_length, previous_global_slot) + (blockchain_length, global_slot_since_genesis) in let default_epoch_data = Genesis_epoch_data.Data. @@ -3625,12 +3625,12 @@ let%test_module "Proof of stake tests" = | Some fork -> assert ( Mina_numbers.Global_slot.( - equal fork.previous_global_slot + equal fork.global_slot_since_genesis previous_consensus_state.global_slot_since_genesis) ) ; assert ( Mina_numbers.Length.( equal - (succ fork.previous_length) + (succ fork.blockchain_length) previous_consensus_state.blockchain_length) ) ) ; let global_slot = Core_kernel.Time.now () |> Time.of_time @@ -3701,12 +3701,12 @@ let%test_module "Proof of stake tests" = assert ( Mina_numbers.Global_slot.( equal - (add fork.previous_global_slot slot_diff) + (add fork.global_slot_since_genesis slot_diff) next_consensus_state.global_slot_since_genesis) ) ; assert ( Mina_numbers.Length.( equal - (succ (succ fork.previous_length)) + (succ (succ fork.blockchain_length)) next_consensus_state.blockchain_length) ) ) ; (* build pieces needed to apply "update_var" *) let checked_computation = @@ -3800,13 +3800,13 @@ let%test_module "Proof of stake tests" = let constraint_constants_with_fork = let fork_constants = Some - { Genesis_constants.Fork_constants.previous_state_hash = + { Genesis_constants.Fork_constants.state_hash = Result.ok_or_failwith (State_hash.of_yojson (`String "3NL3bc213VQEFx6XTLbc3HxHqHH9ANbhHxRxSnBcRzXcKgeFA6TY" ) ) - ; previous_length = Mina_numbers.Length.of_int 100 - ; previous_global_slot = Mina_numbers.Global_slot.of_int 200 + ; blockchain_length = Mina_numbers.Length.of_int 100 + ; global_slot_since_genesis = Mina_numbers.Global_slot.of_int 200 } in { constraint_constants with fork = fork_constants } diff --git a/src/lib/genesis_constants/genesis_constants.ml b/src/lib/genesis_constants/genesis_constants.ml index 8c82979e46d..d2d757cea0c 100644 --- a/src/lib/genesis_constants/genesis_constants.ml +++ b/src/lib/genesis_constants/genesis_constants.ml @@ -26,9 +26,9 @@ end module Fork_constants = struct type t = - { previous_state_hash : Pickles.Backend.Tick.Field.Stable.Latest.t - ; previous_length : Mina_numbers.Length.Stable.Latest.t - ; previous_global_slot : Mina_numbers.Global_slot.Stable.Latest.t + { state_hash : Pickles.Backend.Tick.Field.Stable.Latest.t + ; blockchain_length : Mina_numbers.Length.Stable.Latest.t + ; global_slot_since_genesis : Mina_numbers.Global_slot.Stable.Latest.t } [@@deriving bin_io_unversioned, sexp, equal, compare, yojson] end @@ -67,13 +67,12 @@ module Constraint_constants = struct ; account_creation_fee = Currency.Fee.to_uint64 t.account_creation_fee ; fork = ( match t.fork with - | Some { previous_length; previous_state_hash; previous_global_slot } -> + | Some { blockchain_length; state_hash; global_slot_since_genesis } -> Some - { previous_length = Unsigned.UInt32.to_int previous_length - ; previous_state_hash = - Pickles.Backend.Tick.Field.to_string previous_state_hash - ; previous_global_slot = - Unsigned.UInt32.to_int previous_global_slot + { blockchain_length = Unsigned.UInt32.to_int blockchain_length + ; state_hash = Pickles.Backend.Tick.Field.to_string state_hash + ; global_slot_since_genesis = + Unsigned.UInt32.to_int global_slot_since_genesis } | None -> None ) @@ -152,27 +151,28 @@ module Constraint_constants = struct Core_kernel.Int.ceil_log2 (((transaction_capacity_log_2 + 1) * (work_delay + 1)) + 1) - [%%ifndef fork_previous_length] + [%%ifndef fork_blockchain_length] let fork = None [%%else] - [%%inject "fork_previous_length", fork_previous_length] + [%%inject "fork_blockchain_length", fork_blockchain_length] [%%inject "fork_previous_state_hash", fork_previous_state_hash] - [%%inject "fork_previous_global_slot", fork_previous_global_slot] + [%%inject + "fork_global_slot_since_genesis", fork_global_slot_since_genesis] let fork = Some - { Fork_constants.previous_length = - Mina_numbers.Length.of_int fork_previous_length - ; previous_state_hash = + { Fork_constants.blockchain_length = + Mina_numbers.Length.of_int fork_blockchain_length + ; state_hash = Data_hash_lib.State_hash.of_base58_check_exn fork_previous_state_hash - ; previous_global_slot = - Mina_numbers.Global_slot.of_int fork_previous_global_slot + ; global_slot_since_genesis = + Mina_numbers.Global_slot.of_int fork_global_slot_since_genesis } [%%endif] diff --git a/src/lib/genesis_ledger_helper/lib/genesis_ledger_helper_lib.ml b/src/lib/genesis_ledger_helper/lib/genesis_ledger_helper_lib.ml index 49f90b2b491..7d74216af76 100644 --- a/src/lib/genesis_ledger_helper/lib/genesis_ledger_helper_lib.ml +++ b/src/lib/genesis_ledger_helper/lib/genesis_ledger_helper_lib.ml @@ -430,13 +430,12 @@ let make_constraint_constants ( match config.fork with | None -> default.fork - | Some { previous_state_hash; previous_length; previous_global_slot } -> + | Some { state_hash; blockchain_length; global_slot_since_genesis } -> Some - { previous_state_hash = - State_hash.of_base58_check_exn previous_state_hash - ; previous_length = Mina_numbers.Length.of_int previous_length - ; previous_global_slot = - Mina_numbers.Global_slot.of_int previous_global_slot + { state_hash = State_hash.of_base58_check_exn state_hash + ; blockchain_length = Mina_numbers.Length.of_int blockchain_length + ; global_slot_since_genesis = + Mina_numbers.Global_slot.of_int global_slot_since_genesis } ) } @@ -465,13 +464,12 @@ let runtime_config_of_constraint_constants ; account_creation_fee = Some constraint_constants.account_creation_fee ; fork = Option.map constraint_constants.fork - ~f:(fun { previous_state_hash; previous_length; previous_global_slot } - -> - { Runtime_config.Fork_config.previous_state_hash = - State_hash.to_base58_check previous_state_hash - ; previous_length = Mina_numbers.Length.to_int previous_length - ; previous_global_slot = - Mina_numbers.Global_slot.to_int previous_global_slot + ~f:(fun { state_hash; blockchain_length; global_slot_since_genesis } -> + { Runtime_config.Fork_config.state_hash = + State_hash.to_base58_check state_hash + ; blockchain_length = Mina_numbers.Length.to_int blockchain_length + ; global_slot_since_genesis = + Mina_numbers.Global_slot.to_int global_slot_since_genesis } ) } diff --git a/src/lib/mina_state/genesis_protocol_state.ml b/src/lib/mina_state/genesis_protocol_state.ml index 0ec590a0c85..79fc3359b5b 100644 --- a/src/lib/mina_state/genesis_protocol_state.ml +++ b/src/lib/mina_state/genesis_protocol_state.ml @@ -28,7 +28,7 @@ let t ~genesis_ledger ~genesis_epoch_data ~constraint_constants ~previous_state_hash: (Option.value_map constraint_constants.fork ~default:negative_one_protocol_state_hash - ~f:(fun { previous_state_hash; _ } -> previous_state_hash) ) + ~f:(fun { state_hash; _ } -> state_hash) ) ~blockchain_state: (Blockchain_state.genesis ~constraint_constants ~consensus_constants ~genesis_ledger_hash ~snarked_next_available_token ) diff --git a/src/lib/network_pool/indexed_pool.ml b/src/lib/network_pool/indexed_pool.ml index 40ed92f83a3..0ee6da54d50 100644 --- a/src/lib/network_pool/indexed_pool.ml +++ b/src/lib/network_pool/indexed_pool.ml @@ -350,8 +350,8 @@ let current_global_slot t = |> to_global_slot) in match t.constraint_constants.fork with - | Some { previous_global_slot; _ } -> - Mina_numbers.Global_slot.(add previous_global_slot current_slot) + | Some { global_slot_since_genesis; _ } -> + Mina_numbers.Global_slot.(add global_slot_since_genesis current_slot) | None -> current_slot diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index e3a5d3df229..d8444bf7722 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1,22 +1,22 @@ open Core_kernel module Fork_config = struct - (* Note that previous_length might be smaller than the gernesis_slot + (* Note that length might be smaller than the gernesis_slot or equal if a block was produced in every slot possible. *) type t = - { previous_state_hash : string - ; previous_length : int (* number of blocks produced since genesis *) - ; previous_global_slot : int (* global slot since genesis *) + { state_hash : string + ; blockchain_length : int (* number of blocks produced since genesis *) + ; global_slot_since_genesis : int (* global slot since genesis *) } [@@deriving yojson, dhall_type, bin_io_unversioned] let gen = let open Quickcheck.Generator.Let_syntax in - let%bind previous_global_slot = Int.gen_incl 0 1_000_000 in - let%bind previous_length = Int.gen_incl 0 previous_global_slot in + let%bind global_slot_since_genesis = Int.gen_incl 0 1_000_000 in + let%bind blockchain_length = Int.gen_incl 0 global_slot_since_genesis in let%map state_hash = Mina_base.State_hash.gen in - let previous_state_hash = Mina_base.State_hash.to_base58_check state_hash in - { previous_state_hash; previous_length; previous_global_slot } + let state_hash = Mina_base.State_hash.to_base58_check state_hash in + { state_hash; blockchain_length; global_slot_since_genesis } end let yojson_strip_fields ~keep_fields = function @@ -1297,7 +1297,7 @@ let make_fork_config ~staged_ledger ~global_slot ~blockchain_length ~protocol_state ~staking_ledger ~staking_epoch_seed ~next_epoch_ledger ~next_epoch_seed (runtime_config : t) = let open Async.Deferred.Result.Let_syntax in - let global_slot = Mina_numbers.Global_slot.to_int global_slot in + let global_slot_since_genesis = Mina_numbers.Global_slot.to_int global_slot in let blockchain_length = Unsigned.UInt32.to_int blockchain_length in let yield () = let open Async.Deferred.Infix in @@ -1309,11 +1309,11 @@ let make_fork_config ~staged_ledger ~global_slot ~blockchain_length |> ledger_accounts in let ledger = Option.value_exn runtime_config.ledger in - let previous_length = + let fork_blockchain_length = let open Option.Let_syntax in let%bind proof = runtime_config.proof in let%map fork = proof.fork in - fork.previous_length + blockchain_length + fork.blockchain_length + blockchain_length in let protocol_constants = Mina_state.Protocol_state.constants protocol_state in let genesis = @@ -1332,12 +1332,12 @@ let make_fork_config ~staged_ledger ~global_slot ~blockchain_length in let fork = Fork_config. - { previous_state_hash = + { state_hash = Mina_base.State_hash.to_base58_check - protocol_state.Mina_state.Protocol_state.Poly.previous_state_hash - ; previous_length = - Option.value ~default:blockchain_length previous_length - ; previous_global_slot = global_slot + (Mina_state.Protocol_state.hashes protocol_state).state_hash + ; blockchain_length = + Option.value ~default:blockchain_length fork_blockchain_length + ; global_slot_since_genesis } in let%bind () = yield () in diff --git a/src/lib/snark_keys_header/snark_keys_header.ml b/src/lib/snark_keys_header/snark_keys_header.ml index e34b387c773..c774f34fa05 100644 --- a/src/lib/snark_keys_header/snark_keys_header.ml +++ b/src/lib/snark_keys_header/snark_keys_header.ml @@ -87,9 +87,9 @@ module Constraint_constants = struct module Fork_config = struct (** Fork data *) type t = - { previous_state_hash : string - ; previous_length : int - ; previous_global_slot : int + { state_hash : string + ; blockchain_length : int + ; global_slot_since_genesis : int } [@@deriving yojson, sexp, ord, equal]