diff --git a/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml b/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml index 3fd6fc9789d7d983f11a169380bdd25a41736c88..9e488514ac7445c69c52dcfbdd186986592d702d 100644 --- a/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml +++ b/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.ml @@ -224,12 +224,33 @@ let slot_pages | Some `Unconfirmed -> return_none | None -> storage_invariant_broken published_level index +let get_page node_ctxt ~inbox_level page_id = + let open Lwt_result_syntax in + let Dal.Page.{slot_id; page_index} = page_id in + let Dal.Slot.Header.{published_level; index} = slot_id in + let index = Sc_rollup_proto_types.Dal.Slot_index.to_octez index in + let* pages = + download_confirmed_slot_pages node_ctxt ~published_level ~index + in + match List.nth_opt pages page_index with + | Some page -> + let*! () = + Event.(emit page_reveal) + ( index, + page_index, + Raw_level.to_int32 published_level, + inbox_level, + page ) + in + return @@ Some page + | None -> tzfail @@ Dal_invalid_page_for_slot page_id + let page_content (dal_constants : Octez_smart_rollup.Rollup_constants.dal_constants) ~dal_activation_level ~inbox_level node_ctxt page_id - ~dal_attested_slots_validity_lag = + ~dal_attested_slots_validity_lag ~adal_attestation_threshold_per_mil = let open Lwt_result_syntax in - let Dal.Page.{slot_id; page_index} = page_id in + let Dal.Page.{slot_id; page_index = _} = page_id in let Dal.Slot.Header.{published_level; index} = slot_id in let Node_context.{genesis_info = {level = origination_level; _}; _} = node_ctxt @@ -245,13 +266,28 @@ let page_content page_id then return_none else + let cctxt = node_ctxt.cctxt in + let attestation_level = + Int32.add + (Raw_level.to_int32 published_level) + (Int32.of_int dal_constants.attestation_lag) + in + let* attestations_statuses = + Plugin.RPC.Dal.dal_published_slot_headers_status + (new Protocol_client_context.wrap_full cctxt) + (cctxt#chain, `Level attestation_level) + () + in + let index = Sc_rollup_proto_types.Dal.Slot_index.to_octez index in + (* ADAL/TODO: If the new design is adopted, DAL slots statuses in the rollup + node are not needed anymore. *) + (* let* confirmed_in_block_hash = store_entry_from_published_level ~dal_attestation_lag:dal_constants.attestation_lag ~published_level node_ctxt in - let index = Sc_rollup_proto_types.Dal.Slot_index.to_octez index in let* processed = Node_context.find_slot_status node_ctxt ~confirmed_in_block_hash index in @@ -274,3 +310,54 @@ let page_content | None -> tzfail @@ Dal_invalid_page_for_slot page_id) | Some `Unconfirmed -> return_none | None -> storage_invariant_broken published_level index +*) + let target_slot_attestation_status = + List.filter + (fun ((slot_header : Sc_rollup_proto_types.Dal.Slot_header.t), _) -> + let id = slot_header.id in + Raw_level.equal id.published_level slot_id.published_level + && Dal.Slot_index.equal id.index slot_id.index) + attestations_statuses + in + match + (target_slot_attestation_status, adal_attestation_threshold_per_mil) + with + | [], _ -> + Format.eprintf "#### Slot not published at all@." ; + return_none + | _ :: _ :: _, _ -> storage_invariant_broken published_level index + | [(_slot_header, (attested, _num_attested_shards, _total_shards))], None -> + if attested then + let () = Format.eprintf "#### DAL Slot published and attested@." in + get_page node_ctxt ~inbox_level page_id + else + let () = + Format.eprintf "#### DAL Slot published not NOT attested@." + in + return_none + | ( [(_slot_header, (_attested, num_attested_shards, total_shards))], + Some attestation_threshold_per_mil ) -> + let threshold = + Q.make (Z.of_int attestation_threshold_per_mil) (Z.of_int 1000) + in + let current = + Q.make (Z.of_int num_attested_shards) (Z.of_int total_shards) + in + let is_accepted = Q.compare current threshold >= 0 in + if is_accepted then + let () = + Format.eprintf + "#### Adaptive DAL Slot published and sufficiently attested. \ + Threshold:%a, Current:%a@." + Q.pp_print + threshold + Q.pp_print + current + in + get_page node_ctxt ~inbox_level page_id + else + let () = + Format.eprintf + "#### DAL Slot published but NOT sufficiently attested@." + in + return_none diff --git a/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.mli b/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.mli index 17d384fed0c2f8d24c757918828c7a506d81b981..f5d2229b45da95af88c9cc90998a720262a48eaf 100644 --- a/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.mli +++ b/src/proto_alpha/lib_sc_rollup_node/dal_pages_request.mli @@ -75,6 +75,7 @@ val slot_pages : which the content has already been downloaded and saved to the store. [dal_attestation_lag] is used to retrieve the correct entry in [store]. + TODO: Extend doc-string *) val page_content : Octez_smart_rollup.Rollup_constants.dal_constants -> @@ -83,4 +84,5 @@ val page_content : _ Node_context.t -> Dal.Page.t -> dal_attested_slots_validity_lag:int -> + adal_attestation_threshold_per_mil:int option -> Dal.Page.content option tzresult Lwt.t diff --git a/src/proto_alpha/lib_sc_rollup_node/fueled_pvm.ml b/src/proto_alpha/lib_sc_rollup_node/fueled_pvm.ml index 4ea839c860264a3a7353ca6ee10d169161e93a6f..97201b25eecce2ee1fb39d855af62c5a3e2bd946 100644 --- a/src/proto_alpha/lib_sc_rollup_node/fueled_pvm.ml +++ b/src/proto_alpha/lib_sc_rollup_node/fueled_pvm.ml @@ -153,6 +153,7 @@ module Make_fueled (F : Fuel.S) : FUELED_PVM with type fuel = F.t = struct ~dal_activation_level ~dal_attested_slots_validity_lag ~inbox_level:(Int32.of_int level) + ~adal_attestation_threshold_per_mil:None node_ctxt dal_page in @@ -174,9 +175,33 @@ module Make_fueled (F : Fuel.S) : FUELED_PVM with type fuel = F.t = struct (Data_encoding.Binary.to_string_exn Sc_rollup.Dal_parameters.encoding dal_parameters) - | Request_adal_page _ -> - (* ADAL/FIXME: to be implemented. *) - assert false + | Request_adal_page {page_id = dal_page; attestation_threshold_per_mil} + -> ( + Format.eprintf + "### Page:(?, ?), attestation_threshold_per_mil:%d@." + attestation_threshold_per_mil ; + let*! content = + Dal_pages_request.page_content + constants.dal + ~dal_activation_level + ~dal_attested_slots_validity_lag + ~inbox_level:(Int32.of_int level) + ~adal_attestation_threshold_per_mil: + (Some attestation_threshold_per_mil) + node_ctxt + dal_page + in + match content with + | Error error -> + (* The [Error_wrapper] must be caught upstream and converted into + a tzresult. *) + (* This happens when, for example, the kernel requests a page from a future level. *) + Lwt.fail (Error_wrapper error) + | Ok None -> + (* The page was not confirmed by L1. + We return empty string in this case, as done in the slow executon. *) + Lwt.return "" + | Ok (Some b) -> Lwt.return (Bytes.to_string b)) in let eval_tick_consume_fuel fuel failing_ticks state = @@ -303,6 +328,27 @@ module Make_fueled (F : Fuel.S) : FUELED_PVM with type fuel = F.t = struct ~inbox_level:(Int32.of_int level) ~dal_activation_level ~dal_attested_slots_validity_lag + ~adal_attestation_threshold_per_mil:None + node_ctxt + page_id + in + let*! next_state = + PVM.set_input (Reveal (Dal_page content_opt)) state + in + go fuel (Int64.succ current_tick) failing_ticks next_state) + | Needs_reveal + (Request_adal_page {page_id; attestation_threshold_per_mil}) -> ( + match F.consume F.one_tick_consumption fuel with + | None -> abort state fuel current_tick + | Some fuel -> + let* content_opt = + Dal_pages_request.page_content + constants.dal + ~inbox_level:(Int32.of_int level) + ~dal_activation_level + ~dal_attested_slots_validity_lag + ~adal_attestation_threshold_per_mil: + (Some attestation_threshold_per_mil) node_ctxt page_id in @@ -322,11 +368,7 @@ module Make_fueled (F : Fuel.S) : FUELED_PVM with type fuel = F.t = struct go fuel (Int64.succ current_tick) failing_ticks next_state) | Initial | First_after _ -> complete state fuel current_tick failing_ticks - | Needs_reveal (Request_adal_page _) -> - (* ADAL/FIXME: to be implemented. *) - assert false in - go fuel start_tick failing_ticks (PVM.Ctxt_wrapper.of_node_pvmstate state) (** [mutate input] corrupts the payload of [input] for testing purposes. *)