diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 5cb8ffb7458c3cafe27b0ec0fe5e2fc049c59373..3fb6ea422a9d6921e4558c08bc29293ee53901d3 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -57,8 +57,8 @@ "Entrypoint_repr", "Dal_slot_index_repr", - "Dal_slot_repr", "Dal_attestation_repr", + "Dal_slot_repr", "Michelson_v1_gas_costs_generated", "Michelson_v1_gas_costs", diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 7e7944632c3f58a635455043891a806039af543a..f0731d911004f4037fb1580deaeb130e24717783 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -142,6 +142,7 @@ module Dal = struct end module Attestation = struct + include Dal_attestation_repr.Accountability include Dal_attestation_repr include Raw_context.Dal end diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 8532ba0fc6564da77a0386771cc4b118a561a58b..eb0311381e2d2763c51e680bb215dc7ef90c9577 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2776,6 +2776,12 @@ module Dal : sig type shard_index = int + type attestation_status = { + total_shards : int; + attested_shards : int; + is_proto_attested : bool; + } + module Shard_map : Map.S with type key = shard_index val encoding : t Data_encoding.t @@ -2874,11 +2880,6 @@ module Dal : sig val finalize_pending_slot_headers : context -> number_of_slots:int -> (context * Attestation.t) tzresult Lwt.t - - val compute_attested_slot_headers : - is_slot_attested:(Header.t -> bool) -> - Header.t list -> - Header.t list * Attestation.t end module Operations : sig @@ -2922,19 +2923,19 @@ module Dal : sig module History_cache : Bounded_history_repr.S with type key = hash and type value = t - val add_confirmed_slot_headers_no_cache : + val update_skip_list_no_cache : t -> Raw_level.t -> number_of_slots:int -> - Slot.Header.t list -> + (Slot.Header.t * Attestation.attestation_status) list -> t tzresult - val add_confirmed_slot_headers : + val update_skip_list : t -> History_cache.t -> Raw_level.t -> number_of_slots:int -> - Slot.Header.t list -> + (Slot.Header.t * Attestation.attestation_status) list -> (t * History_cache.t) tzresult type proof diff --git a/src/proto_alpha/lib_protocol/dal_attestation_repr.ml b/src/proto_alpha/lib_protocol/dal_attestation_repr.ml index 920e04d7da5c538073280427030a9d51c463aee4..d8429e61a2e9e0b6ce8ad0314b88dc0bcc0f55fe 100644 --- a/src/proto_alpha/lib_protocol/dal_attestation_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_attestation_repr.ml @@ -95,6 +95,12 @@ module Accountability = struct type t = {number_of_attested_shards : int SlotMap.t; number_of_slots : int} + type attestation_status = { + total_shards : int; + attested_shards : int; + is_proto_attested : bool; + } + let init ~number_of_slots = {number_of_attested_shards = SlotMap.empty; number_of_slots} @@ -129,6 +135,25 @@ module Accountability = struct let number_of_attested_shards = iter 0 t.number_of_attested_shards in {t with number_of_attested_shards} + (* Given a slot encoded as [number_of_shards] shards and for which + [number_of_attested_shards] are attested by the bakers. The slot is + declated as attested_slots IFF at least [threshold] % of the total shards + are attested by bakers. + + On rationals, the condition above means: + + number_of_attested_shards / number_of_shards >= threshold / 100, + + which is equivalent, on rationals, to: + + number_of_attested_shards >= (threshold * number_of_shards) / 100 + + Note that the last reformulation translates to integers. *) + let compute_proto_attestation_status ~number_of_attested_shards ~threshold + ~number_of_shards = + Compare.Int.( + number_of_attested_shards >= threshold * number_of_shards / 100) + let is_slot_attested t ~threshold ~number_of_shards slot_index = let index = Dal_slot_index_repr.to_int slot_index in let number_of_attested_shards = @@ -136,6 +161,15 @@ module Accountability = struct | None -> 0 | Some v -> v in - Compare.Int.( - number_of_attested_shards >= threshold * number_of_shards / 100) + let is_proto_attested = + compute_proto_attestation_status + ~number_of_attested_shards + ~threshold + ~number_of_shards + in + { + is_proto_attested; + attested_shards = number_of_attested_shards; + total_shards = number_of_shards; + } end diff --git a/src/proto_alpha/lib_protocol/dal_attestation_repr.mli b/src/proto_alpha/lib_protocol/dal_attestation_repr.mli index a9edc93ac34c401191bc219e44ccc5fc49ef9290..b923708702237178488709cc2725a923e9a0b766 100644 --- a/src/proto_alpha/lib_protocol/dal_attestation_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_attestation_repr.mli @@ -92,6 +92,15 @@ module Accountability : sig (** The data-structure used to record the shards attestations. *) type t + type attestation_status = { + total_shards : int; (** The total number of (attestable) shards. *) + attested_shards : int; + (** The total number of shards that have been attested. *) + is_proto_attested : bool; + (** The boolean is set to [true] IFF the [attestation_ratio] is below or + equal to the threshold defined by the protocol. *) + } + (** DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3145 Consider using the [Bounded] module. In particular, change the @@ -113,7 +122,15 @@ module Accountability : sig [threshold] with respect to the total number of shards specified by [number_of_shards]. Returns [false] otherwise or if the [index] is out of the interval [0; number_of_slots - 1] where [number_of_slots] is the value - provided to the [init] function. *) + provided to the [init] function. + + Whether the slot is attested by the protocol or not, the function also + returns the ratio of attested shards w.r.t. total shards, as a rational + number. *) val is_slot_attested : - t -> threshold:int -> number_of_shards:int -> Dal_slot_index_repr.t -> bool + t -> + threshold:int -> + number_of_shards:int -> + Dal_slot_index_repr.t -> + attestation_status end diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index c1d216aee8850cbeace00167e4d7ac2354be263d..87fc6d51ab7e0dca6deb3809b4f3cec5983f77dd 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -552,7 +552,7 @@ module History = struct - [l] is well sorted wrt. slots indices. *) let fill_slot_headers ~number_of_slots ~published_level - attested_slot_headers = + slot_headers_with_statuses = let open Result_syntax in let module I = Dal_slot_index_repr in let* all_indices = @@ -561,6 +561,8 @@ module History = struct let mk_unattested index = Content.Unattested Header.{published_level; index} in + (* TODO: Follow-up MR: Take the value of _s_status into account. *) + let attested_slot_headers = List.map fst slot_headers_with_statuses in (* Hypothesis: both lists are sorted in increasing order w.r.t. slots indices. *) let rec aux indices slots = @@ -584,37 +586,37 @@ module History = struct insert exactly [number_of_slots] cells in the skip list per level. This will simplify the shape of proofs and help bounding the history cache required for their generation. *) - let add_confirmed_slot_headers (t : t) cache published_level - ~number_of_slots attested_slot_headers = + let update_skip_list (t : t) cache published_level ~number_of_slots + slot_headers_with_statuses = let open Result_syntax in let* () = List.iter_e - (fun slot_header -> + (fun (slot_header, _status) -> error_unless Raw_level_repr.( published_level = slot_header.Header.id.published_level) Add_element_in_slots_skip_list_violates_ordering) - attested_slot_headers + slot_headers_with_statuses in let* slot_headers = fill_slot_headers ~number_of_slots ~published_level - attested_slot_headers + slot_headers_with_statuses in List.fold_left_e (add_cell ~number_of_slots) (t, cache) slot_headers - let add_confirmed_slot_headers_no_cache = + let update_skip_list_no_cache = let empty_cache = History_cache.empty ~capacity:0L in - fun t published_level ~number_of_slots slots -> + fun t published_level ~number_of_slots slot_headers_with_statuses -> let open Result_syntax in let+ cell, (_ : History_cache.t) = - add_confirmed_slot_headers + update_skip_list t empty_cache published_level ~number_of_slots - slots + slot_headers_with_statuses in cell diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index 40c8f94c91f02258ff1d024983f0553e21f924ca..568e27b34844b7bc48092dc710d596c08821e193 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -229,12 +229,12 @@ module History : sig {!Raw_level_repr.root} as published level and no attested slots. Since Dal is not necessarily activated in the genesis block (e.g. this will be the case on mainnet), the skip list is reset at the first call to - {!add_confirmed_slot_headers} to enforce the invariant that there are no gaps + {!update_skip_list} to enforce the invariant that there are no gaps in the levels of the cells of the skip list. So, a skip list is initialized with this genesis cell. It's then replaced with a growing (non-dummy) skip list as soon as a call to - {!add_confirmed_slot_headers} with a level bigger than + {!update_skip_list} with a level bigger than {!Raw_level_repr.root} is performed. This allows to activate Dal at any level and having a contiguous skip list (w.r.t. L1 levels). This representation allows to produce simpler proofs with a bounded history @@ -254,10 +254,10 @@ module History : sig module History_cache : Bounded_history_repr.S with type key = hash and type value = t - (** [add_confirmed_slots hist cache published_level ~number_of_slots - slot_headers] updates the given structure [hist] with the list of - [slot_headers]. The given [cache] is also updated to add successive values - of [cell] to it. + (** [update_skip_list hist cache published_level ~number_of_slots + slot_headers_with_statuses] updates the given structure [hist] with the + list of [slot_headers_with_statuses]. The given [cache] is also updated to + add successive values of [cell] to it. This function checks the following pre-conditions before updating the @@ -268,20 +268,24 @@ module History : sig - [published_level] is the successor the last inserted cell's level. - - [slot_headers] is sorted in increasing order w.r.t. slots indices. - *) - val add_confirmed_slot_headers : + - [slot_headers_with_statuses] is sorted in increasing order w.r.t. slots + indices. *) + val update_skip_list : t -> History_cache.t -> Raw_level_repr.t -> number_of_slots:int -> - Header.t list -> + (Header.t * Dal_attestation_repr.Accountability.attestation_status) list -> (t * History_cache.t) tzresult - (** Similiar to {!add_confirmed_slot_headers}, but no cache is provided or + (** Similiar to {!update_skip_list}, but no cache is provided or updated. *) - val add_confirmed_slot_headers_no_cache : - t -> Raw_level_repr.t -> number_of_slots:int -> Header.t list -> t tzresult + val update_skip_list_no_cache : + t -> + Raw_level_repr.t -> + number_of_slots:int -> + (Header.t * Dal_attestation_repr.Accountability.attestation_status) list -> + t tzresult (** [equal a b] returns true iff a is equal to b. *) val equal : t -> t -> bool diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.ml b/src/proto_alpha/lib_protocol/dal_slot_storage.ml index 6245a97db954ff42624304eb4e6aa9f8300f317f..a5f8621c6bf4405e0b3f43c03066f1d26acb10ef 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.ml @@ -33,13 +33,20 @@ let finalize_current_slot_headers ctxt = (Raw_context.current_level ctxt).level (Raw_context.Dal.candidates ctxt) -let compute_attested_slot_headers ~is_slot_attested seen_slot_headers = +let compute_slot_headers_statuses ~is_slot_attested seen_slot_headers = let open Dal_slot_repr in let fold_attested_slots (rev_attested_slot_headers, attestation) slot = - if is_slot_attested slot then - ( slot :: rev_attested_slot_headers, - Dal_attestation_repr.commit attestation slot.Header.id.index ) - else (rev_attested_slot_headers, attestation) + let attestation_status = is_slot_attested slot in + let rev_attested_slot_headers = + (slot, attestation_status) :: rev_attested_slot_headers + in + let attestation = + if + attestation_status.Dal_attestation_repr.Accountability.is_proto_attested + then Dal_attestation_repr.commit attestation slot.Header.id.index + else attestation + in + (rev_attested_slot_headers, attestation) in let rev_attested_slot_headers, bitset = List.fold_left @@ -56,7 +63,7 @@ let get_slot_headers_history ctxt = | None -> Dal_slot_repr.History.genesis | Some slots_history -> slots_history -let update_skip_list ctxt ~confirmed_slot_headers ~level_attested +let update_skip_list ctxt ~slot_headers_statuses ~level_attested ~number_of_slots = let open Lwt_result_syntax in let open Dal_slot_repr.History in @@ -68,12 +75,12 @@ let update_skip_list ctxt ~confirmed_slot_headers ~level_attested *) (* We expect to put exactly [number_of_slots] cells in the cache. *) let cache = History_cache.empty ~capacity:(Int64.of_int number_of_slots) in - add_confirmed_slot_headers + update_skip_list ~number_of_slots slots_history cache level_attested - confirmed_slot_headers + slot_headers_statuses in let*! ctxt = Storage.Dal.Slot.History.add ctxt slots_history in let*! ctxt = @@ -91,24 +98,24 @@ let finalize_pending_slot_headers ctxt ~number_of_slots = | Some level_attested -> let* seen_slots = find_slot_headers ctxt level_attested in let*! ctxt = Storage.Dal.Slot.Headers.remove ctxt level_attested in - let* ctxt, attestation, confirmed_slot_headers = + let* ctxt, attestation, slot_headers_statuses = match seen_slots with | None -> return (ctxt, Dal_attestation_repr.empty, []) | Some seen_slots -> - let attested_slot_headers, attestation = + let slot_headers_statuses, attestation = let is_slot_attested slot = Raw_context.Dal.is_slot_index_attested ctxt slot.Dal_slot_repr.Header.id.index in - compute_attested_slot_headers ~is_slot_attested seen_slots + compute_slot_headers_statuses ~is_slot_attested seen_slots in - return (ctxt, attestation, attested_slot_headers) + return (ctxt, attestation, slot_headers_statuses) in let* ctxt = update_skip_list ctxt - ~confirmed_slot_headers + ~slot_headers_statuses ~level_attested ~number_of_slots in diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.mli b/src/proto_alpha/lib_protocol/dal_slot_storage.mli index 792b69997e054be9bf404c9a8a27ff8651db7852..d93cb76463eb8a08c1660c7f5e8decaabdf0343b 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.mli @@ -82,11 +82,3 @@ val finalize_pending_slot_headers : in [ctxt], or Slots_history.genesis if no value is stored yet. *) val get_slot_headers_history : Raw_context.t -> Dal_slot_repr.History.t tzresult Lwt.t - -(** [compute_attested_slot_headers ~is_slot_attested published_slot_headers] - filter the given [published_slot_headers] and return the list of attested - slot headers and the corresponding bitset. *) -val compute_attested_slot_headers : - is_slot_attested:(Dal_slot_repr.Header.t -> bool) -> - Dal_slot_repr.Header.t list -> - Dal_slot_repr.Header.t list * Dal_attestation_repr.t diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index 24f8b2a0e10347a2ac712f815a49ae619691d201..f50c2d3c1c8aacf534e309183ecfe287cecf176d 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -84,8 +84,8 @@ Indexable Entrypoint_repr Dal_slot_index_repr - Dal_slot_repr Dal_attestation_repr + Dal_slot_repr Michelson_v1_gas_costs_generated Michelson_v1_gas_costs Sc_rollup_repr @@ -379,8 +379,8 @@ indexable.ml indexable.mli entrypoint_repr.ml entrypoint_repr.mli dal_slot_index_repr.ml dal_slot_index_repr.mli - dal_slot_repr.ml dal_slot_repr.mli dal_attestation_repr.ml dal_attestation_repr.mli + dal_slot_repr.ml dal_slot_repr.mli michelson_v1_gas_costs_generated.ml michelson_v1_gas_costs.ml sc_rollup_repr.ml sc_rollup_repr.mli @@ -678,8 +678,8 @@ indexable.ml indexable.mli entrypoint_repr.ml entrypoint_repr.mli dal_slot_index_repr.ml dal_slot_index_repr.mli - dal_slot_repr.ml dal_slot_repr.mli dal_attestation_repr.ml dal_attestation_repr.mli + dal_slot_repr.ml dal_slot_repr.mli michelson_v1_gas_costs_generated.ml michelson_v1_gas_costs.ml sc_rollup_repr.ml sc_rollup_repr.mli @@ -961,8 +961,8 @@ indexable.ml indexable.mli entrypoint_repr.ml entrypoint_repr.mli dal_slot_index_repr.ml dal_slot_index_repr.mli - dal_slot_repr.ml dal_slot_repr.mli dal_attestation_repr.ml dal_attestation_repr.mli + dal_slot_repr.ml dal_slot_repr.mli michelson_v1_gas_costs_generated.ml michelson_v1_gas_costs.ml sc_rollup_repr.ml sc_rollup_repr.mli diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index 9fa26519d4ddf30062f54e43f98eced0178e57a7..d9de5caa53419c236e2bc5f1816125e7977d65ee 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -454,8 +454,15 @@ module Dal : sig val candidates : t -> Dal_slot_repr.Header.t list (** [is_slot_index_attested ctxt slot_index] returns [true] if the - [slot_index] is declared available by the protocol. [false] - otherwise. If the [index] is out of the interval - [0;number_of_slots - 1], returns [false]. *) - val is_slot_index_attested : t -> Dal_slot_index_repr.t -> bool + [slot_index] is declared available by the protocol. [false] otherwise. If + the [index] is out of the interval [0;number_of_slots - 1], returns + [false]. + + Whether the slot is attested by the protocol or not, the function also + returns the ratio of attested shards w.r.t. total shards, as a rational + number. *) + val is_slot_index_attested : + t -> + Dal_slot_index_repr.t -> + Dal_attestation_repr.Accountability.attestation_status end diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_dal_slot_proof.ml b/src/proto_alpha/lib_protocol/test/pbt/test_dal_slot_proof.ml index b2d174b5c1eb8fc297dd17101aa83dd993eba9dd..d3808cc558b1dc95d9a317c73e6bf3c038577ceb 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_dal_slot_proof.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_dal_slot_proof.ml @@ -99,23 +99,32 @@ struct skip_slot )) slots_data in - let attested_slots_headers = + let slots_headers = List.filter_map - (fun (slot, skip_slot) -> if skip_slot then None else Some slot) + (fun (slot, skip_slot) -> + let attestation_status = + Dal_attestation_repr.Accountability. + { + attested_shards = (if skip_slot then 0 else 1); + total_shards = 1; + is_proto_attested = not skip_slot; + } + in + if skip_slot then None else Some (slot, attestation_status)) slots_headers in let*?@ cell, cache = - Dal_slot_repr.History.add_confirmed_slot_headers + Dal_slot_repr.History.update_skip_list ~number_of_slots:Parameters.dal_parameters.number_of_slots cell cache curr_level - attested_slots_headers + slots_headers in let slots_info = List.fold_left - (fun slots_info (slot, skip_slot) -> - (polynomial, slot, skip_slot) :: slots_info) + (fun slots_info (slot, slot_status) -> + (polynomial, slot, slot_status) :: slots_info) slots_info slots_headers in @@ -128,9 +137,10 @@ struct (** This function returns the (correct) information of a page to prove that it is confirmed, or None if the page's slot is skipped. *) - let request_confirmed_page (poly, slot, skip_slot) = + let request_confirmed_page (poly, slot, slot_status) = let open Lwt_result_syntax in - if skip_slot then + if not slot_status.Dal_attestation_repr.Accountability.is_proto_attested + then (* We cannot check that a page of an unconfirmed slot is confirmed. *) return_none else @@ -142,10 +152,11 @@ struct (but the slot is not confirmed). Otherwise, we increment the publish_level field to simulate a non confirmed slot (as for even levels, no slot is confirmed. See {!populate_slots_history}). *) - let request_unconfirmed_page (poly, slot, skip_slot) = + let request_unconfirmed_page (poly, slot, slot_status) = let open Lwt_result_syntax in let open Dal_slot_repr.Header in - if skip_slot then + if not slot_status.Dal_attestation_repr.Accountability.is_proto_attested + then let level = slot.id.published_level in let* _page_info, page_id = mk_page_info ~level slot poly in (* We should not provide the page's info if we want to build an diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml b/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml index befd6e8f0515a84ee330e5d3e0aba32aa3d3f8f0..e24ca6075133c6182cc866e40fce31f55ccef13f 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_sc_rollup_encoding.ml @@ -122,13 +122,18 @@ module Index = Dal_slot_index_repr let pack_slots_headers_by_level list = let module ML = Map.Make (Raw_level_repr) in let module SSH = Set.Make (struct - include Dal_slot_repr.Header + type t = + Dal_slot_repr.Header.t + * Dal_attestation_repr.Accountability.attestation_status - let compare a b = Dal_slot_index_repr.compare a.id.index b.id.index + let compare (a, _) (b, _) = + let open Dal_slot_repr.Header in + Dal_slot_index_repr.compare a.id.index b.id.index end) in let map = List.fold_left - (fun map (Dal_slot_repr.Header.{id = {published_level; _}; _} as sh) -> + (fun map + ((Dal_slot_repr.Header.{id = {published_level; _}; _}, _status) as sh) -> let l = ML.find published_level map |> Option.value ~default:SSH.empty in @@ -160,10 +165,18 @@ let gen_dal_slots_history () = in let number_of_slots = constants.dal.number_of_slots in (* Generate a list of (level * confirmed slot ID). *) - let* list = small_list (pair small_nat small_nat) in + let* list = small_list (triple small_nat small_nat bool) in let list = List.rev_map - (fun (level, slot_index) -> + (fun (level, slot_index, is_proto_attested) -> + let attestation_status = + Dal_attestation_repr.Accountability. + { + attested_shards = (if is_proto_attested then 1 else 0); + total_shards = 1; + is_proto_attested; + } + in let published_level = Raw_level_repr.( (* use succ to avoid having a published_level = 0, as it's the @@ -174,7 +187,8 @@ let gen_dal_slots_history () = Index.of_int_opt ~number_of_slots slot_index |> Option.value ~default:Index.zero in - Header.{id = {published_level; index}; commitment = Commitment.zero}) + ( Header.{id = {published_level; index}; commitment = Commitment.zero}, + attestation_status )) list in let rec loop history = function @@ -183,7 +197,7 @@ let gen_dal_slots_history () = let slot_headers = (* Sort the list in the right ordering before adding slots to slots_history. *) List.sort_uniq - (fun {Header.id = a; _} {id = b; _} -> + (fun ({Header.id = a; _}, _status) ({id = b; _}, _status) -> let c = Raw_level_repr.compare a.published_level b.published_level in @@ -191,11 +205,7 @@ let gen_dal_slots_history () = slot_headers in History.( - add_confirmed_slot_headers_no_cache - ~number_of_slots - history - level - slot_headers) + update_skip_list_no_cache ~number_of_slots history level slot_headers) |> function | Ok history -> loop history llist | Error e -> diff --git a/src/proto_alpha/lib_protocol/test/unit/test_dal_slot_proof.ml b/src/proto_alpha/lib_protocol/test/unit/test_dal_slot_proof.ml index cd08a067d25543be46de04d88de8d393042757fc..f767d21e5971348034c869204eeeb7d9add8937d 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_dal_slot_proof.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_dal_slot_proof.ml @@ -51,6 +51,10 @@ struct Dal_helpers.mk_cryptobox Parameters.dal_parameters.cryptobox_parameters end) + let mk_attested = + Dal_attestation_repr.Accountability. + {total_shards = 1; attested_shards = 1; is_proto_attested = true} + (* Tests to check insertion of slots in a dal skip list. *) (** Check insertion of a new slot in the given skip list. *) @@ -63,13 +67,12 @@ struct let index = mk_slot_index id in let* _data, _poly, slot = mk_slot ~level ~index () in let@ result = - Hist.add_confirmed_slot_headers_no_cache + Hist.update_skip_list_no_cache skip_list level - [slot] + [(slot, mk_attested)] ~number_of_slots:Parameters.dal_parameters.number_of_slots in - check_result result (** This test attempts to add a slot on top of genesis cell zero which would @@ -188,12 +191,12 @@ struct let open Lwt_result_wrap_syntax in let* _slot_data, polynomial, slot = mk_slot ~level ?index () in let*?@ skip_list, cache = - Hist.add_confirmed_slot_headers + Hist.update_skip_list ~number_of_slots:Parameters.dal_parameters.number_of_slots genesis_history genesis_history_cache level - [slot] + [(slot, mk_attested)] in let* page_info, page_id = mk_page_info slot polynomial in produce_and_verify_proof diff --git a/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml b/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml index d8f5db8cac625da9b4ec6fc815545ecc86fef542..614a3c5d26d234f0d58d330261a60c2448c14c51 100644 --- a/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml +++ b/src/proto_alpha/lib_sc_rollup_node/test/test_octez_conversions.ml @@ -220,45 +220,59 @@ let compare_slot_header_id (s1 : Octez_smart_rollup.Dal.Slot_header.id) let c = Int32.compare s1.published_level s2.published_level in if c <> 0 then c else Int.compare s1.index s2.index -let gen_slot_headers = +let gen_slot_header_with_status = + let open Protocol.Alpha_context in + let open QCheck2.Gen in + let* status = bool in + let status = + let total_shards = 1 in + let attested_shards = if status then total_shards else 0 in + Dal.Attestation.{total_shards; attested_shards; is_proto_attested = status} + in + let+ header = gen_slot_header in + (header, status) + +let gen_slot_headers_with_statuses = let open QCheck2.Gen in let size = int_bound 50 in - let+ l = list_size size gen_slot_header in + let+ l = list_size size gen_slot_header_with_status in List.sort - (fun (h1 : Octez_smart_rollup.Dal.Slot_header.t) - (h2 : Octez_smart_rollup.Dal.Slot_header.t) -> + (fun ((h1 : Octez_smart_rollup.Dal.Slot_header.t), _status1) + ((h2 : Octez_smart_rollup.Dal.Slot_header.t), _status2) -> compare_slot_header_id h1.id h2.id) l |> fun l -> match l with | [] -> [] - | (h : Octez_smart_rollup.Dal.Slot_header.t) :: _ -> + | ((h : Octez_smart_rollup.Dal.Slot_header.t), _status) :: _ -> let min_level = h.id.published_level in (* smallest level *) List.mapi - (fun i (h : Octez_smart_rollup.Dal.Slot_header.t) -> + (fun i ((h : Octez_smart_rollup.Dal.Slot_header.t), status) -> (* patch the published level to comply with the invariants *) let published_level = Int32.(add min_level (of_int i)) in let h = {h with id = {h.id with published_level}} in - (published_level, [h])) + (published_level, [(h, status)])) l let gen_slot_history = let open Protocol.Alpha_context in let open QCheck2.Gen in - let+ l = gen_slot_headers in + let+ l = gen_slot_headers_with_statuses in let l = List.map (fun (lvl, h) -> ( Raw_level.of_int32_exn lvl, List.map - (Sc_rollup_proto_types.Dal.Slot_header.of_octez ~number_of_slots) + (fun (h, status) -> + ( Sc_rollup_proto_types.Dal.Slot_header.of_octez ~number_of_slots h, + status )) h )) l in List.fold_left_e (fun hist (published_level, attested_slots) -> - Dal.Slots_history.add_confirmed_slot_headers_no_cache + Dal.Slots_history.update_skip_list_no_cache ~number_of_slots hist published_level @@ -273,20 +287,22 @@ let gen_slot_history = let gen_slot_history_cache = let open Protocol.Alpha_context in let open QCheck2.Gen in - let+ l = gen_slot_headers in + let+ l = gen_slot_headers_with_statuses in let cache = Dal.Slots_history.History_cache.empty ~capacity:Int64.max_int in let l = List.map (fun (lvl, h) -> ( Raw_level.of_int32_exn lvl, List.map - (Sc_rollup_proto_types.Dal.Slot_header.of_octez ~number_of_slots) + (fun (h, status) -> + ( Sc_rollup_proto_types.Dal.Slot_header.of_octez ~number_of_slots h, + status )) h )) l in List.fold_left_e (fun (hist, cache) (published_level, attested_slots) -> - Dal.Slots_history.add_confirmed_slot_headers + Dal.Slots_history.update_skip_list ~number_of_slots hist cache