Skip to content

Commit

Permalink
Merge pull request #15077 from MinaProtocol/fix/fork-config-rename
Browse files Browse the repository at this point in the history
Fork_config loses previous_ label
  • Loading branch information
mrmr1993 authored Feb 14, 2024
2 parents 00f2712 + 6a44a94 commit 524c0c6
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 69 deletions.
6 changes: 3 additions & 3 deletions src/config/fork.mlh
Original file line number Diff line number Diff line change
@@ -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]
6 changes: 3 additions & 3 deletions src/config/fork_at_3757.mlh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[%%define fork_previous_length 3757]
[%%define fork_previous_state_hash "3NKR3QYJ7qwxiGgX39umahgdT8BH5yXBQwQtpYZdvodCXcsndK7f"]
[%%define fork_previous_global_slot 12796]
[%%define fork_blockchain_length 3757]
[%%define fork_state_hash "3NKR3QYJ7qwxiGgX39umahgdT8BH5yXBQwQtpYZdvodCXcsndK7f"]
[%%define fork_global_slot_since_genesis 12796]
2 changes: 1 addition & 1 deletion src/lib/blockchain_snark/blockchain_snark_state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/consensus/constants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
18 changes: 9 additions & 9 deletions src/lib/consensus/proof_of_stake.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 }
Expand Down
34 changes: 17 additions & 17 deletions src/lib/genesis_constants/genesis_constants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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]
Expand Down
24 changes: 11 additions & 13 deletions src/lib/genesis_ledger_helper/lib/genesis_ledger_helper_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
} )
}

Expand Down Expand Up @@ -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
} )
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/mina_state/genesis_protocol_state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions src/lib/network_pool/indexed_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 16 additions & 16 deletions src/lib/runtime_config/runtime_config.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 =
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/lib/snark_keys_header/snark_keys_header.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 524c0c6

Please sign in to comment.