From 5c5c34174bcce5031cff02b75d6c53d03964ddaa Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Tue, 24 Jan 2023 10:55:56 +0100 Subject: [PATCH 1/4] Proto/Baker: use the defined wrapper create_round_durations --- src/proto_alpha/lib_delegate/baking_scheduling.ml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_scheduling.ml b/src/proto_alpha/lib_delegate/baking_scheduling.ml index a47a6a52f993..5b4c6d5c5b7e 100644 --- a/src/proto_alpha/lib_delegate/baking_scheduling.ml +++ b/src/proto_alpha/lib_delegate/baking_scheduling.ml @@ -653,13 +653,7 @@ let create_initial_state cctxt ?(synchronize = true) ~chain config } in (if synchronize then - let round_durations = - Stdlib.Option.get - @@ Round.Durations.create_opt - ~first_round_duration:constants.parametric.minimal_block_delay - ~delay_increment_per_round: - constants.parametric.delay_increment_per_round - in + create_round_durations constants >>? fun round_durations -> Baking_actions.compute_round current_proposal round_durations >>? fun current_round -> ok {current_round; current_phase = Idle} else ok {Baking_state.current_round = Round.zero; current_phase = Idle}) -- GitLab From 4621605415e2a57f1e631a8845acc6fe07d03303 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Tue, 24 Jan 2023 10:57:40 +0100 Subject: [PATCH 2/4] Proto/Baker: use the round_durations field cached in state --- .../lib_delegate/baking_scheduling.ml | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_scheduling.ml b/src/proto_alpha/lib_delegate/baking_scheduling.ml index 5b4c6d5c5b7e..a8b4fd1044c9 100644 --- a/src/proto_alpha/lib_delegate/baking_scheduling.ml +++ b/src/proto_alpha/lib_delegate/baking_scheduling.ml @@ -220,32 +220,20 @@ let compute_next_round_time state = repropose a block at next level. *) None | None -> ( - let first_round_duration = - state.global_state.constants.parametric.minimal_block_delay - in - let delay_increment_per_round = - state.global_state.constants.parametric.delay_increment_per_round - in + let round_durations = state.global_state.round_durations in + let predecessor_timestamp = proposal.predecessor.shell.timestamp in + let predecessor_round = proposal.predecessor.round in + let next_round = Round.succ state.round_state.current_round in match - Round.Durations.create_opt - ~first_round_duration - ~delay_increment_per_round + timestamp_of_round + state.global_state.cache.known_timestamps + round_durations + ~predecessor_timestamp + ~predecessor_round + ~round:next_round with - | Some round_durations -> ( - let predecessor_timestamp = proposal.predecessor.shell.timestamp in - let predecessor_round = proposal.predecessor.round in - let next_round = Round.succ state.round_state.current_round in - match - timestamp_of_round - state.global_state.cache.known_timestamps - round_durations - ~predecessor_timestamp - ~predecessor_round - ~round:next_round - with - | Ok timestamp -> Some (timestamp, next_round) - | _ -> assert false) - | None -> assert false) + | Ok timestamp -> Some (timestamp, next_round) + | _ -> assert false) (** [first_potential_round_at_next_level state ~earliest_round] yields an optional pair of the earliest possible round (at or after -- GitLab From 7ea386ae814f2ac4fff36118e49afaf62cabc7ac Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Tue, 24 Jan 2023 11:03:48 +0100 Subject: [PATCH 3/4] Proto/Baker: simplify implementation of timestamp_of_round --- src/proto_alpha/lib_delegate/baking_scheduling.ml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_scheduling.ml b/src/proto_alpha/lib_delegate/baking_scheduling.ml index a8b4fd1044c9..96350fe3ba3e 100644 --- a/src/proto_alpha/lib_delegate/baking_scheduling.ml +++ b/src/proto_alpha/lib_delegate/baking_scheduling.ml @@ -68,9 +68,9 @@ let find_in_known_round_intervals known_round_intervals ~predecessor_timestamp {predecessor_timestamp; predecessor_round; time_interval = (now, now)}) (** Memoization wrapper for [Round.timestamp_of_round]. *) -let timestamp_of_round known_timestamps round_durations ~predecessor_timestamp - ~predecessor_round ~round = +let timestamp_of_round state ~predecessor_timestamp ~predecessor_round ~round = let open Baking_cache in + let known_timestamps = state.global_state.cache.known_timestamps in match Timestamp_of_round_cache.find_opt known_timestamps @@ -79,7 +79,7 @@ let timestamp_of_round known_timestamps round_durations ~predecessor_timestamp (* Compute and register the timestamp if not already existing. *) | None -> Protocol.Alpha_context.Round.timestamp_of_round - round_durations + state.global_state.round_durations ~predecessor_timestamp ~predecessor_round ~round @@ -220,14 +220,12 @@ let compute_next_round_time state = repropose a block at next level. *) None | None -> ( - let round_durations = state.global_state.round_durations in let predecessor_timestamp = proposal.predecessor.shell.timestamp in let predecessor_round = proposal.predecessor.round in let next_round = Round.succ state.round_state.current_round in match timestamp_of_round - state.global_state.cache.known_timestamps - round_durations + state ~predecessor_timestamp ~predecessor_round ~round:next_round @@ -375,8 +373,7 @@ let compute_next_potential_baking_time_at_next_level state = >>= fun () -> Lwt.return_none | None | Some _ -> ( timestamp_of_round - state.global_state.cache.known_timestamps - round_durations + state ~predecessor_timestamp ~predecessor_round ~round:first_potential_round -- GitLab From 50f46b532b9e64b13106a81d098f6344dc8ad177 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Mon, 23 Jan 2023 15:29:17 +0100 Subject: [PATCH 4/4] Tezt/Baking: add two tests to play with minimal_timestamp flag --- tezt/tests/baking.ml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tezt/tests/baking.ml b/tezt/tests/baking.ml index 7d099b7af055..d37c44cead41 100644 --- a/tezt/tests/baking.ml +++ b/tezt/tests/baking.ml @@ -712,10 +712,31 @@ let test_operation_pool_ordering check_hashes op_hashes hashes ; Lwt.return_unit +(** This test activates a protocol with a timestamps [Now]. It then bakes a + block with the given [minimal_timestamp] flag. *) +let baking_with_given_minimal_timestamp ~minimal_timestamp = + Protocol.register_test + ~supports:Protocol.(From_protocol (number Mumbai + 1)) + ~__FILE__ + ~title:(sf "Baking minimal timestamp (%b)" minimal_timestamp) + ~tags:["baking"; "timestamp"] + @@ fun protocol -> + let* _node, client = + Client.init_with_protocol + ~timestamp:(Ago (Tezos_base.Time.System.Span.of_seconds_exn 60.)) + ~nodes_args:[Synchronisation_threshold 0] + ~protocol + `Client + () + in + Client.bake_for_and_wait ~minimal_timestamp client + let register ~protocols = test_ordering protocols ; wrong_branch_operation_dismissal protocols ; - baking_operation_exception protocols + baking_operation_exception protocols ; + baking_with_given_minimal_timestamp ~minimal_timestamp:false protocols ; + baking_with_given_minimal_timestamp ~minimal_timestamp:true protocols let register_operations_pool ~protocols = List.iter -- GitLab