From 287e7cf268caa4d609f2d2483727fb63a9ad961b Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Fri, 20 Jan 2023 20:55:07 +0100 Subject: [PATCH 1/2] Baker: move confusing event placement If the round start (of the first potential round at next level) is in the past, the event will show something like ``` waiting -38min15s until it's time to bake at ... ``` which is quite confusing. Actually the baker does not wait. So the baker now emits this event only when it really waits. Fixes https://gitlab.com/tezos/tezos/-/issues/4646 --- src/proto_alpha/lib_delegate/baking_scheduling.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_delegate/baking_scheduling.ml b/src/proto_alpha/lib_delegate/baking_scheduling.ml index 38d42a06cc3d..a47a6a52f993 100644 --- a/src/proto_alpha/lib_delegate/baking_scheduling.ml +++ b/src/proto_alpha/lib_delegate/baking_scheduling.ml @@ -475,13 +475,14 @@ let compute_next_timeout state : Baking_state.timeout_kind Lwt.t tzresult Lwt.t let wait_baking_time_next_level (next_baking_time, next_baking_round) = let now = Time.System.now () in let delay = Ptime.diff (Time.System.of_protocol_exn next_baking_time) now in - Events.(emit waiting_time_to_bake (delay, next_baking_time)) >>= fun () -> match sleep_until next_baking_time with | None -> Events.(emit no_need_to_wait_for_proposal ()) >>= fun () -> return (Lwt.return (Time_to_bake_next_level {at_round = next_baking_round})) | Some t -> + Events.(emit waiting_time_to_bake (delay, next_baking_time)) + >>= fun () -> return ( t >>= fun () -> Lwt.return (Time_to_bake_next_level {at_round = next_baking_round}) -- GitLab From 3a0af20b3cdf3150a7564f0b874d539edb6eb14b Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 4 Jan 2023 15:50:36 +0100 Subject: [PATCH 2/2] Baker: simplify type `endorsing_slot` --- src/proto_alpha/lib_delegate/baking_state.ml | 19 ++++++++++++------- src/proto_alpha/lib_delegate/baking_state.mli | 2 +- .../lib_delegate/state_transitions.ml | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_state.ml b/src/proto_alpha/lib_delegate/baking_state.ml index 0130ec952817..475306cac7d8 100644 --- a/src/proto_alpha/lib_delegate/baking_state.ml +++ b/src/proto_alpha/lib_delegate/baking_state.ml @@ -241,7 +241,7 @@ module SlotMap : Map.S with type key = Slot.t = Map.Make (Slot) list of slots (i.e., a list of position indexes in the slot map, in other words the list of rounds when it will be the proposer), and its endorsing power. *) -type endorsing_slot = {slots : Slot.t list; endorsing_power : int} +type endorsing_slot = {first_slot : Slot.t; endorsing_power : int} (* FIXME: determine if the slot map should contain all slots or just the first one *) @@ -782,7 +782,12 @@ let compute_delegate_slots (cctxt : Protocol_client_context.full) List.fold_left (fun (own_map, all_map) slot -> let {Plugin.RPC.Validators.consensus_key; delegate; slots; _} = slot in - let endorsing_slot = {endorsing_power = List.length slots; slots} in + let endorsing_slot = + { + endorsing_power = List.length slots; + first_slot = Stdlib.List.hd slots; + } + in let all_map = List.fold_left (fun all_map slot -> SlotMap.add slot endorsing_slot all_map) @@ -916,13 +921,13 @@ let pp_elected_block fmt {proposal; endorsement_qc} = proposal.block (List.length endorsement_qc) -let pp_endorsing_slot fmt (consensus_key_and_delegate, {slots; endorsing_power}) - = +let pp_endorsing_slot fmt + (consensus_key_and_delegate, {first_slot; endorsing_power}) = Format.fprintf fmt - "slots: @[[%a]@],@ delegate: %a,@ endorsing_power: %d" - Format.(pp_print_list ~pp_sep:pp_print_space Slot.pp) - slots + "slots: @[first_slot: %a@],@ delegate: %a,@ endorsing_power: %d" + Slot.pp + first_slot pp_consensus_key_and_delegate consensus_key_and_delegate endorsing_power diff --git a/src/proto_alpha/lib_delegate/baking_state.mli b/src/proto_alpha/lib_delegate/baking_state.mli index 198cde1a9f96..fef6d3ccc336 100644 --- a/src/proto_alpha/lib_delegate/baking_state.mli +++ b/src/proto_alpha/lib_delegate/baking_state.mli @@ -96,7 +96,7 @@ val round_of_shell_header : Block_header.shell_header -> Round.t tzresult module SlotMap : Map.S with type key = Slot.t -type endorsing_slot = {slots : Slot.t list; endorsing_power : int} +type endorsing_slot = {first_slot : Slot.t; endorsing_power : int} type delegate_slots = { own_delegate_slots : (consensus_key_and_delegate * endorsing_slot) SlotMap.t; diff --git a/src/proto_alpha/lib_delegate/state_transitions.ml b/src/proto_alpha/lib_delegate/state_transitions.ml index 196d248f553e..d39c05dbc8cd 100644 --- a/src/proto_alpha/lib_delegate/state_transitions.ml +++ b/src/proto_alpha/lib_delegate/state_transitions.ml @@ -81,7 +81,7 @@ let make_consensus_list state proposal = SlotMap.fold (fun _slot (consensus_key_and_delegate, slots) acc -> ( consensus_key_and_delegate, - {slot = Stdlib.List.hd slots.slots; level; round; block_payload_hash} ) + {slot = slots.first_slot; level; round; block_payload_hash} ) :: acc) state.level_state.delegate_slots.own_delegate_slots [] -- GitLab