diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index dfe8cd142c1edd8554487c56834927b463fe5ba2..a753e897fe382022c0b64ed09e2fb4b2dcf38833 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -134,9 +134,13 @@ module Handler = struct match Node_context.get_status ctxt with | Starting -> return_unit | Ready {plugin = (module Plugin); _} -> - let* slot_headers = - Plugin.get_published_slot_headers (`Hash (block_hash, 0)) cctxt + let* block_info = + Plugin.block_info + cctxt + ~block:(`Hash (block_hash, 0)) + ~metadata:`Always in + let* slot_headers = Plugin.get_published_slot_headers block_info in let*! () = Slot_manager.store_slot_headers ~block_level:header.shell.level diff --git a/src/lib_dal_node/dal_plugin.ml b/src/lib_dal_node/dal_plugin.ml index afa48462275ccbc7f829a7408e169ef81c9851d3..104dbf770cebe0bd5815bad9d0f1cabc762e8cae 100644 --- a/src/lib_dal_node/dal_plugin.ml +++ b/src/lib_dal_node/dal_plugin.ml @@ -25,15 +25,26 @@ type operation_application_result = Succeeded | Failed +type slot_index = int + type slot_header = { published_level : int32; - slot_index : int; + slot_index : slot_index; commitment : Tezos_crypto_dal.Cryptobox.Verifier.commitment; } module type T = sig module Proto : Registered_protocol.T + type block_info + + val block_info : + ?chain:Tezos_shell_services.Block_services.chain -> + ?block:Tezos_shell_services.Block_services.block -> + metadata:[`Always | `Never] -> + Client_context.full -> + block_info tzresult Lwt.t + val get_constants : Tezos_shell_services.Chain_services.chain -> Tezos_shell_services.Block_services.block -> @@ -41,8 +52,7 @@ module type T = sig Tezos_crypto_dal.Cryptobox.Verifier.parameters tzresult Lwt.t val get_published_slot_headers : - Tezos_shell_services.Block_services.block -> - Client_context.full -> + block_info -> (slot_header * operation_application_result) list tzresult Lwt.t module RPC : sig diff --git a/src/lib_dal_node/dal_plugin.mli b/src/lib_dal_node/dal_plugin.mli index 9b841b0087b605401f40c005566539c8a5ab8b77..3408f6ecf2745bfc118f7bc1f1a3cfe41f1deb25 100644 --- a/src/lib_dal_node/dal_plugin.mli +++ b/src/lib_dal_node/dal_plugin.mli @@ -31,18 +31,33 @@ type operation_application_result = (** The associated operation is included in a block but its application was not successful (failed, backtracked or skipped). *) +type slot_index = int + (** Information extracted from DAL slots headers operations included in L1 blocks. Each slot header is made of an L1 level for which it is published, the slot's index and commitment. *) type slot_header = { published_level : int32; - slot_index : int; + slot_index : slot_index; commitment : Tezos_crypto_dal.Cryptobox.Verifier.commitment; } module type T = sig module Proto : Registered_protocol.T + type block_info + + (** [block_info ?chain ?block ~metadata ctxt] returns the information of the + [block] in [ctxt] for the given [chain]. Block's metadata are included or + skipped depending on the value of [metadata]. This is a wrapper on top of + {!Protocol_client_context.Alpha_block_services.info}. *) + val block_info : + ?chain:Tezos_shell_services.Block_services.chain -> + ?block:Tezos_shell_services.Block_services.block -> + metadata:[`Always | `Never] -> + Client_context.full -> + block_info tzresult Lwt.t + val get_constants : Tezos_shell_services.Chain_services.chain -> Tezos_shell_services.Block_services.block -> @@ -50,8 +65,7 @@ module type T = sig Tezos_crypto_dal.Cryptobox.Verifier.parameters tzresult Lwt.t val get_published_slot_headers : - Tezos_shell_services.Block_services.block -> - Client_context.full -> + block_info -> (slot_header * operation_application_result) list tzresult Lwt.t module RPC : sig diff --git a/src/lib_dal_node_services/services.ml b/src/lib_dal_node_services/services.ml index 37e7453e8b04f037ecffd4c5673b84ea9f1da315..cbe1803a5dfc2056f7adb770bd123529a8e7da06 100644 --- a/src/lib_dal_node_services/services.ml +++ b/src/lib_dal_node_services/services.ml @@ -69,7 +69,7 @@ module Types = struct (fun (slot_level, slot_index) -> {slot_level; slot_index}) (obj2 (req "slot_level" int32) (req "slot_index" uint8)) - let slot_content = Data_encoding.bytes + let slot_encoding = Data_encoding.bytes end let post_slots : @@ -85,7 +85,7 @@ let post_slots : "Add a slot in the node's context if not already present. The \ corresponding commitment is returned." ~query:Tezos_rpc.Query.empty - ~input:Types.slot_content + ~input:Types.slot_encoding ~output:Cryptobox.Commitment.encoding Tezos_rpc.Path.(open_root / "slots") @@ -116,7 +116,7 @@ let get_slot : ~description: "Retrieve the content of the slot associated with the given commitment." ~query:Tezos_rpc.Query.empty - ~output:Types.slot_content + ~output:Types.slot_encoding Tezos_rpc.Path.(open_root / "slots" /: Cryptobox.Commitment.rpc_arg) let get_slot_commitment_proof : 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 1279f4e636e9a2a3155766d65a3cfcab1541368e..3a1af0ef89506a416ccdac1f1be7fc14bfb4eb54 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 @@ -27,24 +27,6 @@ open Protocol open Alpha_context module Block_services = Block_services.Make (Protocol) (Protocol) -type error += Cannot_read_block_metadata of Tezos_crypto.Block_hash.t - -let () = - register_error_kind - ~id:"sc_rollup.node.cannot_read_receipt_of_block" - ~title:"Cannot read receipt of block from L1" - ~description:"The receipt of a block could not be read." - ~pp:(fun ppf hash -> - Format.fprintf - ppf - "Could not read block receipt for block with hash %a." - Tezos_crypto.Block_hash.pp - hash) - `Temporary - Data_encoding.(obj1 (req "hash" Tezos_crypto.Block_hash.encoding)) - (function Cannot_read_block_metadata hash -> Some hash | _ -> None) - (fun hash -> Cannot_read_block_metadata hash) - let ancestor_hash ~number_of_levels {Node_context.genesis_info; l1_ctxt; _} head = let genesis_level = genesis_info.level in @@ -106,7 +88,7 @@ let slots_info node_ctxt (Layer1.{hash; _} as head) = in let*? metadata = Option.to_result - ~none:(TzTrace.make @@ Cannot_read_block_metadata hash) + ~none:(TzTrace.make @@ Layer1_services.Cannot_read_block_metadata hash) metadata in (* `metadata.protocol_data.dal_attestation` is `None` if we are behind @@ -139,7 +121,7 @@ let is_slot_confirmed node_ctxt (Layer1.{hash; _} as head) slot_index = let open Lwt_result_syntax in let* slots_info_opt = slots_info node_ctxt head in match slots_info_opt with - | None -> tzfail @@ Cannot_read_block_metadata hash + | None -> tzfail @@ Layer1_services.Cannot_read_block_metadata hash | Some {confirmed_slots_indexes; _} -> let*? is_confirmed = Environment.wrap_tzresult diff --git a/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.mli b/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.mli index c5da7b2ebcb35598b1c2a9529ed457de57e4bfa2..0e77b548a6011761faed07145439b3d2b8cc2aac 100644 --- a/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.mli +++ b/src/proto_alpha/bin_sc_rollup_node/dal_slots_tracker.mli @@ -33,8 +33,6 @@ open Alpha_context The state of slots per block is persistent. *) -type error += Cannot_read_block_metadata of Tezos_crypto.Block_hash.t - (** [is_slot_confirmed node_ctxt head slot_index] checks whether the slot with index [slot_index] has been confirmed in [head]. *) val is_slot_confirmed : diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index 7c3a450b8c9fac4b1f2013122a3329ba8c74b12c..3308cda47b34c875a45f7f56032cbfcde2167c5e 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -26,29 +26,32 @@ module Plugin = struct module Proto = Registerer.Registered + type block_info = Protocol_client_context.Alpha_block_services.block_info + let get_constants chain block ctxt = let cpctxt = new Protocol_client_context.wrap_full ctxt in let open Lwt_result_syntax in let* constants = Protocol.Constants_services.all cpctxt (chain, block) in return constants.parametric.dal.cryptobox_parameters + let block_info ?chain ?block ~metadata ctxt = + let cpctxt = new Protocol_client_context.wrap_full ctxt in + Protocol_client_context.Alpha_block_services.info + cpctxt + ?chain + ?block + ~metadata + () + (* Turn the given value of type {!Protocol.Apply_operation_result.operation_result} into a value of type {!Dal_plugin.operation_application_result}. *) let status_of_result = function | Protocol.Apply_operation_result.Applied _ -> Dal_plugin.Succeeded | _ -> Dal_plugin.Failed - let get_published_slot_headers block ctxt = + let get_published_slot_headers (block : block_info) = let open Lwt_result_syntax in let open Protocol.Alpha_context in - let cpctxt = new Protocol_client_context.wrap_full ctxt in - let* block = - Protocol_client_context.Alpha_block_services.info - cpctxt - ~block - ~metadata:`Always - () - in let apply_internal acc ~source:_ _op _res = acc in let apply (type kind) acc ~source:_ (op : kind manager_operation) (result : (kind, _, _) Protocol.Apply_operation_result.operation_result) diff --git a/src/proto_alpha/lib_layer2_utils/layer1_services.ml b/src/proto_alpha/lib_layer2_utils/layer1_services.ml index 22773e17db82ac5acb19a5b6545bcce5d4534c08..6c1cfa5ad007724618e23cf0763a833c8fe8a82d 100644 --- a/src/proto_alpha/lib_layer2_utils/layer1_services.ml +++ b/src/proto_alpha/lib_layer2_utils/layer1_services.ml @@ -28,6 +28,24 @@ open Alpha_context open Apply_results open Protocol_client_context.Alpha_block_services +type error += Cannot_read_block_metadata of Tezos_crypto.Block_hash.t + +let () = + register_error_kind + ~id:"cannot_read_receipt_of_block" + ~title:"Cannot read receipt of block from L1" + ~description:"The receipt of a block could not be read." + ~pp:(fun ppf hash -> + Format.fprintf + ppf + "Could not read block receipt for block with hash %a." + Tezos_crypto.Block_hash.pp + hash) + `Temporary + Data_encoding.(obj1 (req "hash" Tezos_crypto.Block_hash.encoding)) + (function Cannot_read_block_metadata hash -> Some hash | _ -> None) + (fun hash -> Cannot_read_block_metadata hash) + type 'accu successful_operation_processor = { apply : 'kind. diff --git a/src/proto_alpha/lib_layer2_utils/layer1_services.mli b/src/proto_alpha/lib_layer2_utils/layer1_services.mli index bbcf372491af5e1f66c5f9e0e951ef2dbb69575a..1255d70b764e28ea88c6794ec2d1e0e199294360 100644 --- a/src/proto_alpha/lib_layer2_utils/layer1_services.mli +++ b/src/proto_alpha/lib_layer2_utils/layer1_services.mli @@ -27,6 +27,8 @@ open Protocol open Alpha_context open Protocol_client_context.Alpha_block_services +type error += Cannot_read_block_metadata of Tezos_crypto.Block_hash.t + type 'accu successful_operation_processor = { apply : 'kind.