diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index bd74853aa9244e1da9a20708b42ef1364ae4f758..867a6b1da8d500382072744819210e10ed1f1321 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_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index a5d848ae8392e39f984f5368f22742f264be7de7..c1d216aee8850cbeace00167e4d7ac2354be263d 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 diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.ml b/src/proto_alpha/lib_protocol/dal_slot_storage.ml index 699577121df3eec2ee83ea3d7c3538e6e9dbe9dd..30520c86d171e821150f0eaecbd9ad6acba804c5 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.ml @@ -32,18 +32,21 @@ 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) 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,10 +82,14 @@ 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 = - compute_attested_slot_headers ctxt seen_slots + let attested_slot_headers, 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 in - let attested_slot_headers = List.rev rev_attested_slot_headers in return (ctxt, attestation, attested_slot_headers) in let* ctxt = diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.mli b/src/proto_alpha/lib_protocol/dal_slot_storage.mli index eafa34e3cc615acf520047f69ad8046b26073cf7..4dc2d270fca377d7bb566d726e436d56f39636cb 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