diff --git a/src/app/best_tip_merger/best_tip_merger.ml b/src/app/best_tip_merger/best_tip_merger.ml index 5682f29ec5b..54a2e7664ad 100644 --- a/src/app/best_tip_merger/best_tip_merger.ml +++ b/src/app/best_tip_merger/best_tip_merger.ml @@ -231,7 +231,8 @@ module Compact_display = struct ; global_slot = Mina_state.Protocol_state.consensus_state t.state.protocol_state - |> Consensus.Data.Consensus_state.curr_global_slot + |> Consensus.Data.Consensus_state + .global_slot_since_genesis } in { state; peers = Set.length t.peer_ids } ) ) diff --git a/src/app/test_executive/slot_end_test.ml b/src/app/test_executive/slot_end_test.ml index 4d846a7d48a..3c04cd4c424 100644 --- a/src/app/test_executive/slot_end_test.ml +++ b/src/app/test_executive/slot_end_test.ml @@ -116,10 +116,10 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct (Time.Span.of_ms @@ float_of_int (num_slots * window_ms)) in let slot_tx_end = - Mina_numbers.Global_slot_since_hard_fork.of_int slot_tx_end + Mina_numbers.Global_slot_since_genesis.of_int slot_tx_end in let slot_chain_end = - Mina_numbers.Global_slot_since_hard_fork.of_int slot_chain_end + Mina_numbers.Global_slot_since_genesis.of_int slot_chain_end in let%bind () = section_hard "spawn transaction sending" @@ -160,8 +160,8 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section "blocks produced before slot_tx_end" ( ok_if_true "only empty blocks were produced before slot_tx_end" @@ List.exists blocks ~f:(fun block -> - Mina_numbers.Global_slot_since_hard_fork.( - block.slot < slot_tx_end) + Mina_numbers.Global_slot_since_genesis.( + block.slot_since_genesis < slot_tx_end) && ( block.command_transaction_count <> 0 || block.snark_work_count <> 0 || Currency.Amount.(block.coinbase <> zero) ) ) ) @@ -173,13 +173,14 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct Printf.sprintf "non-empty block after slot_tx_end. block slot since genesis: \ %s, txn count: %d, snark work count: %d, coinbase: %s" - (Mina_numbers.Global_slot_since_hard_fork.to_string block.slot) + (Mina_numbers.Global_slot_since_genesis.to_string + block.slot_since_genesis ) block.command_transaction_count block.snark_work_count (Currency.Amount.to_string block.coinbase) in ok_if_true msg - ( Mina_numbers.Global_slot_since_hard_fork.( - block.slot < slot_tx_end) + ( Mina_numbers.Global_slot_since_genesis.( + block.slot_since_genesis < slot_tx_end) || block.command_transaction_count = 0 && block.snark_work_count = 0 && Currency.Amount.(block.coinbase = zero) ) ) ) @@ -188,13 +189,13 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct section "blocks produced before slot_chain_end" ( ok_if_true "no block produced before slot_chain_end" @@ List.exists blocks ~f:(fun block -> - Mina_numbers.Global_slot_since_hard_fork.( - block.slot < slot_chain_end) ) ) + Mina_numbers.Global_slot_since_genesis.( + block.slot_since_genesis < slot_chain_end) ) ) in section "no blocks produced after slot_chain_end" ( ok_if_true "blocks produced after slot_chain_end" @@ not @@ List.exists blocks ~f:(fun block -> - Mina_numbers.Global_slot_since_hard_fork.( - block.slot >= slot_chain_end) ) ) + Mina_numbers.Global_slot_since_genesis.( + block.slot_since_genesis >= slot_chain_end) ) ) end diff --git a/src/lib/block_producer/block_producer.ml b/src/lib/block_producer/block_producer.ml index 3c2c207ff33..aa42a702d99 100644 --- a/src/lib/block_producer/block_producer.ml +++ b/src/lib/block_producer/block_producer.ml @@ -168,18 +168,17 @@ let generate_next_state ~zkapp_cmd_limit ~constraint_constants ~winner_pk ~scheduled_time ~log_block_creation ~block_reward_threshold ~zkapp_cmd_limit_hardcap ~slot_tx_end ~slot_chain_end = let open Interruptible.Let_syntax in - let global_slot_since_hard_fork = - Consensus.Data.Block_data.global_slot block_data + let global_slot_since_genesis = + Consensus.Data.Block_data.global_slot_since_genesis block_data in match slot_chain_end with | Some slot_chain_end - when Mina_numbers.Global_slot_since_hard_fork.( - global_slot_since_hard_fork >= slot_chain_end) -> + when Mina_numbers.Global_slot_since_genesis.( + global_slot_since_genesis >= slot_chain_end) -> [%log info] "Reached slot_chain_end $slot_chain_end, not producing blocks" ~metadata: [ ( "slot_chain_end" - , Mina_numbers.Global_slot_since_hard_fork.to_yojson slot_chain_end - ) + , Mina_numbers.Global_slot_since_genesis.to_yojson slot_chain_end ) ] ; Interruptible.return None | None | Some _ -> ( @@ -212,13 +211,13 @@ let generate_next_state ~zkapp_cmd_limit ~constraint_constants let diff = match slot_tx_end with | Some slot_tx_end - when Mina_numbers.Global_slot_since_hard_fork.( - global_slot_since_hard_fork >= slot_tx_end) -> + when Mina_numbers.Global_slot_since_genesis.( + global_slot_since_genesis >= slot_tx_end) -> [%log info] "Reached slot_tx_end $slot_tx_end, producing empty block" ~metadata: [ ( "slot_tx_end" - , Mina_numbers.Global_slot_since_hard_fork.to_yojson + , Mina_numbers.Global_slot_since_genesis.to_yojson slot_tx_end ) ] ; Result.return @@ -1097,10 +1096,26 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier let new_global_slot = epoch_data_for_vrf.global_slot in let log_if_slot_diff_is_less_than = let current_global_slot = - Consensus.Data.Consensus_time.( - to_global_slot - (of_time_exn ~constants:consensus_constants - (Block_time.now time_controller) )) + let open Mina_numbers in + let global_slots_since_hard_fork = + let global_slot_since_hard_fork = + Consensus.Data.Consensus_time.( + to_global_slot + (of_time_exn ~constants:consensus_constants + (Block_time.now time_controller) )) + in + Option.value_exn + @@ Global_slot_since_hard_fork.( + diff global_slot_since_hard_fork zero) + in + let open Mina_numbers in + Global_slot_since_genesis.add + ( match constraint_constants.fork with + | None -> + Global_slot_since_genesis.zero + | Some { global_slot_since_genesis; _ } -> + global_slot_since_genesis ) + global_slots_since_hard_fork in fun ~diff_limit ~every ~message -> function | None -> @@ -1109,8 +1124,7 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier let slot_diff = let open Mina_numbers in Option.map ~f:Global_slot_span.to_int - @@ Global_slot_since_hard_fork.diff slot - current_global_slot + @@ Global_slot_since_genesis.diff slot current_global_slot in Option.iter slot_diff ~f:(fun slot_diff' -> if slot_diff' <= diff_limit && slot_diff' mod every = 0 diff --git a/src/lib/mina_graphql/mina_graphql.ml b/src/lib/mina_graphql/mina_graphql.ml index e4127371564..96b35968e18 100644 --- a/src/lib/mina_graphql/mina_graphql.ml +++ b/src/lib/mina_graphql/mina_graphql.ml @@ -2396,10 +2396,11 @@ module Queries = struct let global_slot = Mina_state.Protocol_state.consensus_state protocol_state - |> Consensus.Data.Consensus_state.curr_global_slot + |> Consensus.Data.Consensus_state + .global_slot_since_genesis in if - Mina_numbers.Global_slot_since_hard_fork.( < ) + Mina_numbers.Global_slot_since_genesis.( < ) global_slot stop_slot then return breadcrumb else diff --git a/src/lib/network_pool/indexed_pool.ml b/src/lib/network_pool/indexed_pool.ml index 733e53de6d6..600a067fa4a 100644 --- a/src/lib/network_pool/indexed_pool.ml +++ b/src/lib/network_pool/indexed_pool.ml @@ -26,7 +26,7 @@ module Config = struct { constraint_constants : Genesis_constants.Constraint_constants.t ; consensus_constants : Consensus.Constants.t ; time_controller : Block_time.Controller.t - ; slot_tx_end : Mina_numbers.Global_slot_since_hard_fork.t option + ; slot_tx_end : Mina_numbers.Global_slot_since_genesis.t option } [@@deriving sexp_of, equal, compare] end @@ -906,16 +906,29 @@ module Add_from_gossip_exn (M : Writer_result.S) = struct let open Command_error in let open M.Let_syntax in let current_global_slot = - Consensus.Data.Consensus_time.( - to_global_slot - (of_time_exn ~constants:consensus_constants - (Block_time.now time_controller) )) + let global_slots_since_hard_fork = + let global_slot_since_hard_fork = + Consensus.Data.Consensus_time.( + to_global_slot + (of_time_exn ~constants:consensus_constants + (Block_time.now time_controller) )) + in + Option.value_exn + @@ Global_slot_since_hard_fork.(diff global_slot_since_hard_fork zero) + in + Global_slot_since_genesis.add + ( match constraint_constants.fork with + | None -> + Global_slot_since_genesis.zero + | Some { global_slot_since_genesis; _ } -> + global_slot_since_genesis ) + global_slots_since_hard_fork in let%bind () = M.of_result @@ Result.ok_if_true ~error:After_slot_tx_end @@ Option.value_map slot_tx_end ~default:true ~f:(fun slot_tx_end' -> - Global_slot_since_hard_fork.(current_global_slot < slot_tx_end') ) + Global_slot_since_genesis.(current_global_slot < slot_tx_end') ) in let unchecked_cmd = Transaction_hash.User_command.of_checked cmd in let unchecked = Transaction_hash.User_command.data unchecked_cmd in @@ -1169,15 +1182,28 @@ let add_from_backtrack : } as t ) cmd -> let open Result.Let_syntax in let current_global_slot = - Consensus.Data.Consensus_time.( - to_global_slot - (of_time_exn ~constants:consensus_constants - (Block_time.now time_controller) )) + let global_slots_since_hard_fork = + let global_slot_since_hard_fork = + Consensus.Data.Consensus_time.( + to_global_slot + (of_time_exn ~constants:consensus_constants + (Block_time.now time_controller) )) + in + Option.value_exn + @@ Global_slot_since_hard_fork.(diff global_slot_since_hard_fork zero) + in + Global_slot_since_genesis.add + ( match constraint_constants.fork with + | None -> + Global_slot_since_genesis.zero + | Some { global_slot_since_genesis; _ } -> + global_slot_since_genesis ) + global_slots_since_hard_fork in let%bind () = Result.ok_if_true ~error:Command_error.After_slot_tx_end @@ Option.value_map slot_tx_end ~default:true ~f:(fun slot_tx_end' -> - Global_slot_since_hard_fork.(current_global_slot < slot_tx_end') ) + Global_slot_since_genesis.(current_global_slot < slot_tx_end') ) in let unchecked = Transaction_hash.User_command_with_valid_signature.command cmd diff --git a/src/lib/network_pool/indexed_pool.mli b/src/lib/network_pool/indexed_pool.mli index d2a25ebb0eb..a7f9852109c 100644 --- a/src/lib/network_pool/indexed_pool.mli +++ b/src/lib/network_pool/indexed_pool.mli @@ -49,7 +49,7 @@ val empty : constraint_constants:Genesis_constants.Constraint_constants.t -> consensus_constants:Consensus.Constants.t -> time_controller:Block_time.Controller.t - -> slot_tx_end:Mina_numbers.Global_slot_since_hard_fork.t option + -> slot_tx_end:Mina_numbers.Global_slot_since_genesis.t option -> t (** How many transactions are currently in the pool *) diff --git a/src/lib/network_pool/intf.ml b/src/lib/network_pool/intf.ml index 80dd0891a2d..8bb001bb80f 100644 --- a/src/lib/network_pool/intf.ml +++ b/src/lib/network_pool/intf.ml @@ -390,7 +390,7 @@ module type Transaction_resource_pool_intf = sig -> pool_max_size:int -> verifier:Verifier.t -> genesis_constants:Genesis_constants.t - -> slot_tx_end:Mina_numbers.Global_slot_since_hard_fork.t option + -> slot_tx_end:Mina_numbers.Global_slot_since_genesis.t option -> Config.t val member : t -> Transaction_hash.User_command_with_valid_signature.t -> bool diff --git a/src/lib/network_pool/transaction_pool.ml b/src/lib/network_pool/transaction_pool.ml index ec9640a0ec6..8d68105fd8a 100644 --- a/src/lib/network_pool/transaction_pool.ml +++ b/src/lib/network_pool/transaction_pool.ml @@ -288,7 +288,7 @@ struct *) ; verifier : (Verifier.t[@sexp.opaque]) ; genesis_constants : Genesis_constants.t - ; slot_tx_end : Mina_numbers.Global_slot_since_hard_fork.t option + ; slot_tx_end : Mina_numbers.Global_slot_since_genesis.t option } [@@deriving sexp_of] @@ -3127,13 +3127,9 @@ let%test_module _ = let%test_unit "transactions added before slot_tx_end are accepted" = Thread_safe.block_on_async_exn (fun () -> - let curr_slot = - Mina_numbers.( - Global_slot_since_hard_fork.of_uint32 - @@ Global_slot_since_genesis.to_uint32 @@ current_global_slot ()) - in + let curr_slot = current_global_slot () in let slot_tx_end = - Mina_numbers.Global_slot_since_hard_fork.(succ @@ succ curr_slot) + Mina_numbers.Global_slot_since_genesis.(succ @@ succ curr_slot) in let%bind t = setup_test ~slot_tx_end () in assert_pool_txs t [] ; @@ -3141,26 +3137,18 @@ let%test_module _ = let%test_unit "transactions added at slot_tx_end are rejected" = Thread_safe.block_on_async_exn (fun () -> - let curr_slot = - Mina_numbers.( - Global_slot_since_hard_fork.of_uint32 - @@ Global_slot_since_genesis.to_uint32 @@ current_global_slot ()) - in + let curr_slot = current_global_slot () in let%bind t = setup_test ~slot_tx_end:curr_slot () in assert_pool_txs t [] ; add_commands t independent_cmds >>| assert_pool_apply [] ) let%test_unit "transactions added after slot_tx_end are rejected" = Thread_safe.block_on_async_exn (fun () -> - let curr_slot = - Mina_numbers.( - Global_slot_since_hard_fork.of_uint32 - @@ Global_slot_since_genesis.to_uint32 @@ current_global_slot ()) - in + let curr_slot = current_global_slot () in let slot_tx_end = Option.value_exn @@ Mina_numbers.( - Global_slot_since_hard_fork.( + Global_slot_since_genesis.( sub curr_slot @@ Global_slot_span.of_int 1)) in let%bind t = setup_test ~slot_tx_end () in diff --git a/src/lib/runtime_config/runtime_config.ml b/src/lib/runtime_config/runtime_config.ml index a71ec6c5f8a..a19cd2ecc96 100644 --- a/src/lib/runtime_config/runtime_config.ml +++ b/src/lib/runtime_config/runtime_config.ml @@ -1587,7 +1587,7 @@ let make_fork_config ~staged_ledger ~global_slot ~state_hash ~blockchain_length let slot_tx_end_or_default, slot_chain_end_or_default = let f compile get_runtime t = - Option.map ~f:Mina_numbers.Global_slot_since_hard_fork.of_int + Option.map ~f:Mina_numbers.Global_slot_since_genesis.of_int @@ Option.value_map t.daemon ~default:compile ~f:(fun daemon -> Option.merge compile ~f:(fun _c r -> r) @@ get_runtime daemon ) in diff --git a/src/lib/transition_handler/validator.ml b/src/lib/transition_handler/validator.ml index e5a9ba87f58..ea5f9084023 100644 --- a/src/lib/transition_handler/validator.ml +++ b/src/lib/transition_handler/validator.ml @@ -31,15 +31,15 @@ let validate_transition ~context:(module Context : CONTEXT) ~frontier let root_breadcrumb = Transition_frontier.root frontier in let transition_data = With_hash.data transition in let block_slot = - Consensus.Data.Consensus_state.curr_global_slot + Consensus.Data.Consensus_state.global_slot_since_genesis @@ Protocol_state.consensus_state @@ Header.protocol_state @@ Mina_block.header transition_data in let%bind () = match slot_chain_end with | Some slot_chain_end - when Mina_numbers.Global_slot_since_hard_fork.( - block_slot >= slot_chain_end) -> + when Mina_numbers.Global_slot_since_genesis.(block_slot >= slot_chain_end) + -> [%log info] "Block after slot_chain_end, rejecting" ; Result.fail `Block_after_after_stop_slot | None | Some _ -> @@ -48,8 +48,7 @@ let validate_transition ~context:(module Context : CONTEXT) ~frontier let%bind () = match slot_tx_end with | Some slot_tx_end - when Mina_numbers.Global_slot_since_hard_fork.(block_slot >= slot_tx_end) - -> + when Mina_numbers.Global_slot_since_genesis.(block_slot >= slot_tx_end) -> [%log info] "Block after slot_tx_end, validating it is empty" ; let staged_ledger_diff = Body.staged_ledger_diff @@ body transition_data @@ -242,8 +241,9 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~time_controller , `String "not empty staged ledger diff after slot_tx_end" ) ; ( "block_slot" - , Mina_numbers.Global_slot_since_hard_fork.to_yojson - @@ Consensus.Data.Consensus_state.curr_global_slot + , Mina_numbers.Global_slot_since_genesis.to_yojson + @@ Consensus.Data.Consensus_state + .global_slot_since_genesis @@ Protocol_state.consensus_state @@ Header.protocol_state @@ Mina_block.header @@ transition ) ] @@ -256,8 +256,9 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~time_controller [ ("state_hash", State_hash.to_yojson transition_hash) ; ("reason", `String "block after slot_chain_end") ; ( "block_slot" - , Mina_numbers.Global_slot_since_hard_fork.to_yojson - @@ Consensus.Data.Consensus_state.curr_global_slot + , Mina_numbers.Global_slot_since_genesis.to_yojson + @@ Consensus.Data.Consensus_state + .global_slot_since_genesis @@ Protocol_state.consensus_state @@ Header.protocol_state @@ Mina_block.header @@ transition ) ]