From aa7a6af707c0fd5f3166fa1703e8bcb5d65dd907 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 22 Feb 2024 13:07:00 +0100 Subject: [PATCH 1/4] Proto/Dal: refactor compute_attested_slot_headers to prepare its export --- src/proto_alpha/lib_protocol/dal_slot_storage.ml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.ml b/src/proto_alpha/lib_protocol/dal_slot_storage.ml index 699577121df3..ada255e2cca9 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.ml @@ -32,10 +32,10 @@ let finalize_current_slot_headers ctxt = | [] -> Lwt.return ctxt | _ :: _ -> Storage.Dal.Slot.Headers.add ctxt current_level.level slot_headers -let compute_attested_slot_headers ctxt seen_slot_headers = +let compute_attested_slot_headers ~is_slot_attested seen_slot_headers = let open Dal_slot_repr in let fold_attested_slots (rev_attested_slot_headers, attestation) slot = - if Raw_context.Dal.is_slot_index_attested ctxt slot.Header.id.index then + 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) @@ -80,7 +80,12 @@ let finalize_pending_slot_headers ctxt ~number_of_slots = | None -> return (ctxt, Dal_attestation_repr.empty, []) | Some seen_slots -> let rev_attested_slot_headers, attestation = - compute_attested_slot_headers ctxt seen_slots + 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 in let attested_slot_headers = List.rev rev_attested_slot_headers in return (ctxt, attestation, attested_slot_headers) -- GitLab From 909b31176a5affcb5146f9709fd7acd477a829ec Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 22 Feb 2024 13:41:55 +0100 Subject: [PATCH 2/4] Proto/Dal: right ordering in compute_attested_slot_headers' result --- src/proto_alpha/lib_protocol/dal_slot_storage.ml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.ml b/src/proto_alpha/lib_protocol/dal_slot_storage.ml index ada255e2cca9..30520c86d171 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.ml @@ -40,10 +40,13 @@ let compute_attested_slot_headers ~is_slot_attested seen_slot_headers = Dal_attestation_repr.commit attestation slot.Header.id.index ) else (rev_attested_slot_headers, attestation) in - List.fold_left - fold_attested_slots - ([], Dal_attestation_repr.empty) - seen_slot_headers + let rev_attested_slot_headers, bitset = + List.fold_left + fold_attested_slots + ([], Dal_attestation_repr.empty) + seen_slot_headers + in + (List.rev rev_attested_slot_headers, bitset) let get_slot_headers_history ctxt = let open Lwt_result_syntax in @@ -79,7 +82,7 @@ let finalize_pending_slot_headers ctxt ~number_of_slots = match seen_slots with | None -> return (ctxt, Dal_attestation_repr.empty, []) | Some seen_slots -> - let rev_attested_slot_headers, attestation = + let attested_slot_headers, attestation = let is_slot_attested slot = Raw_context.Dal.is_slot_index_attested ctxt @@ -87,7 +90,6 @@ let finalize_pending_slot_headers ctxt ~number_of_slots = in compute_attested_slot_headers ~is_slot_attested seen_slots in - let attested_slot_headers = List.rev rev_attested_slot_headers in return (ctxt, attestation, attested_slot_headers) in let* ctxt = -- GitLab From 1a4fa7d1aeb21a38f24d4a63f6ec46ac81240765 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 22 Feb 2024 13:38:35 +0100 Subject: [PATCH 3/4] Proto/Dal: export function compute_attested_slot_headers --- src/proto_alpha/lib_protocol/alpha_context.mli | 5 +++++ src/proto_alpha/lib_protocol/dal_slot_storage.mli | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index bd74853aa924..867a6b1da8d5 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2881,6 +2881,11 @@ 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 diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.mli b/src/proto_alpha/lib_protocol/dal_slot_storage.mli index eafa34e3cc61..4dc2d270fca3 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.mli @@ -72,3 +72,11 @@ 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 -- GitLab From 06326af3b4357cf78a7f8d47e8570ee8b8f04341 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 22 Feb 2024 14:57:09 +0100 Subject: [PATCH 4/4] Proto/Dal: always have all the cells of a level in the cache, including the last one --- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index a5d848ae8392..c1d216aee885 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -526,19 +526,20 @@ module History = struct let Header.{published_level; _} = Skip_list.content t |> Content.content_id in - if Raw_level_repr.equal published_level genesis_level then - (* If this is the first real cell of DAL, replace dummy genesis. *) - return (Skip_list.genesis next_cell_content, cache) - else - let* cache = History_cache.remember prev_cell_ptr t cache in - let* new_head = + let* new_head = + if Raw_level_repr.equal published_level genesis_level then + (* If this is the first real cell of DAL, replace dummy genesis. *) + return (Skip_list.genesis next_cell_content) + else Skip_list.next ~prev_cell:t ~prev_cell_ptr next_cell_content ~number_of_slots - in - return (new_head, cache) + in + let new_head_hash = hash new_head in + let* cache = History_cache.remember new_head_hash new_head cache in + return (new_head, cache) (* Given a list [attested_slot_headers] of well-ordered (wrt slots indices) (attested) slot headers, this function builds an extension [l] of -- GitLab