From 6e4a651226098624c35a9b1500cbddb407bea1a4 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Mon, 15 Dec 2025 09:37:29 +0100 Subject: [PATCH 1/3] Alpha/DAL: add new `Slot_availability` module Currently, basically an alias to `Dal_attestation_repr`. This is to distinguish between baker DAL attestations and protocol (aggregated) DAL attestations. Currently they have the same format, but they don't need to (and with dynamic lags they will be different). --- .../lib_dal/dal_plugin_registration.ml | 3 +- src/proto_alpha/lib_protocol/alpha_context.ml | 2 ++ .../lib_protocol/alpha_context.mli | 21 +++++++++++- src/proto_alpha/lib_protocol/apply.ml | 12 +++---- src/proto_alpha/lib_protocol/apply_results.ml | 12 +++---- .../lib_protocol/apply_results.mli | 2 +- src/proto_alpha/lib_protocol/dal_apply.ml | 14 ++++---- src/proto_alpha/lib_protocol/dal_apply.mli | 8 ++--- .../lib_protocol/dal_attestation_repr.ml | 20 +++++++++++ .../lib_protocol/dal_attestation_repr.mli | 33 +++++++++++++++++++ .../lib_protocol/dal_slot_storage.ml | 16 ++++++--- .../lib_protocol/dal_slot_storage.mli | 2 +- .../integration/consensus/test_attestation.ml | 4 ++- 13 files changed, 116 insertions(+), 33 deletions(-) diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index 42e0194dbb23..d1933c2450cf 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -410,7 +410,8 @@ module Plugin = struct ~none: (TzTrace.make @@ Layer1_services.Cannot_read_block_metadata block.hash) in - return (metadata.protocol_data.dal_attestation :> Environment.Bitset.t) + return + (metadata.protocol_data.dal_slot_availability :> Environment.Bitset.t) let is_attested attestation slot_index = match Environment.Bitset.mem attestation slot_index with diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 5f493d904455..7d62b90044e7 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -147,6 +147,8 @@ module Dal = struct include Raw_context.Dal end + module Slot_availability = Dal_attestation_repr.Slot_availability + type slot_id = Dal_slot_repr.Header.id = { published_level : Raw_level_repr.t; index : Dal_slot_index_repr.t; diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 42910cf11965..806fa5c7e124 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3024,6 +3024,23 @@ module Dal : sig end end + (** See {!Dal_attestation_repr.Slot_availability}. *) + module Slot_availability : sig + type t = private Bitset.t + + val empty : t + + val encoding : t Data_encoding.t + + val is_attested : t -> Slot_index.t -> bool + + val commit : t -> Slot_index.t -> t + + val number_of_attested_slots : t -> int + + val intersection : t -> Attestation.t -> t + end + type slot_id = {published_level : Raw_level.t; index : Slot_index.t} module Page : sig @@ -3109,7 +3126,9 @@ module Dal : sig val finalize_current_slot_headers : context -> context Lwt.t val finalize_pending_slot_headers : - context -> number_of_slots:int -> (context * Attestation.t) tzresult Lwt.t + context -> + number_of_slots:int -> + (context * Slot_availability.t) tzresult Lwt.t end module Shard_with_proof : sig diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index b412a56dcbc7..18aaf484e9e6 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -3035,7 +3035,7 @@ let are_attestations_required ctxt ~level = Compare.Int32.(level_position_in_protocol > 1l) (* It also records participation in the DAL. *) -let record_attesting_participation ctxt dal_attestation = +let record_attesting_participation ctxt dal_slot_availability = let open Lwt_result_syntax in match Consensus.allowed_attestations ctxt with | None -> tzfail (Consensus.Slot_map_not_found {loc = __LOC__}) @@ -3062,7 +3062,7 @@ let record_attesting_participation ctxt dal_attestation = consensus_key.delegate initial_slot ~dal_power - dal_attestation) + dal_slot_availability) validators ctxt @@ -3258,13 +3258,13 @@ let finalize_application ctxt block_data_contents ~round ~predecessor_hash | Some nonce_hash -> Nonce.record_hash ctxt {nonce_hash; delegate = block_producer.delegate} in - let* ctxt, dal_attestation = Dal_apply.finalisation ctxt in + let* ctxt, dal_slot_availability = Dal_apply.finalisation ctxt in let* ctxt, reward_bonus, attestation_result = let* required_attestations = are_attestations_required ctxt ~level:current_level.level in if required_attestations then - let* ctxt = record_attesting_participation ctxt dal_attestation in + let* ctxt = record_attesting_participation ctxt dal_slot_availability in (* The attested level is the predecessor of the block's level. *) match Level.pred ctxt current_level with | None -> @@ -3358,7 +3358,7 @@ let finalize_application ctxt block_data_contents ~round ~predecessor_hash balance_updates; liquidity_baking_toggle_ema; implicit_operations_results; - dal_attestation; + dal_slot_availability; abaab_activation_level; attestations = attestation_result; preattestations = preattestation_result; @@ -3480,7 +3480,7 @@ let finalize_block (application_state : application_state) shell_header_opt = balance_updates = migration_balance_updates; liquidity_baking_toggle_ema; implicit_operations_results; - dal_attestation = Dal.Attestation.empty; + dal_slot_availability = Dal.Slot_availability.empty; abaab_activation_level = None; attestations = None; preattestations = None; diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index 5513562d0fe7..941992c28609 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -2627,7 +2627,7 @@ type block_metadata = { balance_updates : Receipt.balance_updates; liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; implicit_operations_results : packed_successful_manager_operation_result list; - dal_attestation : Dal.Attestation.t; + dal_slot_availability : Dal.Slot_availability.t; abaab_activation_level : Level.t option; attestations : attestations_result option; preattestations : attestations_result option; @@ -2649,7 +2649,7 @@ let block_metadata_encoding = balance_updates; liquidity_baking_toggle_ema; implicit_operations_results; - dal_attestation; + dal_slot_availability; abaab_activation_level; attestations; preattestations; @@ -2667,7 +2667,7 @@ let block_metadata_encoding = proposer_active_key, baker_active_key, consumed_gas, - dal_attestation, + dal_slot_availability, abaab_activation_level, attestations, preattestations ) )) @@ -2683,7 +2683,7 @@ let block_metadata_encoding = proposer_active_key, baker_active_key, consumed_gas, - dal_attestation, + dal_slot_availability, abaab_activation_level, attestations, preattestations ) ) @@ -2699,7 +2699,7 @@ let block_metadata_encoding = balance_updates; liquidity_baking_toggle_ema; implicit_operations_results; - dal_attestation; + dal_slot_availability; abaab_activation_level; attestations; preattestations; @@ -2723,7 +2723,7 @@ let block_metadata_encoding = (req "proposer_consensus_key" Signature.Public_key_hash.encoding) (req "baker_consensus_key" Signature.Public_key_hash.encoding) (req "consumed_milligas" Gas.Arith.n_fp_encoding) - (req "dal_attestation" Dal.Attestation.encoding) + (req "dal_attestation" Dal.Slot_availability.encoding) (req "all_bakers_attest_activation_level" (option Level.encoding)) (req "attestations" (option attestations_result_encoding)) (req "preattestations" (option attestations_result_encoding)))) diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index 638d0ea99bbb..ded224a2626f 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -344,7 +344,7 @@ type block_metadata = { balance_updates : Receipt.balance_updates; liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; implicit_operations_results : packed_successful_manager_operation_result list; - dal_attestation : Dal.Attestation.t; + dal_slot_availability : Dal.Slot_availability.t; abaab_activation_level : Level.t option; attestations : attestations_result option; preattestations : attestations_result option; diff --git a/src/proto_alpha/lib_protocol/dal_apply.ml b/src/proto_alpha/lib_protocol/dal_apply.ml index 4de63c5aeca3..db9608d6fd42 100644 --- a/src/proto_alpha/lib_protocol/dal_apply.ml +++ b/src/proto_alpha/lib_protocol/dal_apply.ml @@ -99,7 +99,7 @@ let apply_publish_commitment ctxt operation ~source = let* ctxt = Dal.Slot.register_slot_header ctxt slot_header ~source in return (ctxt, slot_header) -let record_participation ctxt delegate tb_slot ~dal_power dal_attestation = +let record_participation ctxt delegate tb_slot ~dal_power slot_availability = let open Lwt_result_syntax in let*? () = Dal.assert_feature_enabled ctxt in Dal.only_if_incentives_enabled @@ -117,12 +117,12 @@ let record_participation ctxt delegate tb_slot ~dal_power dal_attestation = with | None -> 0 | Some delegate_attestation -> - Dal.Attestation.( - intersection dal_attestation delegate_attestation + Dal.Slot_availability.( + intersection slot_availability delegate_attestation |> number_of_attested_slots) in let number_of_protocol_attested_slots = - Dal.Attestation.number_of_attested_slots dal_attestation + Dal.Slot_availability.number_of_attested_slots slot_availability in Delegate.record_dal_participation ctxt @@ -134,7 +134,7 @@ let finalisation ctxt = let open Lwt_result_syntax in Dal.only_if_feature_enabled ctxt - ~default:(fun ctxt -> return (ctxt, Dal.Attestation.empty)) + ~default:(fun ctxt -> return (ctxt, Dal.Slot_availability.empty)) (fun ctxt -> let*! ctxt = Dal.Slot.finalize_current_slot_headers ctxt in (* The fact that slots confirmation is done at finalization is very @@ -153,7 +153,7 @@ let finalisation ctxt = level where the game started. *) let number_of_slots = Constants.dal_number_of_slots ctxt in - let+ ctxt, attestation = + let+ ctxt, slot_availability = Dal.Slot.finalize_pending_slot_headers ctxt ~number_of_slots in - (ctxt, attestation)) + (ctxt, slot_availability)) diff --git a/src/proto_alpha/lib_protocol/dal_apply.mli b/src/proto_alpha/lib_protocol/dal_apply.mli index 950e75f872bf..5dbac6f1b312 100644 --- a/src/proto_alpha/lib_protocol/dal_apply.mli +++ b/src/proto_alpha/lib_protocol/dal_apply.mli @@ -68,8 +68,8 @@ val apply_publish_commitment : source:Contract.t -> (t * Dal.Slot.Header.t) tzresult -(** [record_dal_participation ctxt delegate tb_slot ~dal_power dal_attestation] - records the number of protocol-attested slots (given in [dal_attestation] +(** [record_participation ctxt delegate tb_slot ~dal_power slot_availability] + records the number of protocol-attested slots (given in [slot_availability]) attested by [delegate] (with the initial TB slot [tb_slot] and [dal_power] assigned shards per slot) in the current block. *) val record_participation : @@ -77,7 +77,7 @@ val record_participation : Signature.Public_key_hash.t -> Slot.t -> dal_power:int -> - Dal.Attestation.t -> + Dal.Slot_availability.t -> t tzresult Lwt.t (** [finalisation ctxt] should be executed at block finalisation @@ -86,4 +86,4 @@ val record_participation : [lag] is a parametric constant specific to the data-availability layer. *) -val finalisation : t -> (t * Dal.Attestation.t) tzresult Lwt.t +val finalisation : t -> (t * Dal.Slot_availability.t) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/dal_attestation_repr.ml b/src/proto_alpha/lib_protocol/dal_attestation_repr.ml index 5b3a5da42d5d..84fea8f1cfcc 100644 --- a/src/proto_alpha/lib_protocol/dal_attestation_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_attestation_repr.ml @@ -232,6 +232,26 @@ module Dal_dependent_signing = struct t end +type attestation = t + +(** Slot availability represents the protocol's attestation result for a block. + It is an alias to the main attestation type. *) +module Slot_availability = struct + type nonrec t = t + + let empty = empty + + let encoding = encoding + + let is_attested = is_attested + + let commit = commit + + let number_of_attested_slots = number_of_attested_slots + + let intersection = intersection +end + module Internal_for_tests = struct let of_z = Bitset.from_z end diff --git a/src/proto_alpha/lib_protocol/dal_attestation_repr.mli b/src/proto_alpha/lib_protocol/dal_attestation_repr.mli index 52205443ae30..5dacc11d0b83 100644 --- a/src/proto_alpha/lib_protocol/dal_attestation_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_attestation_repr.mli @@ -178,6 +178,39 @@ module Dal_dependent_signing : sig Bls.t option end +(** Type alias for use in submodules. *) +type attestation = t + +(** Slot availability represents the protocol's attestation result for a block. + + This wraps {!t} but is kept as a separate module to allow for potential + future interface differences between attestations in operations and + attestation results in block metadata. *) +module Slot_availability : sig + (** The slot availability type. Currently identical to {!t}. *) + type t = private Bitset.t + + (** [empty] is the empty slot availability. *) + val empty : t + + (** [encoding] is the data encoding for slot availability (bitset). *) + val encoding : t Data_encoding.t + + (** [is_attested t slot_index] returns [true] if the slot at [slot_index] + is attested as available. *) + val is_attested : t -> Dal_slot_index_repr.t -> bool + + (** [commit t slot_index] marks the slot at [slot_index] as attested. *) + val commit : t -> Dal_slot_index_repr.t -> t + + (** [number_of_attested_slots t] returns the number of attested slots. *) + val number_of_attested_slots : t -> int + + (** [intersection slot_availability attestation] returns the slots attested in both + [sa] and [attestation]. *) + val intersection : t -> attestation -> t +end + module Internal_for_tests : sig (** Builds a {!type-t} from its integer representation, that is, the sum of powers of two of the indexes of attested slots. diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.ml b/src/proto_alpha/lib_protocol/dal_slot_storage.ml index d3914d486840..4515dfc490f0 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.ml @@ -44,7 +44,10 @@ let compute_slot_headers_statuses ~is_slot_attested published_slot_headers = let attestation = if attestation_status.Dal_attestation_repr.Accountability.is_proto_attested - then Dal_attestation_repr.commit attestation slot.Header.id.index + then + Dal_attestation_repr.Slot_availability.commit + attestation + slot.Header.id.index else attestation in (rev_attested_slot_headers, attestation) @@ -52,7 +55,7 @@ let compute_slot_headers_statuses ~is_slot_attested published_slot_headers = let rev_attested_slot_headers, bitset = List.fold_left fold_attested_slots - ([], Dal_attestation_repr.empty) + ([], Dal_attestation_repr.Slot_availability.empty) published_slot_headers in (List.rev rev_attested_slot_headers, bitset) @@ -126,7 +129,7 @@ let finalize_slot_headers_for_published_level ctxt ~number_of_slots let*! ctxt = remove_old_headers ctxt ~published_level in let* ctxt, attestation, slot_headers_statuses = match published_slots with - | None -> return (ctxt, Dal_attestation_repr.empty, []) + | None -> return (ctxt, Dal_attestation_repr.Slot_availability.empty, []) | Some published_slots -> let slot_headers_statuses, attestation = compute_slot_headers_statuses ~is_slot_attested published_slots @@ -191,7 +194,10 @@ let finalize_slot_headers_at_lag_migration ctxt ~target_published_level match Raw_level_repr.(sub target_published_level current_gap) with | None -> (* Defensive: not expected on our networks. *) - return (ctxt, Dal_attestation_repr.empty, cells_of_pub_levels) + return + ( ctxt, + Dal_attestation_repr.Slot_availability.empty, + cells_of_pub_levels ) | Some published_level -> (* Finalize this published level. *) let* ctxt, attestation_bitset = @@ -231,7 +237,7 @@ let finalize_pending_slot_headers ctxt ~number_of_slots = let Constants_parametric_repr.{dal; _} = Raw_context.constants ctxt in let curr_attestation_lag = dal.attestation_lag in match Raw_level_repr.(sub raw_level curr_attestation_lag) with - | None -> return (ctxt, Dal_attestation_repr.empty) + | None -> return (ctxt, Dal_attestation_repr.Slot_availability.empty) | Some published_level -> (* DAL/TODO: remove after P1->P2 migration: diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.mli b/src/proto_alpha/lib_protocol/dal_slot_storage.mli index 2ad95e5146fe..d3148ed85528 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.mli @@ -77,7 +77,7 @@ val finalize_current_slot_headers : Raw_context.t -> Raw_context.t Lwt.t val finalize_pending_slot_headers : Raw_context.t -> number_of_slots:int -> - (Raw_context.t * Dal_attestation_repr.t) tzresult Lwt.t + (Raw_context.t * Dal_attestation_repr.Slot_availability.t) tzresult Lwt.t (** [get_slot_headers_history ctxt] returns the current value of slots_history stored in [ctxt], or Slots_history.genesis if no value is stored yet. *) diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_attestation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_attestation.ml index 1ec4b0405ad5..1791e1ddb0d6 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_attestation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_attestation.ml @@ -783,7 +783,9 @@ let test_dal_attestation_threshold () = in let attested_expected = power >= min_power in let attested = - Dal.Attestation.is_attested metadata.dal_attestation slot_index + Dal.Slot_availability.is_attested + metadata.dal_slot_availability + slot_index in Log.info "With %d power, the slot is attested: %b " power attested ; Check.(attested = attested_expected) -- GitLab From a9af8efd7a85fbbf6d2868651784aa1ee946abe7 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Mon, 15 Dec 2025 14:44:39 +0100 Subject: [PATCH 2/3] Alpha/DAL: remove unused `Dal_attestation_repr.intersection` --- src/proto_alpha/lib_protocol/alpha_context.mli | 2 -- src/proto_alpha/lib_protocol/dal_attestation_repr.ml | 4 +--- src/proto_alpha/lib_protocol/dal_attestation_repr.mli | 3 --- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 806fa5c7e124..a72e6da59fd1 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2980,8 +2980,6 @@ module Dal : sig val number_of_attested_slots : t -> int - val intersection : t -> t -> t - val record_number_of_attested_shards : context -> t -> int -> context val record_attestation : context -> tb_slot:Slot.t -> t -> context diff --git a/src/proto_alpha/lib_protocol/dal_attestation_repr.ml b/src/proto_alpha/lib_protocol/dal_attestation_repr.ml index 84fea8f1cfcc..9a2f3187efa8 100644 --- a/src/proto_alpha/lib_protocol/dal_attestation_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_attestation_repr.ml @@ -65,8 +65,6 @@ let expected_size_in_bits ~max_index = let number_of_attested_slots = Bitset.cardinal -let intersection = Bitset.inter - type shard_index = int module Shard_map = Map.Make (struct @@ -249,7 +247,7 @@ module Slot_availability = struct let number_of_attested_slots = number_of_attested_slots - let intersection = intersection + let intersection = Bitset.inter end module Internal_for_tests = struct diff --git a/src/proto_alpha/lib_protocol/dal_attestation_repr.mli b/src/proto_alpha/lib_protocol/dal_attestation_repr.mli index 5dacc11d0b83..4f0871ea6e03 100644 --- a/src/proto_alpha/lib_protocol/dal_attestation_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_attestation_repr.mli @@ -73,9 +73,6 @@ val expected_size_in_bits : max_index:Dal_slot_index_repr.t -> int slots in an attestation. *) val number_of_attested_slots : t -> int -(** [intersection a1 a2] returns the slots attested in both [a1] and [a2]. *) -val intersection : t -> t -> t - (** A shard_index is a positive number. *) type shard_index = int -- GitLab From 5126a328df9904bd2aaae48a8eae3e1cc6737872 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Mon, 15 Dec 2025 09:45:42 +0100 Subject: [PATCH 3/3] DAL/Plugin: distinguish baker and protocol attestations --- src/lib_dal_node/accuser.ml | 2 +- src/lib_dal_node/block_handler.ml | 10 ++++----- src/lib_dal_node/dal_plugin.ml | 8 +++++-- src/lib_dal_node/dal_plugin.mli | 22 +++++++++++++------ .../lib_dal/dal_plugin_registration.ml | 11 ++++++++-- .../lib_dal/dal_plugin_registration.ml | 11 ++++++++-- .../lib_dal/dal_plugin_registration.ml | 11 ++++++++-- .../lib_dal/dal_plugin_registration.ml | 11 ++++++++-- .../lib_dal/dal_plugin_registration.ml | 11 ++++++++-- 9 files changed, 72 insertions(+), 25 deletions(-) diff --git a/src/lib_dal_node/accuser.ml b/src/lib_dal_node/accuser.ml index 2e747fd1a4ec..a9bf42793983 100644 --- a/src/lib_dal_node/accuser.ml +++ b/src/lib_dal_node/accuser.ml @@ -119,7 +119,7 @@ let inject_entrapment_evidences shard_proof, tb_slot ) -> - if Plugin.is_attested dal_attestation slot_index then + if Plugin.is_baker_attested dal_attestation slot_index then let*! () = Event.emit_trap_injection ~delegate diff --git a/src/lib_dal_node/block_handler.ml b/src/lib_dal_node/block_handler.ml index 0a3c6fcf4e61..2bf65eaad205 100644 --- a/src/lib_dal_node/block_handler.ml +++ b/src/lib_dal_node/block_handler.ml @@ -539,9 +539,9 @@ let process_finalized_block_data ctxt cctxt store ~prev_proto_parameters [@profiler.record_s {verbosity = Notice} "store_skip_list_cells"] else return_unit in - let*? dal_attestation = - (Plugin.dal_attestation - block_info [@profiler.record_f {verbosity = Notice} "dal_attestation"]) + let*? slot_availability = + (Plugin.slot_availability + block_info [@profiler.record_f {verbosity = Notice} "slot_availability"]) in let () = update_slot_headers_statuses @@ -555,7 +555,7 @@ let process_finalized_block_data ctxt cctxt store ~prev_proto_parameters proto_parameters ctxt ~attested_level:block_level - (Plugin.is_attested dal_attestation) + (Plugin.is_protocol_attested slot_availability) [@profiler.record_s {verbosity = Notice} "remove_unattested_slots_and_shards"]) in @@ -584,7 +584,7 @@ let process_finalized_block_data ctxt cctxt store ~prev_proto_parameters proto_parameters ~block_level attestations - Plugin.is_attested + Plugin.is_baker_attested Plugin.tb_slot_to_int [@profiler.record_s {verbosity = Notice} "check_attesters_attested"]) in diff --git a/src/lib_dal_node/dal_plugin.ml b/src/lib_dal_node/dal_plugin.ml index ff6fa1438b58..41d135b3c1ac 100644 --- a/src/lib_dal_node/dal_plugin.ml +++ b/src/lib_dal_node/dal_plugin.ml @@ -42,6 +42,8 @@ module type T = sig type dal_attestation + type slot_availability + type attestation_operation type tb_slot @@ -77,9 +79,11 @@ module type T = sig level:int32 -> (int list * int) Signature.Public_key_hash.Map.t tzresult Lwt.t - val dal_attestation : block_info -> dal_attestation tzresult + val slot_availability : block_info -> slot_availability tzresult + + val is_baker_attested : dal_attestation -> slot_index -> bool - val is_attested : dal_attestation -> slot_index -> bool + val is_protocol_attested : slot_availability -> slot_index -> bool val number_of_attested_slots : dal_attestation -> int diff --git a/src/lib_dal_node/dal_plugin.mli b/src/lib_dal_node/dal_plugin.mli index 29f8704477f2..1317c219d448 100644 --- a/src/lib_dal_node/dal_plugin.mli +++ b/src/lib_dal_node/dal_plugin.mli @@ -49,8 +49,12 @@ module type T = sig type block_info + (* The DAL content an attester includes in its attestation operation. *) type dal_attestation + (* The slot availability information from a block's metadata. *) + type slot_availability + type attestation_operation type tb_slot @@ -102,17 +106,21 @@ module type T = sig level:int32 -> (int list * int) Signature.Public_key_hash.Map.t tzresult Lwt.t - (** [dal_attestation block_info] returns the metadata of the given - [block_info] as an abstract value of type [dal_attestation] to be passed - to the [is_attested] function. + (** [slot_availability block_info] returns the metadata of the given + [block_info] as an abstract value of type [slot_availability] to be passed + to the [is_protocol_attested] function. Fails with [Cannot_read_block_metadata] if [block_info]'s metadata are stripped. *) - val dal_attestation : block_info -> dal_attestation tzresult + val slot_availability : block_info -> slot_availability tzresult + + (** [is_baker_attested dal_attestation slot_index] returns [true] if [slot_index] + is set in the bitset of the [dal_attestation] and [false] otherwise. *) + val is_baker_attested : dal_attestation -> slot_index -> bool - (** [is_attested dal_attestation index] returns [true] if [index] - is one of the [dal_attestation] and [false] otherwise. *) - val is_attested : dal_attestation -> slot_index -> bool + (** [is_protocol_attested slot_availability slot_index] returns [true] if [slot_index] + is one of the attested slots in [slot_availability] and [false] otherwise. *) + val is_protocol_attested : slot_availability -> slot_index -> bool (** [number_of_attested_slots] returns the number of slots attested in the [dal_attestation]. *) val number_of_attested_slots : dal_attestation -> int diff --git a/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml b/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml index 9a961e134d55..8fe1f6c7057f 100644 --- a/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml +++ b/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml @@ -35,6 +35,8 @@ module Plugin = struct type dal_attestation = Bitset.t + type slot_availability = Bitset.t + type attestation_operation = Kind.attestation Alpha_context.operation type tb_slot = int @@ -241,7 +243,7 @@ module Plugin = struct Tezos_crypto.Signature.Public_key_hash.Map.empty pkh_to_shards - let dal_attestation (block : block_info) = + let slot_availability (block : block_info) = let open Result_syntax in let* metadata = Option.to_result @@ -251,9 +253,14 @@ module Plugin = struct in return (metadata.protocol_data.dal_attestation :> Bitset.t) - let is_attested attestation slot_index = + let is_baker_attested attestation slot_index = match Bitset.mem attestation slot_index with Ok b -> b | Error _ -> false + let is_protocol_attested slot_availability slot_index = + match Bitset.mem slot_availability slot_index with + | Ok b -> b + | Error _ -> false + let number_of_attested_slots attestation = Bitset.hamming_weight attestation let is_delegate ctxt ~pkh = diff --git a/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml b/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml index 25dbe72ae2bc..1d4bed778353 100644 --- a/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml +++ b/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml @@ -35,6 +35,8 @@ module Plugin = struct type dal_attestation = Environment.Bitset.t + type slot_availability = Environment.Bitset.t + type attestation_operation = Kind.attestation Alpha_context.operation type tb_slot = int @@ -269,7 +271,7 @@ module Plugin = struct Tezos_crypto.Signature.Public_key_hash.Map.empty pkh_to_shards - let dal_attestation (block : block_info) = + let slot_availability (block : block_info) = let open Result_syntax in let* metadata = Option.to_result @@ -279,11 +281,16 @@ module Plugin = struct in return (metadata.protocol_data.dal_attestation :> Environment.Bitset.t) - let is_attested attestation slot_index = + let is_baker_attested attestation slot_index = match Environment.Bitset.mem attestation slot_index with | Ok b -> b | Error _ -> false + let is_protocol_attested slot_availability slot_index = + match Environment.Bitset.mem slot_availability slot_index with + | Ok b -> b + | Error _ -> false + let number_of_attested_slots attestation = Environment.Bitset.cardinal attestation diff --git a/src/proto_023_PtSeouLo/lib_dal/dal_plugin_registration.ml b/src/proto_023_PtSeouLo/lib_dal/dal_plugin_registration.ml index cdf0b9e9fd37..d99859236b66 100644 --- a/src/proto_023_PtSeouLo/lib_dal/dal_plugin_registration.ml +++ b/src/proto_023_PtSeouLo/lib_dal/dal_plugin_registration.ml @@ -35,6 +35,8 @@ module Plugin = struct type dal_attestation = Environment.Bitset.t + type slot_availability = Environment.Bitset.t + type attestation_operation = | Op : 'a Kind.consensus Alpha_context.operation -> attestation_operation @@ -323,7 +325,7 @@ module Plugin = struct Tezos_crypto.Signature.Public_key_hash.Map.empty pkh_to_shards - let dal_attestation (block : block_info) = + let slot_availability (block : block_info) = let open Result_syntax in let* metadata = Option.to_result @@ -333,11 +335,16 @@ module Plugin = struct in return (metadata.protocol_data.dal_attestation :> Environment.Bitset.t) - let is_attested attestation slot_index = + let is_baker_attested attestation slot_index = match Environment.Bitset.mem attestation slot_index with | Ok b -> b | Error _ -> false + let is_protocol_attested slot_availability slot_index = + match Environment.Bitset.mem slot_availability slot_index with + | Ok b -> b + | Error _ -> false + let number_of_attested_slots attestation = Environment.Bitset.cardinal attestation diff --git a/src/proto_024_PtTALLiN/lib_dal/dal_plugin_registration.ml b/src/proto_024_PtTALLiN/lib_dal/dal_plugin_registration.ml index 1add99f4757c..e152929b0606 100644 --- a/src/proto_024_PtTALLiN/lib_dal/dal_plugin_registration.ml +++ b/src/proto_024_PtTALLiN/lib_dal/dal_plugin_registration.ml @@ -35,6 +35,8 @@ module Plugin = struct type dal_attestation = Environment.Bitset.t + type slot_availability = Environment.Bitset.t + type attestation_operation = | Op : 'a Kind.consensus Alpha_context.operation -> attestation_operation @@ -365,7 +367,7 @@ module Plugin = struct Tezos_crypto.Signature.Public_key_hash.Map.empty pkh_to_shards - let dal_attestation (block : block_info) = + let slot_availability (block : block_info) = let open Result_syntax in let* metadata = Option.to_result @@ -375,11 +377,16 @@ module Plugin = struct in return (metadata.protocol_data.dal_attestation :> Environment.Bitset.t) - let is_attested attestation slot_index = + let is_baker_attested attestation slot_index = match Environment.Bitset.mem attestation slot_index with | Ok b -> b | Error _ -> false + let is_protocol_attested slot_availability slot_index = + match Environment.Bitset.mem slot_availability slot_index with + | Ok b -> b + | Error _ -> false + let number_of_attested_slots attestation = Environment.Bitset.cardinal attestation diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index d1933c2450cf..04e5765f81e5 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -35,6 +35,8 @@ module Plugin = struct type dal_attestation = Environment.Bitset.t + type slot_availability = Environment.Bitset.t + type attestation_operation = | Op : 'a Kind.consensus Alpha_context.operation -> attestation_operation @@ -402,7 +404,7 @@ module Plugin = struct Tezos_crypto.Signature.Public_key_hash.Map.empty pkh_to_shards - let dal_attestation (block : block_info) = + let slot_availability (block : block_info) = let open Result_syntax in let* metadata = Option.to_result @@ -413,11 +415,16 @@ module Plugin = struct return (metadata.protocol_data.dal_slot_availability :> Environment.Bitset.t) - let is_attested attestation slot_index = + let is_baker_attested attestation slot_index = match Environment.Bitset.mem attestation slot_index with | Ok b -> b | Error _ -> false + let is_protocol_attested slot_availability slot_index = + match Environment.Bitset.mem slot_availability slot_index with + | Ok b -> b + | Error _ -> false + let number_of_attested_slots attestation = Environment.Bitset.cardinal attestation -- GitLab