From 8faa75220e8c65f4ab1e680631bb453bb6e64475 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 15 Nov 2024 11:05:43 +0100 Subject: [PATCH 1/7] Rollups/Dal: add a helper function get_page --- .../lib_sc_rollup_node/dal_pages_request.ml | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) 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 3fd6fc9789d7..4b9c69e58d0a 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 @@ -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 -- GitLab From 50ad90b28752734ff703ea62e6e09b2271c5e0e2 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 15 Nov 2024 14:24:08 +0100 Subject: [PATCH 2/7] DAL/Proto: add a doc-string above published/attested/attestation levels --- src/proto_alpha/lib_protocol/dal_slot_repr.mli | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index cf9c1dcfda5b..7381878797b7 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. *) -- GitLab From 682058c06c196ba53a49405eb259bd38c2d4e436 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 15 Nov 2024 14:56:09 +0100 Subject: [PATCH 3/7] Rollups/DAL: fix a typo in argument name (due to recent refactoring) --- src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 4b9c69e58d0a..a9a6340689d4 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 -- GitLab From 8ecbe692cc2cf11f810a843f472d44e7d8aa1816 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 15 Nov 2024 16:19:03 +0100 Subject: [PATCH 4/7] DAL/Proto: expose function slot_id_equal --- src/proto_alpha/lib_protocol/alpha_context.mli | 2 ++ src/proto_alpha/lib_protocol/dal_slot_repr.mli | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 4b8b2f96633d..8a991c8337b5 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 : diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index 7381878797b7..f754c59061c1 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -125,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. *) -- GitLab From e2f8d2b64be1e3987fbbc61c3b1acef9db7f1c66 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 15 Nov 2024 16:20:00 +0100 Subject: [PATCH 5/7] DAL/Proto: expose the content of skip list cells --- .../lib_protocol/alpha_context.mli | 12 +++++++++++ src/proto_alpha/lib_protocol/dal_slot_repr.ml | 12 +++++++++++ .../lib_protocol/dal_slot_repr.mli | 20 +++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 8a991c8337b5..63fc520cb169 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2925,6 +2925,18 @@ 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 + 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 5fc7d39ec131..3973b7e44c6f 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1314,6 +1314,18 @@ module History = struct let hash = hash ?with_migration:None + 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 + module Internal_for_tests = struct type cell_content = Content.t = | Unpublished of Header.id diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index f754c59061c1..8b9ef489bdf0 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -239,6 +239,26 @@ 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 + module Pointer_hash : S.HASH (** Type of hashes of history. *) -- GitLab From 6e83e68251e9643d257a3c34e09918971daa7c15 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 15 Nov 2024 16:30:25 +0100 Subject: [PATCH 6/7] DAL/Proto: remove some duplicate code from Dal_slot_repr.Internal_for_tests --- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 12 ----------- .../lib_protocol/dal_slot_repr.mli | 20 ------------------- .../lib_protocol/test/helpers/dal_helpers.ml | 3 +-- .../lib_protocol/test/helpers/dal_helpers.mli | 3 +-- .../test/unit/test_dal_slot_proof.ml | 10 +++------- 5 files changed, 5 insertions(+), 43 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index 3973b7e44c6f..1a4eed43abe7 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1327,18 +1327,6 @@ module History = struct let content = Skip_list.content 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 - 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 8b9ef489bdf0..cc7d69b3c81a 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -438,26 +438,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 b896155b7c4a..67473e244f76 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 29b721cdc1a0..940b8b25ac5a 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 cef8c27b053f..32b1e228d5c3 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) -- GitLab From 520421b18bb1e5da5488e1ac1462bdd8fa0fa625 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 15 Nov 2024 17:01:53 +0100 Subject: [PATCH 7/7] DAL/Proto: expose a function `content_id` --- src/proto_alpha/lib_protocol/alpha_context.mli | 2 ++ src/proto_alpha/lib_protocol/dal_slot_repr.ml | 2 ++ src/proto_alpha/lib_protocol/dal_slot_repr.mli | 3 +++ 3 files changed, 7 insertions(+) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 63fc520cb169..7c2abac0de98 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2937,6 +2937,8 @@ module Dal : sig 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 1a4eed43abe7..aea65d068c79 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -1326,6 +1326,8 @@ module History = struct 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 diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index cc7d69b3c81a..ab893aa0b8bc 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -259,6 +259,9 @@ module History : sig (** 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. *) -- GitLab