From a45f3d224b0a814462d5af563549516df89872f0 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 6 Jun 2024 09:52:48 +0200 Subject: [PATCH 01/14] DAL/Node: add post_slot in dal_node_client --- src/lib_dal_node/dal_node_client.ml | 8 ++++++++ src/lib_dal_node/dal_node_client.mli | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/lib_dal_node/dal_node_client.ml b/src/lib_dal_node/dal_node_client.ml index e9ef961cfd03..f308f015d67b 100644 --- a/src/lib_dal_node/dal_node_client.ml +++ b/src/lib_dal_node/dal_node_client.ml @@ -62,3 +62,11 @@ let get_slot_page_proof cctxt (slot_id : Types.slot_id) page_index = ((((), slot_id.slot_level), slot_id.slot_index), page_index) () () + +let post_slot cctxt slot = + let padding = + object + method padding = '\000' + end + in + call cctxt Services.post_slot () padding slot diff --git a/src/lib_dal_node/dal_node_client.mli b/src/lib_dal_node/dal_node_client.mli index 3e77dbd9966f..4687f51c2686 100644 --- a/src/lib_dal_node/dal_node_client.mli +++ b/src/lib_dal_node/dal_node_client.mli @@ -51,3 +51,10 @@ val get_slot_page_proof : Tezos_dal_node_services.Types.slot_id -> int -> Cryptobox.page_proof tzresult Lwt.t + +(** [post_slot cctxt slot_data] posts the given data as a slot to the DAL node, + and returns the corresponding commitment hash alongside its proof. *) +val post_slot : + cctxt -> + string -> + (Cryptobox.commitment * Cryptobox.commitment_proof) tzresult Lwt.t -- GitLab From 84bcb6685207335bfb2cd049e4393563db6499f5 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 6 Jun 2024 09:55:30 +0200 Subject: [PATCH 02/14] SORU: expose pp functions in DAL's Commitment module --- src/lib_smart_rollup/dal.mli | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib_smart_rollup/dal.mli b/src/lib_smart_rollup/dal.mli index f87ad4438b32..d019674afd25 100644 --- a/src/lib_smart_rollup/dal.mli +++ b/src/lib_smart_rollup/dal.mli @@ -44,6 +44,12 @@ module Commitment : sig type t = Tezos_crypto_dal.Cryptobox.Verifier.commitment val encoding : t Data_encoding.t + + val pp : + Format.formatter -> Tezos_crypto_dal.Cryptobox.Verifier.commitment -> unit + + val pp_short : + Format.formatter -> Tezos_crypto_dal.Cryptobox.Verifier.commitment -> unit end module Slot_header : sig -- GitLab From 80da62c5c6f35d33dcd72b4238e556098130715a Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 6 Jun 2024 09:57:28 +0200 Subject: [PATCH 03/14] SORU: expose proofs type and encoding for DAL commitments --- src/lib_smart_rollup/dal.ml | 6 ++++++ src/lib_smart_rollup/dal.mli | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/lib_smart_rollup/dal.ml b/src/lib_smart_rollup/dal.ml index cea43bf90159..6fe9eaefb1e6 100644 --- a/src/lib_smart_rollup/dal.ml +++ b/src/lib_smart_rollup/dal.ml @@ -41,6 +41,12 @@ module Commitment = struct type t = Tezos_crypto_dal.Cryptobox.Verifier.commitment end +module Commitment_proof = struct + include Tezos_crypto_dal.Cryptobox.Verifier.Commitment_proof + + type t = Tezos_crypto_dal.Cryptobox.Verifier.commitment_proof +end + module Slot_header = struct module V1 = struct type id = {published_level : int32; index : Slot_index.t} diff --git a/src/lib_smart_rollup/dal.mli b/src/lib_smart_rollup/dal.mli index d019674afd25..49df5e9c4677 100644 --- a/src/lib_smart_rollup/dal.mli +++ b/src/lib_smart_rollup/dal.mli @@ -52,6 +52,14 @@ module Commitment : sig Format.formatter -> Tezos_crypto_dal.Cryptobox.Verifier.commitment -> unit end +(** A slot commitment proof, same as protocol slot commitments' proofs through + environment. *) +module Commitment_proof : sig + type t = Tezos_crypto_dal.Cryptobox.Verifier.commitment_proof + + val encoding : t Data_encoding.t +end + module Slot_header : sig (** A slot header. *) module V1 : sig -- GitLab From 0eca76fe22655bb89619ff94cbd59adc6411ebe1 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 6 Jun 2024 10:31:05 +0200 Subject: [PATCH 04/14] SORU: add a Publish_dal_commitment operation kind --- src/lib_smart_rollup/operation_kind.ml | 4 ++++ src/lib_smart_rollup/operation_kind.mli | 1 + src/lib_smart_rollup_node/configuration.ml | 2 ++ src/lib_smart_rollup_node/injector.ml | 1 + 4 files changed, 8 insertions(+) diff --git a/src/lib_smart_rollup/operation_kind.ml b/src/lib_smart_rollup/operation_kind.ml index b0927747194a..d2b3f94d11b0 100644 --- a/src/lib_smart_rollup/operation_kind.ml +++ b/src/lib_smart_rollup/operation_kind.ml @@ -17,6 +17,7 @@ type t = | Refute | Recover | Execute_outbox_message + | Publish_dal_commitment let all = [ @@ -27,6 +28,7 @@ let all = Refute; Recover; Execute_outbox_message; + Publish_dal_commitment; ] module Map = Map.Make (struct @@ -43,6 +45,7 @@ let to_string = function | Refute -> "refute" | Recover -> "recover" | Execute_outbox_message -> "execute_outbox_message" + | Publish_dal_commitment -> "publish_dal_commitment" let of_string = function | "publish" -> Some Publish @@ -52,6 +55,7 @@ let of_string = function | "refute" -> Some Refute | "recover" -> Some Recover | "execute_outbox_message" -> Some Execute_outbox_message + | "publish_dal_commitment" -> Some Publish_dal_commitment | _ -> None let of_string_exn s = diff --git a/src/lib_smart_rollup/operation_kind.mli b/src/lib_smart_rollup/operation_kind.mli index 7a2066a1a088..bc963e1833cd 100644 --- a/src/lib_smart_rollup/operation_kind.mli +++ b/src/lib_smart_rollup/operation_kind.mli @@ -17,6 +17,7 @@ type t = | Refute | Recover | Execute_outbox_message + | Publish_dal_commitment (** List of possible operations kind for operator specialization. *) val all : t list diff --git a/src/lib_smart_rollup_node/configuration.ml b/src/lib_smart_rollup_node/configuration.ml index ae4a5cafceb3..512d2da70319 100644 --- a/src/lib_smart_rollup_node/configuration.ml +++ b/src/lib_smart_rollup_node/configuration.ml @@ -162,6 +162,7 @@ let default_fee : Operation_kind.t -> Injector_common.tez = function lose the 10k deposit or we can get the reward). *) tez 5 | Execute_outbox_message -> tez 1 + | Publish_dal_commitment -> tez 1 let default_burn : Operation_kind.t -> Injector_common.tez = function | Publish -> @@ -175,6 +176,7 @@ let default_burn : Operation_kind.t -> Injector_common.tez = function (* A refutation move can store data, e.g. opening a game. *) tez 1 | Execute_outbox_message -> tez 1 + | Publish_dal_commitment -> tez 1 (* Copied from src/proto_alpha/lib_plugin/mempool.ml *) let default_fee_parameter operation_kind = diff --git a/src/lib_smart_rollup_node/injector.ml b/src/lib_smart_rollup_node/injector.ml index adfafc678237..7af2292fa9e8 100644 --- a/src/lib_smart_rollup_node/injector.ml +++ b/src/lib_smart_rollup_node/injector.ml @@ -70,6 +70,7 @@ module Parameters : | Refute -> 1 | Recover -> 1 | Execute_outbox_message -> 1 + | Publish_dal_commitment -> 1 let operation_tag : Operation.t -> Tag.t = function | Add_messages _ -> Add_messages -- GitLab From 59a025e9fc9f26444b19e6d31bbfce009521591a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Fri, 9 Feb 2024 09:22:51 +0100 Subject: [PATCH 05/14] SORU: add a new Publish_dal_commitment L1 operation (not used yet) --- src/lib_smart_rollup/l1_operation.ml | 30 +++++++++++++++++-- src/lib_smart_rollup/l1_operation.mli | 5 ++++ src/lib_smart_rollup_node/injector.ml | 8 +++-- .../lib_sc_rollup_node/sc_rollup_injector.ml | 2 ++ .../lib_sc_rollup_node/sc_rollup_injector.ml | 2 ++ .../lib_sc_rollup_node/sc_rollup_injector.ml | 3 ++ .../lib_sc_rollup_node/sc_rollup_injector.ml | 2 ++ 7 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/lib_smart_rollup/l1_operation.ml b/src/lib_smart_rollup/l1_operation.ml index 5d63ed803b44..baaada0ac066 100644 --- a/src/lib_smart_rollup/l1_operation.ml +++ b/src/lib_smart_rollup/l1_operation.ml @@ -39,6 +39,11 @@ type t = cemented_commitment : Commitment.Hash.t; output_proof : string; } + | Publish_dal_commitment of { + slot_index : Dal.Slot_index.t; + commitment : Dal.Commitment.t; + commitment_proof : Dal.Commitment_proof.t; + } let encoding : t Data_encoding.t = let open Data_encoding in @@ -125,6 +130,20 @@ let encoding : t Data_encoding.t = | _ -> None) (fun (rollup, cemented_commitment, output_proof) -> Execute_outbox_message {rollup; cemented_commitment; output_proof}); + case + 7 + "publish_dal_commitment" + (obj3 + (req "slot_index" Dal.Slot_index.encoding) + (req "commitment" Dal.Commitment.encoding) + (req "commitment_proof" Dal.Commitment_proof.encoding)) + (function + | Publish_dal_commitment {slot_index; commitment; commitment_proof} + -> + Some (slot_index, commitment, commitment_proof) + | _ -> None) + (fun (slot_index, commitment, commitment_proof) -> + Publish_dal_commitment {slot_index; commitment; commitment_proof}); ] let pp ppf = function @@ -182,10 +201,17 @@ let pp ppf = function | Recover_bond {rollup = _; staker = _} -> Format.fprintf ppf "recover" | Execute_outbox_message {rollup = _; cemented_commitment = _; output_proof = _} -> - Format.fprintf ppf "Execute outbox message" + Format.fprintf ppf "execute outbox message" + | Publish_dal_commitment {slot_index; commitment; commitment_proof = _} -> + Format.fprintf + ppf + "publishing DAL commitment %a at slot index %d@." + Dal.Commitment.pp + commitment + slot_index let unique = function - | Add_messages _ | Cement _ -> false + | Add_messages _ | Cement _ | Publish_dal_commitment _ -> false | Publish _ | Refute _ | Timeout _ | Recover_bond _ | Execute_outbox_message _ -> true diff --git a/src/lib_smart_rollup/l1_operation.mli b/src/lib_smart_rollup/l1_operation.mli index 65956a1d6922..9a6a651d34ef 100644 --- a/src/lib_smart_rollup/l1_operation.mli +++ b/src/lib_smart_rollup/l1_operation.mli @@ -41,6 +41,11 @@ type t = cemented_commitment : Commitment.Hash.t; output_proof : string; } + | Publish_dal_commitment of { + slot_index : Dal.Slot_index.t; + commitment : Dal.Commitment.t; + commitment_proof : Dal.Commitment_proof.t; + } val encoding : t Data_encoding.t diff --git a/src/lib_smart_rollup_node/injector.ml b/src/lib_smart_rollup_node/injector.ml index 7af2292fa9e8..1fbf020bf8d0 100644 --- a/src/lib_smart_rollup_node/injector.ml +++ b/src/lib_smart_rollup_node/injector.ml @@ -80,6 +80,7 @@ module Parameters : | Refute _ -> Refute | Recover_bond _ -> Recover | Execute_outbox_message _ -> Execute_outbox_message + | Publish_dal_commitment _ -> Publish_dal_commitment let fee_parameter {fee_parameters; _} operation = let operation_kind = operation_tag operation in @@ -100,6 +101,7 @@ module Parameters : Some 300 | Add_messages _ | Cement _ | Recover_bond _ | Execute_outbox_message _ -> None + | Publish_dal_commitment _ -> None let persist_operation (op : Operation.t) = match op with @@ -111,7 +113,9 @@ module Parameters : requeued by the node automatically depending on the state of the game on L1 on startup. *) -> false - | Add_messages _ | Recover_bond _ | Execute_outbox_message _ -> true + | Add_messages _ | Recover_bond _ | Execute_outbox_message _ + | Publish_dal_commitment _ -> + true let retry_unsuccessful_operation _state (op : Operation.t) status = let open Lwt_syntax in @@ -140,7 +144,7 @@ module Parameters : injector as they are requeued by the node automatically. *) return Forget | Refute _ | Timeout _ | Add_messages _ | Recover_bond _ - | Execute_outbox_message _ -> ( + | Execute_outbox_message _ | Publish_dal_commitment _ -> ( match classify_trace error with | Permanent | Outdated -> return Forget | Branch | Temporary -> return Retry)) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml index 6c63f0c1f800..0102442e59ad 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml @@ -66,6 +66,8 @@ let injector_operation_to_manager : Manager (Sc_rollup_execute_outbox_message {rollup; cemented_commitment; output_proof}) + | Publish_dal_commitment _ -> + Stdlib.failwith "Publish_dal_commitment not supported in Nairobi" let injector_operation_of_manager : type kind. diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_018_Proxford/lib_sc_rollup_node/sc_rollup_injector.ml index d4afab7ace70..1c5bf7aa0b33 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/sc_rollup_injector.ml @@ -63,6 +63,8 @@ let injector_operation_to_manager : Manager (Sc_rollup_execute_outbox_message {rollup; cemented_commitment; output_proof}) + | Publish_dal_commitment _ -> + Stdlib.failwith "Publish_dal_commitment not supported in Oxford" let injector_operation_of_manager : type kind. diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml index 6fb74e1753ba..9fd43f7b8a58 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml @@ -63,6 +63,9 @@ let injector_operation_to_manager : Manager (Sc_rollup_execute_outbox_message {rollup; cemented_commitment; output_proof}) + | Publish_dal_commitment _ -> + Stdlib.failwith + "Publish_dal_commitment is not yet supported in Paris (but will be)" let injector_operation_of_manager : type kind. diff --git a/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml index 6fb74e1753ba..6fbdc66a9608 100644 --- a/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml @@ -63,6 +63,8 @@ let injector_operation_to_manager : Manager (Sc_rollup_execute_outbox_message {rollup; cemented_commitment; output_proof}) + | Publish_dal_commitment _ -> + Stdlib.failwith "Publish_dal_commitment will be supported in Alpha" let injector_operation_of_manager : type kind. -- GitLab From 8c1143e712004d47fc97ada52f687e945d08989b Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 6 Jun 2024 10:54:05 +0200 Subject: [PATCH 06/14] SORU/Proto: extend injector_operation_of_manager for Dal_publish_commitment --- src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml index 6fbdc66a9608..d4f6f47d0545 100644 --- a/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml @@ -97,6 +97,15 @@ let injector_operation_of_manager : Sc_rollup_proto_types.Commitment_hash.to_octez cemented_commitment in Some (Execute_outbox_message {rollup; cemented_commitment; output_proof}) + | Dal_publish_commitment {slot_index; commitment; commitment_proof} -> + Some + (Publish_dal_commitment + { + slot_index = + Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index; + commitment; + commitment_proof; + }) | _ -> None module Proto_client = struct -- GitLab From 000fccce286cedbd68fe8b49ff9cfeb97b7532b1 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Thu, 6 Jun 2024 10:55:19 +0200 Subject: [PATCH 07/14] SORU: implement Publish_dal_commitment case in injector_operation_to_manager --- .../lib_sc_rollup_node/sc_rollup_injector.ml | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml index d4f6f47d0545..b17627dfc44d 100644 --- a/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml @@ -63,8 +63,25 @@ let injector_operation_to_manager : Manager (Sc_rollup_execute_outbox_message {rollup; cemented_commitment; output_proof}) - | Publish_dal_commitment _ -> - Stdlib.failwith "Publish_dal_commitment will be supported in Alpha" + | Publish_dal_commitment {slot_index; commitment; commitment_proof} -> + let open Sc_rollup_proto_types.Dal in + (* FIXME: https://gitlab.com/tezos/tezos/-/issues/7319 + + commitment and commitment_proof should be versionned in + Sc_rollup_proto_types.Dal *) + + (* Below we use number_of_slots = slot_index + 1, because we don't have + access to number_of_slots parameters. We could add it to + [Publish_dal_commitment], but then, we'll not be able to set it + correctly in function {!injector_operation_of_manager} below. *) + let number_of_slots = slot_index + 1 in + Manager + (Dal_publish_commitment + { + slot_index = Slot_index.of_octez ~number_of_slots slot_index; + commitment; + commitment_proof; + }) let injector_operation_of_manager : type kind. -- GitLab From 37f1d01c34ad40c30e177d15467e8351f5eb40b9 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Fri, 7 Jun 2024 09:03:47 +0200 Subject: [PATCH 08/14] SORU/Dal: minimal worker for DAL slots injection + dal_injection RPC --- src/lib_smart_rollup/rollup_node_services.ml | 16 ++ .../dal_injection_queue.ml | 210 ++++++++++++++++++ .../dal_injection_queue.mli | 17 ++ src/lib_smart_rollup_node/rpc_directory.ml | 5 + 4 files changed, 248 insertions(+) create mode 100644 src/lib_smart_rollup_node/dal_injection_queue.ml create mode 100644 src/lib_smart_rollup_node/dal_injection_queue.mli diff --git a/src/lib_smart_rollup/rollup_node_services.ml b/src/lib_smart_rollup/rollup_node_services.ml index acda19ec5501..1ae692fefc24 100644 --- a/src/lib_smart_rollup/rollup_node_services.ml +++ b/src/lib_smart_rollup/rollup_node_services.ml @@ -777,6 +777,22 @@ module Local = struct ~output:Encodings.message_status_output (path / "batcher" / "queue" /: Arg.l2_message_id) + let dal_injection = + let input_encoding = + Data_encoding.( + obj2 + (req "slot_content" Data_encoding.Variable.string) + (req "slot_index" uint8)) + in + Tezos_rpc.Service.post_service + ~description:"Inject the given slot in the DAL queue" + ~query:Tezos_rpc.Query.empty + ~input: + Data_encoding.( + def "dal_slot" ~description:"Slot to inject" input_encoding) + ~output:Data_encoding.unit + (path / "dal" / "injection") + let synchronized = Tezos_rpc.Service.get_service ~description: diff --git a/src/lib_smart_rollup_node/dal_injection_queue.ml b/src/lib_smart_rollup_node/dal_injection_queue.ml new file mode 100644 index 000000000000..bf73e0762585 --- /dev/null +++ b/src/lib_smart_rollup_node/dal_injection_queue.ml @@ -0,0 +1,210 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2024 Functori *) +(* SPDX-FileCopyrightText: 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +module Dal_worker_types = struct + module Request = struct + type ('a, 'b) t = + | Register : { + slot_content : string; + slot_index : int; + } + -> (unit, error trace) t + + type view = View : _ t -> view + + let view req = View req + + let encoding : view Data_encoding.t = + let open Data_encoding in + conv + (function + | View (Register {slot_content; slot_index}) -> + ((), slot_content, slot_index)) + (fun ((), slot_content, slot_index) -> + View (Register {slot_content; slot_index})) + (obj3 + (req "request" (constant "register")) + (req "slot_content" string) + (req "slot_index" int31)) + + let pp ppf (View r) = + match r with + | Register {slot_content = _; slot_index} -> + Format.fprintf + ppf + "register slot injection request for index %d" + slot_index + end +end + +open Dal_worker_types + +type state = {node_ctxt : Node_context.ro} + +let inject_slot state ~slot_content ~slot_index = + let open Lwt_result_syntax in + let {Node_context.dal_cctxt; _} = state.node_ctxt in + let* operation = + match dal_cctxt with + | Some dal_cctxt -> + let* commitment, commitment_proof = + Dal_node_client.post_slot dal_cctxt slot_content + in + return + @@ L1_operation.Publish_dal_commitment + {slot_index; commitment; commitment_proof} + | None -> + (* This should not be reachable, as we tested that some [dal_cctxt] is set + at startup before launching the worker. *) + assert false + in + let* l1_hash = + Injector.check_and_add_pending_operation + state.node_ctxt.config.mode + operation + in + let+ l1_hash = + match l1_hash with + | Some l1_hash -> return l1_hash + | None -> + let op = Injector.Inj_operation.make operation in + return op.id + in + ignore l1_hash ; + () + +let on_register state ~slot_content ~slot_index : unit tzresult Lwt.t = + let open Lwt_result_syntax in + let number_of_slots = + (Reference.get state.node_ctxt.current_protocol).constants.dal + .number_of_slots + in + let* () = + fail_unless (slot_index >= 0 && slot_index < number_of_slots) + @@ error_of_fmt "Slot index %d out of range" slot_index + in + inject_slot state ~slot_content ~slot_index + +let init_dal_worker_state node_ctxt = {node_ctxt} + +module Types = struct + type nonrec state = state + + type parameters = {node_ctxt : Node_context.ro} +end + +module Name = struct + (* We only have a single DAL worker in the node *) + type t = unit + + let encoding = Data_encoding.unit + + let base = ["dal-injection"; "worker"] + + let pp _ _ = () + + let equal () () = true +end + +module Worker = Worker.MakeSingle (Name) (Request) (Types) + +type worker = Worker.infinite Worker.queue Worker.t + +module Handlers = struct + type self = worker + + let on_request : + type r request_error. + worker -> (r, request_error) Request.t -> (r, request_error) result Lwt.t + = + fun w request -> + let state = Worker.state w in + match request with + | Request.Register {slot_content; slot_index} -> + protect @@ fun () -> on_register state ~slot_content ~slot_index + + type launch_error = error trace + + let on_launch _w () Types.{node_ctxt} = + let open Lwt_result_syntax in + let state = init_dal_worker_state node_ctxt in + return state + + let on_error (type a b) _w _st (r : (a, b) Request.t) (errs : b) : + unit tzresult Lwt.t = + let open Lwt_result_syntax in + let _request_view = Request.view r in + let emit_and_return_errors _errs = return_unit in + match r with Request.Register _ -> emit_and_return_errors errs + + let on_completion _w r _ _st = + match Request.view r with Request.View (Register _) -> Lwt.return_unit + + let on_no_request _ = Lwt.return_unit + + let on_close _w = Lwt.return_unit +end + +let table = Worker.create_table Queue + +let (worker_promise : Worker.infinite Worker.queue Worker.t Lwt.t), worker_waker + = + Lwt.task () + +let start node_ctxt = + let open Lwt_result_syntax in + let node_ctxt = Node_context.readonly node_ctxt in + let+ worker = Worker.launch table () {node_ctxt} (module Handlers) in + Lwt.wakeup worker_waker worker + +let start_in_mode mode = + let open Configuration in + match mode with + | Batcher | Operator -> true + | Observer | Accuser | Bailout | Maintenance -> false + | Custom ops -> purpose_matches_mode (Custom ops) Batching + +let init (node_ctxt : _ Node_context.t) = + let open Lwt_result_syntax in + match Lwt.state worker_promise with + | Lwt.Return _ -> + (* Worker already started, nothing to do. *) + return_unit + | Lwt.Fail exn -> + (* Worker crashed, not recoverable. *) + fail [Rollup_node_errors.No_batcher; Exn exn] + | Lwt.Sleep -> + (* Never started, start it. *) + if start_in_mode node_ctxt.config.mode then start node_ctxt + else return_unit + +(* This is a DAL inection worker for a single scoru *) +let worker = + lazy + (match Lwt.state worker_promise with + | Lwt.Return worker -> Ok worker + | Lwt.Fail exn -> Error (Error_monad.error_of_exn exn) + | Lwt.Sleep -> Error Rollup_node_errors.No_batcher) + +let handle_request_error rq = + let open Lwt_syntax in + let* rq in + match rq with + | Ok res -> return_ok res + | Error (Worker.Request_error errs) -> Lwt.return_error errs + | Error (Closed None) -> Lwt.return_error [Worker_types.Terminated] + | Error (Closed (Some errs)) -> Lwt.return_error errs + | Error (Any exn) -> Lwt.return_error [Exn exn] + +let register_dal_slot ~slot_content ~slot_index = + let open Lwt_result_syntax in + let* w = lwt_map_error TzTrace.make (Lwt.return (Lazy.force worker)) in + Worker.Queue.push_request_and_wait + w + (Request.Register {slot_content; slot_index}) + |> handle_request_error diff --git a/src/lib_smart_rollup_node/dal_injection_queue.mli b/src/lib_smart_rollup_node/dal_injection_queue.mli new file mode 100644 index 000000000000..4216cefe000e --- /dev/null +++ b/src/lib_smart_rollup_node/dal_injection_queue.mli @@ -0,0 +1,17 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2024 Functori *) +(* SPDX-FileCopyrightText: 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +(** [init node_ctxt] initializes and starts the DAL injection + worker. *) +val init : _ Node_context.t -> unit tzresult Lwt.t + +(** [register_dal_slot ~slot_content ~slot_index] registers a new DAL slot + [slot_content] in the queue for future injection on L1 and DAL with index + [slot_index]. *) +val register_dal_slot : + slot_content:string -> slot_index:int -> unit tzresult Lwt.t diff --git a/src/lib_smart_rollup_node/rpc_directory.ml b/src/lib_smart_rollup_node/rpc_directory.ml index 07fe46976e47..c8cc75175b65 100644 --- a/src/lib_smart_rollup_node/rpc_directory.ml +++ b/src/lib_smart_rollup_node/rpc_directory.ml @@ -390,6 +390,11 @@ let () = @@ fun _node_ctxt drop_duplicate messages -> Batcher.register_messages ~drop_duplicate messages +let () = + Local_directory.register0 Rollup_node_services.Local.dal_injection + @@ fun _node_ctxt () (slot_content, slot_index) -> + Dal_injection_queue.register_dal_slot ~slot_content ~slot_index + let () = Local_directory.register0 Rollup_node_services.Local.batcher_queue @@ fun _node_ctxt () () -> -- GitLab From 2e3861192f24b2231a7da9153f75eb52f9297704 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Tue, 11 Jun 2024 06:45:49 +0200 Subject: [PATCH 09/14] SORU/Damon: initialize Dal_injection_queue worker --- src/lib_smart_rollup_node/rollup_node_daemon.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib_smart_rollup_node/rollup_node_daemon.ml b/src/lib_smart_rollup_node/rollup_node_daemon.ml index f39c5396137e..8ba630125fc0 100644 --- a/src/lib_smart_rollup_node/rollup_node_daemon.ml +++ b/src/lib_smart_rollup_node/rollup_node_daemon.ml @@ -51,6 +51,7 @@ let start_workers (plugin : (module Protocol_plugin_sig.S)) let open Lwt_result_syntax in let* () = Publisher.init node_ctxt in let* () = Batcher.init plugin node_ctxt in + let* () = Dal_injection_queue.init node_ctxt in let* () = Refutation_coordinator.init node_ctxt in return_unit -- GitLab From 5e976cf899459f3e6f035e93b7ee54589f9190bd Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Tue, 11 Jun 2024 22:50:29 +0200 Subject: [PATCH 10/14] Rollup: attach Publish_dal_commitment to Batching purpose --- src/lib_smart_rollup_node/purpose.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_smart_rollup_node/purpose.ml b/src/lib_smart_rollup_node/purpose.ml index 3b800d1bd2d4..d1b12c96d27f 100644 --- a/src/lib_smart_rollup_node/purpose.ml +++ b/src/lib_smart_rollup_node/purpose.ml @@ -180,7 +180,7 @@ let () = (* For each purpose, it returns a list of associated operation kinds *) let operation_kind : ex_purpose -> Operation_kind.t list = function - | Purpose Batching -> [Add_messages] + | Purpose Batching -> [Add_messages; Publish_dal_commitment] | Purpose Cementing -> [Cement] | Purpose Operating -> [Publish; Refute; Timeout] | Purpose Recovering -> [Recover] -- GitLab From 72c86edc02187119b4205641eed89f19bef9fe66 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Wed, 19 Jun 2024 15:35:38 +0200 Subject: [PATCH 11/14] Rollups: Publish_dal_commitment operations are injected at blocks reception --- src/lib_smart_rollup_node/rollup_node_daemon.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib_smart_rollup_node/rollup_node_daemon.ml b/src/lib_smart_rollup_node/rollup_node_daemon.ml index 8ba630125fc0..ab897dcc8049 100644 --- a/src/lib_smart_rollup_node/rollup_node_daemon.ml +++ b/src/lib_smart_rollup_node/rollup_node_daemon.ml @@ -496,8 +496,9 @@ let make_signers_for_injector operators = in let strategy = match operation_kinds with - | [Operation_kind.Add_messages] -> - (* For the batcher we delay of 0.5 sec to allow more + | [Operation_kind.Add_messages; Publish_dal_commitment] + | [Publish_dal_commitment; Add_messages] -> + (* For the batcher we delay half a block to allow more operations to get in. *) `Delay_block 0.5 | _ -> `Each_block -- GitLab From 10757a964f733d20811630d90cc428f29cd17051 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Tue, 18 Jun 2024 10:39:13 +0200 Subject: [PATCH 12/14] SORU: do not start a DAL slots injector if no DAL node is given --- src/lib_smart_rollup_node/dal_injection_queue.ml | 9 ++++++--- src/lib_smart_rollup_node/rollup_node_errors.ml | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/lib_smart_rollup_node/dal_injection_queue.ml b/src/lib_smart_rollup_node/dal_injection_queue.ml index bf73e0762585..3defdbc00bfa 100644 --- a/src/lib_smart_rollup_node/dal_injection_queue.ml +++ b/src/lib_smart_rollup_node/dal_injection_queue.ml @@ -177,10 +177,13 @@ let init (node_ctxt : _ Node_context.t) = return_unit | Lwt.Fail exn -> (* Worker crashed, not recoverable. *) - fail [Rollup_node_errors.No_batcher; Exn exn] + fail [Rollup_node_errors.No_dal_injector; Exn exn] | Lwt.Sleep -> (* Never started, start it. *) - if start_in_mode node_ctxt.config.mode then start node_ctxt + if + Option.is_some node_ctxt.Node_context.dal_cctxt + && start_in_mode node_ctxt.config.mode + then start node_ctxt else return_unit (* This is a DAL inection worker for a single scoru *) @@ -189,7 +192,7 @@ let worker = (match Lwt.state worker_promise with | Lwt.Return worker -> Ok worker | Lwt.Fail exn -> Error (Error_monad.error_of_exn exn) - | Lwt.Sleep -> Error Rollup_node_errors.No_batcher) + | Lwt.Sleep -> Error Rollup_node_errors.No_dal_injector) let handle_request_error rq = let open Lwt_syntax in diff --git a/src/lib_smart_rollup_node/rollup_node_errors.ml b/src/lib_smart_rollup_node/rollup_node_errors.ml index 70344bc0e976..36ec8d51030f 100644 --- a/src/lib_smart_rollup_node/rollup_node_errors.ml +++ b/src/lib_smart_rollup_node/rollup_node_errors.ml @@ -58,6 +58,7 @@ type error += | Cannot_checkout_context of Block_hash.t * Smart_rollup_context_hash.t option | Cannot_checkout_l2_header | No_batcher + | No_dal_injector | No_publisher | Refutation_player_failed_to_start | No_refutation_coordinator @@ -349,6 +350,17 @@ let () = (function No_batcher -> Some () | _ -> None) (fun () -> No_batcher) ; + register_error_kind + ~id:"sc_rollup.node.no_dal_injector" + ~title:"No dal injector for this node" + ~description:"This node does not have a ADL injector" + ~pp:(fun ppf () -> + Format.fprintf ppf "This rollup node does not have DAL injector.") + `Permanent + Data_encoding.unit + (function No_dal_injector -> Some () | _ -> None) + (fun () -> No_dal_injector) ; + register_error_kind ~id:"sc_rollup.node.no_publisher" ~title:"No publisher for this node" -- GitLab From 58d3772f08efc0f88c1c70578b22541fb3d677cd Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Wed, 19 Jun 2024 15:48:55 +0200 Subject: [PATCH 13/14] Dal/SORU: port Publish_dal_commitment support to protocol ParisC --- .../lib_sc_rollup_node/sc_rollup_injector.ml | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/proto_020_PsParisC/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_020_PsParisC/lib_sc_rollup_node/sc_rollup_injector.ml index 6fb74e1753ba..b17627dfc44d 100644 --- a/src/proto_020_PsParisC/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_020_PsParisC/lib_sc_rollup_node/sc_rollup_injector.ml @@ -63,6 +63,25 @@ let injector_operation_to_manager : Manager (Sc_rollup_execute_outbox_message {rollup; cemented_commitment; output_proof}) + | Publish_dal_commitment {slot_index; commitment; commitment_proof} -> + let open Sc_rollup_proto_types.Dal in + (* FIXME: https://gitlab.com/tezos/tezos/-/issues/7319 + + commitment and commitment_proof should be versionned in + Sc_rollup_proto_types.Dal *) + + (* Below we use number_of_slots = slot_index + 1, because we don't have + access to number_of_slots parameters. We could add it to + [Publish_dal_commitment], but then, we'll not be able to set it + correctly in function {!injector_operation_of_manager} below. *) + let number_of_slots = slot_index + 1 in + Manager + (Dal_publish_commitment + { + slot_index = Slot_index.of_octez ~number_of_slots slot_index; + commitment; + commitment_proof; + }) let injector_operation_of_manager : type kind. @@ -95,6 +114,15 @@ let injector_operation_of_manager : Sc_rollup_proto_types.Commitment_hash.to_octez cemented_commitment in Some (Execute_outbox_message {rollup; cemented_commitment; output_proof}) + | Dal_publish_commitment {slot_index; commitment; commitment_proof} -> + Some + (Publish_dal_commitment + { + slot_index = + Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index; + commitment; + commitment_proof; + }) | _ -> None module Proto_client = struct -- GitLab From 1f560a6b7b7c49626442ded3a1bc90cb07467ac2 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Wed, 19 Jun 2024 15:50:35 +0200 Subject: [PATCH 14/14] Dal/SORU: port Publish_dal_commitment support to protocol ParisB --- .../lib_sc_rollup_node/sc_rollup_injector.ml | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml index 9fd43f7b8a58..b17627dfc44d 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/sc_rollup_injector.ml @@ -63,9 +63,25 @@ let injector_operation_to_manager : Manager (Sc_rollup_execute_outbox_message {rollup; cemented_commitment; output_proof}) - | Publish_dal_commitment _ -> - Stdlib.failwith - "Publish_dal_commitment is not yet supported in Paris (but will be)" + | Publish_dal_commitment {slot_index; commitment; commitment_proof} -> + let open Sc_rollup_proto_types.Dal in + (* FIXME: https://gitlab.com/tezos/tezos/-/issues/7319 + + commitment and commitment_proof should be versionned in + Sc_rollup_proto_types.Dal *) + + (* Below we use number_of_slots = slot_index + 1, because we don't have + access to number_of_slots parameters. We could add it to + [Publish_dal_commitment], but then, we'll not be able to set it + correctly in function {!injector_operation_of_manager} below. *) + let number_of_slots = slot_index + 1 in + Manager + (Dal_publish_commitment + { + slot_index = Slot_index.of_octez ~number_of_slots slot_index; + commitment; + commitment_proof; + }) let injector_operation_of_manager : type kind. @@ -98,6 +114,15 @@ let injector_operation_of_manager : Sc_rollup_proto_types.Commitment_hash.to_octez cemented_commitment in Some (Execute_outbox_message {rollup; cemented_commitment; output_proof}) + | Dal_publish_commitment {slot_index; commitment; commitment_proof} -> + Some + (Publish_dal_commitment + { + slot_index = + Sc_rollup_proto_types.Dal.Slot_index.to_octez slot_index; + commitment; + commitment_proof; + }) | _ -> None module Proto_client = struct -- GitLab