diff --git a/src/proto_alpha/bin_sc_rollup_node/dal_node_client.mli b/src/proto_alpha/bin_sc_rollup_node/dal_node_client.mli index 15b832d4239a82834e0986c518ca69afccfbf0a6..b7a769149ed63a39aa8d18ceee91ec9b9bc29b81 100644 --- a/src/proto_alpha/bin_sc_rollup_node/dal_node_client.mli +++ b/src/proto_alpha/bin_sc_rollup_node/dal_node_client.mli @@ -44,7 +44,7 @@ class unix_cctxt : val make_unix_cctxt : Configuration.t -> cctxt val get_slot : - #cctxt -> ?trim_slot:bool -> Dal.Slot.header -> string tzresult Lwt.t + #cctxt -> ?trim_slot:bool -> Dal.Slot_header.t -> string tzresult Lwt.t val get_shard : - #cctxt -> Dal.Slot.header -> int -> Cryptobox.shard tzresult Lwt.t + #cctxt -> Dal.Slot_header.t -> int -> Cryptobox.shard tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 0b4d291eb75aacfe96babdf8829f08a0ed801ef1..77b3de3910ae9d304926c16eeb11fa0c83c22d1d 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -109,6 +109,8 @@ module Dal = struct include Dal_slot_repr.Page end + module Slot_header = Dal_slot_repr.Header + module Slot = struct include Dal_slot_repr include Dal_slot_storage diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 6a073710a4ceeb798005d12e9e8ad5c224396959..0b6aefe149068988e66b712e63a77f4b49913f3c 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2794,19 +2794,22 @@ module Dal : sig val equal : t -> t -> bool end + (** This module re-exports definitions from {!Dal_slot_repr.Header}. *) + module Slot_header : sig + type t = Dal.commitment + + val zero : t + end + (** This module re-exports definitions from {!Dal_slot_repr}, {!Dal_slot_storage} and {!Raw_context.Dal}. *) module Slot : sig - type header = Dal.commitment - type t = { published_level : Raw_level.t; index : Slot_index.t; - header : header; + header : Slot_header.t; } - val zero : header - val encoding : t Data_encoding.t val pp : Format.formatter -> t -> unit diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index 58ece202ea6eb287c1f7917f7e9897a12922e179..af1bbc76fab9ea0a81d50d4af8871f63c88933c0 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -36,6 +36,8 @@ module Header = struct let pp ppf commitment = Format.fprintf ppf "%s" (Dal.Commitment.to_b58check commitment) + + let zero = Dal.Commitment.zero end module Index = struct @@ -61,11 +63,11 @@ module Index = struct let equal = Compare.Int.equal end -type header = Header.t - -let zero = Dal.Commitment.zero - -type t = {published_level : Raw_level_repr.t; index : Index.t; header : header} +type t = { + published_level : Raw_level_repr.t; + index : Index.t; + header : Header.t; +} type slot = t @@ -76,6 +78,15 @@ let slot_equal ({published_level; index; header} : t) s2 = && Index.equal index s2.index && Header.equal header s2.header +let zero = + { + (* We don't expect to have any published slot at level + Raw_level_repr.root. *) + published_level = Raw_level_repr.root; + index = Index.zero; + header = Header.zero; + } + module Slot_index = Index module Page = struct @@ -241,7 +252,7 @@ module Slots_history = struct type history = (content, ptr) Skip_list.cell - type t = history option + type t = history let history_encoding = Skip_list.encoding Pointer_hash.encoding slot_encoding @@ -249,11 +260,11 @@ module Slots_history = struct let equal_history : history -> history -> bool = Skip_list.equal Pointer_hash.equal slot_equal - let encoding = Data_encoding.option history_encoding + let encoding = history_encoding - let equal : t -> t -> bool = Option.equal equal_history + let equal : t -> t -> bool = equal_history - let genesis : t = None + let genesis : t = Skip_list.genesis (zero : slot) let hash_skip_list_cell cell = let current_slot = Skip_list.content cell in @@ -290,17 +301,18 @@ module Slots_history = struct let add_confirmed_slot (t, cache) slot = let open Tzresult_syntax in - match t with - | None -> return (Some (Skip_list.genesis slot), cache) - | Some t -> - let content = slot in - let prev_cell_ptr = hash_skip_list_cell t in - let* cache = History_cache.remember prev_cell_ptr t cache in - return - ( Skip_list.next ~prev_cell:t ~prev_cell_ptr content |> Option.some, - cache ) - - let add_confirmed_slots t cache slots = + let* () = + error_when + Raw_level_repr.(slot.published_level <= zero.published_level) + (failwith + "No slot is supposed to be published at level \ + 'Raw_level_repr.root'") + in + let prev_cell_ptr = hash_skip_list_cell t in + let* cache = History_cache.remember prev_cell_ptr t cache in + return (Skip_list.next ~prev_cell:t ~prev_cell_ptr slot, cache) + + let add_confirmed_slots (t : t) cache slots = List.fold_left_e add_confirmed_slot (t, cache) slots let add_confirmed_slots_no_cache = diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index 18ded1f945b557df98ea573d68cf1ea9faedf888..9f93381aab87c5c1ddce5c3700d6663f2af2daa7 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -50,6 +50,8 @@ module Header : sig type t = Dal.commitment val encoding : t Data_encoding.t + + val zero : t end (** An `Index.t` is a possible value for a slot index. We assume this value @@ -84,12 +86,14 @@ module Index : sig val equal : t -> t -> bool end -type header = Header.t - (** For Layer-1, a slot is described by the level at which it is published, the slot's index (in the list of slots), and the slot's header (KATE commitment hash). *) -type t = {published_level : Raw_level_repr.t; index : Index.t; header : header} +type t = { + published_level : Raw_level_repr.t; + index : Index.t; + header : Header.t; +} type slot = t @@ -132,8 +136,6 @@ end (** The encoding ensures the slot is always a non-negative number. *) val encoding : t Data_encoding.t -val zero : header - val pp : Format.formatter -> t -> unit (** Only one slot header is accepted per slot index. If two slots diff --git a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml index 58b381a5be0a1d5d229a00c5390865298c79ea28..0709c58728e44a7876c840a66456516edd4f368e 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml @@ -662,7 +662,7 @@ let generate_dal_publish_slot_header random_state : let gen_dal_publish _ = let published_level = Alpha_context.Raw_level.of_int32_exn Int32.zero in let index = Alpha_context.Dal.Slot_index.zero in - let header = Alpha_context.Dal.Slot.zero in + let header = Alpha_context.Dal.Slot_header.zero in let slot = Alpha_context.Dal.Slot.{published_level; index; header} in Dal_publish_slot_header {slot} in diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml index c6e0d8fa4ad8f9e04b223b17f062131fe20719cd..b3394c31f09c1a3e6b87b40f08a2044642349ade 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml @@ -1028,7 +1028,7 @@ let mk_sc_rollup_return_bond (oinfos : operation_req) (infos : infos) = let mk_dal_publish_slot_header (oinfos : operation_req) (infos : infos) = let published_level = Alpha_context.Raw_level.of_int32_exn Int32.zero in let index = Alpha_context.Dal.Slot_index.zero in - let header = Alpha_context.Dal.Slot.zero in + let header = Alpha_context.Dal.Slot_header.zero in let slot = Alpha_context.Dal.Slot.{published_level; index; header} in Op.dal_publish_slot_header ?fee:oinfos.fee