diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 4b8b2f96633daa4ff3a31df3f9bd9fd1016b25be..7c2abac0de985007e5c558b7a8d839a18876305b 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2883,6 +2883,8 @@ module Dal : sig val pp : Format.formatter -> t -> unit val equal : t -> t -> bool + + val slot_id_equal : id -> id -> bool end val register_slot_header : @@ -2923,6 +2925,20 @@ module Dal : sig module Slots_history : sig type t + type cell_content = private + | Unpublished of Slot.Header.id + | Published of { + header : Slot.Header.t; + publisher : Contract.t; + is_proto_attested : bool; + attested_shards : int; + total_shards : int; + } + + val content : t -> cell_content + + val content_id : cell_content -> Slot.Header.id + module Pointer_hash : S.HASH type hash = Pointer_hash.t diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index 5fc7d39ec13138e017fdfe480ba4bbd5ca1c6fe0..aea65d068c791bc5fc9854b7325587f177b6e5d1 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1314,19 +1314,21 @@ module History = struct let hash = hash ?with_migration:None - module Internal_for_tests = struct - type cell_content = Content.t = - | Unpublished of Header.id - | Published of { - header : Header.t; - publisher : Contract_repr.t; - is_proto_attested : bool; - attested_shards : int; - total_shards : int; - } - - let content cell : cell_content = Skip_list.content cell + type cell_content = Content_v2.t = + | Unpublished of Header.id + | Published of { + header : Header.t; + publisher : Contract_repr.t; + is_proto_attested : bool; + attested_shards : int; + total_shards : int; + } + let content = Skip_list.content + + let content_id = Content_v2.content_id + + module Internal_for_tests = struct let proof_statement_is serialized_proof expected = match deserialize_proof serialized_proof with | Error _ -> false diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index cf9c1dcfda5b1720dc15837e990c8d7ca15ef0eb..ab893aa0b8bc85cd139f4b40602bcecde804473b 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -84,6 +84,23 @@ module Commitment_proof : sig val zero : t end +(** The module below provides some data types and helper functions for DAL + commitments published at some level on some slot index. There are mainly + three important levels for a DAL commitment successfully included in a + block: + + - `published_level`: The level of the block that contains the DAL publish + commitment operation. Such operations are typically injected on top of the + block whose level is `published_level - 1` or earlier. + + - `attested_level`: The level of the block / context that includes the + attestation status of a slot published `attestation_lag` levels + earlier. Formally, `attested_level = published_level + attestation_lag`. + + - `attestation_level`: The level of the block on top of which DAL + attestations are injected for a commitment published at published_level. + Formally, attestation_level = attested_level - 1 = published_level + + attestation_lag - 1. *) module Header : sig (** For Layer-1, a slot is identified by the level at which it is published and the slot's index. *) @@ -108,6 +125,9 @@ module Header : sig (** equal function for values of type {!t}. *) val equal : t -> t -> bool + (** equal function for values of type id. *) + val slot_id_equal : id -> id -> bool + (** [verify_commitment cryptobox commitment commitment_proof] check that for the given commitment, the commitment proof is correct using the [cryptbox] primitives. *) @@ -219,6 +239,29 @@ module History : sig confirmed slot headers. *) type t + (** The content of a cell in the DAL skip list. We have [number_of_slots] new + cells per level (one per slot index). For a given slot index in + [0..number_of_slots-1], the commitment is either [Unpublished] or + [Published]. In this second case, we attach extra information in addition + to the id such as the commitment, the publisher, the number of attested + shards and whether the commitment is attested from the point of view of + the protocol. *) + type cell_content = private + | Unpublished of Header.id + | Published of { + header : Header.t; + publisher : Contract_repr.t; + is_proto_attested : bool; + attested_shards : int; + total_shards : int; + } + + (** Returns the {!cell_content} of the given skip list cell. *) + val content : t -> cell_content + + (** Returns the slot id of the cell whose content is given. *) + val content_id : cell_content -> Header.id + module Pointer_hash : S.HASH (** Type of hashes of history. *) @@ -398,26 +441,6 @@ module History : sig | Unexpected_page_size of {expected_size : int; page_size : int} module Internal_for_tests : sig - (** The content of a cell in the DAL skip list. We have [number_of_slots] - new cells per level (one per slot index). For a given slot index in - [0..number_of_slots-1], the commitment is either [Unpublished] or - [Published]. In this second case, we attach extra information in - addition to the id such as the commitment, the publisher, the number of - attested shards and whether the commitment is attested from the point of - view of the protocol. *) - type cell_content = - | Unpublished of Header.id - | Published of { - header : Header.t; - publisher : Contract_repr.t; - is_proto_attested : bool; - attested_shards : int; - total_shards : int; - } - - (** Returns the content of the last cell in the given skip list. *) - val content : t -> cell_content - (** [proof_statement_is serialized_proof expected] will return [true] if the deserialized proof and the [expected] proof shape match and [false] otherwise. diff --git a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml index b896155b7c4a477c8c87425943381967910d5032..67473e244f7644b8ffabeb3d288fbaababfcb3b1 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml @@ -69,8 +69,7 @@ let derive_dal_parameters (reference : Cryptobox.parameters) ~redundancy_factor } let content_slot_id = function - | Hist.Internal_for_tests.Unpublished id | Published {header = {id; _}; _} -> - id + | Hist.Unpublished id | Published {header = {id; _}; _} -> id module Make (Parameters : sig val dal_parameters : Alpha_context.Constants.Parametric.dal diff --git a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.mli b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.mli index 29b721cdc1a0368f83ed5d5d4021c84669c72778..940b8b25ac5a54fa81f5570c9529678b03c6e783 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.mli @@ -40,8 +40,7 @@ val derive_dal_parameters : (** Returns the slot id of the given cell's content . *) val content_slot_id : - Dal_slot_repr.History.Internal_for_tests.cell_content -> - Dal_slot_repr.Header.id + Dal_slot_repr.History.cell_content -> Dal_slot_repr.Header.id module Make (P : sig val dal_parameters : Alpha_context.Constants.Parametric.dal 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 cef8c27b053fca7fe13038640ce0fb48d6f1d840..32b1e228d5c386ae3c186e1e52bf0bdb2a27dfca 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 @@ -60,9 +60,7 @@ struct (** Check insertion of a new slot in the given skip list. *) let skip_list_ordering skip_list ~mk_level ~mk_slot_index ~check_result = let open Lwt_result_wrap_syntax in - let id = - Hist.Internal_for_tests.content skip_list |> Dal_helpers.content_slot_id - in + let id = Hist.content skip_list |> Dal_helpers.content_slot_id in let level = mk_level id in let index = mk_slot_index id in let* _data, _poly, slot = mk_slot ~level ~index () in @@ -148,8 +146,7 @@ struct genesis skip list. Proof production is expected to succeed. *) let unconfirmed_page_on_genesis () = let Dal_slot_repr.Header.{published_level; index} = - Hist.Internal_for_tests.content genesis_history - |> Dal_helpers.content_slot_id + Hist.content genesis_history |> Dal_helpers.content_slot_id in let page_id = mk_page_id published_level index P.Index.zero in produce_and_verify_proof @@ -167,8 +164,7 @@ struct history cache. *) let unconfirmed_page_on_genesis_bad_cache () = let Dal_slot_repr.Header.{published_level; index} = - Hist.Internal_for_tests.content genesis_history - |> Dal_helpers.content_slot_id + Hist.content genesis_history |> Dal_helpers.content_slot_id in let level, sindex = if false then (Raw_level_repr.succ published_level, index) diff --git a/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml b/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml index 3fd6fc9789d7d983f11a169380bdd25a41736c88..a9a6340689d4156c96bf426178c05946fdbb269c 100644 --- a/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml +++ b/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml @@ -114,10 +114,10 @@ module Pages_cache = let get_slot_pages = let pages_cache = Pages_cache.create 16 (* 130MB *) in - fun dal_cctxt commitment -> + fun dal_cctxt slot_id -> Pages_cache.bind_or_put pages_cache - commitment + slot_id (Dal_node_client.get_slot_pages dal_cctxt) Lwt.return @@ -137,6 +137,27 @@ let download_confirmed_slot_pages ({Node_context.dal_cctxt; _} as node_ctxt) in get_slot_pages dal_cctxt slot_id +let get_page node_ctxt ~inbox_level page_id = + let open Lwt_result_syntax in + let Dal.Page.{slot_id; page_index} = page_id in + let Dal.Slot.Header.{published_level; index} = slot_id in + let index = Sc_rollup_proto_types.Dal.Slot_index.to_octez index in + let* pages = + download_confirmed_slot_pages node_ctxt ~published_level ~index + in + match List.nth_opt pages page_index with + | Some page -> + let*! () = + Event.(emit page_reveal) + ( index, + page_index, + Raw_level.to_int32 published_level, + inbox_level, + page ) + in + return @@ Some page + | None -> tzfail @@ Dal_invalid_page_for_slot page_id + let storage_invariant_broken published_level index = failwith "Internal error: [Node_context.find_slot_status] is supposed to have \ @@ -229,8 +250,7 @@ let page_content ~dal_activation_level ~inbox_level node_ctxt page_id ~dal_attested_slots_validity_lag = let open Lwt_result_syntax in - let Dal.Page.{slot_id; page_index} = page_id in - let Dal.Slot.Header.{published_level; index} = slot_id in + let Dal.Slot.Header.{published_level; index} = page_id.Dal.Page.slot_id in let Node_context.{genesis_info = {level = origination_level; _}; _} = node_ctxt in @@ -256,21 +276,6 @@ let page_content Node_context.find_slot_status node_ctxt ~confirmed_in_block_hash index in match processed with - | Some `Confirmed -> ( - let* pages = - download_confirmed_slot_pages node_ctxt ~published_level ~index - in - match List.nth_opt pages page_index with - | Some page -> - let*! () = - Event.(emit page_reveal) - ( index, - page_index, - Raw_level.to_int32 published_level, - inbox_level, - page ) - in - return @@ Some page - | None -> tzfail @@ Dal_invalid_page_for_slot page_id) + | Some `Confirmed -> get_page node_ctxt ~inbox_level page_id | Some `Unconfirmed -> return_none | None -> storage_invariant_broken published_level index