From 34c55df4c5d53ee153cae3d31a196d7e9f58f9d6 Mon Sep 17 00:00:00 2001 From: Andrea Cerone Date: Tue, 21 Jun 2022 18:14:41 +0100 Subject: [PATCH] Proto/DAL: Move errors to Dal_errors_repr --- .../lib_protocol/dal_errors_repr.ml | 57 ++++++++++++++++++- .../lib_protocol/sc_rollup_errors.ml | 57 ------------------- .../lib_protocol/sc_rollup_storage.ml | 8 +-- .../lib_protocol/sc_rollup_storage.mli | 6 +- .../test/unit/test_sc_rollup_storage.ml | 6 +- 5 files changed, 66 insertions(+), 68 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_errors_repr.ml b/src/proto_alpha/lib_protocol/dal_errors_repr.ml index 21d5248bb12a..67995977e308 100644 --- a/src/proto_alpha/lib_protocol/dal_errors_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_errors_repr.ml @@ -40,6 +40,10 @@ type error += } | 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 + (Sc_rollup_repr.t * Dal_slot_repr.Index.t) + | Dal_requested_subscriptions_at_future_level of + (Raw_level_repr.t * Raw_level_repr.t) let () = let open Data_encoding in @@ -189,4 +193,55 @@ let () = (obj1 (req "proposed" Dal_slot_repr.encoding)) (function | Dal_publish_slot_header_duplicate {slot} -> Some slot | _ -> None) - (fun slot -> Dal_publish_slot_header_duplicate {slot}) + (fun slot -> Dal_publish_slot_header_duplicate {slot}) ; + register_error_kind + `Permanent + ~id:"Dal_rollup_already_subscribed_to_slot" + ~title:"DAL rollup already subscribed to slot" + ~description + ~pp:(fun ppf (rollup, slot_index) -> + Format.fprintf + ppf + "Rollup %a is already subscribed to data availability slot %a" + Sc_rollup_repr.pp + rollup + Dal_slot_repr.Index.pp + slot_index) + Data_encoding.( + obj2 + (req "rollup" Sc_rollup_repr.encoding) + (req "slot_index" Dal_slot_repr.Index.encoding)) + (function + | Dal_rollup_already_registered_to_slot (rollup, slot_index) -> + Some (rollup, slot_index) + | _ -> None) + (fun (rollup, slot_index) -> + Dal_rollup_already_registered_to_slot (rollup, slot_index)) ; + let description = + "Requested List of subscribed rollups to slot at a future level" + in + register_error_kind + `Temporary + ~id:"Dal_requested_subscriptions_at_future_level" + ~title:"Requested list of subscribed dal slots at a future level" + ~description + ~pp:(fun ppf (current_level, future_level) -> + Format.fprintf + ppf + "The list of subscribed dal slot indices has been requested for level \ + %a, but the current level is %a" + Raw_level_repr.pp + future_level + Raw_level_repr.pp + current_level) + Data_encoding.( + obj2 + (req "current_level" Raw_level_repr.encoding) + (req "future_level" Raw_level_repr.encoding)) + (function + | Dal_requested_subscriptions_at_future_level (current_level, future_level) + -> + Some (current_level, future_level) + | _ -> None) + (fun (current_level, future_level) -> + Dal_requested_subscriptions_at_future_level (current_level, future_level)) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_errors.ml b/src/proto_alpha/lib_protocol/sc_rollup_errors.ml index c4b932e3ef0a..0fd44b809ead 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_errors.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_errors.ml @@ -64,14 +64,6 @@ type error += staker_balance : Tez_repr.t; min_expected_balance : Tez_repr.t; } - | (* DAL/FIXME: https://gitlab.com/tezos/tezos/-/issues/3169 - Move the errors below to Dal_errors_repr. *) - (* `Permanent *) - Sc_rollup_dal_slot_already_registered of - (Sc_rollup_repr.t * Dal_slot_repr.Index.t) - | (* ` Temporary *) - Sc_rollup_requested_dal_slot_subscriptions_of_future_level of - (Raw_level_repr.t * Raw_level_repr.t) let () = let description = "Maximum number of available messages reached" in @@ -433,53 +425,4 @@ let () = (fun (staker, sc_rollup, staker_balance, min_expected_balance) -> Sc_rollup_staker_funds_too_low {staker; sc_rollup; staker_balance; min_expected_balance}) ; - register_error_kind - `Permanent - ~id:"Sc_rollup_dal_slot_already_registered" - ~title:"DAL slot already registered for rollup" - ~description - ~pp:(fun ppf (rollup, slot_index) -> - Format.fprintf - ppf - "Rollup %a is already subscribed to data availability slot %a" - Sc_rollup_repr.pp - rollup - Dal_slot_repr.Index.pp - slot_index) - Data_encoding.( - obj2 - (req "rollup" Sc_rollup_repr.encoding) - (req "slot_index" Dal_slot_repr.Index.encoding)) - (function - | Sc_rollup_dal_slot_already_registered (rollup, slot_index) -> - Some (rollup, slot_index) - | _ -> None) - (fun (rollup, slot_index) -> - Sc_rollup_dal_slot_already_registered (rollup, slot_index)) ; - register_error_kind - `Temporary - ~id:"Sc_rollup_requested_dal_slot_subscriptions_at_future_level" - ~title:"Requested list of subscribed dal slots at a future level" - ~description - ~pp:(fun ppf (current_level, future_level) -> - Format.fprintf - ppf - "The list of subscribed dal slot indices has been requested for level \ - %a, but the current level is %a" - Raw_level_repr.pp - future_level - Raw_level_repr.pp - current_level) - Data_encoding.( - obj2 - (req "current_level" Raw_level_repr.encoding) - (req "future_level" Raw_level_repr.encoding)) - (function - | Sc_rollup_requested_dal_slot_subscriptions_of_future_level - (current_level, future_level) -> - Some (current_level, future_level) - | _ -> None) - (fun (current_level, future_level) -> - Sc_rollup_requested_dal_slot_subscriptions_of_future_level - (current_level, future_level)) ; () diff --git a/src/proto_alpha/lib_protocol/sc_rollup_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_storage.ml index 87d067fc2657..fef6feec18a1 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_storage.ml @@ -131,6 +131,8 @@ let parameters_type ctxt rollup = (res, ctxt) module Dal_slot = struct + open Dal_errors_repr + let slot_of_int_e n = let open Tzresult_syntax in match Dal_slot_repr.Index.of_int n with @@ -161,9 +163,7 @@ module Dal_slot = struct let open Lwt_tzresult_syntax in let current_level = (Raw_context.current_level ctxt).level in if Raw_level_repr.(level > current_level) then - fail - (Sc_rollup_requested_dal_slot_subscriptions_of_future_level - (current_level, level)) + fail (Dal_requested_subscriptions_at_future_level (current_level, level)) else let*! subscription_levels = Store.Slot_subscriptions.keys (ctxt, rollup) @@ -203,7 +203,7 @@ module Dal_slot = struct Bitset.mem subscribed_slots (Dal_slot_repr.Index.to_int slot_index) in if slot_already_subscribed then - fail (Sc_rollup_dal_slot_already_registered (rollup, slot_index)) + fail (Dal_rollup_already_registered_to_slot (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/sc_rollup_storage.mli b/src/proto_alpha/lib_protocol/sc_rollup_storage.mli index b1c16dbb21c2..06e716873bc0 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_storage.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_storage.mli @@ -78,8 +78,8 @@ module Dal_slot : sig {li [Dal_subscribe_rollup_invalid_slot_index of {given=slot_index; maximum}] if the slot_index is either negative or above [maximum], which is the maximum slot index (inclusive) allowed} - {li [Sc_rollup_dal_slot_already_registered slot_index] if [rollup] is - already subscribed to [slot_index]} + {li [Dal_errors_repr.Dal_rollup_already_registered_to_slot (rollup, slot_index)] + if [rollup] is already subscribed to [slot_index]} } *) val subscribe : @@ -94,7 +94,7 @@ module Dal_slot : sig May fail with: {ul {li [Sc_rollup_does_not_exist] if [rollup] does not exist} - {li [Sc_rollup_requested_dal_slot_subscriptions_of_future_level (current, level)] + {li [Dal_errors_repr.Dal_requested_subscriptions_at_future_level (current_level, level)] if [level] is above the current elvel, i.e. [current] = [Raw_context.current_level ctxt] and [level] > [current]} } 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 41ccd2886dc3..79fd7bd52780 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 @@ -2679,7 +2679,7 @@ let test_subscribe_slot_twice_at_same_level () = assert_fails_with ~loc:__LOC__ (Sc_rollup_storage.Dal_slot.subscribe ctxt rollup ~slot_index) - (Sc_rollup_errors.Sc_rollup_dal_slot_already_registered (rollup, slot_index)) + (Dal_errors_repr.Dal_rollup_already_registered_to_slot (rollup, slot_index)) let test_subscribe_slot_twice_at_different_levels () = let* ctxt = new_context () in @@ -2692,7 +2692,7 @@ let test_subscribe_slot_twice_at_different_levels () = assert_fails_with ~loc:__LOC__ (Sc_rollup_storage.Dal_slot.subscribe ctxt rollup ~slot_index) - (Sc_rollup_errors.Sc_rollup_dal_slot_already_registered (rollup, slot_index)) + (Dal_errors_repr.Dal_rollup_already_registered_to_slot (rollup, slot_index)) let test_subscribe_different_slots_at_same_level () = let* ctxt = new_context () in @@ -2853,7 +2853,7 @@ let test_subscribed_slots_at_level_past_context_level () = ctxt rollup future_level) - (Sc_rollup_errors.Sc_rollup_requested_dal_slot_subscriptions_of_future_level + (Dal_errors_repr.Dal_requested_subscriptions_at_future_level (current_level, future_level)) let test_subscribed_slots_entries_at_future_level () = -- GitLab