Skip to content

Commit

Permalink
Fork_config loses previous_ label
Browse files Browse the repository at this point in the history
  • Loading branch information
emberian committed Feb 8, 2024
1 parent 46a00e9 commit 0f7d0ff
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 71 deletions.
4 changes: 2 additions & 2 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_length]
[%%undef fork_previous_state_hash]
[%%undef fork_previous_global_slot]
[%%undef fork_global_slot]
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_length 3757]
[%%define fork_state_hash "3NKR3QYJ7qwxiGgX39umahgdT8BH5yXBQwQtpYZdvodCXcsndK7f"]
[%%define fork_global_slot 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
4 changes: 1 addition & 3 deletions src/lib/consensus/constants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ let create' (type a b c)
| None ->
slots
| Some f ->
M.( + )
(M.constant (Unsigned.UInt32.to_int f.previous_global_slot))
slots
M.( + ) (M.constant (Unsigned.UInt32.to_int f.global_slot)) slots
in
let res : (a, b, c) Poly.t =
{ Poly.k = to_length k
Expand Down
19 changes: 9 additions & 10 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 { length; global_slot; _ } ->
(*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)
(length, global_slot)
in
let default_epoch_data =
Genesis_epoch_data.Data.
Expand Down Expand Up @@ -3625,12 +3625,11 @@ let%test_module "Proof of stake tests" =
| Some fork ->
assert (
Mina_numbers.Global_slot.(
equal fork.previous_global_slot
equal fork.global_slot
previous_consensus_state.global_slot_since_genesis) ) ;
assert (
Mina_numbers.Length.(
equal
(succ fork.previous_length)
equal (succ fork.length)
previous_consensus_state.blockchain_length) ) ) ;
let global_slot =
Core_kernel.Time.now () |> Time.of_time
Expand Down Expand Up @@ -3701,12 +3700,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 slot_diff)
next_consensus_state.global_slot_since_genesis) ) ;
assert (
Mina_numbers.Length.(
equal
(succ (succ fork.previous_length))
(succ (succ fork.length))
next_consensus_state.blockchain_length) ) ) ;
(* build pieces needed to apply "update_var" *)
let checked_computation =
Expand Down Expand Up @@ -3800,13 +3799,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
; length = Mina_numbers.Length.of_int 100
; global_slot = Mina_numbers.Global_slot.of_int 200
}
in
{ constraint_constants with fork = fork_constants }
Expand Down
30 changes: 13 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
; length : Mina_numbers.Length.Stable.Latest.t
; global_slot : Mina_numbers.Global_slot.Stable.Latest.t
}
[@@deriving bin_io_unversioned, sexp, equal, compare, yojson]
end
Expand Down Expand Up @@ -67,13 +67,11 @@ 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 { length; state_hash; global_slot } ->
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
{ length = Unsigned.UInt32.to_int length
; state_hash = Pickles.Backend.Tick.Field.to_string state_hash
; global_slot = Unsigned.UInt32.to_int global_slot
}
| None ->
None )
Expand Down Expand Up @@ -152,27 +150,25 @@ module Constraint_constants = struct
Core_kernel.Int.ceil_log2
(((transaction_capacity_log_2 + 1) * (work_delay + 1)) + 1)

[%%ifndef fork_previous_length]
[%%ifndef fork_length]

let fork = None

[%%else]

[%%inject "fork_previous_length", fork_previous_length]
[%%inject "fork_length", fork_length]

[%%inject "fork_previous_state_hash", fork_previous_state_hash]

[%%inject "fork_previous_global_slot", fork_previous_global_slot]
[%%inject "fork_global_slot", fork_global_slot]

let fork =
Some
{ Fork_constants.previous_length =
Mina_numbers.Length.of_int fork_previous_length
; previous_state_hash =
{ Fork_constants.length = Mina_numbers.Length.of_int fork_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 = Mina_numbers.Global_slot.of_int fork_global_slot
}

[%%endif]
Expand Down
22 changes: 9 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,11 @@ let make_constraint_constants
( match config.fork with
| None ->
default.fork
| Some { previous_state_hash; previous_length; previous_global_slot } ->
| Some { state_hash; length; global_slot } ->
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
; length = Mina_numbers.Length.of_int length
; global_slot = Mina_numbers.Global_slot.of_int global_slot
} )
}

Expand Down Expand Up @@ -465,13 +463,11 @@ 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; length; global_slot } ->
{ Runtime_config.Fork_config.state_hash =
State_hash.to_base58_check state_hash
; length = Mina_numbers.Length.to_int length
; global_slot = Mina_numbers.Global_slot.to_int global_slot
} )
}

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; _ } ->
Mina_numbers.Global_slot.(add global_slot current_slot)
| None ->
current_slot

Expand Down
27 changes: 13 additions & 14 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
; length : int (* number of blocks produced since genesis *)
; global_slot : 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 = Int.gen_incl 0 1_000_000 in
let%bind length = Int.gen_incl 0 global_slot 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; length; global_slot }
end

let yojson_strip_fields ~keep_fields = function
Expand Down Expand Up @@ -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 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.length + blockchain_length
in
let protocol_constants = Mina_state.Protocol_state.constants protocol_state in
let genesis =
Expand All @@ -1332,12 +1332,11 @@ 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
; length = Option.value ~default:blockchain_length length
; global_slot
}
in
let%bind () = yield () in
Expand Down
6 changes: 1 addition & 5 deletions src/lib/snark_keys_header/snark_keys_header.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ module Constraint_constants = struct

module Fork_config = struct
(** Fork data *)
type t =
{ previous_state_hash : string
; previous_length : int
; previous_global_slot : int
}
type t = { state_hash : string; length : int; global_slot : int }
[@@deriving yojson, sexp, ord, equal]

let opt_to_yojson t : Yojson.Safe.t =
Expand Down

0 comments on commit 0f7d0ff

Please sign in to comment.