diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_actions.ml b/src/proto_016_PtMumbai/lib_delegate/baking_actions.ml index 2b796d36b4075cbfede56cad1f5deb74e66cd825..56f56616c1518cb5a86cd02fc7bf9ba59241b6f8 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_actions.ml +++ b/src/proto_016_PtMumbai/lib_delegate/baking_actions.ml @@ -126,14 +126,13 @@ type action = | Inject_block of {block_to_bake : block_to_bake; updated_state : state} | Inject_preendorsements of { preendorsements : (consensus_key_and_delegate * consensus_content) list; - updated_state : state; } | Inject_endorsements of { endorsements : (consensus_key_and_delegate * consensus_content) list; - updated_state : state; } | Update_to_level of level_update | Synchronize_round of round_update + | Watch_proposal and level_update = { new_level_proposal : proposal; @@ -158,6 +157,7 @@ let pp_action fmt = function | Inject_endorsements _ -> Format.fprintf fmt "inject endorsements" | Update_to_level _ -> Format.fprintf fmt "update to level" | Synchronize_round _ -> Format.fprintf fmt "synchronize round" + | Watch_proposal -> Format.fprintf fmt "watch proposal" let generate_seed_nonce_hash config delegate level = if level.Level.expected_commitment then @@ -340,8 +340,7 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = emit block_injected (bh, signed_block_header.shell.level, round, delegate)) >>= fun () -> return updated_state -let inject_preendorsements ~state_recorder state ~preendorsements ~updated_state - = +let inject_preendorsements state ~preendorsements = let cctxt = state.global_state.cctxt in let chain_id = state.global_state.chain_id in (* N.b. signing a lot of operations may take some time *) @@ -404,7 +403,6 @@ let inject_preendorsements ~state_recorder state ~preendorsements ~updated_state return_some (delegate, operation)) preendorsements >>=? fun signed_operations -> - state_recorder ~new_state:updated_state >>=? fun () -> (* TODO: add a RPC to inject multiple operations *) List.iter_ep (fun (delegate, operation) -> @@ -424,7 +422,6 @@ let inject_preendorsements ~state_recorder state ~preendorsements ~updated_state Events.(emit preendorsement_injected (oph, delegate)) >>= fun () -> return_unit)) signed_operations - >>=? fun () -> return updated_state let sign_endorsements state endorsements = let cctxt = state.global_state.cctxt in @@ -491,11 +488,10 @@ let sign_endorsements state endorsements = return_some (delegate, operation)) endorsements -let inject_endorsements ~state_recorder state ~endorsements ~updated_state = +let inject_endorsements state ~endorsements = let cctxt = state.global_state.cctxt in let chain_id = state.global_state.chain_id in sign_endorsements state endorsements >>=? fun signed_operations -> - state_recorder ~new_state:updated_state >>=? fun () -> (* TODO: add a RPC to inject multiple operations *) List.iter_ep (fun (delegate, signed_operation) -> @@ -510,7 +506,6 @@ let inject_endorsements ~state_recorder state ~endorsements ~updated_state = Events.(emit endorsement_injected (oph, delegate)) >>= fun () -> return_unit) signed_operations - >>=? fun () -> return updated_state let prepare_waiting_for_quorum state = let consensus_threshold = @@ -616,31 +611,34 @@ let synchronize_round state {new_round_proposal; handle_proposal} = let new_state = {state with round_state = new_round_state} in handle_proposal new_state >>= return +(* TODO: https://gitlab.com/tezos/tezos/-/issues/4539 + Avoid updating the state here. + (See also comment in {!State_transitions.step}.) + + TODO: https://gitlab.com/tezos/tezos/-/issues/4538 + Improve/clarify when the state is recorded. +*) let rec perform_action ~state_recorder state (action : action) = match action with | Do_nothing -> state_recorder ~new_state:state >>=? fun () -> return state | Inject_block {block_to_bake; updated_state} -> inject_block state ~state_recorder block_to_bake ~updated_state - | Inject_preendorsements {preendorsements; updated_state} -> - inject_preendorsements - ~state_recorder - state - ~preendorsements - ~updated_state - >>=? fun new_state -> - (* We wait for preendorsements to trigger the - [Prequorum_reached] event *) - start_waiting_for_preendorsement_quorum state >>= fun () -> - return new_state - | Inject_endorsements {endorsements; updated_state} -> - inject_endorsements ~state_recorder state ~endorsements ~updated_state - >>=? fun new_state -> + | Inject_preendorsements {preendorsements} -> + inject_preendorsements state ~preendorsements >>=? fun () -> + perform_action ~state_recorder state Watch_proposal + | Inject_endorsements {endorsements} -> + state_recorder ~new_state:state >>=? fun () -> + inject_endorsements state ~endorsements >>=? fun () -> (* We wait for endorsements to trigger the [Quorum_reached] event *) - start_waiting_for_endorsement_quorum state >>= fun () -> return new_state + start_waiting_for_endorsement_quorum state >>= fun () -> return state | Update_to_level level_update -> update_to_level state level_update >>=? fun (new_state, new_action) -> perform_action ~state_recorder new_state new_action | Synchronize_round round_update -> synchronize_round state round_update >>=? fun (new_state, new_action) -> perform_action ~state_recorder new_state new_action + | Watch_proposal -> + (* We wait for preendorsements to trigger the + [Prequorum_reached] event *) + start_waiting_for_preendorsement_quorum state >>= fun () -> return state diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_actions.mli b/src/proto_016_PtMumbai/lib_delegate/baking_actions.mli index da181cda8c3202b695a1e671d5239b9d262c7ee6..91b9bf7729157864c0258c476ae56aeeb30c54ef 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_actions.mli +++ b/src/proto_016_PtMumbai/lib_delegate/baking_actions.mli @@ -48,14 +48,13 @@ type action = | Inject_block of {block_to_bake : block_to_bake; updated_state : state} | Inject_preendorsements of { preendorsements : (consensus_key_and_delegate * consensus_content) list; - updated_state : state; } | Inject_endorsements of { endorsements : (consensus_key_and_delegate * consensus_content) list; - updated_state : state; } | Update_to_level of level_update | Synchronize_round of round_update + | Watch_proposal and level_update = { new_level_proposal : proposal; @@ -87,11 +86,9 @@ val inject_block : state tzresult Lwt.t val inject_preendorsements : - state_recorder:(new_state:state -> unit tzresult Lwt.t) -> state -> preendorsements:(consensus_key_and_delegate * consensus_content) list -> - updated_state:state -> - state tzresult Lwt.t + unit tzresult Lwt.t val sign_endorsements : state -> @@ -99,11 +96,9 @@ val sign_endorsements : (consensus_key_and_delegate * packed_operation) list tzresult Lwt.t val inject_endorsements : - state_recorder:(new_state:state -> unit tzresult Lwt.t) -> state -> endorsements:(consensus_key_and_delegate * consensus_content) list -> - updated_state:state -> - state tzresult Lwt.t + unit tzresult Lwt.t val prepare_waiting_for_quorum : state -> int * (slot:Slot.t -> int) * Operation_worker.candidate diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_commands.ml b/src/proto_016_PtMumbai/lib_delegate/baking_commands.ml index 9d76b8745fff52ab03b1a5827649bc4656ee242f..b827d5b7caddb32dd1275d63b705b5f83824f6f3 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_commands.ml +++ b/src/proto_016_PtMumbai/lib_delegate/baking_commands.ml @@ -166,7 +166,7 @@ let liquidity_baking_toggle_vote_arg = liquidity_baking_toggle_vote_parameter let get_delegates (cctxt : Protocol_client_context.full) - (pkhs : Tezos_crypto.Signature.public_key_hash list) = + (pkhs : Signature.public_key_hash list) = let proj_delegate (alias, public_key_hash, public_key, secret_key_uri) = { Baking_state.alias = Some alias; diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_events.ml b/src/proto_016_PtMumbai/lib_delegate/baking_events.ml index 110ce38543661f136f9202b40e5da2ac07b776e2..9c2af301a0a075638f7ca9a4749da54d4c9e989b 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_events.ml +++ b/src/proto_016_PtMumbai/lib_delegate/baking_events.ml @@ -498,7 +498,7 @@ module Actions = struct ~section ~name:"skipping_preendorsement" ~level:Error - ~msg:"skipping preendorsement for {delegate} -- {trace}" + ~msg:"unable to sign preendorsement for {delegate} -- {trace}" ~pp1:Baking_state.pp_consensus_key_and_delegate ("delegate", Baking_state.consensus_key_and_delegate_encoding) ~pp2:Error_monad.pp_print_trace @@ -509,7 +509,7 @@ module Actions = struct ~section ~name:"skipping_endorsement" ~level:Error - ~msg:"skipping endorsement for {delegate} -- {trace}" + ~msg:"unable to sign endorsement for {delegate} -- {trace}" ~pp1:Baking_state.pp_consensus_key_and_delegate ("delegate", Baking_state.consensus_key_and_delegate_encoding) ~pp2:Error_monad.pp_print_trace diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_highwatermarks.ml b/src/proto_016_PtMumbai/lib_delegate/baking_highwatermarks.ml index 4af172f183fe5e13807314564a2a72cc1c1de5b5..91b56b3e50b1fc062f054f1dcc89668a8c75a03a 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_highwatermarks.ml +++ b/src/proto_016_PtMumbai/lib_delegate/baking_highwatermarks.ml @@ -100,9 +100,9 @@ let () = (fun highwatermark -> Block_previously_endorsed highwatermark) module DelegateMap = Map.Make (struct - type t = Tezos_crypto.Signature.Public_key_hash.t + type t = Signature.Public_key_hash.t - let compare = Tezos_crypto.Signature.Public_key_hash.compare + let compare = Signature.Public_key_hash.compare end) let highwatermark_delegate_map_encoding = @@ -113,7 +113,7 @@ let highwatermark_delegate_map_encoding = fun l -> List.fold_left (fun map (k, v) -> add k v map) empty l) (list (obj2 - (req "delegate" Tezos_crypto.Signature.Public_key_hash.encoding) + (req "delegate" Signature.Public_key_hash.encoding) (req "highwatermark" highwatermark_encoding))) type highwatermarks = { diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_highwatermarks.mli b/src/proto_016_PtMumbai/lib_delegate/baking_highwatermarks.mli index 30d4d6f4ea3ea04f27408ebd410cbb49bf72ede8..757b667c58bb68d5628623b9a234c2ab12ae669d 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_highwatermarks.mli +++ b/src/proto_016_PtMumbai/lib_delegate/baking_highwatermarks.mli @@ -45,7 +45,7 @@ val load : val may_sign_block : #Protocol_client_context.full -> [`Highwatermarks] Baking_files.location -> - delegate:Tezos_crypto.Signature.public_key_hash -> + delegate:Signature.public_key_hash -> level:int32 -> round:Round.t -> bool tzresult Lwt.t @@ -53,7 +53,7 @@ val may_sign_block : val may_sign_preendorsement : #Protocol_client_context.full -> [`Highwatermarks] Baking_files.location -> - delegate:Tezos_crypto.Signature.public_key_hash -> + delegate:Signature.public_key_hash -> level:int32 -> round:Round.t -> bool tzresult Lwt.t @@ -61,7 +61,7 @@ val may_sign_preendorsement : val may_sign_endorsement : #Protocol_client_context.full -> [`Highwatermarks] Baking_files.location -> - delegate:Tezos_crypto.Signature.public_key_hash -> + delegate:Signature.public_key_hash -> level:int32 -> round:Round.t -> bool tzresult Lwt.t @@ -69,7 +69,7 @@ val may_sign_endorsement : val record_block : #Protocol_client_context.full -> [`Highwatermarks] Baking_files.location -> - delegate:Tezos_crypto.Signature.public_key_hash -> + delegate:Signature.public_key_hash -> level:int32 -> round:Round.t -> unit tzresult Lwt.t @@ -77,7 +77,7 @@ val record_block : val record_preendorsement : #Protocol_client_context.full -> [`Highwatermarks] Baking_files.location -> - delegate:Tezos_crypto.Signature.public_key_hash -> + delegate:Signature.public_key_hash -> level:int32 -> round:Round.t -> unit tzresult Lwt.t @@ -85,7 +85,7 @@ val record_preendorsement : val record_endorsement : #Protocol_client_context.full -> [`Highwatermarks] Baking_files.location -> - delegate:Tezos_crypto.Signature.public_key_hash -> + delegate:Signature.public_key_hash -> level:int32 -> round:Round.t -> unit tzresult Lwt.t diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_lib.ml b/src/proto_016_PtMumbai/lib_delegate/baking_lib.ml index 7ec3ae000cd5f97e8fc8281126379232137dee2a..bb2cb7b3f4ec7e05d4ccbb5b18bbfa0c9aa2fd45 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_lib.ml +++ b/src/proto_016_PtMumbai/lib_delegate/baking_lib.ml @@ -86,17 +86,7 @@ let preendorse (cctxt : Protocol_client_context.full) ?(force = false) delegates Baking_state.pp_consensus_key_and_delegate) (List.map fst consensus_list) in - let state_recorder ~new_state = - Baking_state.may_record_new_state ~previous_state:state ~new_state - in - let* _ = - Baking_actions.inject_preendorsements - ~state_recorder - state - ~preendorsements:consensus_list - ~updated_state:state - in - return_unit + Baking_actions.inject_preendorsements state ~preendorsements:consensus_list let endorse (cctxt : Protocol_client_context.full) ?(force = false) delegates = let open State_transitions in @@ -126,17 +116,10 @@ let endorse (cctxt : Protocol_client_context.full) ?(force = false) delegates = Baking_state.pp_consensus_key_and_delegate) (List.map fst consensus_list) in - let state_recorder ~new_state = - Baking_state.may_record_new_state ~previous_state:state ~new_state - in - let* _ = - Baking_actions.inject_endorsements - ~state_recorder - state - ~endorsements:consensus_list - ~updated_state:state + let* () = + Baking_state.may_record_new_state ~previous_state:state ~new_state:state in - return_unit + Baking_actions.inject_endorsements state ~endorsements:consensus_list let bake_at_next_level state = let open Lwt_result_syntax in diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_nonces.ml b/src/proto_016_PtMumbai/lib_delegate/baking_nonces.ml index 5af73f61735e63a47f20d9c57afe2e750ac24ed9..fc1c9ada635ac59fc205b047b43e9a5b0f06aee3 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_nonces.ml +++ b/src/proto_016_PtMumbai/lib_delegate/baking_nonces.ml @@ -239,9 +239,7 @@ let inject_seed_nonce_revelation (cctxt : #Protocol_client_context.full) ~chain ~nonce () >>=? fun bytes -> - let bytes = - Tezos_crypto.Signature.concat bytes Tezos_crypto.Signature.zero - in + let bytes = Signature.concat bytes Signature.zero in Shell_services.Injection.operation ~async:true cctxt ~chain bytes >>=? fun oph -> Events.( diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_scheduling.ml b/src/proto_016_PtMumbai/lib_delegate/baking_scheduling.ml index 38d42a06cc3df5e395c0c4bea0b847273fc490a0..96350fe3ba3e2600154a7750b933f2b8fe12f492 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_scheduling.ml +++ b/src/proto_016_PtMumbai/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,32 +220,18 @@ 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 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 + ~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 @@ -387,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 @@ -475,13 +460,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}) @@ -652,13 +638,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}) diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_state.ml b/src/proto_016_PtMumbai/lib_delegate/baking_state.ml index 984c2bbbd2378d30dc3db42766bad0f93706ce4f..475306cac7d8a5782338e0a041cda4354771fe6a 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_state.ml +++ b/src/proto_016_PtMumbai/lib_delegate/baking_state.ml @@ -31,8 +31,8 @@ open Protocol_client_context public key, its public key hash, and its secret key. *) type consensus_key = { alias : string option; - public_key : Tezos_crypto.Signature.Public_key.t; - public_key_hash : Tezos_crypto.Signature.Public_key_hash.t; + public_key : Signature.Public_key.t; + public_key_hash : Signature.Public_key_hash.t; secret_key_uri : Client_keys.sk_uri; } @@ -56,48 +56,39 @@ let consensus_key_encoding = }) (obj4 (req "alias" (option string)) - (req "public_key" Tezos_crypto.Signature.Public_key.encoding) - (req "public_key_hash" Tezos_crypto.Signature.Public_key_hash.encoding) + (req "public_key" Signature.Public_key.encoding) + (req "public_key_hash" Signature.Public_key_hash.encoding) (req "secret_key_uri" string)) let pp_consensus_key fmt {alias; public_key_hash; _} = match alias with - | None -> - Format.fprintf - fmt - "%a" - Tezos_crypto.Signature.Public_key_hash.pp - public_key_hash + | None -> Format.fprintf fmt "%a" Signature.Public_key_hash.pp public_key_hash | Some alias -> Format.fprintf fmt "%s (%a)" alias - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp public_key_hash -type consensus_key_and_delegate = - consensus_key * Tezos_crypto.Signature.Public_key_hash.t +type consensus_key_and_delegate = consensus_key * Signature.Public_key_hash.t let consensus_key_and_delegate_encoding = let open Data_encoding in merge_objs consensus_key_encoding - (obj1 (req "delegate" Tezos_crypto.Signature.Public_key_hash.encoding)) + (obj1 (req "delegate" Signature.Public_key_hash.encoding)) let pp_consensus_key_and_delegate fmt (consensus_key, delegate) = - if - Tezos_crypto.Signature.Public_key_hash.equal - consensus_key.public_key_hash - delegate - then pp_consensus_key fmt consensus_key + if Signature.Public_key_hash.equal consensus_key.public_key_hash delegate then + pp_consensus_key fmt consensus_key else Format.fprintf fmt "%a@,on behalf of %a" pp_consensus_key consensus_key - Tezos_crypto.Signature.Public_key_hash.pp + Signature.Public_key_hash.pp delegate type validation_mode = Node | Local of Abstract_context_index.t @@ -250,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 *) @@ -358,6 +349,9 @@ type state = { type t = state +let update_current_phase state new_phase = + {state with round_state = {state.round_state with current_phase = new_phase}} + type timeout_kind = | End_of_round of {ending_round : Round.t} | Time_to_bake_next_level of {at_round : Round.t} @@ -760,7 +754,7 @@ module DelegateSet = struct type t = consensus_key let compare {public_key_hash = pkh; _} {public_key_hash = pkh'; _} = - Tezos_crypto.Signature.Public_key_hash.compare pkh pkh' + Signature.Public_key_hash.compare pkh pkh' end) let find_pkh pkh s = @@ -768,8 +762,8 @@ module DelegateSet = struct try iter (fun ({public_key_hash; _} as delegate) -> - if Tezos_crypto.Signature.Public_key_hash.equal pkh public_key_hash - then raise (Found delegate) + if Signature.Public_key_hash.equal pkh public_key_hash then + raise (Found delegate) else ()) s ; None @@ -788,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) @@ -922,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_016_PtMumbai/lib_delegate/baking_state.mli b/src/proto_016_PtMumbai/lib_delegate/baking_state.mli index 34ce3743c4ade8c291590038ccbfaa90cfcde50e..fef6d3ccc33610ab55b5439c5e6b606114b422cf 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_state.mli +++ b/src/proto_016_PtMumbai/lib_delegate/baking_state.mli @@ -28,8 +28,8 @@ open Alpha_context type consensus_key = { alias : string option; - public_key : Tezos_crypto.Signature.public_key; - public_key_hash : Tezos_crypto.Signature.public_key_hash; + public_key : Signature.public_key; + public_key_hash : Signature.public_key_hash; secret_key_uri : Client_keys.sk_uri; } @@ -37,8 +37,7 @@ val consensus_key_encoding : consensus_key Data_encoding.t val pp_consensus_key : Format.formatter -> consensus_key -> unit -type consensus_key_and_delegate = - consensus_key * Tezos_crypto.Signature.Public_key_hash.t +type consensus_key_and_delegate = consensus_key * Signature.Public_key_hash.t val consensus_key_and_delegate_encoding : consensus_key_and_delegate Data_encoding.t @@ -97,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; @@ -147,6 +146,8 @@ type state = { type t = state +val update_current_phase : t -> phase -> t + type timeout_kind = | End_of_round of {ending_round : Round.t} | Time_to_bake_next_level of {at_round : Round.t} diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_vdf.ml b/src/proto_016_PtMumbai/lib_delegate/baking_vdf.ml index cdceb772344abca5048c1fed5458bdb288e711c4..c0e97b55ea74b76b00a2368a7f96d14ab4dc9880 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_vdf.ml +++ b/src/proto_016_PtMumbai/lib_delegate/baking_vdf.ml @@ -156,7 +156,7 @@ let inject_vdf_revelation cctxt hash chain_id solution = ~solution () in - let bytes = Tezos_crypto.Signature.concat bytes Tezos_crypto.Signature.zero in + let bytes = Signature.concat bytes Signature.zero in Shell_services.Injection.operation cctxt ~chain bytes (* Checks if the VDF setup saved in the state is equal to the one computed diff --git a/src/proto_016_PtMumbai/lib_delegate/block_forge.ml b/src/proto_016_PtMumbai/lib_delegate/block_forge.ml index 917133e0e5534b6efb4ea169c29e83d87ca2fcca..062306d6367d7a0c503a6dfa2f283a45716dc282 100644 --- a/src/proto_016_PtMumbai/lib_delegate/block_forge.ml +++ b/src/proto_016_PtMumbai/lib_delegate/block_forge.ml @@ -52,7 +52,7 @@ let forge_faked_protocol_data ?(payload_hash = Block_payload_hash.zero) proof_of_work_nonce = Baking_pow.empty_proof_of_work_nonce; liquidity_baking_toggle_vote; }; - signature = Tezos_crypto.Signature.zero; + signature = Signature.zero; } let convert_operation (op : packed_operation) : Tezos_base.Operation.t = @@ -389,7 +389,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~pred_info let unsigned_block_header = { Block_header.shell = shell_header; - protocol_data = {contents; signature = Tezos_crypto.Signature.zero}; + protocol_data = {contents; signature = Signature.zero}; } in return {unsigned_block_header; operations} diff --git a/src/proto_016_PtMumbai/lib_delegate/client_baking_denunciation.ml b/src/proto_016_PtMumbai/lib_delegate/client_baking_denunciation.ml index cb6f6a02e66edb3399c16c5d855153516148a66d..2ebc4af5961ebbaaaca22a8a95d8ebd310d291f0 100644 --- a/src/proto_016_PtMumbai/lib_delegate/client_baking_denunciation.ml +++ b/src/proto_016_PtMumbai/lib_delegate/client_baking_denunciation.ml @@ -40,7 +40,7 @@ module HLevel = Hashtbl.Make (struct end) (* Blocks are associated to the delegates who baked them *) -module Delegate_Map = Map.Make (Tezos_crypto.Signature.Public_key_hash) +module Delegate_Map = Map.Make (Signature.Public_key_hash) (* (pre)endorsements are associated to the slot they are injected with; we rely on the fact that there is a unique canonical slot @@ -175,9 +175,7 @@ let process_consensus_op (type kind) cctxt ~op2 () >>=? fun bytes -> - let bytes = - Tezos_crypto.Signature.concat bytes Tezos_crypto.Signature.zero - in + let bytes = Signature.concat bytes Signature.zero in let double_op_detected, double_op_denounced = Events.( match op_kind with @@ -303,9 +301,7 @@ let process_block (cctxt : #Protocol_client_context.full) state ~bh2 () >>=? fun bytes -> - let bytes = - Tezos_crypto.Signature.concat bytes Tezos_crypto.Signature.zero - in + let bytes = Signature.concat bytes Signature.zero in Events.(emit double_baking_detected) () >>= fun () -> Shell_services.Injection.operation cctxt ~chain bytes >>=? fun op_hash -> diff --git a/src/proto_016_PtMumbai/lib_delegate/operation_selection.ml b/src/proto_016_PtMumbai/lib_delegate/operation_selection.ml index 089f4b439a9309eb74babbc42dd5f7ea9282ebb4..9a4fbf4d0b92ed64ffd2016bea743c8cebfca75b 100644 --- a/src/proto_016_PtMumbai/lib_delegate/operation_selection.ml +++ b/src/proto_016_PtMumbai/lib_delegate/operation_selection.ml @@ -57,9 +57,7 @@ module PrioritizedManagerSet = Set.Make (struct let compare {source; counter; weight; op; _} {source = source'; counter = counter'; weight = weight'; op = op'; _} = (* Be careful with the [compare] *) - let cmp_src = - Tezos_crypto.Signature.Public_key_hash.compare source source' - in + let cmp_src = Signature.Public_key_hash.compare source source' in if cmp_src = 0 then (* we want the smallest counter first *) let c = Manager_counter.compare counter counter' in diff --git a/src/proto_016_PtMumbai/lib_delegate/state_transitions.ml b/src/proto_016_PtMumbai/lib_delegate/state_transitions.ml index 6e8dd27e628468da9c64a5493c1d137d5a965e28..d39c05dbc8cdd858a589a671db6b74db8b78ebb7 100644 --- a/src/proto_016_PtMumbai/lib_delegate/state_transitions.ml +++ b/src/proto_016_PtMumbai/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 [] @@ -90,16 +90,10 @@ let make_consensus_list state proposal = (* If we do not have any slots, we won't inject any operation but we will still participate to determine an elected block *) let make_preendorse_action state proposal = - let updated_state = - let round_state = - {state.round_state with current_phase = Awaiting_preendorsements} - in - {state with round_state} - in let preendorsements : (consensus_key_and_delegate * consensus_content) list = make_consensus_list state proposal in - Inject_preendorsements {preendorsements; updated_state} + Inject_preendorsements {preendorsements} let update_proposal state proposal = Events.(emit updating_latest_proposal proposal.block.hash) >>= fun () -> @@ -120,12 +114,13 @@ let preendorse state proposal = if Protocol_hash.(proposal.block.protocol <> proposal.block.next_protocol) then (* We do not preendorse the first transition block *) - let new_round_state = {state.round_state with current_phase = Idle} in - let new_state = {state with round_state = new_round_state} in + let new_state = update_current_phase state Idle in Lwt.return (new_state, Do_nothing) else Events.(emit attempting_preendorse_proposal proposal.block.hash) - >>= fun () -> Lwt.return (state, make_preendorse_action state proposal) + >>= fun () -> + let new_state = update_current_phase state Awaiting_preendorsements in + Lwt.return (new_state, make_preendorse_action state proposal) let extract_pqc state (new_proposal : proposal) = match new_proposal.block.prequorum with @@ -247,7 +242,13 @@ let rec handle_new_proposal state (new_proposal : proposal) = | Some {round; _} when Round.(locked_round.round < round) -> (* This PQC is above our locked_round, we can preendorse it *) preendorse new_state new_proposal - | _ -> Lwt.return (new_state, Do_nothing)) + | _ -> + (* We shouldn't preendorse this proposal, but we should at + least watch (pre)quorums events on it *) + let new_state = + update_current_phase new_state Awaiting_preendorsements + in + Lwt.return (new_state, Watch_proposal)) | None -> (* Otherwise, we did not lock on any payload, thus we can preendorse it *) @@ -413,10 +414,7 @@ let propose_fresh_block_action ~endorsements ?last_proposal let kind = Fresh operation_pool in Events.(emit proposing_fresh_block (delegate, round)) >>= fun () -> let block_to_bake = {predecessor; round; delegate; kind} in - let updated_state = - let new_round_state = {state.round_state with current_phase = Idle} in - {state with round_state = new_round_state} - in + let updated_state = update_current_phase state Idle in Lwt.return @@ Inject_block {block_to_bake; updated_state} let propose_block_action state delegate round (proposal : proposal) = @@ -503,10 +501,7 @@ let propose_block_action state delegate round (proposal : proposal) = let block_to_bake = {predecessor = proposal.predecessor; round; delegate; kind} in - let updated_state = - let new_round_state = {state.round_state with current_phase = Idle} in - {state with round_state = new_round_state} - in + let updated_state = update_current_phase state Idle in Lwt.return @@ Inject_block {block_to_bake; updated_state} let end_of_round state current_round = @@ -529,8 +524,7 @@ let end_of_round state current_round = (* We don't have any delegate that may propose a new block for this round -- We will wait for preendorsements when the next level block arrive. Meanwhile, we are idle *) - let new_round_state = {new_state.round_state with current_phase = Idle} in - let new_state = {state with round_state = new_round_state} in + let new_state = update_current_phase new_state Idle in do_nothing new_state | Some (delegate, _) -> let last_proposal = state.level_state.latest_proposal.block in @@ -588,20 +582,10 @@ let update_locked_round state round payload_hash = {state with level_state = new_level_state} let make_endorse_action state proposal = - let updated_state = - let new_round_state = - {state.round_state with current_phase = Awaiting_endorsements} - in - let new_state = {state with round_state = new_round_state} in - update_locked_round - new_state - proposal.block.round - proposal.block.payload_hash - in let endorsements : (consensus_key_and_delegate * consensus_content) list = make_consensus_list state proposal in - Inject_endorsements {endorsements; updated_state} + Inject_endorsements {endorsements} let prequorum_reached_when_awaiting_preendorsements state candidate preendorsements = @@ -642,6 +626,13 @@ let prequorum_reached_when_awaiting_preendorsements state candidate else state.level_state in let new_state = {state with level_state = new_level_state} in + let new_state = + update_locked_round + new_state + latest_proposal.block.round + latest_proposal.block.payload_hash + in + let new_state = update_current_phase new_state Awaiting_endorsements in Lwt.return (new_state, make_endorse_action new_state latest_proposal) let quorum_reached_when_waiting_endorsements state candidate endorsement_qc = @@ -674,6 +665,9 @@ let quorum_reached_when_waiting_endorsements state candidate endorsement_qc = (* Hypothesis: - The state is not to be modified outside this module + (NB: there are exceptions in Baking_actions: the corner cases + [update_to_level] and [synchronize_round] and + the hack used by [inject_block]) - new_proposal's received blocks are expected to belong to our current round diff --git a/src/proto_016_PtMumbai/lib_delegate/state_transitions.mli b/src/proto_016_PtMumbai/lib_delegate/state_transitions.mli index 9dde0efaf02bba9e9c9ca327a709020e226757e3..adc5843123296c8ee79ce2c744a404011edaf46a 100644 --- a/src/proto_016_PtMumbai/lib_delegate/state_transitions.mli +++ b/src/proto_016_PtMumbai/lib_delegate/state_transitions.mli @@ -23,6 +23,9 @@ (* *) (*****************************************************************************) +(** This module, and in particular the {!step} function, modifies the automaton + state, while {!Baking_actions} performs potentially failing side-effects. *) + open Protocol open Alpha_context open Baking_state diff --git a/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 4cadea890daaf394e6626e5b8b88280c6d4a1151..346cea3ee712a470aa51077536cdf5a9cc642167 100644 --- a/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -842,7 +842,7 @@ let baker_process ~(delegates : Baking_state.consensus_key list) ~base_dir Lwt.pick [listener_process (); baker_process ()] >>=? fun () -> User_hooks.check_chain_on_success ~chain:state.chain -let genesis_protocol_data (baker_sk : Tezos_crypto.Signature.secret_key) +let genesis_protocol_data (baker_sk : Signature.secret_key) (predecessor_hash : Block_hash.t) (block_header : Block_header.shell_header) : Bytes.t = let proof_of_work_nonce = @@ -871,7 +871,7 @@ let genesis_protocol_data (baker_sk : Tezos_crypto.Signature.secret_key) (block_header, contents) in let signature = - Tezos_crypto.Signature.sign + Signature.sign ~watermark: Alpha_context.Block_header.(to_watermark (Block_header chain_id)) baker_sk @@ -887,7 +887,7 @@ let deduce_baker_sk (Protocol.Alpha_context.Parameters.bootstrap_account * Tezos_mockup_commands.Mockup_wallet.bootstrap_secret) list) (total_accounts : int) (level : int) : - Tezos_crypto.Signature.secret_key tzresult Lwt.t = + Signature.secret_key tzresult Lwt.t = (match (total_accounts, level) with | _, 0 -> return 0 (* apparently this doesn't really matter *) | _ -> @@ -902,8 +902,7 @@ let deduce_baker_sk |> WithExceptions.Option.get ~loc:__LOC__ in let secret_key = - Tezos_crypto.Signature.Secret_key.of_b58check_exn - (Uri.path (secret.sk_uri :> Uri.t)) + Signature.Secret_key.of_b58check_exn (Uri.path (secret.sk_uri :> Uri.t)) in return secret_key @@ -1078,8 +1077,7 @@ type config = { round0 : int64; round1 : int64; timeout : int; - delegate_selection : - (int32 * (int32 * Tezos_crypto.Signature.public_key_hash) list) list; + delegate_selection : (int32 * (int32 * Signature.public_key_hash) list) list; initial_seed : State_hash.t option; consensus_committee_size : int; consensus_threshold : int; @@ -1215,7 +1213,7 @@ let check_block_signature ~block_hash ~(block_header : Block_header.t) (block_header.shell, protocol_data.contents) in if - Tezos_crypto.Signature.check + Signature.check ~watermark: Alpha_context.Block_header.(to_watermark (Block_header chain_id)) public_key @@ -1227,7 +1225,7 @@ let check_block_signature ~block_hash ~(block_header : Block_header.t) "unexpected signature for %a; tried with %a@." Block_hash.pp block_hash - Tezos_crypto.Signature.Public_key.pp + Signature.Public_key.pp public_key type op_predicate = @@ -1262,7 +1260,7 @@ let op_is_signed_by ~public_key (op_hash : Operation_hash.t) Alpha_context.Operation.to_watermark (Endorsement chain_id) | Preendorsement _ -> Alpha_context.Operation.to_watermark (Preendorsement chain_id) - | _ -> Tezos_crypto.Signature.Generic_operation) + | _ -> Signature.Generic_operation) | _ -> failwith "unexpected contents in %a@." Operation_hash.pp op_hash) >>=? fun watermark -> match d.signature with @@ -1278,7 +1276,7 @@ let op_is_signed_by ~public_key (op_hash : Operation_hash.t) (op.shell, Contents_list d.contents) in return - (Tezos_crypto.Signature.check + (Signature.check ~watermark public_key signature diff --git a/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.mli b/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.mli index 2fc5f544597ab405192ac9fbdbbe698fd555af76..c01782653bdff6cf45ea010cf9df23ed1bd58741 100644 --- a/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.mli +++ b/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.mli @@ -139,8 +139,7 @@ type config = { (** Maximal duration of the test. If the test takes longer to terminate it'll be aborted with an error. *) - delegate_selection : - (int32 * (int32 * Tezos_crypto.Signature.public_key_hash) list) list; + delegate_selection : (int32 * (int32 * Signature.public_key_hash) list) list; (** Desired selection of delegates per level/round *) initial_seed : State_hash.t option; (** Optional initial seed for protocol (used to control delegate selection) *) @@ -172,21 +171,21 @@ val default_config : config to the final result. *) val run : ?config:config -> (int * (module Hooks)) list -> unit tzresult Lwt.t -val bootstrap1 : Tezos_crypto.Signature.public_key +val bootstrap1 : Signature.public_key -val bootstrap2 : Tezos_crypto.Signature.public_key +val bootstrap2 : Signature.public_key -val bootstrap3 : Tezos_crypto.Signature.public_key +val bootstrap3 : Signature.public_key -val bootstrap4 : Tezos_crypto.Signature.public_key +val bootstrap4 : Signature.public_key -val bootstrap5 : Tezos_crypto.Signature.public_key +val bootstrap5 : Signature.public_key (** Check if a block header is signed by a given delegate. *) val check_block_signature : block_hash:Block_hash.t -> block_header:Block_header.t -> - public_key:Tezos_crypto.Signature.public_key -> + public_key:Signature.public_key -> unit tzresult Lwt.t (** A shortcut type for predicates on operations. *) @@ -216,8 +215,7 @@ val mempool_has_op_ref : unit tzresult Lwt.t (** Check if an operation is signed by the given delegate. *) -val op_is_signed_by : - public_key:Tezos_crypto.Signature.public_key -> op_predicate +val op_is_signed_by : public_key:Signature.public_key -> op_predicate (** Check that an operation is a preendorsement. *) val op_is_preendorsement : ?level:int32 -> ?round:int32 -> op_predicate diff --git a/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/lib/tenderbrute.ml b/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/lib/tenderbrute.ml index fdc0a6dc5abb8041ee537196f2761b845287073b..ce3f8bba638032e0e0d5ca935d40cf774956ea05 100644 --- a/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/lib/tenderbrute.ml +++ b/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/lib/tenderbrute.ml @@ -26,9 +26,7 @@ open Protocol type delegate_selection = - (Raw_level_repr.t - * (Round_repr.t * Tezos_crypto.Signature.public_key_hash) list) - list + (Raw_level_repr.t * (Round_repr.t * Signature.public_key_hash) list) list module LevelRoundMap = Map.Make (struct type t = Level_repr.t * Round_repr.t @@ -105,12 +103,8 @@ let check ctxt ~selection = Delegate_sampler.baking_rights_owner ctxt level ~round >|= Environment.wrap_tzresult >>=? fun (ctxt, _, pk) -> - if - not - (Tezos_crypto.Signature.Public_key_hash.equal - delegate - pk.delegate) - then raise Exit + if not (Signature.Public_key_hash.equal delegate pk.delegate) then + raise Exit else return ctxt) selection ctxt diff --git a/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/lib/tenderbrute.mli b/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/lib/tenderbrute.mli index c13cc23edb6002253f31f4d91e524a6833584dfd..7b6915d2cfd283a3fed1b2dd55a2e2be4b3194fb 100644 --- a/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/lib/tenderbrute.mli +++ b/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/lib/tenderbrute.mli @@ -29,9 +29,7 @@ open Protocol one can provide a public key hash that would be the proposer. All non- specified level and rounds are not constrained. *) type delegate_selection = - (Raw_level_repr.t - * (Round_repr.t * Tezos_crypto.Signature.public_key_hash) list) - list + (Raw_level_repr.t * (Round_repr.t * Signature.public_key_hash) list) list (** Brute-force an initial seed nonce for the desired delegate selection. When found, the seed nonce is returned as a byte sequence of size 32. If diff --git a/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/tenderbrute_main.ml b/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/tenderbrute_main.ml index 123db4e59248226fa738d75b7e6225a6cac5e88d..f3558b1a198548993524bde2373b0a8f531d48ed 100644 --- a/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/tenderbrute_main.ml +++ b/src/proto_016_PtMumbai/lib_delegate/test/tenderbrute/tenderbrute_main.ml @@ -49,7 +49,7 @@ let delegate_encoding = case ~title:"Public key hash" (Tag 0) - Tezos_crypto.Signature.Public_key_hash.encoding + Signature.Public_key_hash.encoding (function `Pkh p -> Some p | _ -> None) (fun p -> `Pkh p); case diff --git a/src/proto_016_PtMumbai/lib_delegate/test/test_scenario.ml b/src/proto_016_PtMumbai/lib_delegate/test/test_scenario.ml index f10b60904c24c39e2620965ed7886a116c8d2744..cb34cc8d3d63e0d5f1f31c8ebfff437194229259 100644 --- a/src/proto_016_PtMumbai/lib_delegate/test/test_scenario.ml +++ b/src/proto_016_PtMumbai/lib_delegate/test/test_scenario.ml @@ -1,14 +1,14 @@ open Mockup_simulator -let bootstrap1 = Tezos_crypto.Signature.Public_key.hash bootstrap1 +let bootstrap1 = Signature.Public_key.hash bootstrap1 -let bootstrap2 = Tezos_crypto.Signature.Public_key.hash bootstrap2 +let bootstrap2 = Signature.Public_key.hash bootstrap2 -let bootstrap3 = Tezos_crypto.Signature.Public_key.hash bootstrap3 +let bootstrap3 = Signature.Public_key.hash bootstrap3 -let bootstrap4 = Tezos_crypto.Signature.Public_key.hash bootstrap4 +let bootstrap4 = Signature.Public_key.hash bootstrap4 -let bootstrap5 = Tezos_crypto.Signature.Public_key.hash bootstrap5 +let bootstrap5 = Signature.Public_key.hash bootstrap5 let some_seed s = Some (Protocol.State_hash.of_b58check_exn s) @@ -401,6 +401,14 @@ let test_scenario_f1 () = let d_proposed_l1_r1 = ref false in let a_proposed_l2_r0 = ref false in let stop_on_event0 _ = !a_proposed_l2_r0 in + let pass = + (* This is to be sure that the proposal for round r arrives while + the baker is in round r, and not in round r-1. (See related + issue: + https://gitlab.com/tezos/tezos/-/issues/4143). Otherwise, the + test does not perform as expected. *) + Delay 0.5 + in let module Node_a_hooks : Hooks = struct include Default_hooks @@ -416,7 +424,7 @@ let test_scenario_f1 () = (a_proposed_l2_r0 := true ; return_unit) >>=? fun () -> - return (block_hash, block_header, operations, [Pass; Pass; Pass; Pass]) + return (block_hash, block_header, operations, [pass; pass; pass; pass]) | _ -> failwith "unexpected injection on the node A, level = %ld / round = %ld" @@ -455,7 +463,7 @@ let test_scenario_f1 () = (c_proposed_l1_r0 := true ; return_unit) >>=? fun () -> - return (block_hash, block_header, operations, [Pass; Pass; Pass; Pass]) + return (block_hash, block_header, operations, [pass; pass; pass; pass]) | _ -> failwith "unexpected injection on the node C, level = %ld / round = %ld" @@ -484,7 +492,7 @@ let test_scenario_f1 () = (d_proposed_l1_r1 := true ; return_unit) >>=? fun () -> - return (block_hash, block_header, operations, [Pass; Pass; Pass; Pass]) + return (block_hash, block_header, operations, [pass; pass; pass; pass]) | _ -> failwith "unexpected injection on the node D, level = %ld / round = %ld" @@ -1465,8 +1473,7 @@ let tests = tztest "scenario t1" `Quick test_scenario_t1; tztest "scenario t2" `Quick test_scenario_t2; tztest "scenario t3" `Quick test_scenario_t3; - (* See issue https://gitlab.com/nomadic-labs/tezos/-/issues/518 *) - (* tztest "scenario f1" `Quick test_scenario_f1; *) + tztest "scenario f1" `Quick test_scenario_f1; tztest "scenario f2" `Quick test_scenario_f2; tztest "scenario m1" `Quick test_scenario_m1; tztest "scenario m2" `Quick test_scenario_m2;