From d518e7853904b1dcc4b0569e558f076c92339a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Wed, 5 Oct 2022 07:20:13 +0200 Subject: [PATCH 1/3] Protocol/DAL: Rename Dal.Header into Dal.Commitment --- .../bin_sc_rollup_node/dal_node_client.mli | 6 +-- .../bin_sc_rollup_node/dal_slots_tracker.ml | 4 +- .../lib_dal/dal_plugin_registration.ml | 3 +- .../lib_protocol/alpha_context.mli | 4 +- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 46 +++++++++---------- .../lib_protocol/dal_slot_repr.mli | 7 ++- .../lib_protocol/test/helpers/dal_helpers.ml | 4 +- .../test/helpers/operation_generator.ml | 6 ++- .../validate/manager_operation_helpers.ml | 6 ++- tezt/lib_tezos/operation_core.ml | 10 ++-- tezt/lib_tezos/operation_core.mli | 2 +- tezt/lib_tezos/sc_rollup_client.ml | 2 +- tezt/tests/dal.ml | 19 ++++---- ...y layer node (rollup_node_downloads_sl.out | 6 +-- 14 files changed, 68 insertions(+), 57 deletions(-) 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 9e7362907c6f..08ef6260675a 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,12 +44,12 @@ class unix_cctxt : val make_unix_cctxt : Configuration.t -> cctxt val get_slot : - #cctxt -> ?trim_slot:bool -> Dal.Slot.Header.t -> string tzresult Lwt.t + #cctxt -> ?trim_slot:bool -> Dal.Slot.Commitment.t -> string tzresult Lwt.t val get_shard : - #cctxt -> Dal.Slot.Header.t -> int -> Cryptobox.shard tzresult Lwt.t + #cctxt -> Dal.Slot.Commitment.t -> int -> Cryptobox.shard tzresult Lwt.t (** [get_slot_pages cctxt header ] fetches from the dal node the pages of the slot with header [header]. *) val get_slot_pages : - #cctxt -> Dal.Slot.Header.t -> Dal.Page.content list tzresult Lwt.t + #cctxt -> Dal.Slot.Commitment.t -> Dal.Page.content list tzresult Lwt.t diff --git a/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.ml b/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.ml index c0f4ba7cbce3..2b9b8afdc6b0 100644 --- a/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.ml +++ b/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.ml @@ -261,13 +261,13 @@ let download_and_save_slots if not slot_header_is_stored then failwith "Slot header was not found in store" else - let*! {header; _} = + let*! {commitment; _} = Store.Dal_slots_headers.get store ~primary_key:published_block_hash ~secondary_key:s_slot in - let* pages = Dal_node_client.get_slot_pages dal_cctxt header in + let* pages = Dal_node_client.get_slot_pages dal_cctxt commitment in let*! () = save_confirmed_slot store current_block_hash s_slot pages in diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index b04a04ed66c2..9567eb84f597 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -51,7 +51,8 @@ module Plugin = struct process_manager_operations [] block.operations {apply; apply_internal}) |> List.map_es (fun slot -> return - (Dal.Slot_index.to_int slot.Dal.Slot.id.index, slot.Dal.Slot.header)) + ( Dal.Slot_index.to_int slot.Dal.Slot.id.index, + slot.Dal.Slot.commitment )) end let () = Dal_plugin.register (module Plugin) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index f7bc9ebfaa60..0642b188974d 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2832,7 +2832,7 @@ module Dal : sig {!Dal_slot_storage} and {!Raw_context.Dal}. *) module Slot : sig (** This module re-exports definitions from {!Dal_slot_repr.Header}. *) - module Header : sig + module Commitment : sig type t = Dal.commitment val encoding : t Data_encoding.t @@ -2842,7 +2842,7 @@ module Dal : sig type id = {published_level : Raw_level.t; index : Slot_index.t} - type t = {id : id; header : Header.t} + type t = {id : id; commitment : Commitment.t} val encoding : t Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index a93cac460285..df16d7575ad1 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -23,7 +23,7 @@ (* *) (*****************************************************************************) -module Header = struct +module Commitment = struct (* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3389 It is not clear whether the size of the slot associated to the @@ -65,7 +65,7 @@ end type id = {published_level : Raw_level_repr.t; index : Index.t} -type t = {id : id; header : Header.t} +type t = {id : id; commitment : Commitment.t} type slot = t @@ -75,8 +75,8 @@ let slot_id_equal ({published_level; index} : id) s2 = Raw_level_repr.equal published_level s2.published_level && Index.equal index s2.index -let slot_equal ({id; header} : t) s2 = - slot_id_equal id s2.id && Header.equal header s2.header +let slot_equal ({id; commitment} : t) s2 = + slot_id_equal id s2.id && Commitment.equal commitment s2.commitment let compare_slot_id ({published_level; index} : id) s2 = let c = Raw_level_repr.compare published_level s2.published_level in @@ -90,7 +90,7 @@ let zero_id = index = Index.zero; } -let zero = {id = zero_id; header = Header.zero} +let zero = {id = zero_id; commitment = Commitment.zero} module Slot_index = Index @@ -154,25 +154,25 @@ end let slot_encoding = let open Data_encoding in conv - (fun {id = {published_level; index}; header} -> - (published_level, index, header)) - (fun (published_level, index, header) -> - {id = {published_level; index}; header}) + (fun {id = {published_level; index}; commitment} -> + (published_level, index, commitment)) + (fun (published_level, index, commitment) -> + {id = {published_level; index}; commitment}) (obj3 (req "level" Raw_level_repr.encoding) (req "index" Data_encoding.uint8) - (req "header" Header.encoding)) + (req "commitment" Commitment.encoding)) -let pp_slot fmt {id = {published_level; index}; header} = +let pp_slot fmt {id = {published_level; index}; commitment} = Format.fprintf fmt - "slot:(published_level: %a, index: %a, header: %a)" + "slot:(published_level: %a, index: %a, commitment: %a)" Raw_level_repr.pp published_level Format.pp_print_int index - Header.pp - header + Commitment.pp + commitment module Slot_market = struct (* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3108 @@ -314,7 +314,7 @@ module Slots_history = struct end module V1 = struct - (* The content of a cell is the hash of all the slot headers + (* The content of a cell is the hash of all the slot commitments represented as a merkle list. *) (* TODO/DAL: https://gitlab.com/tezos/tezos/-/issues/3765 Decide how to store attested slots in the skip list's content. *) @@ -603,7 +603,7 @@ module Slots_history = struct let proof_error reason = fail @@ dal_proof_error reason - let check_page_proof dal_params proof data pid slot_header = + let check_page_proof dal_params proof data pid commitment = let open Lwt_tzresult_syntax in let* dal = match Dal.make dal_params with @@ -619,10 +619,10 @@ module Slots_history = struct (Bytes.to_string data) Page.pp pid - Header.pp - slot_header + Commitment.pp + commitment in - match Dal.verify_page dal slot_header page proof with + match Dal.verify_page dal commitment page proof with | Ok true -> return () | Ok false -> fail_with_error_msg @@ -652,7 +652,7 @@ module Slots_history = struct initialized with a min elt (slot zero)." | Some (page_data, page_proof), Found target_cell -> (* The slot to which the page is supposed to belong is found. *) - let {id; header} = Skip_list.content target_cell in + let {id; commitment} = Skip_list.content target_cell in (* We check that the slot is not the dummy slot. *) let* () = fail_when @@ -662,7 +662,7 @@ module Slots_history = struct proof should be constructed with the slot zero.") in let* () = - check_page_proof dal_params page_proof page_data page_id header + check_page_proof dal_params page_proof page_data page_id commitment in let inc_proof = List.rev search_result.Skip_list.rev_path in let* () = @@ -739,7 +739,7 @@ module Slots_history = struct | Page_confirmed {target_cell; page_data; page_proof; inc_proof} -> (* If the page is supposed to be confirmed, the last cell in [inc_proof] should store the slot of the page. *) - let {id; header} = Skip_list.content target_cell in + let {id; commitment} = Skip_list.content target_cell in let* () = fail_when Compare.Int.(compare_slot_id id zero.id = 0) @@ -753,7 +753,7 @@ module Slots_history = struct (* We check that the page indeed belongs to the target slot at the given page index. *) let* () = - check_page_proof dal_params page_proof page_data page_id header + check_page_proof dal_params page_proof page_data page_id commitment in (* If all checks succeed, we return the data/content of the page. *) return_some page_data diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index 457152ae74c6..7472e90860bd 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -46,11 +46,14 @@ The slot header can also be used to prove that a blob of data is a portion of the initial slot. *) -module Header : sig +module Commitment : sig + (** A slot commitment is provided via the environment. *) type t = Dal.commitment val encoding : t Data_encoding.t + (** A dummy value for a commitment. This commitment does not + correspond to any valid pre-image. *) val zero : t end @@ -91,7 +94,7 @@ end (KATE commitment hash). *) type id = {published_level : Raw_level_repr.t; index : Index.t} -type t = {id : id; header : Header.t} +type t = {id : id; commitment : Commitment.t} type slot = t 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 ca2efa04ff7e..6f592aa75e3a 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml @@ -92,11 +92,11 @@ let mk_slot ?(level = level_one) ?(index = S.Index.zero) let params = Cryptobox.Internal_for_tests.parameters dal in let slot_data = Bytes.init params.slot_size fill_function in let* polynomial = dal_mk_polynomial_from_slot dal slot_data in - let kate_commit = Cryptobox.commit dal polynomial in + let commitment = Cryptobox.commit dal polynomial in return ( slot_data, polynomial, - S.{id = S.{published_level = level; index}; header = kate_commit} ) + S.{id = S.{published_level = level; index}; commitment} ) let mk_page_id published_level slot_index page_index = P.{slot_id = {published_level; index = slot_index}; page_index} 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 e0aad4dd7aa0..dbbf65685772 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml @@ -663,8 +663,10 @@ 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.Header.zero in - let slot = Alpha_context.Dal.Slot.{id = {published_level; index}; header} in + let commitment = Alpha_context.Dal.Slot.Commitment.zero in + let slot = + Alpha_context.Dal.Slot.{id = {published_level; index}; commitment} + in Dal_publish_slot_header {slot} in generate_manager random_state gen_dal_publish 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 66743e0a8b08..32107ded65df 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 @@ -1051,8 +1051,10 @@ 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.Header.zero in - let slot = Alpha_context.Dal.Slot.{id = {published_level; index}; header} in + let commitment = Alpha_context.Dal.Slot.Commitment.zero in + let slot = + Alpha_context.Dal.Slot.{id = {published_level; index}; commitment} + in Op.dal_publish_slot_header ?fee:oinfos.fee ?gas_limit:oinfos.gas_limit diff --git a/tezt/lib_tezos/operation_core.ml b/tezt/lib_tezos/operation_core.ml index 7ff3ee5759a2..7506eb2520d3 100644 --- a/tezt/lib_tezos/operation_core.ml +++ b/tezt/lib_tezos/operation_core.ml @@ -342,7 +342,7 @@ module Manager = struct | Dal_publish_slot_header of { level : int; index : int; - header : Tezos_crypto_dal.Cryptobox.commitment; + commitment : Tezos_crypto_dal.Cryptobox.commitment; } | Sc_rollup_dal_slot_subscribe of {rollup : string; slot_index : int} | Delegation of {delegate : Account.key} @@ -362,8 +362,8 @@ module Manager = struct ?(entrypoint = "default") ?(arg = `O [("prim", `String "Unit")]) () = Transfer {amount; dest; parameters = Some {entrypoint; arg}} - let dal_publish_slot_header ~level ~index ~header = - Dal_publish_slot_header {level; index; header} + let dal_publish_slot_header ~level ~index ~commitment = + Dal_publish_slot_header {level; index; commitment} let sc_rollup_dal_slot_subscribe ~rollup ~slot_index = Sc_rollup_dal_slot_subscribe {rollup; slot_index} @@ -401,13 +401,13 @@ module Manager = struct ("destination", `String dest); ] @ parameters - | Dal_publish_slot_header {level; index; header} -> + | Dal_publish_slot_header {level; index; commitment} -> let slot = `O [ ("index", json_of_int index); ("level", json_of_int level); - ("header", json_of_commitment header); + ("commitment", json_of_commitment commitment); ] in [("kind", `String "dal_publish_slot_header"); ("slot", slot)] diff --git a/tezt/lib_tezos/operation_core.mli b/tezt/lib_tezos/operation_core.mli index 2d38fd545323..39fdcec51a6c 100644 --- a/tezt/lib_tezos/operation_core.mli +++ b/tezt/lib_tezos/operation_core.mli @@ -281,7 +281,7 @@ module Manager : sig val dal_publish_slot_header : level:int -> index:int -> - header:Tezos_crypto_dal.Cryptobox.commitment -> + commitment:Tezos_crypto_dal.Cryptobox.commitment -> payload (** [sc_rollup_dal_slot_subscribe ~rollup ~slot_index] builds an diff --git a/tezt/lib_tezos/sc_rollup_client.ml b/tezt/lib_tezos/sc_rollup_client.ml index 1cb40a65427f..3dfd2fd5bfaf 100644 --- a/tezt/lib_tezos/sc_rollup_client.ml +++ b/tezt/lib_tezos/sc_rollup_client.ml @@ -228,7 +228,7 @@ let dal_slots_metadata ?hooks sc_client = |> List.map (fun obj -> { level = obj |> get "level" |> as_int; - header = obj |> get "header" |> as_string; + header = obj |> get "commitment" |> as_string; index = obj |> get "index" |> as_int; })) diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index 2632c7133f9f..5cb48b1ee52e 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -220,7 +220,7 @@ let test_feature_flag _protocol _sc_rollup_node sc_rollup_address node client = in let* parameters = Rollup.Dal.Parameters.from_client client in let cryptobox = Rollup.Dal.make parameters in - let header = + let commitment = Rollup.Dal.Commitment.dummy_commitment parameters cryptobox "coucou" in Check.( @@ -239,7 +239,7 @@ let test_feature_flag _protocol _sc_rollup_node sc_rollup_address node client = Operation.Manager.( inject ~force:true - [make @@ dal_publish_slot_header ~index:0 ~level:1 ~header] + [make @@ dal_publish_slot_header ~index:0 ~level:1 ~commitment] client) in let* (`OpHash oph3) = @@ -260,28 +260,31 @@ let test_feature_flag _protocol _sc_rollup_node sc_rollup_address node client = Test.fail "Unexpected entry dal in the context when DAL is disabled" ; unit -let publish_slot ~source ?fee ~index ~header node client = +let publish_slot ~source ?fee ~index ~commitment node client = let level = Node.get_level node in Operation.Manager.( inject - [make ~source ?fee @@ dal_publish_slot_header ~index ~level ~header] + [make ~source ?fee @@ dal_publish_slot_header ~index ~level ~commitment] client) let publish_dummy_slot ~source ?fee ~index ~message parameters cryptobox = - let header = + let commitment = Rollup.Dal.Commitment.dummy_commitment parameters cryptobox message in - publish_slot ~source ?fee ~index ~header + publish_slot ~source ?fee ~index ~commitment let publish_slot_header ~source ?(fee = 1200) ~index ~header node client = let level = Node.get_level node in let header = Tezos_crypto_dal.Cryptobox.Commitment.of_b58check_opt header in match header with | None -> assert false - | Some header -> + | Some commitment -> Operation.Manager.( inject - [make ~source ~fee @@ dal_publish_slot_header ~index ~level ~header] + [ + make ~source ~fee + @@ dal_publish_slot_header ~index ~level ~commitment; + ] client) let slot_availability ~signer availability client = diff --git a/tezt/tests/expected/dal.ml/Alpha- Testing rollup and Data availability layer node (rollup_node_downloads_sl.out b/tezt/tests/expected/dal.ml/Alpha- Testing rollup and Data availability layer node (rollup_node_downloads_sl.out index d489422e55a4..6b83e48ff913 100644 --- a/tezt/tests/expected/dal.ml/Alpha- Testing rollup and Data availability layer node (rollup_node_downloads_sl.out +++ b/tezt/tests/expected/dal.ml/Alpha- Testing rollup and Data availability layer node (rollup_node_downloads_sl.out @@ -39,13 +39,13 @@ This sequence of operations was run: ./octez-sc-rollup-client-alpha rpc get /global/dal/slots [ { "level": 4, "index": 0, - "header": + "commitment": "sh23JCJDe5NojHgzFFhFmRZayf5QGo7C3rVv9eyPA7bqR592hQo4fB7Zg67dY8iAW4tmSrff6v" }, { "level": 4, "index": 1, - "header": + "commitment": "[DAL_SLOT_HEADER]" }, { "level": 4, "index": 2, - "header": + "commitment": "sh26FkLr6i1hb3CDtx7kWEYbS28byamyW7brBjCwdciGCFKNmkyyWt6wX1wvL7A7n25YyHFmEB" } ] ./octez-sc-rollup-client-alpha rpc get /global/dal/slot_pages -- GitLab From f8e5d16bf4c571a9113b9f4147bd1889d02a3d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Wed, 5 Oct 2022 07:22:07 +0200 Subject: [PATCH 2/3] Protocol/DAL: Update outdated comment --- src/proto_alpha/lib_protocol/dal_slot_repr.mli | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index 7472e90860bd..4e2f0d03a0cf 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -74,12 +74,7 @@ module Index : sig val max_value : t - (** [of_int n] constructs a`Slot_index.t` - May fail with: - {ul - {li [Dal_invalid_slot_header n] if [n] is either negative or greater than [max_slot_value].} - } - *) + (** [of_int n] constructs a`Slot_index.t` *) val of_int : int -> t option val to_int : t -> int -- GitLab From 100e59dcafbfe66500b45bed1da7c6b4c25e9bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Wed, 5 Oct 2022 08:25:36 +0200 Subject: [PATCH 3/3] Protocol/DAL: Rename slots into slot headers --- src/proto_alpha/bin_sc_rollup_node/daemon.ml | 6 +- .../bin_sc_rollup_node/dal_slots_tracker.ml | 4 +- src/proto_alpha/bin_sc_rollup_node/store.ml | 6 +- src/proto_alpha/bin_sc_rollup_node/store.mli | 2 +- .../lib_client/operation_result.ml | 6 +- .../lib_dal/dal_plugin_registration.ml | 8 +- src/proto_alpha/lib_plugin/RPC.ml | 15 +- src/proto_alpha/lib_protocol/alpha_context.ml | 2 +- .../lib_protocol/alpha_context.mli | 37 ++-- src/proto_alpha/lib_protocol/apply.ml | 4 +- src/proto_alpha/lib_protocol/dal_apply.ml | 15 +- src/proto_alpha/lib_protocol/dal_apply.mli | 14 +- .../lib_protocol/dal_errors_repr.ml | 19 +- src/proto_alpha/lib_protocol/dal_slot_repr.ml | 170 +++++++++--------- .../lib_protocol/dal_slot_repr.mli | 50 +++--- .../lib_protocol/dal_slot_storage.ml | 57 +++--- .../lib_protocol/dal_slot_storage.mli | 36 ++-- .../lib_protocol/operation_repr.ml | 9 +- .../lib_protocol/operation_repr.mli | 2 +- src/proto_alpha/lib_protocol/raw_context.ml | 27 ++- src/proto_alpha/lib_protocol/raw_context.mli | 20 +-- .../lib_protocol/sc_rollup_storage.ml | 2 +- src/proto_alpha/lib_protocol/storage.ml | 62 ++++--- src/proto_alpha/lib_protocol/storage.mli | 26 +-- .../lib_protocol/test/helpers/dal_helpers.ml | 6 +- .../lib_protocol/test/helpers/dal_helpers.mli | 22 +-- .../lib_protocol/test/helpers/op.ml | 4 +- .../lib_protocol/test/helpers/op.mli | 2 +- .../test/helpers/operation_generator.ml | 6 +- .../validate/manager_operation_helpers.ml | 2 +- .../test/pbt/test_dal_slot_proof.ml | 9 +- .../test/unit/test_dal_slot_proof.ml | 33 ++-- .../test/unit/test_sc_rollup_storage.ml | 6 +- src/proto_alpha/lib_protocol/validate.ml | 4 +- .../lib_sc_rollup/sc_rollup_services.ml | 4 +- tezt/lib_tezos/RPC.ml | 4 +- tezt/lib_tezos/RPC.mli | 8 +- tezt/lib_tezos/operation_core.ml | 7 +- tezt/lib_tezos/sc_rollup_client.ml | 8 +- tezt/lib_tezos/sc_rollup_client.mli | 8 +- tezt/tests/dal.ml | 45 ++--- ...y layer node (rollup_node_downloads_sl.out | 2 +- 42 files changed, 414 insertions(+), 365 deletions(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/daemon.ml b/src/proto_alpha/bin_sc_rollup_node/daemon.ml index 17c60aae4da3..f1c9ea2bd33b 100644 --- a/src/proto_alpha/bin_sc_rollup_node/daemon.ml +++ b/src/proto_alpha/bin_sc_rollup_node/daemon.ml @@ -113,8 +113,8 @@ module Make (PVM : Pvm.S) = struct balance_updates in tzfail (Sc_rollup_node_errors.Lost_game (loser, reason, slashed_amount)) - | Dal_publish_slot_header {slot}, Dal_publish_slot_header_result _ -> - let {Dal.Slot.id = {index; _}; _} = slot in + | Dal_publish_slot_header {slot_header}, Dal_publish_slot_header_result _ -> + let {Dal.Slot.Header.id = {index; _}; _} = slot_header in (* DAL/FIXME: https://gitlab.com/tezos/tezos/-/issues/3510 We store slot headers for all slots. In practice, it would be convenient to store only information about @@ -126,7 +126,7 @@ module Make (PVM : Pvm.S) = struct node_ctxt.store ~primary_key:head ~secondary_key:index - slot + slot_header in return_unit | _, _ -> diff --git a/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.ml b/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.ml index 2b9b8afdc6b0..a139cc8a9a57 100644 --- a/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.ml +++ b/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.ml @@ -395,7 +395,7 @@ module Confirmed_slots_history = struct let slots_to_save = let open Dal in List.fast_sort - (fun Slot.{id = {index = a; _}; _} {id = {index = b; _}; _} -> + (fun Slot.Header.{id = {index = a; _}; _} {id = {index = b; _}; _} -> Slot_index.compare a b) slots_to_save in @@ -403,7 +403,7 @@ module Confirmed_slots_history = struct let* slots_history = slots_history_of_hash node_ctxt pred in let* slots_cache = slots_history_cache_of_hash node_ctxt pred in let*? slots_history, slots_cache = - Dal.Slots_history.add_confirmed_slots + Dal.Slots_history.add_confirmed_slot_headers slots_history slots_cache slots_to_save diff --git a/src/proto_alpha/bin_sc_rollup_node/store.ml b/src/proto_alpha/bin_sc_rollup_node/store.ml index dfa775d077f3..ccc8519cc024 100644 --- a/src/proto_alpha/bin_sc_rollup_node/store.ml +++ b/src/proto_alpha/bin_sc_rollup_node/store.ml @@ -318,15 +318,15 @@ module Dal_slots_headers = Make_nested_map (struct let compare_secondary_keys = Dal.Slot_index.compare - type value = Dal.Slot.t + type value = Dal.Slot.Header.t let secondary_key_encoding = Dal.Slot_index.encoding let secondary_key_name = "slot_index" - let value_encoding = Dal.Slot.encoding + let value_encoding = Dal.Slot.Header.encoding - let value_name = "slot_metadata" + let value_name = "slot_header" end) (** Confirmed DAL slots history. See documentation of diff --git a/src/proto_alpha/bin_sc_rollup_node/store.mli b/src/proto_alpha/bin_sc_rollup_node/store.mli index 7be1b2686706..fd633850ad87 100644 --- a/src/proto_alpha/bin_sc_rollup_node/store.mli +++ b/src/proto_alpha/bin_sc_rollup_node/store.mli @@ -148,7 +148,7 @@ module Dal_slots_headers : Store_utils.Nested_map with type primary_key = Block_hash.t and type secondary_key = Dal.Slot_index.t - and type value = Dal.Slot.t + and type value = Dal.Slot.Header.t (** Confirmed DAL slots history. See documentation of {Dal_slot_repr.Slots_history} for more details. *) diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index 529d0ed8306f..e0c8d5a1e1c5 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -412,12 +412,12 @@ let pp_manager_operation_content (type kind) source ppf slot_index Sc_rollup.Address.pp rollup - | Dal_publish_slot_header {slot} -> + | Dal_publish_slot_header {slot_header} -> Format.fprintf ppf "Data availability slot header publishing:@,Slot: %a" - Dal.Slot.pp - slot + Dal.Slot.Header.pp + slot_header | Zk_rollup_origination _ -> Format.fprintf ppf "Zk rollup origination:@,From: %a" Contract.pp source | Zk_rollup_publish _ -> diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index 9567eb84f597..cc3589bd2f76 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -45,14 +45,16 @@ module Plugin = struct in let apply_internal acc ~source:_ _op _res = acc in let apply (type kind) acc ~source:_ (op : kind manager_operation) _res = - match op with Dal_publish_slot_header {slot} -> slot :: acc | _ -> acc + match op with + | Dal_publish_slot_header {slot_header} -> slot_header :: acc + | _ -> acc in Layer1_services.( process_manager_operations [] block.operations {apply; apply_internal}) |> List.map_es (fun slot -> return - ( Dal.Slot_index.to_int slot.Dal.Slot.id.index, - slot.Dal.Slot.commitment )) + ( Dal.Slot_index.to_int slot.Dal.Slot.Header.id.index, + slot.Dal.Slot.Header.commitment )) end let () = Dal_plugin.register (module Plugin) diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 4f63b6481ca3..f61e70eb899f 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -2288,7 +2288,7 @@ end module Dal = struct module S = struct - let dal_confirmed_slots_history = + let dal_confirmed_slot_headers_history = let output = Data_encoding.option Dal.Slots_history.encoding in let query = RPC_query.(seal @@ query ()) in RPC_service.get_service @@ -2297,22 +2297,23 @@ module Dal = struct DAL is enabled, or [None] otherwise." ~output ~query - RPC_path.(open_root / "context" / "dal" / "confirmed_slots_history") + RPC_path.( + open_root / "context" / "dal" / "confirmed_slot_headers_history") end - let register_dal_confirmed_slots_history () = + let register_dal_confirmed_slot_headers_history () = Registration.register0 ~chunked:false - S.dal_confirmed_slots_history + S.dal_confirmed_slot_headers_history (fun ctxt () () -> if (Constants.parametric ctxt).dal.feature_enable then - Dal.Slots_storage.get_slots_history ctxt >|=? Option.some + Dal.Slots_storage.get_slot_headers_history ctxt >|=? Option.some else return None) - let register () = register_dal_confirmed_slots_history () + let register () = register_dal_confirmed_slot_headers_history () let dal_confirmed_slots_history ctxt block = - RPC_context.make_call0 S.dal_confirmed_slots_history ctxt block () () + RPC_context.make_call0 S.dal_confirmed_slot_headers_history ctxt block () () end module Tx_rollup = struct diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index c8daaa0291ab..032c6b2ffc2c 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -116,7 +116,7 @@ module Dal = struct include Raw_context.Dal end - module Slots_history = Dal_slot_repr.Slots_history + module Slots_history = Dal_slot_repr.History module Slots_storage = Dal_slot_storage end diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 0642b188974d..1c9a7ed52b97 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2840,23 +2840,26 @@ module Dal : sig val zero : t end - type id = {published_level : Raw_level.t; index : Slot_index.t} + module Header : sig + type id = {published_level : Raw_level.t; index : Slot_index.t} - type t = {id : id; commitment : Commitment.t} + type t = {id : id; commitment : Commitment.t} - val encoding : t Data_encoding.t + val encoding : t Data_encoding.t - val pp : Format.formatter -> t -> unit + val pp : Format.formatter -> t -> unit - val equal : t -> t -> bool + val equal : t -> t -> bool + end - val register_slot : context -> t -> (context * bool) tzresult + val register_slot_header : context -> Header.t -> (context * bool) tzresult - val find : context -> Raw_level.t -> t list option tzresult Lwt.t + val find_slot_headers : + context -> Raw_level.t -> Header.t list option tzresult Lwt.t - val finalize_current_slots : context -> context Lwt.t + val finalize_current_slot_headers : context -> context Lwt.t - val finalize_pending_slots : + val finalize_pending_slot_headers : context -> (context * Endorsement.t) tzresult Lwt.t end @@ -2873,10 +2876,14 @@ module Dal : sig module History_cache : Bounded_history_repr.S - val add_confirmed_slots_no_cache : t -> Slot.t list -> t tzresult + val add_confirmed_slot_headers_no_cache : + t -> Slot.Header.t list -> t tzresult - val add_confirmed_slots : - t -> History_cache.t -> Slot.t list -> (t * History_cache.t) tzresult + val add_confirmed_slot_headers : + t -> + History_cache.t -> + Slot.Header.t list -> + (t * History_cache.t) tzresult type dal_parameters = Dal.parameters = { redundancy_factor : int; @@ -2889,7 +2896,7 @@ module Dal : sig end module Slots_storage : sig - val get_slots_history : t -> Slots_history.t tzresult Lwt.t + val get_slot_headers_history : t -> Slots_history.t tzresult Lwt.t end end @@ -2912,7 +2919,7 @@ module Dal_errors : sig } | Dal_publish_slot_header_candidate_with_low_fees of {proposed_fees : Tez.t} | Dal_endorsement_size_limit_exceeded of {maximum_size : int; got : int} - | Dal_publish_slot_header_duplicate of {slot : Dal.Slot.t} + | Dal_publish_slot_header_duplicate of {slot_header : Dal.Slot.Header.t} end (** This module re-exports definitions from {!Sc_rollup_storage} and @@ -4357,7 +4364,7 @@ and _ manager_operation = } -> Kind.transfer_ticket manager_operation | Dal_publish_slot_header : { - slot : Dal.Slot.t; + slot_header : Dal.Slot.Header.t; } -> Kind.dal_publish_slot_header manager_operation | Sc_rollup_originate : { diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 3481fe2d425c..95e8eb0ea389 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1290,8 +1290,8 @@ let apply_manager_operation : in return (ctxt, result, []) | None -> fail Tx_rollup_errors.Proof_undecodable) - | Dal_publish_slot_header {slot} -> - Dal_apply.apply_publish_slot_header ctxt slot >>?= fun ctxt -> + | Dal_publish_slot_header {slot_header} -> + Dal_apply.apply_publish_slot_header ctxt slot_header >>?= fun ctxt -> let consumed_gas = Gas.consumed ~since:ctxt_before_op ~until:ctxt in let result = Dal_publish_slot_header_result {consumed_gas} in return (ctxt, result, []) diff --git a/src/proto_alpha/lib_protocol/dal_apply.ml b/src/proto_alpha/lib_protocol/dal_apply.ml index 34c812e5a87f..bec17e6d7966 100644 --- a/src/proto_alpha/lib_protocol/dal_apply.ml +++ b/src/proto_alpha/lib_protocol/dal_apply.ml @@ -62,7 +62,7 @@ let apply_data_availability ctxt data_availability ~endorser = Dal.Endorsement.record_available_shards ctxt data_availability shards |> return -let validate_publish_slot_header ctxt Dal.Slot.{id = {index; _}; _} = +let validate_publish_slot_header ctxt Dal.Slot.Header.{id = {index; _}; _} = assert_dal_feature_enabled ctxt >>? fun () -> let open Tzresult_syntax in let open Constants in @@ -75,16 +75,17 @@ let validate_publish_slot_header ctxt Dal.Slot.{id = {index; _}; _} = (Dal_publish_slot_header_invalid_index {given = index; maximum = number_of_slots}) -let apply_publish_slot_header ctxt slot = +let apply_publish_slot_header ctxt slot_header = assert_dal_feature_enabled ctxt >>? fun () -> - Dal.Slot.register_slot ctxt slot >>? fun (ctxt, updated) -> - if updated then ok ctxt else error (Dal_publish_slot_header_duplicate {slot}) + Dal.Slot.register_slot_header ctxt slot_header >>? fun (ctxt, updated) -> + if updated then ok ctxt + else error (Dal_publish_slot_header_duplicate {slot_header}) let dal_finalisation ctxt = only_if_dal_feature_enabled ctxt ~default:(fun ctxt -> return (ctxt, None)) (fun ctxt -> - Dal.Slot.finalize_current_slots ctxt >>= fun ctxt -> - Dal.Slot.finalize_pending_slots ctxt >|=? fun (ctxt, slot_availability) -> - (ctxt, Some slot_availability)) + Dal.Slot.finalize_current_slot_headers ctxt >>= fun ctxt -> + Dal.Slot.finalize_pending_slot_headers ctxt + >|=? fun (ctxt, slot_availability) -> (ctxt, Some slot_availability)) diff --git a/src/proto_alpha/lib_protocol/dal_apply.mli b/src/proto_alpha/lib_protocol/dal_apply.mli index 7db324166d36..0f02a75a8ec4 100644 --- a/src/proto_alpha/lib_protocol/dal_apply.mli +++ b/src/proto_alpha/lib_protocol/dal_apply.mli @@ -43,16 +43,16 @@ val apply_data_availability : endorser:Signature.Public_key_hash.t -> t tzresult Lwt.t -(** [validate_publish_slot_header ctxt slot] ensures that [slot] is - valid and cannot prevent an operation containing [slot] to be - refused on top of [ctxt]. If an [Error _] is returned, the [slot] +(** [validate_publish_slot_header ctxt slot] ensures that [slot_header] is + valid and cannot prevent an operation containing [slot_header] to be + refused on top of [ctxt]. If an [Error _] is returned, the [slot_header] is not valid. *) -val validate_publish_slot_header : t -> Dal.Slot.t -> unit tzresult +val validate_publish_slot_header : t -> Dal.Slot.Header.t -> unit tzresult -(** [apply_publish_slot_header ctxt slot] applies the publication of - slot header [slot] on top of [ctxt]. Fails if the slot contains +(** [apply_publish_slot_header ctxt slot_header] applies the publication of + slot header [slot_header] on top of [ctxt]. Fails if the slot contains already a slot header. *) -val apply_publish_slot_header : t -> Dal.Slot.t -> t tzresult +val apply_publish_slot_header : t -> Dal.Slot.Header.t -> t tzresult (** [dal_finalisation ctxt] should be executed at block finalisation time. A set of slots available at level [ctxt.current_level - lag] diff --git a/src/proto_alpha/lib_protocol/dal_errors_repr.ml b/src/proto_alpha/lib_protocol/dal_errors_repr.ml index 67995977e308..cf09c8d1715d 100644 --- a/src/proto_alpha/lib_protocol/dal_errors_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_errors_repr.ml @@ -39,8 +39,8 @@ type error += proposed_fees : Tez_repr.t; } | Dal_endorsement_size_limit_exceeded of {maximum_size : int; got : int} - | Dal_publish_slot_header_duplicate of {slot : Dal_slot_repr.t} - | Dal_rollup_already_registered_to_slot of + | Dal_publish_slot_header_duplicate of {slot_header : Dal_slot_repr.Header.t} + | Dal_rollup_already_registered_to_slot_index of (Sc_rollup_repr.t * Dal_slot_repr.Index.t) | Dal_requested_subscriptions_at_future_level of (Raw_level_repr.t * Raw_level_repr.t) @@ -51,7 +51,7 @@ let () = register_error_kind `Permanent ~id:"dal_subscribe_rollup_invalid_slot_index" - ~title:"DAL slot invalid index for subscribing sc rollup" + ~title:"DAL invalid slot index for subscribing sc rollup" ~description ~pp:(fun ppf (given, maximum) -> Format.fprintf @@ -190,10 +190,11 @@ let () = ~title:"DAL publish slot header duplicate" ~description ~pp:(fun ppf _proposed -> Format.fprintf ppf "%s" description) - (obj1 (req "proposed" Dal_slot_repr.encoding)) + (obj1 (req "proposed" Dal_slot_repr.Header.encoding)) (function - | Dal_publish_slot_header_duplicate {slot} -> Some slot | _ -> None) - (fun slot -> Dal_publish_slot_header_duplicate {slot}) ; + | Dal_publish_slot_header_duplicate {slot_header} -> Some slot_header + | _ -> None) + (fun slot_header -> Dal_publish_slot_header_duplicate {slot_header}) ; register_error_kind `Permanent ~id:"Dal_rollup_already_subscribed_to_slot" @@ -202,7 +203,7 @@ let () = ~pp:(fun ppf (rollup, slot_index) -> Format.fprintf ppf - "Rollup %a is already subscribed to data availability slot %a" + "Rollup %a is already subscribed to data availability slot index %a" Sc_rollup_repr.pp rollup Dal_slot_repr.Index.pp @@ -212,11 +213,11 @@ let () = (req "rollup" Sc_rollup_repr.encoding) (req "slot_index" Dal_slot_repr.Index.encoding)) (function - | Dal_rollup_already_registered_to_slot (rollup, slot_index) -> + | Dal_rollup_already_registered_to_slot_index (rollup, slot_index) -> Some (rollup, slot_index) | _ -> None) (fun (rollup, slot_index) -> - Dal_rollup_already_registered_to_slot (rollup, slot_index)) ; + Dal_rollup_already_registered_to_slot_index (rollup, slot_index)) ; let description = "Requested List of subscribed rollups to slot at a future level" in diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.ml b/src/proto_alpha/lib_protocol/dal_slot_repr.ml index df16d7575ad1..f467d706a268 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.ml @@ -63,40 +63,63 @@ module Index = struct let equal = Compare.Int.equal end -type id = {published_level : Raw_level_repr.t; index : Index.t} +module Header = struct + type id = {published_level : Raw_level_repr.t; index : Index.t} -type t = {id : id; commitment : Commitment.t} + type t = {id : id; commitment : Commitment.t} -type slot = t + let slot_id_equal ({published_level; index} : id) s2 = + Raw_level_repr.equal published_level s2.published_level + && Index.equal index s2.index -type slot_index = Index.t + let equal {id; commitment} s2 = + slot_id_equal id s2.id && Commitment.equal commitment s2.commitment -let slot_id_equal ({published_level; index} : id) s2 = - Raw_level_repr.equal published_level s2.published_level - && Index.equal index s2.index + let compare_slot_id {published_level; index} s2 = + let c = Raw_level_repr.compare published_level s2.published_level in + if Compare.Int.(c <> 0) then c else Index.compare index s2.index -let slot_equal ({id; commitment} : t) s2 = - slot_id_equal id s2.id && Commitment.equal commitment s2.commitment + let zero_id = + { + (* We don't expect to have any published slot at level + Raw_level_repr.root. *) + published_level = Raw_level_repr.root; + index = Index.zero; + } -let compare_slot_id ({published_level; index} : id) s2 = - let c = Raw_level_repr.compare published_level s2.published_level in - if Compare.Int.(c <> 0) then c else Index.compare index s2.index + let zero = {id = zero_id; commitment = Commitment.zero} -let zero_id = - { - (* We don't expect to have any published slot at level - Raw_level_repr.root. *) - published_level = Raw_level_repr.root; - index = Index.zero; - } + let encoding = + let open Data_encoding in + conv + (fun {id = {published_level; index}; commitment} -> + (published_level, index, commitment)) + (fun (published_level, index, commitment) -> + {id = {published_level; index}; commitment}) + (obj3 + (req "level" Raw_level_repr.encoding) + (req "index" Data_encoding.uint8) + (req "commitment" Commitment.encoding)) -let zero = {id = zero_id; commitment = Commitment.zero} + let pp fmt {id = {published_level; index}; commitment} = + Format.fprintf + fmt + "published_level: %a index: %a commitment: %a" + Raw_level_repr.pp + published_level + Format.pp_print_int + index + Commitment.pp + commitment +end module Slot_index = Index module Page = struct type content = Bytes.t + type slot_index = Index.t + module Index = struct type t = int @@ -111,7 +134,7 @@ module Page = struct let equal = Compare.Int.equal end - type t = {slot_id : id; page_index : Index.t} + type t = {slot_id : Header.id; page_index : Index.t} type proof = Dal.page_proof @@ -128,7 +151,8 @@ module Page = struct (req "page_index" Index.encoding)) let equal {slot_id; page_index} p = - slot_id_equal slot_id p.slot_id && Index.equal page_index p.page_index + Header.slot_id_equal slot_id p.slot_id + && Index.equal page_index p.page_index let proof_encoding = Dal.page_proof_encoding @@ -151,29 +175,6 @@ module Page = struct (Data_encoding.Json.construct proof_encoding proof) end -let slot_encoding = - let open Data_encoding in - conv - (fun {id = {published_level; index}; commitment} -> - (published_level, index, commitment)) - (fun (published_level, index, commitment) -> - {id = {published_level; index}; commitment}) - (obj3 - (req "level" Raw_level_repr.encoding) - (req "index" Data_encoding.uint8) - (req "commitment" Commitment.encoding)) - -let pp_slot fmt {id = {published_level; index}; commitment} = - Format.fprintf - fmt - "slot:(published_level: %a, index: %a, commitment: %a)" - Raw_level_repr.pp - published_level - Format.pp_print_int - index - Commitment.pp - commitment - module Slot_market = struct (* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3108 @@ -182,44 +183,50 @@ module Slot_market = struct module Slot_index_map = Map.Make (Index) - type t = {length : int; slots : slot Slot_index_map.t} + type t = {length : int; slot_headers : Header.t Slot_index_map.t} let init ~length = if Compare.Int.(length < 0) then invalid_arg "Dal_slot_repr.Slot_market.init: length cannot be negative" ; - let slots = Slot_index_map.empty in - {length; slots} + let slot_headers = Slot_index_map.empty in + {length; slot_headers} let length {length; _} = length - let register t new_slot = - if not Compare.Int.(0 <= new_slot.id.index && new_slot.id.index < t.length) + let register t new_slot_header = + let open Header in + if + not + Compare.Int.( + 0 <= new_slot_header.id.index && new_slot_header.id.index < t.length) then None else let has_changed = ref false in let update = function | None -> has_changed := true ; - Some new_slot + Some new_slot_header | Some x -> Some x in - let slots = Slot_index_map.update new_slot.id.index update t.slots in - let t = {t with slots} in + let slot_headers = + Slot_index_map.update new_slot_header.id.index update t.slot_headers + in + let t = {t with slot_headers} in Some (t, !has_changed) let candidates t = - t.slots |> Slot_index_map.to_seq |> Seq.map snd |> List.of_seq + t.slot_headers |> Slot_index_map.to_seq |> Seq.map snd |> List.of_seq end -module Slots_history = struct +module History = struct (* History is represented via a skip list. The content of the cell is the hash of a merkle proof. *) (* A leaf of the merkle tree is a slot. *) module Leaf = struct - type t = slot + type t = Header.t - let to_bytes = Data_encoding.Binary.to_bytes_exn slot_encoding + let to_bytes = Data_encoding.Binary.to_bytes_exn Header.encoding end module Content_prefix = struct @@ -296,7 +303,7 @@ module Slots_history = struct guarantee that it can only be called with the adequate compare function. *) - let compare = compare_slot_id + let compare = Header.compare_slot_id let compare_lwt a b = Lwt.return @@ compare a b @@ -304,13 +311,16 @@ module Slots_history = struct let open Tzresult_syntax in let* () = error_when - (Compare.Int.( <= ) (compare elt.id (content prev_cell).id) 0) + (Compare.Int.( <= ) + (compare elt.Header.id (content prev_cell).Header.id) + 0) Add_element_in_slots_skip_list_violates_ordering in return @@ next ~prev_cell ~prev_cell_ptr elt let search ~deref ~cell ~target_id = - search ~deref ~cell ~compare:(fun slot -> compare_lwt slot.id target_id) + search ~deref ~cell ~compare:(fun slot -> + compare_lwt slot.Header.id target_id) end module V1 = struct @@ -318,7 +328,7 @@ module Slots_history = struct represented as a merkle list. *) (* TODO/DAL: https://gitlab.com/tezos/tezos/-/issues/3765 Decide how to store attested slots in the skip list's content. *) - type content = slot + type content = Header.t (* A pointer to a cell is the hash of its content and all the back pointers. *) @@ -329,21 +339,21 @@ module Slots_history = struct type t = history let history_encoding = - Skip_list.encoding Pointer_hash.encoding slot_encoding + Skip_list.encoding Pointer_hash.encoding Header.encoding let equal_history : history -> history -> bool = - Skip_list.equal Pointer_hash.equal slot_equal + Skip_list.equal Pointer_hash.equal Header.equal let encoding = history_encoding let equal : t -> t -> bool = equal_history - let genesis : t = Skip_list.genesis (zero : slot) + let genesis : t = Skip_list.genesis Header.zero let hash_skip_list_cell cell = let current_slot = Skip_list.content cell in let back_pointers_hashes = Skip_list.back_pointers cell in - Data_encoding.Binary.to_bytes_exn slot_encoding current_slot + Data_encoding.Binary.to_bytes_exn Header.encoding current_slot :: List.map Pointer_hash.to_bytes back_pointers_hashes |> Pointer_hash.hash_bytes @@ -354,7 +364,7 @@ module Slots_history = struct "@[hash : %a@;%a@]" Pointer_hash.pp history_hash - (Skip_list.pp ~pp_content:pp_slot ~pp_ptr:Pointer_hash.pp) + (Skip_list.pp ~pp_content:Header.pp ~pp_ptr:Pointer_hash.pp) history module History_cache = @@ -373,20 +383,20 @@ module Slots_history = struct let equal = equal_history end) - let add_confirmed_slot (t, cache) slot = + let add_confirmed_slot_header (t, cache) slot_header = let open Tzresult_syntax in let prev_cell_ptr = hash_skip_list_cell t in let* cache = History_cache.remember prev_cell_ptr t cache in - let* new_cell = Skip_list.next ~prev_cell:t ~prev_cell_ptr slot in + let* new_cell = Skip_list.next ~prev_cell:t ~prev_cell_ptr slot_header in return (new_cell, cache) - let add_confirmed_slots (t : t) cache slots = - List.fold_left_e add_confirmed_slot (t, cache) slots + let add_confirmed_slot_headers (t : t) cache slot_headers = + List.fold_left_e add_confirmed_slot_header (t, cache) slot_headers - let add_confirmed_slots_no_cache = + let add_confirmed_slot_headers_no_cache = let no_cache = History_cache.empty ~capacity:0L in fun t slots -> - List.fold_left_e add_confirmed_slot (t, no_cache) slots >|? fst + List.fold_left_e add_confirmed_slot_header (t, no_cache) slots >|? fst (* Dal proofs section *) @@ -652,11 +662,11 @@ module Slots_history = struct initialized with a min elt (slot zero)." | Some (page_data, page_proof), Found target_cell -> (* The slot to which the page is supposed to belong is found. *) - let {id; commitment} = Skip_list.content target_cell in + let Header.{id; commitment} = Skip_list.content target_cell in (* We check that the slot is not the dummy slot. *) let* () = fail_when - Compare.Int.(compare_slot_id id zero.id = 0) + Compare.Int.(Header.compare_slot_id id Header.zero.id = 0) (dal_proof_error "Skip_list.search returned 'Found ': No existence \ proof should be constructed with the slot zero.") @@ -739,10 +749,10 @@ module Slots_history = struct | Page_confirmed {target_cell; page_data; page_proof; inc_proof} -> (* If the page is supposed to be confirmed, the last cell in [inc_proof] should store the slot of the page. *) - let {id; commitment} = Skip_list.content target_cell in + let Header.{id; commitment} = Skip_list.content target_cell in let* () = fail_when - Compare.Int.(compare_slot_id id zero.id = 0) + Compare.Int.(Header.compare_slot_id id Header.zero.id = 0) (dal_proof_error "verify_proof: cannot construct a confirmation page proof \ with 'zero' as target slot.") @@ -759,7 +769,7 @@ module Slots_history = struct return_some page_data | Page_unconfirmed {prev_cell; next_cell_opt; next_inc_proof} -> (* The page's slot is supposed to be unconfirmed. *) - let ( < ) a b = Compare.Int.(compare_slot_id a b < 0) in + let ( < ) a b = Compare.Int.(Header.compare_slot_id a b < 0) in (* We retrieve the last cell of the inclusion proof to be able to call {!verify_inclusion_proof}. We also do some well-formedness on the shape of the inclusion proof (see the case [Page_unconfirmed] @@ -833,9 +843,3 @@ module Slots_history = struct include V1 end - -let encoding = slot_encoding - -let pp = pp_slot - -let equal = slot_equal diff --git a/src/proto_alpha/lib_protocol/dal_slot_repr.mli b/src/proto_alpha/lib_protocol/dal_slot_repr.mli index 4e2f0d03a0cf..cb39a47ea04c 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_repr.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_repr.mli @@ -84,20 +84,21 @@ module Index : sig val equal : t -> t -> bool end -(** For Layer-1, a slot is described by the level at which it is published, +module Header : sig + (** 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 id = {published_level : Raw_level_repr.t; index : Index.t} + type id = {published_level : Raw_level_repr.t; index : Index.t} -type t = {id : id; commitment : Commitment.t} + type t = {id : id; commitment : Commitment.t} -type slot = t - -val equal : t -> t -> bool + (** The encoding ensures the slot is always a non-negative number. *) + val encoding : t Data_encoding.t -val pp_slot : Format.formatter -> t -> unit + val pp : Format.formatter -> t -> unit -type slot_index = Index.t + val equal : t -> t -> bool +end (** A DAL slot is decomposed to a successive list of pages with fixed content size. The size is chosen so that it's possible to inject a page in a Tezos @@ -106,6 +107,8 @@ type slot_index = Index.t module Page : sig type content = Bytes.t + type slot_index = Index.t + module Index : sig type t = int @@ -125,7 +128,7 @@ module Page : sig (** A page is identified by its slot id and by its own index in the list of pages of the slot. *) - type t = {slot_id : id; page_index : Index.t} + type t = {slot_id : Header.id; page_index : Index.t} type proof = Dal.page_proof @@ -138,11 +141,6 @@ module Page : sig val pp : Format.formatter -> t -> unit end -(** The encoding ensures the slot is always a non-negative number. *) -val encoding : t Data_encoding.t - -val pp : Format.formatter -> t -> unit - (** Only one slot header is accepted per slot index. If two slots headers are included into a block, the second one will fail. @@ -167,10 +165,10 @@ module Slot_market : sig registered. Returns [Some (_, false)] otherwise. Returns [None] if the [index] is not in the interval [0;length] where [length] is the value provided to the [init] function. *) - val register : t -> slot -> (t * bool) option + val register : t -> Header.t -> (t * bool) option - (** [candidates t] returns a list of slot candidates. *) - val candidates : t -> slot list + (** [candidates t] returns a list of slot header candidates. *) + val candidates : t -> Header.t list end (** This module provides an abstract data structure (type {!t}) that represents a @@ -184,7 +182,7 @@ end maintained and used by the rollup node to produce refutation proofs involving DAL slot inputs. *) -module Slots_history : sig +module History : sig (** Abstract representation of a skip list specialized for confirmed slot headers. *) type t @@ -204,15 +202,15 @@ module Slots_history : sig the cache are needed to produce proofs involving slots' pages. *) module History_cache : Bounded_history_repr.S - (** [add_confirmed_slots hist cache slots] updates the given structure - [hist] with the list of [slots]. The given [cache] is also updated to + (** [add_confirmed_slots hist cache slot_headers] updates the given structure + [hist] with the list of [slot_headers]. The given [cache] is also updated to add successive values of [cell] to it. *) - val add_confirmed_slots : - t -> History_cache.t -> slot list -> (t * History_cache.t) tzresult + val add_confirmed_slot_headers : + t -> History_cache.t -> Header.t list -> (t * History_cache.t) tzresult - (** [add_confirmed_slots_no_cache cell slots] same as {!add_confirmed_slots}, - but no cache is updated. *) - val add_confirmed_slots_no_cache : t -> slot list -> t tzresult + (** [add_confirmed_slot_headers_no_cache cell slot_headers] same as + {!add_confirmed_slot_headers}, but no cache is updated. *) + val add_confirmed_slot_headers_no_cache : t -> Header.t list -> t tzresult (** [equal a b] returns true iff a is equal to b. *) val equal : t -> t -> bool @@ -300,7 +298,7 @@ module Slots_history : sig type error += Dal_proof_error of string module Internal_for_tests : sig - val content : t -> slot + val content : t -> Header.t val proof_statement_is : proof -> [`Confirmed | `Unconfirmed] -> bool end diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.ml b/src/proto_alpha/lib_protocol/dal_slot_storage.ml index d5374f52bdb5..fc01ef7c5c78 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.ml @@ -23,55 +23,56 @@ (* *) (*****************************************************************************) -let find ctxt level = Storage.Dal.Slot_headers.find ctxt level +let find_slot_headers ctxt level = Storage.Dal.Slot.Headers.find ctxt level -let finalize_current_slots ctxt = +let finalize_current_slot_headers ctxt = let current_level = Raw_context.current_level ctxt in - let slots = Raw_context.Dal.candidates ctxt in - match slots with + let slot_headers = Raw_context.Dal.candidates ctxt in + match slot_headers with | [] -> Lwt.return ctxt - | _ :: _ -> Storage.Dal.Slot_headers.add ctxt current_level.level slots + | _ :: _ -> Storage.Dal.Slot.Headers.add ctxt current_level.level slot_headers -let compute_available_slots ctxt seen_slots = +let compute_available_slot_headers ctxt seen_slot_headers = let open Dal_slot_repr in - let fold_available_slots (rev_slots, available_slots) slot = - if Raw_context.Dal.is_slot_available ctxt slot.id.index then - ( slot :: rev_slots, - Dal_endorsement_repr.commit available_slots slot.id.index ) - else (rev_slots, available_slots) + let fold_available_slots (rev_slot_headers, available_slot_headers) slot = + if Raw_context.Dal.is_slot_index_available ctxt slot.Header.id.index then + ( slot :: rev_slot_headers, + Dal_endorsement_repr.commit available_slot_headers slot.Header.id.index + ) + else (rev_slot_headers, available_slot_headers) in List.fold_left fold_available_slots ([], Dal_endorsement_repr.empty) - seen_slots + seen_slot_headers -let get_slots_history ctxt = - Storage.Dal.Slots_history.find ctxt >|=? function - | None -> Dal_slot_repr.Slots_history.genesis +let get_slot_headers_history ctxt = + Storage.Dal.Slot.History.find ctxt >|=? function + | None -> Dal_slot_repr.History.genesis | Some slots_history -> slots_history -let update_skip_list ctxt ~confirmed_slots = - get_slots_history ctxt >>=? fun slots_history -> +let update_skip_list ctxt ~confirmed_slot_headers = + get_slot_headers_history ctxt >>=? fun slots_history -> Lwt.return - @@ Dal_slot_repr.Slots_history.add_confirmed_slots_no_cache + @@ Dal_slot_repr.History.add_confirmed_slot_headers_no_cache slots_history - confirmed_slots + confirmed_slot_headers >>=? fun slots_history -> - Storage.Dal.Slots_history.add ctxt slots_history >|= ok + Storage.Dal.Slot.History.add ctxt slots_history >|= ok -let finalize_pending_slots ctxt = +let finalize_pending_slot_headers ctxt = let {Level_repr.level = raw_level; _} = Raw_context.current_level ctxt in let Constants_parametric_repr.{dal; _} = Raw_context.constants ctxt in match Raw_level_repr.(sub raw_level dal.endorsement_lag) with | None -> return (ctxt, Dal_endorsement_repr.empty) | Some level_endorsed -> ( - Storage.Dal.Slot_headers.find ctxt level_endorsed >>=? function + Storage.Dal.Slot.Headers.find ctxt level_endorsed >>=? function | None -> return (ctxt, Dal_endorsement_repr.empty) | Some seen_slots -> - let rev_confirmed_slots, available_slots = - compute_available_slots ctxt seen_slots + let rev_confirmed_slot_headers, available_slot_headers = + compute_available_slot_headers ctxt seen_slots in - let confirmed_slots = List.rev rev_confirmed_slots in - update_skip_list ctxt ~confirmed_slots >>=? fun ctxt -> - Storage.Dal.Slot_headers.remove ctxt level_endorsed >>= fun ctxt -> - return (ctxt, available_slots)) + let confirmed_slot_headers = List.rev rev_confirmed_slot_headers in + update_skip_list ctxt ~confirmed_slot_headers >>=? fun ctxt -> + Storage.Dal.Slot.Headers.remove ctxt level_endorsed >>= fun ctxt -> + return (ctxt, available_slot_headers)) diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.mli b/src/proto_alpha/lib_protocol/dal_slot_storage.mli index 3c6c1fb7edde..7009bd9fa23a 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.mli +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.mli @@ -44,27 +44,29 @@ - For every level below [current_level - lag], there should not be any slot in the storage. *) -(** [find ctxt level] returns [Some slots] where [slots] are pending - slots at level [level]. [None] is returned if no [slot] was - registered at this level. The function fails if the reading into - the context fails. *) -val find : +(** [find_slot_headers ctxt level] returns [Some slot_headers] where [slot_headers] + are pending slots at level [level]. [None] is returned if no + [slot_header] was registered at this level. The function fails if + the reading into the context fails. *) +val find_slot_headers : Raw_context.t -> Raw_level_repr.t -> - Dal_slot_repr.t list option tzresult Lwt.t + Dal_slot_repr.Header.t list option tzresult Lwt.t -(** [finalize_current_slots ctxt] finalizes the current slots posted - on this block and marks them as pending into the context. *) -val finalize_current_slots : Raw_context.t -> Raw_context.t Lwt.t +(** [finalize_current_slot_headers ctxt] finalizes the current slot + headers posted on this block and marks them as pending into the + context. *) +val finalize_current_slot_headers : Raw_context.t -> Raw_context.t Lwt.t -(** [finalize_pending_slots ctxt] finalizes pending slots which are - old enough (i.e. registered at level [current_level - lag]). All - slots marked as available are returned. All the pending slots at - [current_level - lag] level are removed from the context. *) -val finalize_pending_slots : +(** [finalize_pending_slot_headers ctxt] finalizes pending slot + headers which are old enough (i.e. registered at level + [current_level - lag]). All slots marked as available are + returned. All the pending slots at [current_level - lag] level are + removed from the context. *) +val finalize_pending_slot_headers : Raw_context.t -> (Raw_context.t * Dal_endorsement_repr.t) tzresult Lwt.t -(** [get_slots_history ctxt] returns the current value of slots_history stored +(** [get_slot_headers_history ctxt] returns the current value of slots_history stored in [ctxt], or Slots_history.genesis if no value is stored yet. *) -val get_slots_history : - Raw_context.t -> Dal_slot_repr.Slots_history.t tzresult Lwt.t +val get_slot_headers_history : + Raw_context.t -> Dal_slot_repr.History.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index d66b5f465fed..a66d09dc635a 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -426,7 +426,7 @@ and _ manager_operation = } -> Kind.transfer_ticket manager_operation | Dal_publish_slot_header : { - slot : Dal_slot_repr.t; + slot_header : Dal_slot_repr.Header.t; } -> Kind.dal_publish_slot_header manager_operation | Sc_rollup_originate : { @@ -1146,12 +1146,13 @@ module Encoding = struct { tag = dal_publish_slot_header_tag; name = "dal_publish_slot_header"; - encoding = obj1 (req "slot" Dal_slot_repr.encoding); + encoding = obj1 (req "slot_header" Dal_slot_repr.Header.encoding); select = (function | Manager (Dal_publish_slot_header _ as op) -> Some op | _ -> None); - proj = (function Dal_publish_slot_header {slot} -> slot); - inj = (fun slot -> Dal_publish_slot_header {slot}); + proj = + (function Dal_publish_slot_header {slot_header} -> slot_header); + inj = (fun slot_header -> Dal_publish_slot_header {slot_header}); } let sc_rollup_add_messages_case = diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 28f631f9b07d..73e42f975ed4 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -495,7 +495,7 @@ and _ manager_operation = } -> Kind.transfer_ticket manager_operation | Dal_publish_slot_header : { - slot : Dal_slot_repr.t; + slot_header : Dal_slot_repr.Header.t; } -> Kind.dal_publish_slot_header manager_operation (** [Sc_rollup_originate] allows an implicit account to originate a new diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 00287df4a49f..e0816e4fcb95 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1555,7 +1555,10 @@ end module Dal = struct type error += - | Dal_register_invalid_slot of {length : int; slot : Dal_slot_repr.t} + | Dal_register_invalid_slot_header of { + length : int; + slot_header : Dal_slot_repr.Header.t; + } let () = register_error_kind @@ -1572,13 +1575,17 @@ module Dal = struct %d. Found: %a." length Dal_slot_repr.Index.pp - slot.Dal_slot_repr.id.index) + slot.Dal_slot_repr.Header.id.index) Data_encoding.( - obj2 (req "length" int31) (req "slot" Dal_slot_repr.encoding)) + obj2 + (req "length" int31) + (req "slot_header" Dal_slot_repr.Header.encoding)) (function - | Dal_register_invalid_slot {length; slot} -> Some (length, slot) + | Dal_register_invalid_slot_header {length; slot_header} -> + Some (length, slot_header) | _ -> None) - (fun (length, slot) -> Dal_register_invalid_slot {length; slot}) + (fun (length, slot_header) -> + Dal_register_invalid_slot_header {length; slot_header}) let record_available_shards ctxt slots shards = let dal_endorsement_slot_accountability = @@ -1589,22 +1596,24 @@ module Dal = struct in {ctxt with back = {ctxt.back with dal_endorsement_slot_accountability}} - let register_slot ctxt slot = + let register_slot_header ctxt slot_header = match - Dal_slot_repr.Slot_market.register ctxt.back.dal_slot_fee_market slot + Dal_slot_repr.Slot_market.register + ctxt.back.dal_slot_fee_market + slot_header with | None -> let length = Dal_slot_repr.Slot_market.length ctxt.back.dal_slot_fee_market in - error (Dal_register_invalid_slot {length; slot}) + error (Dal_register_invalid_slot_header {length; slot_header}) | Some (dal_slot_fee_market, updated) -> ok ({ctxt with back = {ctxt.back with dal_slot_fee_market}}, updated) let candidates ctxt = Dal_slot_repr.Slot_market.candidates ctxt.back.dal_slot_fee_market - let is_slot_available ctxt = + let is_slot_index_available ctxt = let threshold = ctxt.back.constants.Constants_parametric_repr.dal.availability_threshold in diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index da8419d76d57..858922d856ab 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -401,23 +401,23 @@ module Dal : sig no-op. *) val record_available_shards : t -> Dal_endorsement_repr.t -> int list -> t - (** [register_slot ctxt slot] returns a new context where the new - candidate [slot] have been taken into account. Returns [Some - (ctxt,updated)] where [updated=true] if the candidate is - registered. [Some (ctxt,false)] if another candidate was already - registered previously. Returns an error if the slot is - invalid. *) - val register_slot : t -> Dal_slot_repr.t -> (t * bool) tzresult + (** [register_slot_header ctxt slot_header] returns a new context + where the new candidate [slot] have been taken into + account. Returns [Some (ctxt,updated)] where [updated=true] if + the candidate is registered. [Some (ctxt,false)] if another + candidate was already registered previously. Returns an error if + the slot is invalid. *) + val register_slot_header : t -> Dal_slot_repr.Header.t -> (t * bool) tzresult (** [candidates ctxt] returns the current list of slot for which there is at least one candidate. *) - val candidates : t -> Dal_slot_repr.t list + val candidates : t -> Dal_slot_repr.Header.t list - (** [is_slot_available ctxt slot_index] returns [true] if the + (** [is_slot_index_available ctxt slot_index] returns [true] if the [slot_index] is declared available by the protocol. [false] otherwise. If the [index] is out of the interval [0;number_of_slots - 1], returns [false]. *) - val is_slot_available : t -> Dal_slot_repr.Index.t -> bool + val is_slot_index_available : t -> Dal_slot_repr.Index.t -> bool (** [shards ctxt ~endorser] returns the shard assignment for the [endorser] for the current level. *) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_storage.ml index 53ea9c65de3c..ec7e3384f17e 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_storage.ml @@ -234,7 +234,7 @@ module Dal_slot = struct Bitset.mem subscribed_slots (Dal_slot_repr.Index.to_int slot_index) in if slot_already_subscribed then - fail (Dal_rollup_already_registered_to_slot (rollup, slot_index)) + fail (Dal_rollup_already_registered_to_slot_index (rollup, slot_index)) else let*? subscribed_slots = Bitset.add subscribed_slots (Dal_slot_repr.Index.to_int slot_index) diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 87668addf5c0..9b47de7bd99c 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -1950,14 +1950,6 @@ module Dal = struct let name = ["dal"] end) - module Level_context = - Make_indexed_subcontext - (Make_subcontext (Registered) (Raw_context) - (struct - let name = ["level"] - end)) - (Make_index (Raw_level_repr.Index)) - (* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3113 This is only for prototyping. Probably something smarter would be @@ -1965,28 +1957,44 @@ module Dal = struct (* DAL/FIXME: https://gitlab.com/tezos/tezos/-/issues/3684 This storage should be carbonated. *) - module Slot_headers = - Level_context.Make_map - (Registered) - (struct - let name = ["slots"] - end) - (struct - type t = Dal_slot_repr.t list + module Slot = struct + module Slot_context = + Make_subcontext (Registered) (Raw_context) + (struct + let name = ["slot"] + end) - let encoding = Data_encoding.(list Dal_slot_repr.encoding) - end) + module Level_context = + Make_indexed_subcontext + (Make_subcontext (Registered) (Raw_context) + (struct + let name = ["level"] + end)) + (Make_index (Raw_level_repr.Index)) - module Slots_history = - Make_single_data_storage (Registered) (Raw_context) - (struct - let name = ["slots_history"] - end) - (struct - type t = Dal_slot_repr.Slots_history.t + module Headers = + Level_context.Make_map + (Registered) + (struct + let name = ["slot_headers"] + end) + (struct + type t = Dal_slot_repr.Header.t list - let encoding = Dal_slot_repr.Slots_history.encoding - end) + let encoding = Data_encoding.(list Dal_slot_repr.Header.encoding) + end) + + module History = + Make_single_data_storage (Registered) (Raw_context) + (struct + let name = ["slot_headers_history"] + end) + (struct + type t = Dal_slot_repr.History.t + + let encoding = Dal_slot_repr.History.encoding + end) + end end module Zk_rollup = struct diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 96be4baef007..c7ae069a2062 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -902,18 +902,20 @@ module Sc_rollup : sig end module Dal : sig - (** This is a temporary storage for slot header proposed onto the L1. *) - module Slot_headers : - Non_iterable_indexed_data_storage - with type t = Raw_context.t - and type key = Raw_level_repr.t - and type value = Dal_slot_repr.slot list - - (** This is a permanent storage for slot header confirmed by the L1. *) - module Slots_history : - Single_data_storage - with type t := Raw_context.t - and type value = Dal_slot_repr.Slots_history.t + module Slot : sig + (** This is a temporary storage for slot headers proposed onto the L1. *) + module Headers : + Non_iterable_indexed_data_storage + with type t = Raw_context.t + and type key = Raw_level_repr.t + and type value = Dal_slot_repr.Header.t list + + (** This is a permanent storage for slot headers confirmed by the L1. *) + module History : + Single_data_storage + with type t := Raw_context.t + and type value = Dal_slot_repr.History.t + end end module Zk_rollup : sig 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 6f592aa75e3a..2564b612d923 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.ml @@ -26,7 +26,7 @@ open Protocol module S = Dal_slot_repr module P = S.Page -module Hist = S.Slots_history +module Hist = S.History module Ihist = Hist.Internal_for_tests (* Some global constants. *) @@ -96,7 +96,7 @@ let mk_slot ?(level = level_one) ?(index = S.Index.zero) return ( slot_data, polynomial, - S.{id = S.{published_level = level; index}; commitment} ) + S.Header.{id = {published_level = level; index}; commitment} ) let mk_page_id published_level slot_index page_index = P.{slot_id = {published_level; index = slot_index}; page_index} @@ -104,7 +104,7 @@ let mk_page_id published_level slot_index page_index = let no_data = Some (fun ~default_char:_ _ -> None) let mk_page_info ?(default_char = 'x') ?level ?(page_index = P.Index.zero) - ?(custom_data = None) dal (slot : S.t) polynomial = + ?(custom_data = None) dal (slot : S.Header.t) polynomial = let open Result_syntax in let level = match level with None -> slot.id.published_level | Some level -> level 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 f6a81558236f..1d79e7f06683 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/dal_helpers.mli @@ -27,9 +27,9 @@ open Protocol (** Some global constants. *) -val genesis_history : Dal_slot_repr.Slots_history.t +val genesis_history : Dal_slot_repr.History.t -val genesis_history_cache : Dal_slot_repr.Slots_history.History_cache.t +val genesis_history_cache : Dal_slot_repr.History.History_cache.t val level_one : Raw_level_repr.t @@ -58,14 +58,14 @@ val dal_mk_prove_page : commitment). *) val mk_slot : ?level:Raw_level_repr.t -> - ?index:Dal_slot_repr.slot_index -> + ?index:Dal_slot_repr.Index.t -> ?fill_function:(int -> char) -> Cryptobox.t -> - (bytes * Cryptobox.polynomial * Dal_slot_repr.t, error trace) result + (bytes * Cryptobox.polynomial * Dal_slot_repr.Header.t, error trace) result (** Constructs a record value of type Page.id. *) val mk_page_id : - Raw_level_repr.t -> Dal_slot_repr.slot_index -> int -> Dal_slot_repr.Page.t + Raw_level_repr.t -> Dal_slot_repr.Index.t -> int -> Dal_slot_repr.Page.t val no_data : (default_char:char -> int -> bytes option) option @@ -81,7 +81,7 @@ val mk_page_info : ?page_index:int -> ?custom_data:(default_char:char -> int -> bytes option) option -> Cryptobox.t -> - Dal_slot_repr.t -> + Dal_slot_repr.Header.t -> Cryptobox.polynomial -> ( (bytes * Cryptobox.page_proof) option * Dal_slot_repr.Page.t, error trace ) @@ -92,7 +92,7 @@ val mk_page_info : val next_char : char -> char (** Increment the given slot index. Returns zero in case of overflow. *) -val succ_slot_index : Dal_slot_repr.slot_index -> Dal_slot_repr.slot_index +val succ_slot_index : Dal_slot_repr.Index.t -> Dal_slot_repr.Index.t (** Auxiliary test function used by both unit and PBT tests: This function produces a proof from the given information and verifies the produced result, @@ -100,7 +100,7 @@ val succ_slot_index : Dal_slot_repr.slot_index -> Dal_slot_repr.slot_index [check_verify_result], respectively. *) val produce_and_verify_proof : check_produce: - ((Dal_slot_repr.Slots_history.proof * bytes option) tzresult -> + ((Dal_slot_repr.History.proof * bytes option) tzresult -> (bytes * Cryptobox.page_proof) option -> (unit, tztrace) result Lwt.t) -> ?check_verify: @@ -108,8 +108,8 @@ val produce_and_verify_proof : (bytes * Cryptobox.page_proof) option -> (unit, tztrace) result Lwt.t) -> Cryptobox.t -> - Dal_slot_repr.Slots_history.t -> - Dal_slot_repr.Slots_history.History_cache.t -> + Dal_slot_repr.History.t -> + Dal_slot_repr.History.History_cache.t -> page_info:(bytes * Cryptobox.page_proof) option -> page_id:Dal_slot_repr.Page.t -> (unit, tztrace) result Lwt.t @@ -121,7 +121,7 @@ val eq_page_proof : Cryptobox.page_proof -> Cryptobox.page_proof -> bool val successful_check_produce_result : __LOC__:string -> [`Confirmed | `Unconfirmed] -> - (Dal_slot_repr.Slots_history.proof * bytes option, tztrace) result -> + (Dal_slot_repr.History.proof * bytes option, tztrace) result -> (bytes * 'a) option -> (unit, tztrace) result Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index 274dc0b5e92d..5fbc14b0f8ad 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -971,7 +971,7 @@ let sc_rollup_timeout ?force_reveal ?counter ?fee ?gas_limit ?storage_limit ctxt sign account.sk ctxt to_sign_op let dal_publish_slot_header ?force_reveal ?counter ?fee ?gas_limit - ?storage_limit ctxt (src : Contract.t) slot = + ?storage_limit ctxt (src : Contract.t) slot_header = manager_operation ?force_reveal ?counter @@ -980,7 +980,7 @@ let dal_publish_slot_header ?force_reveal ?counter ?fee ?gas_limit ?storage_limit ~source:src ctxt - (Dal_publish_slot_header {slot}) + (Dal_publish_slot_header {slot_header}) >>=? fun to_sign_op -> Context.Contract.manager ctxt src >|=? fun account -> sign account.sk ctxt to_sign_op diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.mli b/src/proto_alpha/lib_protocol/test/helpers/op.mli index 563fe5b97a24..1dea72fd81c1 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/op.mli @@ -721,7 +721,7 @@ val dal_publish_slot_header : ?storage_limit:counter -> Context.t -> Contract.t -> - Dal.Slot.t -> + Dal.Slot.Header.t -> (packed_operation, tztrace) result Lwt.t (** [zk_rollup_origination ctxt source ~public_parameters ~circuits_info 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 dbbf65685772..6a995b2927dc 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml @@ -664,10 +664,10 @@ let generate_dal_publish_slot_header random_state : let published_level = Alpha_context.Raw_level.of_int32_exn Int32.zero in let index = Alpha_context.Dal.Slot_index.zero in let commitment = Alpha_context.Dal.Slot.Commitment.zero in - let slot = - Alpha_context.Dal.Slot.{id = {published_level; index}; commitment} + let slot_header = + Alpha_context.Dal.Slot.Header.{id = {published_level; index}; commitment} in - Dal_publish_slot_header {slot} + Dal_publish_slot_header {slot_header} in generate_manager random_state gen_dal_publish 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 32107ded65df..82b7af64aff6 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 @@ -1053,7 +1053,7 @@ let mk_dal_publish_slot_header (oinfos : operation_req) (infos : infos) = let index = Alpha_context.Dal.Slot_index.zero in let commitment = Alpha_context.Dal.Slot.Commitment.zero in let slot = - Alpha_context.Dal.Slot.{id = {published_level; index}; commitment} + Alpha_context.Dal.Slot.Header.{id = {published_level; index}; commitment} in Op.dal_publish_slot_header ?fee:oinfos.fee diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_dal_slot_proof.ml b/src/proto_alpha/lib_protocol/test/pbt/test_dal_slot_proof.ml index abeef1f4b020..3af2aa4dc51a 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_dal_slot_proof.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_dal_slot_proof.ml @@ -63,7 +63,7 @@ let populate_slots_history dal (levels_data : levels) = let* cell, cache = if skip_slot then return (cell, cache) else - Dal_slot_repr.Slots_history.add_confirmed_slots cell cache [slot] + Dal_slot_repr.History.add_confirmed_slot_headers cell cache [slot] |> Environment.wrap_tzresult in return (cell, cache, (poly, slot, skip_slot) :: slots_info) @@ -104,8 +104,9 @@ let request_unconfirmed_page dal (poly, slot, skip_slot) = slot at the next level is unconfirmed (since we insert levels without any confirmed slot). *) let level = - if skip_slot then Dal_slot_repr.(slot.id.published_level) - else Raw_level_repr.succ Dal_slot_repr.(slot.id.published_level) + let open Dal_slot_repr.Header in + if skip_slot then slot.id.published_level + else Raw_level_repr.succ slot.id.published_level in let* _page_info, page_id = mk_page_info ~level dal slot poly in (* We should not provide the page's info if we want to build an @@ -167,7 +168,7 @@ let tests = Result.value_f (dal_mk_env { - Dal_slot_repr.Slots_history.redundancy_factor = 16; + Dal_slot_repr.History.redundancy_factor = 16; page_size = 4096 / 64; slot_size = 1048576 / 64; number_of_shards = 2048 / 64; 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 f695945bdca5..2cf9853bc999 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 @@ -34,7 +34,7 @@ open Protocol module S = Dal_slot_repr module P = S.Page -module Hist = S.Slots_history +module Hist = S.History open Dal_helpers (* Tests to check insertion of slots in a dal skip list. *) @@ -42,11 +42,11 @@ open Dal_helpers (** Check insertion of a new slot in the given skip list. *) let skip_list_ordering dal skip_list ~mk_level ~mk_slot_index ~check_result = let open Lwt_result_syntax in - let {S.id; _} = Hist.Internal_for_tests.content skip_list in + let {S.Header.id; _} = Hist.Internal_for_tests.content skip_list in let*? _data, _poly, slot = mk_slot ~level:(mk_level id) ~index:(mk_slot_index id) dal in - Hist.add_confirmed_slots_no_cache skip_list [slot] + Hist.add_confirmed_slot_headers_no_cache skip_list [slot] |> Environment.wrap_tzresult |> check_result (** This test attempts to add a slot on top of genesis cell zero which would @@ -59,8 +59,8 @@ let insertion_breaks_skip_list_ordering dal () = skip_list_ordering dal genesis_history - ~mk_level:(fun id -> id.S.published_level) - ~mk_slot_index:(fun id -> id.S.index) + ~mk_level:(fun id -> id.S.Header.published_level) + ~mk_slot_index:(fun id -> id.S.Header.index) ~check_result:(fun res -> Assert.proto_error ~loc:__LOC__ res (function | Hist.Add_element_in_slots_skip_list_violates_ordering -> true @@ -73,8 +73,8 @@ let correct_insertion_in_skip_list_ordering_1 dal () = skip_list_ordering dal genesis_history - ~mk_level:(fun id -> Raw_level_repr.succ id.S.published_level) - ~mk_slot_index:(fun id -> id.S.index) + ~mk_level:(fun id -> Raw_level_repr.succ id.S.Header.published_level) + ~mk_slot_index:(fun id -> id.S.Header.index) ~check_result:(fun res -> let* _skip_list = Assert.get_ok ~__LOC__ res in return_unit) @@ -86,8 +86,8 @@ let correct_insertion_in_skip_list_ordering_2 dal () = skip_list_ordering dal genesis_history - ~mk_level:(fun id -> id.S.published_level) - ~mk_slot_index:(fun id -> succ_slot_index id.S.index) + ~mk_level:(fun id -> id.S.Header.published_level) + ~mk_slot_index:(fun id -> succ_slot_index id.S.Header.index) ~check_result:(fun res -> let* _skip_list = Assert.get_ok ~__LOC__ res in return_unit) @@ -99,15 +99,16 @@ let correct_insertion_in_skip_list_ordering_3 dal () = skip_list_ordering dal genesis_history - ~mk_level:(fun id -> id.S.published_level) - ~mk_slot_index:(fun id -> succ_slot_index id.S.index) + ~mk_level:(fun id -> id.S.Header.published_level) + ~mk_slot_index:(fun id -> succ_slot_index id.S.Header.index) ~check_result:(fun res -> let* skip_list = Assert.get_ok ~__LOC__ res in skip_list_ordering dal skip_list - ~mk_level:(fun id -> Raw_level_repr.(succ (succ id.S.published_level))) - ~mk_slot_index:(fun id -> id.S.index) + ~mk_level:(fun id -> + Raw_level_repr.(succ (succ id.S.Header.published_level))) + ~mk_slot_index:(fun id -> id.S.Header.index) ~check_result:(fun res -> let* _skip_list = Assert.get_ok ~__LOC__ res in return_unit)) @@ -118,7 +119,7 @@ let correct_insertion_in_skip_list_ordering_3 dal () = (** This test attempts to construct a proof to confirm a slot page from the genesis skip list. Proof production is expected to fail. *) let confirmed_page_on_genesis dal () = - let {S.id = {published_level; index}; _} = + let {S.Header.id = {published_level; index}; _} = Hist.Internal_for_tests.content genesis_history in let page_id = mk_page_id published_level index P.Index.zero in @@ -136,7 +137,7 @@ let confirmed_page_on_genesis dal () = (** This test attempts to construct a proof to unconfirm a slot page from the genesis skip list. Proof production is expected to succeed. *) let unconfirmed_page_on_genesis dal incr_level = - let {S.id = {published_level; index}; _} = + let {S.Header.id = {published_level; index}; _} = Hist.Internal_for_tests.content genesis_history in let level, sindex = @@ -162,7 +163,7 @@ let helper_confirmed_slot_on_genesis ~level ~mk_page_info ~check_produce let open Lwt_result_syntax in let*? _slot_data, polynomial, slot = mk_slot ~level dal in let*? skip_list, cache = - Hist.add_confirmed_slots genesis_history genesis_history_cache [slot] + Hist.add_confirmed_slot_headers genesis_history genesis_history_cache [slot] |> Environment.wrap_tzresult in let*? page_info, page_id = mk_page_info dal slot polynomial in diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml index 1846fd0353ae..a9524f05ae08 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml @@ -2666,7 +2666,8 @@ let test_subscribe_slot_twice_at_same_level () = assert_fails_with ~loc:__LOC__ (Sc_rollup_storage.Dal_slot.subscribe ctxt rollup ~slot_index) - (Dal_errors_repr.Dal_rollup_already_registered_to_slot (rollup, slot_index)) + (Dal_errors_repr.Dal_rollup_already_registered_to_slot_index + (rollup, slot_index)) let test_subscribe_slot_twice_at_different_levels () = let* ctxt = new_context () in @@ -2679,7 +2680,8 @@ let test_subscribe_slot_twice_at_different_levels () = assert_fails_with ~loc:__LOC__ (Sc_rollup_storage.Dal_slot.subscribe ctxt rollup ~slot_index) - (Dal_errors_repr.Dal_rollup_already_registered_to_slot (rollup, slot_index)) + (Dal_errors_repr.Dal_rollup_already_registered_to_slot_index + (rollup, slot_index)) let test_subscribe_different_slots_at_same_level () = let* ctxt = new_context () in diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 71aad10a61ff..83414ab00446 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2439,8 +2439,8 @@ module Manager = struct | Sc_rollup_dal_slot_subscribe _ -> let* () = assert_sc_rollup_feature_enabled vi in assert_dal_feature_enabled vi - | Dal_publish_slot_header {slot} -> - Dal_apply.validate_publish_slot_header vi.ctxt slot + | Dal_publish_slot_header {slot_header} -> + Dal_apply.validate_publish_slot_header vi.ctxt slot_header | Zk_rollup_origination _ | Zk_rollup_publish _ -> assert_zk_rollup_feature_enabled vi in diff --git a/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml b/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml index 61247419be5c..50fab690b23d 100644 --- a/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml +++ b/src/proto_alpha/lib_sc_rollup/sc_rollup_services.ml @@ -149,8 +149,8 @@ module Global = struct RPC_service.get_service ~description:"Data availability slots for a given block hash" ~query:RPC_query.empty - ~output:(Data_encoding.list Dal.Slot.encoding) - (prefix / "dal" / "slots") + ~output:(Data_encoding.list Dal.Slot.Header.encoding) + (prefix / "dal" / "slot_headers") let outbox_proof_query = let open RPC_query in diff --git a/tezt/lib_tezos/RPC.ml b/tezt/lib_tezos/RPC.ml index 848cffb38071..21027cdae474 100644 --- a/tezt/lib_tezos/RPC.ml +++ b/tezt/lib_tezos/RPC.ml @@ -1031,7 +1031,7 @@ let get_chain_block_context_delegate_voting_power ?(chain = "main") ] Fun.id -let get_chain_block_context_dal_confirmed_slots_history ?(chain = "main") +let get_chain_block_context_dal_confirmed_slot_headers_history ?(chain = "main") ?(block = "head") () = make GET @@ -1042,7 +1042,7 @@ let get_chain_block_context_dal_confirmed_slots_history ?(chain = "main") block; "context"; "dal"; - "confirmed_slots_history"; + "confirmed_slot_headers_history"; ] Fun.id diff --git a/tezt/lib_tezos/RPC.mli b/tezt/lib_tezos/RPC.mli index 7a75e5a93b08..ec4ea6364cba 100644 --- a/tezt/lib_tezos/RPC.mli +++ b/tezt/lib_tezos/RPC.mli @@ -875,10 +875,10 @@ val get_chain_block_context_delegate_voting_info : val get_chain_block_context_delegate_voting_power : ?chain:string -> ?block:string -> string -> JSON.t t -(** Call RPC /chains/[chain]/blocks/[block]/context/dal/confirmed_slots_history. - [chain] defaults to ["main"]. - [block] defaults to ["head"]. *) -val get_chain_block_context_dal_confirmed_slots_history : +(** Call RPC + /chains/[chain]/blocks/[block]/context/dal/confirmed_slot_headers_history. + [chain] defaults to ["main"]. [block] defaults to ["head"]. *) +val get_chain_block_context_dal_confirmed_slot_headers_history : ?chain:string -> ?block:string -> unit -> JSON.t t (** Call RPC /chains/[chain]/blocks/[block]/context/raw/json. diff --git a/tezt/lib_tezos/operation_core.ml b/tezt/lib_tezos/operation_core.ml index 7506eb2520d3..57e152da0b1e 100644 --- a/tezt/lib_tezos/operation_core.ml +++ b/tezt/lib_tezos/operation_core.ml @@ -402,7 +402,7 @@ module Manager = struct ] @ parameters | Dal_publish_slot_header {level; index; commitment} -> - let slot = + let slot_header = `O [ ("index", json_of_int index); @@ -410,7 +410,10 @@ module Manager = struct ("commitment", json_of_commitment commitment); ] in - [("kind", `String "dal_publish_slot_header"); ("slot", slot)] + [ + ("kind", `String "dal_publish_slot_header"); + ("slot_header", slot_header); + ] | Sc_rollup_dal_slot_subscribe {rollup; slot_index} -> [ ("kind", `String "sc_rollup_dal_slot_subscribe"); diff --git a/tezt/lib_tezos/sc_rollup_client.ml b/tezt/lib_tezos/sc_rollup_client.ml index 3dfd2fd5bfaf..372ef8e19c69 100644 --- a/tezt/lib_tezos/sc_rollup_client.ml +++ b/tezt/lib_tezos/sc_rollup_client.ml @@ -38,7 +38,7 @@ type commitment = { number_of_ticks : int; } -type slot_metadata = {level : int; header : string; index : int} +type slot_header = {level : int; commitment : string; index : int} let commitment_from_json json = if JSON.is_null json then None @@ -220,15 +220,15 @@ let dal_slot_subscriptions ?hooks sc_client = in JSON.as_list json |> List.map JSON.as_int -let dal_slots_metadata ?hooks sc_client = +let dal_slot_headers ?hooks sc_client = let open Lwt.Syntax in - let+ json = rpc_get ?hooks sc_client ["global"; "dal"; "slots"] in + let+ json = rpc_get ?hooks sc_client ["global"; "dal"; "slot_headers"] in JSON.( as_list json |> List.map (fun obj -> { level = obj |> get "level" |> as_int; - header = obj |> get "commitment" |> as_string; + commitment = obj |> get "commitment" |> as_string; index = obj |> get "index" |> as_int; })) diff --git a/tezt/lib_tezos/sc_rollup_client.mli b/tezt/lib_tezos/sc_rollup_client.mli index cdd30d233a9f..83c2474c9dc0 100644 --- a/tezt/lib_tezos/sc_rollup_client.mli +++ b/tezt/lib_tezos/sc_rollup_client.mli @@ -33,7 +33,7 @@ type commitment = { number_of_ticks : int; } -type slot_metadata = {level : int; header : string; index : int} +type slot_header = {level : int; commitment : string; index : int} (** [create ?name ?path ?base_dir ?path node] returns a fresh client identified by a specified [name], logging in [color], executing the @@ -129,9 +129,9 @@ val last_published_commitment : (** [dal_slot_subscriptions client] gets the slots to which the rollup node is subscribed to *) val dal_slot_subscriptions : ?hooks:Process.hooks -> t -> int list Lwt.t -(** [dal_slots_metadata client] returns the dal slots metadata of the last tezos - head seen by the rollup node. *) -val dal_slots_metadata : ?hooks:Process.hooks -> t -> slot_metadata list Lwt.t +(** [dal_slot_headers client] returns the dal slot headers of the last + tezos head seen by the rollup node. *) +val dal_slot_headers : ?hooks:Process.hooks -> t -> slot_header list Lwt.t (** [dal_downloaded_slots client] returns the slots downloaded after processing the last tezos head seen by the rollup node. *) diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index 5cb48b1ee52e..740ec6df2fc3 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -273,10 +273,12 @@ let publish_dummy_slot ~source ?fee ~index ~message parameters cryptobox = in publish_slot ~source ?fee ~index ~commitment -let publish_slot_header ~source ?(fee = 1200) ~index ~header node client = +let publish_slot_header ~source ?(fee = 1200) ~index ~commitment node client = let level = Node.get_level node in - let header = Tezos_crypto_dal.Cryptobox.Commitment.of_b58check_opt header in - match header with + let commitment = + Tezos_crypto_dal.Cryptobox.Commitment.of_b58check_opt commitment + in + match commitment with | None -> assert false | Some commitment -> Operation.Manager.( @@ -294,8 +296,6 @@ let slot_availability ~signer availability client = List.iter (fun i -> endorsement.(i) <- true) availability ; Operation.Consensus.(inject ~signer (slot_availability ~endorsement) client) -let header_of_slot_metadata {Sc_rollup_client.header; _} = header - type status = Applied | Failed of {error_id : string} let pp fmt = function @@ -346,7 +346,9 @@ let check_dal_raw_context node = JSON.unannotate j |> Ezjsonm.wrap |> Ezjsonm.to_string in let* confirmed_slots_opt = - RPC.call node (RPC.get_chain_block_context_dal_confirmed_slots_history ()) + RPC.call + node + (RPC.get_chain_block_context_dal_confirmed_slot_headers_history ()) in if JSON.is_null confirmed_slots_opt then Test.fail @@ -354,7 +356,7 @@ let check_dal_raw_context node = enabled" ; let confirmed_slots = json_to_string confirmed_slots_opt in let confirmed_slots_from_ctxt = - json_to_string @@ JSON.(dal_raw_json |-> "slots_history") + json_to_string @@ JSON.(dal_raw_json |-> "slot_headers_history") in if not (String.equal confirmed_slots confirmed_slots_from_ctxt) then Test.fail "Confirmed slots history mismatch." ; @@ -556,11 +558,11 @@ let test_dal_node_slot_management = let publish_and_store_slot node client dal_node source index content = let* slot_header = RPC.call dal_node (Rollup.Dal.RPC.split_slot content) in - let header = + let commitment = Tezos_crypto_dal.Cryptobox.Commitment.of_b58check_opt slot_header |> mandatory "The b58check-encoded slot header is not valid" in - let* _ = publish_slot ~source ~fee:1_200 ~index ~header node client in + let* _ = publish_slot ~source ~fee:1_200 ~index ~commitment node client in return (index, slot_header) let test_dal_node_slots_headers_tracking = @@ -712,15 +714,15 @@ let rollup_node_stores_dal_slots _protocol dal_node sc_rollup_node (* 1. Send three slots to dal node and obtain corresponding headers. *) let slot_contents_0 = "DEADC0DE" in - let* slot_header_0 = + let* commitment_0 = RPC.call dal_node (Rollup.Dal.RPC.split_slot slot_contents_0) in let slot_contents_1 = "CAFEDEAD" in - let* slot_header_1 = + let* commitment_1 = RPC.call dal_node (Rollup.Dal.RPC.split_slot slot_contents_1) in let slot_contents_2 = "C0FFEE" in - let* slot_header_2 = + let* commitment_2 = RPC.call dal_node (Rollup.Dal.RPC.split_slot slot_contents_2) in (* 2. Run rollup node for an originated rollup. *) @@ -753,7 +755,7 @@ let rollup_node_stores_dal_slots _protocol dal_node sc_rollup_node publish_slot_header ~source:Constant.bootstrap1 ~index:0 - ~header:slot_header_0 + ~commitment:commitment_0 node client in @@ -761,7 +763,7 @@ let rollup_node_stores_dal_slots _protocol dal_node sc_rollup_node publish_slot_header ~source:Constant.bootstrap2 ~index:1 - ~header:slot_header_1 + ~commitment:commitment_1 node client in @@ -769,7 +771,7 @@ let rollup_node_stores_dal_slots _protocol dal_node sc_rollup_node publish_slot_header ~source:Constant.bootstrap3 ~index:2 - ~header:slot_header_2 + ~commitment:commitment_2 node client in @@ -778,12 +780,15 @@ let rollup_node_stores_dal_slots _protocol dal_node sc_rollup_node let* slots_published_level = Sc_rollup_node.wait_for_level sc_rollup_node (second_subscription_level + 1) in - let* slots_metadata = - Sc_rollup_client.dal_slots_metadata ~hooks sc_rollup_client + let* slots_headers = + Sc_rollup_client.dal_slot_headers ~hooks sc_rollup_client + in + let commitments = + slots_headers + |> List.map (fun Sc_rollup_client.{commitment; _} -> commitment) in - let slot_headers = slots_metadata |> List.map header_of_slot_metadata in - let expected_slot_headers = [slot_header_0; slot_header_1; slot_header_2] in - Check.(slot_headers = expected_slot_headers) + let expected_commitments = [commitment_0; commitment_1; commitment_2] in + Check.(commitments = expected_commitments) (Check.list Check.string) ~error_msg:"Unexpected list of slot headers (%L = %R)" ; (* 6. endorse only slots 1 and 2. *) diff --git a/tezt/tests/expected/dal.ml/Alpha- Testing rollup and Data availability layer node (rollup_node_downloads_sl.out b/tezt/tests/expected/dal.ml/Alpha- Testing rollup and Data availability layer node (rollup_node_downloads_sl.out index 6b83e48ff913..6e2cd605c67a 100644 --- a/tezt/tests/expected/dal.ml/Alpha- Testing rollup and Data availability layer node (rollup_node_downloads_sl.out +++ b/tezt/tests/expected/dal.ml/Alpha- Testing rollup and Data availability layer node (rollup_node_downloads_sl.out @@ -37,7 +37,7 @@ This sequence of operations was run: { "level": 2, "commitment_hash": "[SC_ROLLUP_COMMITMENT_HASH]" } -./octez-sc-rollup-client-alpha rpc get /global/dal/slots +./octez-sc-rollup-client-alpha rpc get /global/dal/slot_headers [ { "level": 4, "index": 0, "commitment": "sh23JCJDe5NojHgzFFhFmRZayf5QGo7C3rVv9eyPA7bqR592hQo4fB7Zg67dY8iAW4tmSrff6v" }, -- GitLab