diff --git a/manifest/main.ml b/manifest/main.ml index 4caf02c0741d139459cd682a5adb4057bec9d157..ad011b80dc2c5000296b2f3dc8b1f54f7a0445d8 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -4095,12 +4095,13 @@ let octez_smart_rollup_node_lib = octez_base_unix; octez_stdlib_unix |> open_; octez_crypto |> open_; + octez_client_base |> open_; + octez_client_base_unix |> open_; cohttp_lwt_unix; octez_node_config; prometheus_app; octez_injector |> open_; octez_version_value |> open_; - octez_client_base |> open_; octez_smart_rollup_lib |> open_; ] @@ -6037,7 +6038,7 @@ let hash = Protocol.hash octez_base |> open_ ~m:"TzPervasives"; main |> open_; octez_injector |> open_; - octez_smart_rollup_lib; + octez_smart_rollup_lib |> open_; ] ~inline_tests:ppx_expect ~linkall:true @@ -6073,6 +6074,7 @@ let hash = Protocol.hash octez_dac_lib |> if_ N.(number >= 018) |> open_; octez_dac_client_lib |> if_ N.(number >= 018) |> open_; octez_shell_services |> open_; + octez_smart_rollup_lib |> open_; octez_sc_rollup |> if_some |> open_; octez_sc_rollup_layer2 |> if_some |> open_; layer2_utils |> if_some |> open_; diff --git a/opam/octez-smart-rollup-node-PtMumbai.opam b/opam/octez-smart-rollup-node-PtMumbai.opam index 2204a1abde4d68296eeccdc48ccb822971188767..c5797475fba135f02f6bc94d0943e1b06f9fa734 100644 --- a/opam/octez-smart-rollup-node-PtMumbai.opam +++ b/opam/octez-smart-rollup-node-PtMumbai.opam @@ -25,6 +25,7 @@ depends: [ "tezos-dal-node-services" "tezos-dal-node-lib" "tezos-shell-services" + "octez-smart-rollup" "tezos-smart-rollup-016-PtMumbai" "tezos-smart-rollup-layer2-016-PtMumbai" "tezos-layer2-utils-016-PtMumbai" diff --git a/opam/octez-smart-rollup-node-PtNairob.opam b/opam/octez-smart-rollup-node-PtNairob.opam index 5a7387c1906b72299194da6e8bf269bcdd563434..5b62360981903f95c574fe7291d07ab91da1681c 100644 --- a/opam/octez-smart-rollup-node-PtNairob.opam +++ b/opam/octez-smart-rollup-node-PtNairob.opam @@ -25,6 +25,7 @@ depends: [ "tezos-dal-node-services" "tezos-dal-node-lib" "tezos-shell-services" + "octez-smart-rollup" "tezos-smart-rollup-017-PtNairob" "tezos-smart-rollup-layer2-017-PtNairob" "tezos-layer2-utils-017-PtNairob" diff --git a/opam/octez-smart-rollup-node-alpha.opam b/opam/octez-smart-rollup-node-alpha.opam index 57e7f9db8e3cf95c4566c54f6f442b4c0d1c0d73..2faca42435c2c9d9c3a78e16c2a4b9d2de7ff370 100644 --- a/opam/octez-smart-rollup-node-alpha.opam +++ b/opam/octez-smart-rollup-node-alpha.opam @@ -28,6 +28,7 @@ depends: [ "tezos-dac-lib" "tezos-dac-client-lib" "tezos-shell-services" + "octez-smart-rollup" "tezos-smart-rollup-alpha" "tezos-smart-rollup-layer2-alpha" "tezos-layer2-utils-alpha" diff --git a/opam/octez-smart-rollup-node.opam b/opam/octez-smart-rollup-node.opam index 1672433b98ce0f62c6eedb01d662936569d6a131..c5215fbb62c011a7f1efcdc7316d4636971b84ae 100644 --- a/opam/octez-smart-rollup-node.opam +++ b/opam/octez-smart-rollup-node.opam @@ -13,12 +13,13 @@ depends: [ "tezos-base" "tezos-stdlib-unix" "tezos-crypto" + "tezos-client-base" + "tezos-client-base-unix" "cohttp-lwt-unix" { >= "4.0.0" & != "5.1.0" } "octez-node-config" "prometheus-app" { >= "1.2" } "octez-injector" "tezos-version" - "tezos-client-base" "octez-smart-rollup" ] build: [ diff --git a/src/proto_alpha/lib_sc_rollup_layer2/l1_operation.ml b/src/lib_smart_rollup/l1_operation.ml similarity index 68% rename from src/proto_alpha/lib_sc_rollup_layer2/l1_operation.ml rename to src/lib_smart_rollup/l1_operation.ml index 79594a70bcc4258cb8a2c60a3bff35f09f890e42..74de8ffb2d7f15bc3c62f7bf30d265fbd79f301a 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/l1_operation.ml +++ b/src/lib_smart_rollup/l1_operation.ml @@ -23,18 +23,16 @@ (* *) (*****************************************************************************) -open Protocol.Alpha_context - type t = | Add_messages of {messages : string list} - | Cement of {rollup : Sc_rollup.t} - | Publish of {rollup : Sc_rollup.t; commitment : Sc_rollup.Commitment.t} + | Cement of {rollup : Address.t; commitment : Commitment.Hash.t} + | Publish of {rollup : Address.t; commitment : Commitment.t} | Refute of { - rollup : Sc_rollup.t; - opponent : Sc_rollup.Staker.t; - refutation : Sc_rollup.Game.refutation; + rollup : Address.t; + opponent : Signature.Public_key_hash.t; + refutation : Game.refutation; } - | Timeout of {rollup : Sc_rollup.t; stakers : Sc_rollup.Game.Index.t} + | Timeout of {rollup : Address.t; stakers : Game.index} let encoding : t Data_encoding.t = let open Data_encoding in @@ -58,15 +56,19 @@ let encoding : t Data_encoding.t = case 1 "cement" - (obj1 (req "rollup" Sc_rollup.Address.encoding)) - (function Cement {rollup} -> Some rollup | _ -> None) - (fun rollup -> Cement {rollup}); + (obj2 + (req "rollup" Address.encoding) + (req "commitment" Commitment.Hash.encoding)) + (function + | Cement {rollup; commitment} -> Some (rollup, commitment) + | _ -> None) + (fun (rollup, commitment) -> Cement {rollup; commitment}); case 2 "publish" (obj2 - (req "rollup" Sc_rollup.Address.encoding) - (req "commitment" Sc_rollup.Commitment.encoding)) + (req "rollup" Address.encoding) + (req "commitment" Commitment.encoding)) (function | Publish {rollup; commitment} -> Some (rollup, commitment) | _ -> None) @@ -75,9 +77,9 @@ let encoding : t Data_encoding.t = 3 "refute" (obj3 - (req "rollup" Sc_rollup.Address.encoding) - (req "opponent" Sc_rollup.Staker.encoding) - (req "refutation" Sc_rollup.Game.refutation_encoding)) + (req "rollup" Address.encoding) + (req "opponent" Signature.Public_key_hash.encoding) + (req "refutation" Game.refutation_encoding)) (function | Refute {rollup; opponent; refutation} -> Some (rollup, opponent, refutation) @@ -88,8 +90,8 @@ let encoding : t Data_encoding.t = 4 "timeout" (obj2 - (req "rollup" Sc_rollup.Address.encoding) - (req "stakers" Sc_rollup.Game.Index.encoding)) + (req "rollup" Address.encoding) + (req "stakers" Game.index_encoding)) (function | Timeout {rollup; stakers} -> Some (rollup, stakers) | _ -> None) (fun (rollup, stakers) -> Timeout {rollup; stakers}); @@ -101,13 +103,14 @@ let pp ppf = function ppf "publishing %d messages to smart rollups' inbox" (List.length messages) - | Cement {rollup = _} -> Format.fprintf ppf "cementing commitment" - | Publish {rollup = _; commitment = Sc_rollup.Commitment.{inbox_level; _}} -> - Format.fprintf - ppf - "publish commitment for level %a" - Raw_level.pp - inbox_level + | Cement {rollup = _; commitment} when Commitment.Hash.(commitment = zero) -> + (* We use zero as a default value for protocol alpha which does + not need the commitment to be specified. *) + Format.fprintf ppf "cementing cementable commitment" + | Cement {rollup = _; commitment} -> + Format.fprintf ppf "cementing commitment %a" Commitment.Hash.pp commitment + | Publish {rollup = _; commitment = Commitment.{inbox_level; _}} -> + Format.fprintf ppf "publish commitment for level %ld" inbox_level | Refute {rollup = _; opponent; refutation = Start _} -> Format.fprintf ppf @@ -124,9 +127,9 @@ let pp ppf = function Format.fprintf ppf "dissection between ticks %a and %a (against %a)" - Sc_rollup.Tick.pp + Z.pp_print first.tick - Sc_rollup.Tick.pp + Z.pp_print last.tick Signature.Public_key_hash.pp opponent @@ -141,32 +144,12 @@ let pp ppf = function Format.fprintf ppf "proof for tick %a (against %a)" - Sc_rollup.Tick.pp + Z.pp_print choice Signature.Public_key_hash.pp opponent | Timeout {rollup = _; stakers = _} -> Format.fprintf ppf "timeout" -let to_manager_operation : t -> packed_manager_operation = function - | Add_messages {messages} -> Manager (Sc_rollup_add_messages {messages}) - | Cement {rollup} -> Manager (Sc_rollup_cement {rollup}) - | Publish {rollup; commitment} -> - Manager (Sc_rollup_publish {rollup; commitment}) - | Refute {rollup; opponent; refutation} -> - Manager (Sc_rollup_refute {rollup; opponent; refutation}) - | Timeout {rollup; stakers} -> Manager (Sc_rollup_timeout {rollup; stakers}) - -let of_manager_operation : type kind. kind manager_operation -> t option = - function - | Sc_rollup_add_messages {messages} -> Some (Add_messages {messages}) - | Sc_rollup_cement {rollup} -> Some (Cement {rollup}) - | Sc_rollup_publish {rollup; commitment} -> - Some (Publish {rollup; commitment}) - | Sc_rollup_refute {rollup; opponent; refutation} -> - Some (Refute {rollup; opponent; refutation}) - | Sc_rollup_timeout {rollup; stakers} -> Some (Timeout {rollup; stakers}) - | _ -> None - let unique = function | Add_messages _ | Cement _ -> false | Publish _ | Refute _ | Timeout _ -> true diff --git a/src/proto_alpha/lib_sc_rollup_layer2/l1_operation.mli b/src/lib_smart_rollup/l1_operation.mli similarity index 80% rename from src/proto_alpha/lib_sc_rollup_layer2/l1_operation.mli rename to src/lib_smart_rollup/l1_operation.mli index d743c0bb694b0e3a33b2ea8163b67e80b45461d0..5e111d5d60b269fb1ce788cddde37d1920645212 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/l1_operation.mli +++ b/src/lib_smart_rollup/l1_operation.mli @@ -23,29 +23,21 @@ (* *) (*****************************************************************************) -open Protocol.Alpha_context - (** L1 operations produced (and injected) by the rollup node. *) type t = | Add_messages of {messages : string list} - | Cement of {rollup : Sc_rollup.t} - | Publish of {rollup : Sc_rollup.t; commitment : Sc_rollup.Commitment.t} + | Cement of {rollup : Address.t; commitment : Commitment.Hash.t} + | Publish of {rollup : Address.t; commitment : Commitment.t} | Refute of { - rollup : Sc_rollup.t; - opponent : Sc_rollup.Staker.t; - refutation : Sc_rollup.Game.refutation; + rollup : Address.t; + opponent : Signature.Public_key_hash.t; + refutation : Game.refutation; } - | Timeout of {rollup : Sc_rollup.t; stakers : Sc_rollup.Game.Index.t} + | Timeout of {rollup : Address.t; stakers : Game.index} (** Encoding for L1 operations (used by injector for on-disk persistence). *) val encoding : t Data_encoding.t -(** Manager operation for a given L1 operation. *) -val to_manager_operation : t -> packed_manager_operation - -(** L1 operation corresponding to a manager operation if any. *) -val of_manager_operation : 'a manager_operation -> t option - (** Pretty printer (human readable) for L1 operations. *) val pp : Format.formatter -> t -> unit diff --git a/src/lib_smart_rollup_node/dune b/src/lib_smart_rollup_node/dune index 728273ae690e7e2433cfaa756d552712e01a4661..bb1a49fc2d077abc58b74e1a3147bc88f07f4ebb 100644 --- a/src/lib_smart_rollup_node/dune +++ b/src/lib_smart_rollup_node/dune @@ -10,19 +10,21 @@ tezos-base.unix tezos-stdlib-unix tezos-crypto + tezos-client-base + tezos-client-base-unix cohttp-lwt-unix octez-node-config prometheus-app octez-injector tezos-version.value - tezos-client-base octez-smart-rollup) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_stdlib_unix -open Tezos_crypto + -open Tezos_client_base + -open Tezos_client_base_unix -open Octez_injector -open Tezos_version_value - -open Tezos_client_base -open Octez_smart_rollup)) diff --git a/src/lib_smart_rollup_node/injector.ml b/src/lib_smart_rollup_node/injector.ml new file mode 100644 index 0000000000000000000000000000000000000000..9b6b0bda9070cea7973567a21f1e7b07b62fe2af --- /dev/null +++ b/src/lib_smart_rollup_node/injector.ml @@ -0,0 +1,128 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Functori, *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +open Injector_sigs + +type state = { + cctxt : Client_context.full; + fee_parameters : Configuration.fee_parameters; + minimal_block_delay : int64; + delay_increment_per_round : int64; +} + +module Parameters : + PARAMETERS + with type state = state + and type Tag.t = Configuration.purpose + and type Operation.t = L1_operation.t = struct + type nonrec state = state + + let events_section = ["sc_rollup_node"] + + module Tag : TAG with type t = Configuration.purpose = struct + type t = Configuration.purpose + + let compare = Stdlib.compare + + let equal = Stdlib.( = ) + + let hash = Hashtbl.hash + + let string_of_tag = Configuration.string_of_purpose + + let pp ppf t = Format.pp_print_string ppf (string_of_tag t) + + let encoding : t Data_encoding.t = + let open Data_encoding in + string_enum + (List.map (fun t -> (string_of_tag t, t)) Configuration.purposes) + end + + module Operation = L1_operation + + (* TODO: https://gitlab.com/tezos/tezos/-/issues/3459 + Very coarse approximation for the number of operation we + expect for each block *) + let table_estimated_size : Tag.t -> int = function + | Publish -> 1 + | Add_messages -> 100 + | Cement -> 1 + | Timeout -> 1 + | Refute -> 1 + + let operation_tag : Operation.t -> Tag.t = function + | Add_messages _ -> Add_messages + | Cement _ -> Cement + | Publish _ -> Publish + | Timeout _ -> Timeout + | Refute _ -> Refute + + let fee_parameter {fee_parameters; _} operation = + let purpose = operation_tag operation in + Configuration.Operator_purpose_map.find purpose fee_parameters + |> Option.value ~default:(Configuration.default_fee_parameter ~purpose ()) + + (* TODO: https://gitlab.com/tezos/tezos/-/issues/3459 + Decide if some batches must have all the operations succeed. See + {!Injector_sigs.Parameter.batch_must_succeed}. *) + let batch_must_succeed _ = `At_least_one + + let retry_unsuccessful_operation _state (_op : Operation.t) status = + let open Lwt_syntax in + match status with + | Backtracked | Skipped | Other_branch -> + (* Always retry backtracked or skipped operations, or operations that + are on another branch because of a reorg: + + - Commitments are always produced on finalized blocks. They don't + need to be recomputed, and as such are valid in another branch. + + - The cementation operations should be re-injected because the node + only keeps track of the last cemented level and the last published + commitment, without rollbacks. + + - Messages posted to an inbox should be re-emitted (i.e. re-queued) + in case of a fork. + + - Timeout should be re-submitted as the timeout may be reached as well + on the other branch. + + - Refutation should be re-submitted in case of fork. + TODO: https://gitlab.com/tezos/tezos/-/issues/3459 + maybe check if game exists on other branch as well. + *) + return Retry + | Failed error -> ( + (* TODO: https://gitlab.com/tezos/tezos/-/issues/4071 + Think about which operations should be retried and when. *) + match classify_trace error with + | Permanent | Outdated -> return Forget + | Branch | Temporary -> return Retry) + | Never_included -> + (* Forget operations that are never included *) + return Forget +end + +include Injector_functor.Make (Parameters) diff --git a/src/lib_smart_rollup_node/injector.mli b/src/lib_smart_rollup_node/injector.mli new file mode 100644 index 0000000000000000000000000000000000000000..a698ff07cdcee63423093091690b47f9153a75cc --- /dev/null +++ b/src/lib_smart_rollup_node/injector.mli @@ -0,0 +1,38 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Nomadic Labs, *) +(* Copyright (c) 2023 Functori, *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +type state = { + cctxt : Client_context.full; + fee_parameters : Configuration.fee_parameters; + minimal_block_delay : int64; + delay_increment_per_round : int64; +} + +include + Injector_sigs.S + with type state := state + and type tag := Configuration.purpose + and type operation := L1_operation.t diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/dune b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/dune index 4b3acb3af745bb9ec3b7a06217f6fd5708764d2c..0906fc85709a997d18a3ea66231734645597ba28 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/dune +++ b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/dune @@ -17,4 +17,5 @@ (:standard) -open Tezos_base.TzPervasives -open Tezos_protocol_016_PtMumbai - -open Octez_injector)) + -open Octez_injector + -open Octez_smart_rollup)) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/l1_operation.ml b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/l1_operation.ml deleted file mode 100644 index 686d7927381163e753afcbafee3af4459633533b..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/l1_operation.ml +++ /dev/null @@ -1,182 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -open Protocol.Alpha_context - -type t = - | Add_messages of {messages : string list} - | Cement of {rollup : Sc_rollup.t; commitment : Sc_rollup.Commitment.Hash.t} - | Publish of {rollup : Sc_rollup.t; commitment : Sc_rollup.Commitment.t} - | Refute of { - rollup : Sc_rollup.t; - opponent : Sc_rollup.Staker.t; - refutation : Sc_rollup.Game.refutation; - } - | Timeout of {rollup : Sc_rollup.t; stakers : Sc_rollup.Game.Index.t} - -let encoding : t Data_encoding.t = - let open Data_encoding in - let case tag kind encoding proj inj = - case - ~title:kind - (Tag tag) - (merge_objs (obj1 (req "kind" (constant kind))) encoding) - (fun o -> Option.map (fun p -> ((), p)) (proj o)) - (fun ((), p) -> inj p) - in - def "sc_rollup_node_l1_operation" - @@ union - [ - case - 0 - "add_messages" - (obj1 (req "message" (list (string' Hex)))) - (function Add_messages {messages} -> Some messages | _ -> None) - (fun messages -> Add_messages {messages}); - case - 1 - "cement" - (obj2 - (req "rollup" Sc_rollup.Address.encoding) - (req "commitment" Sc_rollup.Commitment.Hash.encoding)) - (function - | Cement {rollup; commitment} -> Some (rollup, commitment) - | _ -> None) - (fun (rollup, commitment) -> Cement {rollup; commitment}); - case - 2 - "publish" - (obj2 - (req "rollup" Sc_rollup.Address.encoding) - (req "commitment" Sc_rollup.Commitment.encoding)) - (function - | Publish {rollup; commitment} -> Some (rollup, commitment) - | _ -> None) - (fun (rollup, commitment) -> Publish {rollup; commitment}); - case - 3 - "refute" - (obj3 - (req "rollup" Sc_rollup.Address.encoding) - (req "opponent" Sc_rollup.Staker.encoding) - (req "refutation" Sc_rollup.Game.refutation_encoding)) - (function - | Refute {rollup; opponent; refutation} -> - Some (rollup, opponent, refutation) - | _ -> None) - (fun (rollup, opponent, refutation) -> - Refute {rollup; opponent; refutation}); - case - 4 - "timeout" - (obj2 - (req "rollup" Sc_rollup.Address.encoding) - (req "stakers" Sc_rollup.Game.Index.encoding)) - (function - | Timeout {rollup; stakers} -> Some (rollup, stakers) | _ -> None) - (fun (rollup, stakers) -> Timeout {rollup; stakers}); - ] - -let pp ppf = function - | Add_messages {messages} -> - Format.fprintf - ppf - "publishing %d messages to smart rollups' inbox" - (List.length messages) - | Cement {rollup = _; commitment} -> - Format.fprintf - ppf - "cementing commitment %a" - Sc_rollup.Commitment.Hash.pp - commitment - | Publish {rollup = _; commitment = Sc_rollup.Commitment.{inbox_level; _}} -> - Format.fprintf - ppf - "publish commitment for level %a" - Raw_level.pp - inbox_level - | Refute {rollup = _; opponent; refutation = Start _} -> - Format.fprintf - ppf - "start refutation game against %a" - Signature.Public_key_hash.pp - opponent - | Refute - { - rollup = _; - opponent; - refutation = Move {step = Dissection (first :: _ as d); _}; - } -> - let last = List.last first d in - Format.fprintf - ppf - "dissection between ticks %a and %a (against %a)" - Sc_rollup.Tick.pp - first.tick - Sc_rollup.Tick.pp - last.tick - Signature.Public_key_hash.pp - opponent - | Refute {rollup = _; opponent; refutation = Move {step = Dissection []; _}} - -> - Format.fprintf - ppf - "dissection (against %a)" - Signature.Public_key_hash.pp - opponent - | Refute {rollup = _; opponent; refutation = Move {choice; step = Proof _}} -> - Format.fprintf - ppf - "proof for tick %a (against %a)" - Sc_rollup.Tick.pp - choice - Signature.Public_key_hash.pp - opponent - | Timeout {rollup = _; stakers = _} -> Format.fprintf ppf "timeout" - -let to_manager_operation : t -> packed_manager_operation = function - | Add_messages {messages} -> Manager (Sc_rollup_add_messages {messages}) - | Cement {rollup; commitment} -> - Manager (Sc_rollup_cement {rollup; commitment}) - | Publish {rollup; commitment} -> - Manager (Sc_rollup_publish {rollup; commitment}) - | Refute {rollup; opponent; refutation} -> - Manager (Sc_rollup_refute {rollup; opponent; refutation}) - | Timeout {rollup; stakers} -> Manager (Sc_rollup_timeout {rollup; stakers}) - -let of_manager_operation : type kind. kind manager_operation -> t option = - function - | Sc_rollup_add_messages {messages} -> Some (Add_messages {messages}) - | Sc_rollup_cement {rollup; commitment} -> Some (Cement {rollup; commitment}) - | Sc_rollup_publish {rollup; commitment} -> - Some (Publish {rollup; commitment}) - | Sc_rollup_refute {rollup; opponent; refutation} -> - Some (Refute {rollup; opponent; refutation}) - | Sc_rollup_timeout {rollup; stakers} -> Some (Timeout {rollup; stakers}) - | _ -> None - -let unique = function - | Add_messages _ -> false - | Cement _ | Publish _ | Refute _ | Timeout _ -> true diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/l1_operation.mli b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/l1_operation.mli deleted file mode 100644 index 953cd6f7fb5ee45675058819e90596711672bc56..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/l1_operation.mli +++ /dev/null @@ -1,53 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -open Protocol.Alpha_context - -(** L1 operations produced (and injected) by the rollup node. *) -type t = - | Add_messages of {messages : string list} - | Cement of {rollup : Sc_rollup.t; commitment : Sc_rollup.Commitment.Hash.t} - | Publish of {rollup : Sc_rollup.t; commitment : Sc_rollup.Commitment.t} - | Refute of { - rollup : Sc_rollup.t; - opponent : Sc_rollup.Staker.t; - refutation : Sc_rollup.Game.refutation; - } - | Timeout of {rollup : Sc_rollup.t; stakers : Sc_rollup.Game.Index.t} - -(** Encoding for L1 operations (used by injector for on-disk persistence). *) -val encoding : t Data_encoding.t - -(** Manager operation for a given L1 operation. *) -val to_manager_operation : t -> packed_manager_operation - -(** L1 operation corresponding to a manager operation if any. *) -val of_manager_operation : 'a manager_operation -> t option - -(** Pretty printer (human readable) for L1 operations. *) -val pp : Format.formatter -> t -> unit - -(** [false] if the injector will accept duplicate such operations. *) -val unique : t -> bool diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml index 7782ae1722f451cb094ea1ab8e8215979a17be60..3077c3dcde6d487ee3e2997e6187016af42b1628 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml @@ -600,7 +600,16 @@ let run node_ctxt configuration unless (signers = []) @@ fun () -> Injector.init node_ctxt.cctxt - (Node_context.readonly node_ctxt) + { + cctxt = (node_ctxt.cctxt :> Client_context.full); + fee_parameters = configuration.fee_parameters; + minimal_block_delay = + node_ctxt.protocol_constants.Constants.parametric + .minimal_block_delay |> Period.to_seconds; + delay_increment_per_round = + node_ctxt.protocol_constants.Constants.parametric + .delay_increment_per_round |> Period.to_seconds; + } ~data_dir:node_ctxt.data_dir ~signers ~retention_period:configuration.injector.retention_period diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon_event.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon_event.ml index 700fb8e63867917938aca6f66ebfbd4260f60a3c..2969126bcaabe2c9bf31d2d9030529bb9a2c8081 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon_event.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon_event.ml @@ -149,7 +149,7 @@ let new_heads_processed = new_heads_iteration Simple.new_heads_processed let included_operation (type kind) (operation : kind Protocol.Alpha_context.manager_operation) (result : kind Protocol.Apply_results.manager_operation_result) = - match L1_operation.of_manager_operation operation with + match Sc_rollup_injector.injector_operation_of_manager operation with | None -> Lwt.return_unit | Some operation -> ( match result with diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/dune b/src/proto_016_PtMumbai/lib_sc_rollup_node/dune index 1a64e326ab74c53b49216a3792dc595be7b1cdb9..f2c0eedf96e747877ffbcf05da9b9d4b347ffc37 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/dune +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/dune @@ -23,6 +23,7 @@ tezos-dal-node-services tezos-dal-node-lib tezos-shell-services + octez-smart-rollup tezos-smart-rollup-016-PtMumbai tezos-smart-rollup-layer2-016-PtMumbai tezos-layer2-utils-016-PtMumbai @@ -56,6 +57,7 @@ -open Tezos_workers -open Tezos_dal_node_lib -open Tezos_shell_services + -open Octez_smart_rollup -open Tezos_smart_rollup_016_PtMumbai -open Tezos_smart_rollup_layer2_016_PtMumbai -open Tezos_layer2_utils_016_PtMumbai diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml index 69a87e1b2d599b94889ffef119d1e91c41e6ea8a..4af400c134b80dc24bb28c3bbd5892b389a6cc5b 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml @@ -294,8 +294,7 @@ let init (cctxt : Protocol_client_context.full) ~data_dir ?log_kernel_debug_file let*? () = check_config configuration in let rollup_address = (* Convert to protocol rollup address *) - Tezos_crypto.Hashed.Smart_rollup_address.to_bytes rollup_address - |> Protocol.Alpha_context.Sc_rollup.Address.of_bytes_exn + Sc_rollup_proto_types.Address.of_octez rollup_address in let* lockfile = lock ~data_dir in let* () = diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/publisher.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/publisher.ml index 7265d13488f51e75c4f69a48e6389089ef83fc31..96274d64f95c759ae8b7559ffe013153936f4606 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/publisher.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/publisher.ml @@ -271,7 +271,11 @@ let publish_commitment (node_ctxt : _ Node_context.t) ~source (commitment : Sc_rollup.Commitment.t) = let open Lwt_result_syntax in let publish_operation = - L1_operation.Publish {rollup = node_ctxt.rollup_address; commitment} + L1_operation.Publish + { + rollup = Sc_rollup_proto_types.Address.to_octez node_ctxt.rollup_address; + commitment = Sc_rollup_proto_types.Commitment.to_octez commitment; + } in let*! () = Commitment_event.publish_commitment @@ -404,7 +408,11 @@ let cement_commitment (node_ctxt : _ Node_context.t) ~source commitment_hash = let open Lwt_result_syntax in let cement_operation = L1_operation.Cement - {rollup = node_ctxt.rollup_address; commitment = commitment_hash} + { + rollup = Sc_rollup_proto_types.Address.to_octez node_ctxt.rollup_address; + commitment = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash; + } in let* _hash = Injector.add_pending_operation ~source cement_operation in return_unit diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game.ml index 04948c246cf495b41a5dd9eeef92e74ce3bc4596..e72c67e08c98bce6725443f118ea63c48296f877 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game.ml @@ -70,7 +70,13 @@ let inject_next_move node_ctxt source ~refutation ~opponent = let open Lwt_result_syntax in let refute_operation = L1_operation.Refute - {rollup = node_ctxt.Node_context.rollup_address; refutation; opponent} + { + rollup = + Sc_rollup_proto_types.Address.to_octez + node_ctxt.Node_context.rollup_address; + refutation = Sc_rollup_proto_types.Game.refutation_to_octez refutation; + opponent; + } in let* _hash = Injector.add_pending_operation ~source refute_operation in return_unit @@ -444,7 +450,11 @@ let play_next_move node_ctxt game self opponent = let play_timeout (node_ctxt : _ Node_context.t) self stakers = let open Lwt_result_syntax in let timeout_operation = - L1_operation.Timeout {rollup = node_ctxt.rollup_address; stakers} + L1_operation.Timeout + { + rollup = Sc_rollup_proto_types.Address.to_octez node_ctxt.rollup_address; + stakers = Sc_rollup_proto_types.Game.index_to_octez stakers; + } in let source = Node_context.get_operator node_ctxt Timeout |> Option.value ~default:self diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/injector.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/sc_rollup_injector.ml similarity index 76% rename from src/proto_017_PtNairob/lib_sc_rollup_node/injector.ml rename to src/proto_016_PtMumbai/lib_sc_rollup_node/sc_rollup_injector.ml index c239e844e72bed6715efb7344785a470d06e79da..1e60a17330cd7db216fdfab23f9584d7b70768cd 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/injector.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/sc_rollup_injector.ml @@ -31,103 +31,63 @@ module Block_cache = Aches_lwt.Lache.Make_result (Aches.Rache.Transfer (Aches.Rache.LRU) (Block_hash)) -module Parameters : - PARAMETERS - with type state = Node_context.ro - and type Tag.t = Configuration.purpose - and type Operation.t = L1_operation.t = struct - type state = Node_context.ro - - let events_section = [Protocol.name; "sc_rollup_node"] - - module Tag : TAG with type t = Configuration.purpose = struct - type t = Configuration.purpose - - let compare = Stdlib.compare - - let equal = Stdlib.( = ) - - let hash = Hashtbl.hash - - let string_of_tag = Configuration.string_of_purpose - - let pp ppf t = Format.pp_print_string ppf (string_of_tag t) - - let encoding : t Data_encoding.t = - let open Data_encoding in - string_enum - (List.map (fun t -> (string_of_tag t, t)) Configuration.purposes) - end - - module Operation = L1_operation - - (* TODO: https://gitlab.com/tezos/tezos/-/issues/3459 - Very coarse approximation for the number of operation we - expect for each block *) - let table_estimated_size : Tag.t -> int = function - | Publish -> 1 - | Add_messages -> 100 - | Cement -> 1 - | Timeout -> 1 - | Refute -> 1 - - let operation_tag : Operation.t -> Tag.t = function - | Add_messages _ -> Add_messages - | Cement _ -> Cement - | Publish _ -> Publish - | Timeout _ -> Timeout - | Refute _ -> Refute - - let fee_parameter node_ctxt operation = - Node_context.get_fee_parameter node_ctxt (operation_tag operation) - - (* TODO: https://gitlab.com/tezos/tezos/-/issues/3459 - Decide if some batches must have all the operations succeed. See - {!Injector_sigs.Parameter.batch_must_succeed}. *) - let batch_must_succeed _ = `At_least_one - - let retry_unsuccessful_operation _node_ctxt (_op : Operation.t) status = - let open Lwt_syntax in - match status with - | Backtracked | Skipped | Other_branch -> - (* Always retry backtracked or skipped operations, or operations that - are on another branch because of a reorg: - - - Commitments are always produced on finalized blocks. They don't - need to be recomputed, and as such are valid in another branch. - - - The cementation operations should be re-injected because the node - only keeps track of the last cemented level and the last published - commitment, without rollbacks. - - - Messages posted to an inbox should be re-emitted (i.e. re-queued) - in case of a fork. - - - Timeout should be re-submitted as the timeout may be reached as well - on the other branch. - - - Refutation should be re-submitted in case of fork. - TODO: https://gitlab.com/tezos/tezos/-/issues/3459 - maybe check if game exists on other branch as well. - *) - return Retry - | Failed error -> ( - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4071 - Think about which operations should be retried and when. *) - match classify_trace error with - | Permanent | Outdated -> return Forget - | Branch | Temporary -> return Retry) - | Never_included -> - (* Forget operations that are never included *) - return Forget -end +let injector_operation_to_manager : + L1_operation.t -> Protocol.Alpha_context.packed_manager_operation = function + | Add_messages {messages} -> Manager (Sc_rollup_add_messages {messages}) + | Cement {rollup; commitment} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let commitment = + Sc_rollup_proto_types.Commitment_hash.of_octez commitment + in + Manager (Sc_rollup_cement {rollup; commitment}) + | Publish {rollup; commitment} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let commitment = Sc_rollup_proto_types.Commitment.of_octez commitment in + Manager (Sc_rollup_publish {rollup; commitment}) + | Refute {rollup; opponent; refutation} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let refutation = + Sc_rollup_proto_types.Game.refutation_of_octez refutation + in + Manager (Sc_rollup_refute {rollup; opponent; refutation}) + | Timeout {rollup; stakers} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let stakers = Sc_rollup_proto_types.Game.index_of_octez stakers in + Manager (Sc_rollup_timeout {rollup; stakers}) + +let injector_operation_of_manager : + type kind. + kind Protocol.Alpha_context.manager_operation -> L1_operation.t option = + function + | Sc_rollup_add_messages {messages} -> Some (Add_messages {messages}) + | Sc_rollup_cement {rollup; commitment} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let commitment = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment + in + Some (Cement {rollup; commitment}) + | Sc_rollup_publish {rollup; commitment} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let commitment = Sc_rollup_proto_types.Commitment.to_octez commitment in + Some (Publish {rollup; commitment}) + | Sc_rollup_refute {rollup; opponent; refutation} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let refutation = + Sc_rollup_proto_types.Game.refutation_to_octez refutation + in + Some (Refute {rollup; opponent; refutation}) + | Sc_rollup_timeout {rollup; stakers} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let stakers = Sc_rollup_proto_types.Game.index_to_octez stakers in + Some (Timeout {rollup; stakers}) + | _ -> None module Proto_client = struct open Protocol_client_context - type operation = Parameters.Operation.t + type operation = L1_operation.t - type state = Parameters.state + type state = Injector.state type unsigned_operation = Tezos_base.Operation.shell_header * packed_contents_list @@ -151,7 +111,7 @@ module Proto_client = struct Data_encoding.Binary.length Operation.contents_encoding (Contents contents) let operation_size op = - manager_operation_size (L1_operation.to_manager_operation op) + manager_operation_size (injector_operation_to_manager op) (* The operation size overhead is an upper bound (in practice) of the overhead that will be added to a manager operation. To compute it we can use any @@ -259,10 +219,9 @@ module Proto_client = struct operations) Lwt.return - let operation_status (node_ctxt : Node_context.ro) block_hash operation_hash - ~index = + let operation_status {Injector.cctxt; _} block_hash operation_hash ~index = let open Lwt_result_syntax in - let* operations = get_block_operations node_ctxt.cctxt block_hash in + let* operations = get_block_operations cctxt block_hash in match Operation_hash.Map.find_opt operation_hash operations with | None -> return_none | Some operation -> ( @@ -300,9 +259,7 @@ module Proto_client = struct let annotated_operations = List.map (fun operation -> - let (Manager operation) = - L1_operation.to_manager_operation operation - in + let (Manager operation) = injector_operation_to_manager operation in Annotated_manager_operation (Injection.prepare_manager_operation ~fee:Limit.unknown @@ -397,18 +354,17 @@ module Proto_client = struct in Data_encoding.Binary.to_bytes_exn Operation.encoding op - let time_until_next_block (node_ctxt : Node_context.ro) + let time_until_next_block + {Injector.minimal_block_delay; delay_increment_per_round; _} (header : Tezos_base.Block_header.shell_header option) = let open Result_syntax in - let Constants.Parametric.{minimal_block_delay; delay_increment_per_round; _} - = - node_ctxt.protocol_constants.Constants.parametric - in match header with - | None -> - minimal_block_delay |> Period.to_seconds |> Int64.to_int - |> Ptime.Span.of_int_s + | None -> minimal_block_delay |> Int64.to_int |> Ptime.Span.of_int_s | Some header -> + let minimal_block_delay = Period.of_seconds_exn minimal_block_delay in + let delay_increment_per_round = + Period.of_seconds_exn delay_increment_per_round + in let next_level_timestamp = let* durations = Round.Durations.create @@ -435,6 +391,4 @@ module Proto_client = struct (Time.System.now ()) end -include Injector_functor.Make (Parameters) - -let () = register_proto_client Protocol.hash (module Proto_client) +let () = Injector.register_proto_client Protocol.hash (module Proto_client) diff --git a/src/proto_alpha/lib_sc_rollup_node/injector.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/sc_rollup_injector.mli similarity index 85% rename from src/proto_alpha/lib_sc_rollup_node/injector.mli rename to src/proto_016_PtMumbai/lib_sc_rollup_node/sc_rollup_injector.mli index 0f3db24e434eeded77d995b2d9125bb5dfab40b5..ca4112313ef6449d4ec20d700049ae0d28263944 100644 --- a/src/proto_alpha/lib_sc_rollup_node/injector.mli +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/sc_rollup_injector.mli @@ -23,8 +23,10 @@ (* *) (*****************************************************************************) -include - Injector_sigs.S - with type state := Node_context.ro - and type tag := Configuration.purpose - and type operation := L1_operation.t +(** Manager operation for a given L1 operation. *) +val injector_operation_to_manager : + L1_operation.t -> Protocol.Alpha_context.packed_manager_operation + +(** L1 operation corresponding to a manager operation if any. *) +val injector_operation_of_manager : + 'a Protocol.Alpha_context.manager_operation -> L1_operation.t option diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/dune b/src/proto_017_PtNairob/lib_sc_rollup_layer2/dune index 843a6cb7a85739c8ba69dc8ec50ff9967eaa2958..d46af7ecfe09f7e49fe605b665442bd442f4d15e 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/dune +++ b/src/proto_017_PtNairob/lib_sc_rollup_layer2/dune @@ -17,4 +17,5 @@ (:standard) -open Tezos_base.TzPervasives -open Tezos_protocol_017_PtNairob - -open Octez_injector)) + -open Octez_injector + -open Octez_smart_rollup)) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/l1_operation.ml b/src/proto_017_PtNairob/lib_sc_rollup_layer2/l1_operation.ml deleted file mode 100644 index 686d7927381163e753afcbafee3af4459633533b..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/l1_operation.ml +++ /dev/null @@ -1,182 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -open Protocol.Alpha_context - -type t = - | Add_messages of {messages : string list} - | Cement of {rollup : Sc_rollup.t; commitment : Sc_rollup.Commitment.Hash.t} - | Publish of {rollup : Sc_rollup.t; commitment : Sc_rollup.Commitment.t} - | Refute of { - rollup : Sc_rollup.t; - opponent : Sc_rollup.Staker.t; - refutation : Sc_rollup.Game.refutation; - } - | Timeout of {rollup : Sc_rollup.t; stakers : Sc_rollup.Game.Index.t} - -let encoding : t Data_encoding.t = - let open Data_encoding in - let case tag kind encoding proj inj = - case - ~title:kind - (Tag tag) - (merge_objs (obj1 (req "kind" (constant kind))) encoding) - (fun o -> Option.map (fun p -> ((), p)) (proj o)) - (fun ((), p) -> inj p) - in - def "sc_rollup_node_l1_operation" - @@ union - [ - case - 0 - "add_messages" - (obj1 (req "message" (list (string' Hex)))) - (function Add_messages {messages} -> Some messages | _ -> None) - (fun messages -> Add_messages {messages}); - case - 1 - "cement" - (obj2 - (req "rollup" Sc_rollup.Address.encoding) - (req "commitment" Sc_rollup.Commitment.Hash.encoding)) - (function - | Cement {rollup; commitment} -> Some (rollup, commitment) - | _ -> None) - (fun (rollup, commitment) -> Cement {rollup; commitment}); - case - 2 - "publish" - (obj2 - (req "rollup" Sc_rollup.Address.encoding) - (req "commitment" Sc_rollup.Commitment.encoding)) - (function - | Publish {rollup; commitment} -> Some (rollup, commitment) - | _ -> None) - (fun (rollup, commitment) -> Publish {rollup; commitment}); - case - 3 - "refute" - (obj3 - (req "rollup" Sc_rollup.Address.encoding) - (req "opponent" Sc_rollup.Staker.encoding) - (req "refutation" Sc_rollup.Game.refutation_encoding)) - (function - | Refute {rollup; opponent; refutation} -> - Some (rollup, opponent, refutation) - | _ -> None) - (fun (rollup, opponent, refutation) -> - Refute {rollup; opponent; refutation}); - case - 4 - "timeout" - (obj2 - (req "rollup" Sc_rollup.Address.encoding) - (req "stakers" Sc_rollup.Game.Index.encoding)) - (function - | Timeout {rollup; stakers} -> Some (rollup, stakers) | _ -> None) - (fun (rollup, stakers) -> Timeout {rollup; stakers}); - ] - -let pp ppf = function - | Add_messages {messages} -> - Format.fprintf - ppf - "publishing %d messages to smart rollups' inbox" - (List.length messages) - | Cement {rollup = _; commitment} -> - Format.fprintf - ppf - "cementing commitment %a" - Sc_rollup.Commitment.Hash.pp - commitment - | Publish {rollup = _; commitment = Sc_rollup.Commitment.{inbox_level; _}} -> - Format.fprintf - ppf - "publish commitment for level %a" - Raw_level.pp - inbox_level - | Refute {rollup = _; opponent; refutation = Start _} -> - Format.fprintf - ppf - "start refutation game against %a" - Signature.Public_key_hash.pp - opponent - | Refute - { - rollup = _; - opponent; - refutation = Move {step = Dissection (first :: _ as d); _}; - } -> - let last = List.last first d in - Format.fprintf - ppf - "dissection between ticks %a and %a (against %a)" - Sc_rollup.Tick.pp - first.tick - Sc_rollup.Tick.pp - last.tick - Signature.Public_key_hash.pp - opponent - | Refute {rollup = _; opponent; refutation = Move {step = Dissection []; _}} - -> - Format.fprintf - ppf - "dissection (against %a)" - Signature.Public_key_hash.pp - opponent - | Refute {rollup = _; opponent; refutation = Move {choice; step = Proof _}} -> - Format.fprintf - ppf - "proof for tick %a (against %a)" - Sc_rollup.Tick.pp - choice - Signature.Public_key_hash.pp - opponent - | Timeout {rollup = _; stakers = _} -> Format.fprintf ppf "timeout" - -let to_manager_operation : t -> packed_manager_operation = function - | Add_messages {messages} -> Manager (Sc_rollup_add_messages {messages}) - | Cement {rollup; commitment} -> - Manager (Sc_rollup_cement {rollup; commitment}) - | Publish {rollup; commitment} -> - Manager (Sc_rollup_publish {rollup; commitment}) - | Refute {rollup; opponent; refutation} -> - Manager (Sc_rollup_refute {rollup; opponent; refutation}) - | Timeout {rollup; stakers} -> Manager (Sc_rollup_timeout {rollup; stakers}) - -let of_manager_operation : type kind. kind manager_operation -> t option = - function - | Sc_rollup_add_messages {messages} -> Some (Add_messages {messages}) - | Sc_rollup_cement {rollup; commitment} -> Some (Cement {rollup; commitment}) - | Sc_rollup_publish {rollup; commitment} -> - Some (Publish {rollup; commitment}) - | Sc_rollup_refute {rollup; opponent; refutation} -> - Some (Refute {rollup; opponent; refutation}) - | Sc_rollup_timeout {rollup; stakers} -> Some (Timeout {rollup; stakers}) - | _ -> None - -let unique = function - | Add_messages _ -> false - | Cement _ | Publish _ | Refute _ | Timeout _ -> true diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/l1_operation.mli b/src/proto_017_PtNairob/lib_sc_rollup_layer2/l1_operation.mli deleted file mode 100644 index 953cd6f7fb5ee45675058819e90596711672bc56..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/l1_operation.mli +++ /dev/null @@ -1,53 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -open Protocol.Alpha_context - -(** L1 operations produced (and injected) by the rollup node. *) -type t = - | Add_messages of {messages : string list} - | Cement of {rollup : Sc_rollup.t; commitment : Sc_rollup.Commitment.Hash.t} - | Publish of {rollup : Sc_rollup.t; commitment : Sc_rollup.Commitment.t} - | Refute of { - rollup : Sc_rollup.t; - opponent : Sc_rollup.Staker.t; - refutation : Sc_rollup.Game.refutation; - } - | Timeout of {rollup : Sc_rollup.t; stakers : Sc_rollup.Game.Index.t} - -(** Encoding for L1 operations (used by injector for on-disk persistence). *) -val encoding : t Data_encoding.t - -(** Manager operation for a given L1 operation. *) -val to_manager_operation : t -> packed_manager_operation - -(** L1 operation corresponding to a manager operation if any. *) -val of_manager_operation : 'a manager_operation -> t option - -(** Pretty printer (human readable) for L1 operations. *) -val pp : Format.formatter -> t -> unit - -(** [false] if the injector will accept duplicate such operations. *) -val unique : t -> bool diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml index 1a80d45dfb07178880396d2918650fd8ed34638f..1b5a066383515897e9e2142be0ca20a2c654fe49 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml @@ -593,7 +593,16 @@ let run node_ctxt configuration unless (signers = []) @@ fun () -> Injector.init node_ctxt.cctxt - (Node_context.readonly node_ctxt) + { + cctxt = (node_ctxt.cctxt :> Client_context.full); + fee_parameters = configuration.fee_parameters; + minimal_block_delay = + node_ctxt.protocol_constants.Constants.parametric + .minimal_block_delay |> Period.to_seconds; + delay_increment_per_round = + node_ctxt.protocol_constants.Constants.parametric + .delay_increment_per_round |> Period.to_seconds; + } ~data_dir:node_ctxt.data_dir ~signers ~retention_period:configuration.injector.retention_period diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_event.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_event.ml index 700fb8e63867917938aca6f66ebfbd4260f60a3c..2969126bcaabe2c9bf31d2d9030529bb9a2c8081 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_event.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_event.ml @@ -149,7 +149,7 @@ let new_heads_processed = new_heads_iteration Simple.new_heads_processed let included_operation (type kind) (operation : kind Protocol.Alpha_context.manager_operation) (result : kind Protocol.Apply_results.manager_operation_result) = - match L1_operation.of_manager_operation operation with + match Sc_rollup_injector.injector_operation_of_manager operation with | None -> Lwt.return_unit | Some operation -> ( match result with diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/dune b/src/proto_017_PtNairob/lib_sc_rollup_node/dune index 62c12fad9c09d6bca85efa3278c9961a7cfedf8e..6eeca21991dfd29054f9689b4fe1d2a45e737406 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/dune +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/dune @@ -23,6 +23,7 @@ tezos-dal-node-services tezos-dal-node-lib tezos-shell-services + octez-smart-rollup tezos-smart-rollup-017-PtNairob tezos-smart-rollup-layer2-017-PtNairob tezos-layer2-utils-017-PtNairob @@ -56,6 +57,7 @@ -open Tezos_workers -open Tezos_dal_node_lib -open Tezos_shell_services + -open Octez_smart_rollup -open Tezos_smart_rollup_017_PtNairob -open Tezos_smart_rollup_layer2_017_PtNairob -open Tezos_layer2_utils_017_PtNairob diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml index fa06ce3e7861f3118e9eff14d5a72efad933b5ad..8b7acd4d6cd574d71159923dcbe962085efa3030 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml @@ -294,8 +294,7 @@ let init (cctxt : Protocol_client_context.full) ~data_dir ?log_kernel_debug_file let*? () = check_config configuration in let rollup_address = (* Convert to protocol rollup address *) - Tezos_crypto.Hashed.Smart_rollup_address.to_bytes rollup_address - |> Protocol.Alpha_context.Sc_rollup.Address.of_bytes_exn + Sc_rollup_proto_types.Address.of_octez rollup_address in let* lockfile = lock ~data_dir in let* () = diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/publisher.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/publisher.ml index 7265d13488f51e75c4f69a48e6389089ef83fc31..96274d64f95c759ae8b7559ffe013153936f4606 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/publisher.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/publisher.ml @@ -271,7 +271,11 @@ let publish_commitment (node_ctxt : _ Node_context.t) ~source (commitment : Sc_rollup.Commitment.t) = let open Lwt_result_syntax in let publish_operation = - L1_operation.Publish {rollup = node_ctxt.rollup_address; commitment} + L1_operation.Publish + { + rollup = Sc_rollup_proto_types.Address.to_octez node_ctxt.rollup_address; + commitment = Sc_rollup_proto_types.Commitment.to_octez commitment; + } in let*! () = Commitment_event.publish_commitment @@ -404,7 +408,11 @@ let cement_commitment (node_ctxt : _ Node_context.t) ~source commitment_hash = let open Lwt_result_syntax in let cement_operation = L1_operation.Cement - {rollup = node_ctxt.rollup_address; commitment = commitment_hash} + { + rollup = Sc_rollup_proto_types.Address.to_octez node_ctxt.rollup_address; + commitment = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash; + } in let* _hash = Injector.add_pending_operation ~source cement_operation in return_unit diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game.ml index 7bef664b97a1f42bd8844cc3992d3ac6cb569fb3..893bee817a0a98cdf7898b65d6ca5d24b0622187 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game.ml @@ -70,7 +70,13 @@ let inject_next_move node_ctxt source ~refutation ~opponent = let open Lwt_result_syntax in let refute_operation = L1_operation.Refute - {rollup = node_ctxt.Node_context.rollup_address; refutation; opponent} + { + rollup = + Sc_rollup_proto_types.Address.to_octez + node_ctxt.Node_context.rollup_address; + refutation = Sc_rollup_proto_types.Game.refutation_to_octez refutation; + opponent; + } in let* _hash = Injector.add_pending_operation ~source refute_operation in return_unit @@ -444,7 +450,11 @@ let play_next_move node_ctxt game self opponent = let play_timeout (node_ctxt : _ Node_context.t) self stakers = let open Lwt_result_syntax in let timeout_operation = - L1_operation.Timeout {rollup = node_ctxt.rollup_address; stakers} + L1_operation.Timeout + { + rollup = Sc_rollup_proto_types.Address.to_octez node_ctxt.rollup_address; + stakers = Sc_rollup_proto_types.Game.index_to_octez stakers; + } in let source = Node_context.get_operator node_ctxt Timeout |> Option.value ~default:self diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/injector.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml similarity index 76% rename from src/proto_016_PtMumbai/lib_sc_rollup_node/injector.ml rename to src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml index c239e844e72bed6715efb7344785a470d06e79da..1e60a17330cd7db216fdfab23f9584d7b70768cd 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/injector.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml @@ -31,103 +31,63 @@ module Block_cache = Aches_lwt.Lache.Make_result (Aches.Rache.Transfer (Aches.Rache.LRU) (Block_hash)) -module Parameters : - PARAMETERS - with type state = Node_context.ro - and type Tag.t = Configuration.purpose - and type Operation.t = L1_operation.t = struct - type state = Node_context.ro - - let events_section = [Protocol.name; "sc_rollup_node"] - - module Tag : TAG with type t = Configuration.purpose = struct - type t = Configuration.purpose - - let compare = Stdlib.compare - - let equal = Stdlib.( = ) - - let hash = Hashtbl.hash - - let string_of_tag = Configuration.string_of_purpose - - let pp ppf t = Format.pp_print_string ppf (string_of_tag t) - - let encoding : t Data_encoding.t = - let open Data_encoding in - string_enum - (List.map (fun t -> (string_of_tag t, t)) Configuration.purposes) - end - - module Operation = L1_operation - - (* TODO: https://gitlab.com/tezos/tezos/-/issues/3459 - Very coarse approximation for the number of operation we - expect for each block *) - let table_estimated_size : Tag.t -> int = function - | Publish -> 1 - | Add_messages -> 100 - | Cement -> 1 - | Timeout -> 1 - | Refute -> 1 - - let operation_tag : Operation.t -> Tag.t = function - | Add_messages _ -> Add_messages - | Cement _ -> Cement - | Publish _ -> Publish - | Timeout _ -> Timeout - | Refute _ -> Refute - - let fee_parameter node_ctxt operation = - Node_context.get_fee_parameter node_ctxt (operation_tag operation) - - (* TODO: https://gitlab.com/tezos/tezos/-/issues/3459 - Decide if some batches must have all the operations succeed. See - {!Injector_sigs.Parameter.batch_must_succeed}. *) - let batch_must_succeed _ = `At_least_one - - let retry_unsuccessful_operation _node_ctxt (_op : Operation.t) status = - let open Lwt_syntax in - match status with - | Backtracked | Skipped | Other_branch -> - (* Always retry backtracked or skipped operations, or operations that - are on another branch because of a reorg: - - - Commitments are always produced on finalized blocks. They don't - need to be recomputed, and as such are valid in another branch. - - - The cementation operations should be re-injected because the node - only keeps track of the last cemented level and the last published - commitment, without rollbacks. - - - Messages posted to an inbox should be re-emitted (i.e. re-queued) - in case of a fork. - - - Timeout should be re-submitted as the timeout may be reached as well - on the other branch. - - - Refutation should be re-submitted in case of fork. - TODO: https://gitlab.com/tezos/tezos/-/issues/3459 - maybe check if game exists on other branch as well. - *) - return Retry - | Failed error -> ( - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4071 - Think about which operations should be retried and when. *) - match classify_trace error with - | Permanent | Outdated -> return Forget - | Branch | Temporary -> return Retry) - | Never_included -> - (* Forget operations that are never included *) - return Forget -end +let injector_operation_to_manager : + L1_operation.t -> Protocol.Alpha_context.packed_manager_operation = function + | Add_messages {messages} -> Manager (Sc_rollup_add_messages {messages}) + | Cement {rollup; commitment} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let commitment = + Sc_rollup_proto_types.Commitment_hash.of_octez commitment + in + Manager (Sc_rollup_cement {rollup; commitment}) + | Publish {rollup; commitment} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let commitment = Sc_rollup_proto_types.Commitment.of_octez commitment in + Manager (Sc_rollup_publish {rollup; commitment}) + | Refute {rollup; opponent; refutation} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let refutation = + Sc_rollup_proto_types.Game.refutation_of_octez refutation + in + Manager (Sc_rollup_refute {rollup; opponent; refutation}) + | Timeout {rollup; stakers} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let stakers = Sc_rollup_proto_types.Game.index_of_octez stakers in + Manager (Sc_rollup_timeout {rollup; stakers}) + +let injector_operation_of_manager : + type kind. + kind Protocol.Alpha_context.manager_operation -> L1_operation.t option = + function + | Sc_rollup_add_messages {messages} -> Some (Add_messages {messages}) + | Sc_rollup_cement {rollup; commitment} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let commitment = + Sc_rollup_proto_types.Commitment_hash.to_octez commitment + in + Some (Cement {rollup; commitment}) + | Sc_rollup_publish {rollup; commitment} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let commitment = Sc_rollup_proto_types.Commitment.to_octez commitment in + Some (Publish {rollup; commitment}) + | Sc_rollup_refute {rollup; opponent; refutation} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let refutation = + Sc_rollup_proto_types.Game.refutation_to_octez refutation + in + Some (Refute {rollup; opponent; refutation}) + | Sc_rollup_timeout {rollup; stakers} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let stakers = Sc_rollup_proto_types.Game.index_to_octez stakers in + Some (Timeout {rollup; stakers}) + | _ -> None module Proto_client = struct open Protocol_client_context - type operation = Parameters.Operation.t + type operation = L1_operation.t - type state = Parameters.state + type state = Injector.state type unsigned_operation = Tezos_base.Operation.shell_header * packed_contents_list @@ -151,7 +111,7 @@ module Proto_client = struct Data_encoding.Binary.length Operation.contents_encoding (Contents contents) let operation_size op = - manager_operation_size (L1_operation.to_manager_operation op) + manager_operation_size (injector_operation_to_manager op) (* The operation size overhead is an upper bound (in practice) of the overhead that will be added to a manager operation. To compute it we can use any @@ -259,10 +219,9 @@ module Proto_client = struct operations) Lwt.return - let operation_status (node_ctxt : Node_context.ro) block_hash operation_hash - ~index = + let operation_status {Injector.cctxt; _} block_hash operation_hash ~index = let open Lwt_result_syntax in - let* operations = get_block_operations node_ctxt.cctxt block_hash in + let* operations = get_block_operations cctxt block_hash in match Operation_hash.Map.find_opt operation_hash operations with | None -> return_none | Some operation -> ( @@ -300,9 +259,7 @@ module Proto_client = struct let annotated_operations = List.map (fun operation -> - let (Manager operation) = - L1_operation.to_manager_operation operation - in + let (Manager operation) = injector_operation_to_manager operation in Annotated_manager_operation (Injection.prepare_manager_operation ~fee:Limit.unknown @@ -397,18 +354,17 @@ module Proto_client = struct in Data_encoding.Binary.to_bytes_exn Operation.encoding op - let time_until_next_block (node_ctxt : Node_context.ro) + let time_until_next_block + {Injector.minimal_block_delay; delay_increment_per_round; _} (header : Tezos_base.Block_header.shell_header option) = let open Result_syntax in - let Constants.Parametric.{minimal_block_delay; delay_increment_per_round; _} - = - node_ctxt.protocol_constants.Constants.parametric - in match header with - | None -> - minimal_block_delay |> Period.to_seconds |> Int64.to_int - |> Ptime.Span.of_int_s + | None -> minimal_block_delay |> Int64.to_int |> Ptime.Span.of_int_s | Some header -> + let minimal_block_delay = Period.of_seconds_exn minimal_block_delay in + let delay_increment_per_round = + Period.of_seconds_exn delay_increment_per_round + in let next_level_timestamp = let* durations = Round.Durations.create @@ -435,6 +391,4 @@ module Proto_client = struct (Time.System.now ()) end -include Injector_functor.Make (Parameters) - -let () = register_proto_client Protocol.hash (module Proto_client) +let () = Injector.register_proto_client Protocol.hash (module Proto_client) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/injector.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.mli similarity index 85% rename from src/proto_017_PtNairob/lib_sc_rollup_node/injector.mli rename to src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.mli index 0f3db24e434eeded77d995b2d9125bb5dfab40b5..ca4112313ef6449d4ec20d700049ae0d28263944 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/injector.mli +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.mli @@ -23,8 +23,10 @@ (* *) (*****************************************************************************) -include - Injector_sigs.S - with type state := Node_context.ro - and type tag := Configuration.purpose - and type operation := L1_operation.t +(** Manager operation for a given L1 operation. *) +val injector_operation_to_manager : + L1_operation.t -> Protocol.Alpha_context.packed_manager_operation + +(** L1 operation corresponding to a manager operation if any. *) +val injector_operation_of_manager : + 'a Protocol.Alpha_context.manager_operation -> L1_operation.t option diff --git a/src/proto_alpha/lib_sc_rollup_layer2/dune b/src/proto_alpha/lib_sc_rollup_layer2/dune index 5534f1849eddbad5544e6f40f093459c3e644ff7..304da296654ee6f10b9a421f18f55622a138084e 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/dune +++ b/src/proto_alpha/lib_sc_rollup_layer2/dune @@ -17,4 +17,5 @@ (:standard) -open Tezos_base.TzPervasives -open Tezos_protocol_alpha - -open Octez_injector)) + -open Octez_injector + -open Octez_smart_rollup)) diff --git a/src/proto_alpha/lib_sc_rollup_node/daemon.ml b/src/proto_alpha/lib_sc_rollup_node/daemon.ml index 210ecfdbb4a534eb6679b3e0266f3bfe87fe53ec..022074e8c5f290137140cea8a8d3467e2f3d0d77 100644 --- a/src/proto_alpha/lib_sc_rollup_node/daemon.ml +++ b/src/proto_alpha/lib_sc_rollup_node/daemon.ml @@ -593,7 +593,16 @@ let run node_ctxt configuration unless (signers = []) @@ fun () -> Injector.init node_ctxt.cctxt - (Node_context.readonly node_ctxt) + { + cctxt = (node_ctxt.cctxt :> Client_context.full); + fee_parameters = configuration.fee_parameters; + minimal_block_delay = + node_ctxt.protocol_constants.Constants.parametric + .minimal_block_delay |> Period.to_seconds; + delay_increment_per_round = + node_ctxt.protocol_constants.Constants.parametric + .delay_increment_per_round |> Period.to_seconds; + } ~data_dir:node_ctxt.data_dir ~signers ~retention_period:configuration.injector.retention_period diff --git a/src/proto_alpha/lib_sc_rollup_node/daemon_event.ml b/src/proto_alpha/lib_sc_rollup_node/daemon_event.ml index 700fb8e63867917938aca6f66ebfbd4260f60a3c..2969126bcaabe2c9bf31d2d9030529bb9a2c8081 100644 --- a/src/proto_alpha/lib_sc_rollup_node/daemon_event.ml +++ b/src/proto_alpha/lib_sc_rollup_node/daemon_event.ml @@ -149,7 +149,7 @@ let new_heads_processed = new_heads_iteration Simple.new_heads_processed let included_operation (type kind) (operation : kind Protocol.Alpha_context.manager_operation) (result : kind Protocol.Apply_results.manager_operation_result) = - match L1_operation.of_manager_operation operation with + match Sc_rollup_injector.injector_operation_of_manager operation with | None -> Lwt.return_unit | Some operation -> ( match result with diff --git a/src/proto_alpha/lib_sc_rollup_node/dune b/src/proto_alpha/lib_sc_rollup_node/dune index 3802b8d12f838cc3d02cdbf584df0ec817858f24..cd16eb7b141770c5e53f2396874846925cbfead4 100644 --- a/src/proto_alpha/lib_sc_rollup_node/dune +++ b/src/proto_alpha/lib_sc_rollup_node/dune @@ -26,6 +26,7 @@ tezos-dac-lib tezos-dac-client-lib tezos-shell-services + octez-smart-rollup tezos-smart-rollup-alpha tezos-smart-rollup-layer2-alpha tezos-layer2-utils-alpha @@ -62,6 +63,7 @@ -open Tezos_dac_lib -open Tezos_dac_client_lib -open Tezos_shell_services + -open Octez_smart_rollup -open Tezos_smart_rollup_alpha -open Tezos_smart_rollup_layer2_alpha -open Tezos_layer2_utils_alpha diff --git a/src/proto_alpha/lib_sc_rollup_node/publisher.ml b/src/proto_alpha/lib_sc_rollup_node/publisher.ml index f7b0cc4b168f8770073e60cf4870cb03520ca3e9..f7de047a773382e9d76cc077108257b2145eee23 100644 --- a/src/proto_alpha/lib_sc_rollup_node/publisher.ml +++ b/src/proto_alpha/lib_sc_rollup_node/publisher.ml @@ -271,7 +271,11 @@ let publish_commitment (node_ctxt : _ Node_context.t) ~source (commitment : Sc_rollup.Commitment.t) = let open Lwt_result_syntax in let publish_operation = - L1_operation.Publish {rollup = node_ctxt.rollup_address; commitment} + L1_operation.Publish + { + rollup = node_ctxt.rollup_address; + commitment = Sc_rollup_proto_types.Commitment.to_octez commitment; + } in let*! () = Commitment_event.publish_commitment @@ -400,10 +404,11 @@ let cementable_commitments (node_ctxt : _ Node_context.t) = in if green_light then return cementable else return_nil -let cement_commitment (node_ctxt : _ Node_context.t) ~source = +let cement_commitment (node_ctxt : _ Node_context.t) ~source commitment = let open Lwt_result_syntax in + let commitment = Sc_rollup_proto_types.Commitment_hash.to_octez commitment in let cement_operation = - L1_operation.Cement {rollup = node_ctxt.rollup_address} + L1_operation.Cement {rollup = node_ctxt.rollup_address; commitment} in let* _hash = Injector.add_pending_operation ~source cement_operation in return_unit @@ -417,9 +422,7 @@ let on_cement_commitments (node_ctxt : state) = return_unit | Some source -> let* cementable_commitments = cementable_commitments node_ctxt in - List.iter_es - (fun _cementable_commitment -> cement_commitment node_ctxt ~source) - cementable_commitments + List.iter_es (cement_commitment node_ctxt ~source) cementable_commitments module Types = struct type nonrec state = state diff --git a/src/proto_alpha/lib_sc_rollup_node/refutation_game.ml b/src/proto_alpha/lib_sc_rollup_node/refutation_game.ml index da0ffe65803214ee11ee4ad8667009b8ad17432e..fdd814a08990b1e95b996d53b7f16621d84c9198 100644 --- a/src/proto_alpha/lib_sc_rollup_node/refutation_game.ml +++ b/src/proto_alpha/lib_sc_rollup_node/refutation_game.ml @@ -70,7 +70,11 @@ let inject_next_move node_ctxt source ~refutation ~opponent = let open Lwt_result_syntax in let refute_operation = L1_operation.Refute - {rollup = node_ctxt.Node_context.rollup_address; refutation; opponent} + { + rollup = node_ctxt.Node_context.rollup_address; + refutation = Sc_rollup_proto_types.Game.refutation_to_octez refutation; + opponent; + } in let* _hash = Injector.add_pending_operation ~source refute_operation in return_unit @@ -448,7 +452,11 @@ let play_next_move node_ctxt game self opponent = let play_timeout (node_ctxt : _ Node_context.t) self stakers = let open Lwt_result_syntax in let timeout_operation = - L1_operation.Timeout {rollup = node_ctxt.rollup_address; stakers} + L1_operation.Timeout + { + rollup = node_ctxt.rollup_address; + stakers = Sc_rollup_proto_types.Game.index_to_octez stakers; + } in let source = Node_context.get_operator node_ctxt Timeout |> Option.value ~default:self diff --git a/src/proto_alpha/lib_sc_rollup_node/injector.ml b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml similarity index 76% rename from src/proto_alpha/lib_sc_rollup_node/injector.ml rename to src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml index 9f128729bb9ffd30a6d0592f6d85499eaed8d140..15950e96c941fa9fb87e7dcbe77d5a56ee7f3651 100644 --- a/src/proto_alpha/lib_sc_rollup_node/injector.ml +++ b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.ml @@ -31,103 +31,59 @@ module Block_cache = Aches_lwt.Lache.Make_result (Aches.Rache.Transfer (Aches.Rache.LRU) (Block_hash)) -module Parameters : - PARAMETERS - with type state = Node_context.ro - and type Tag.t = Configuration.purpose - and type Operation.t = L1_operation.t = struct - type state = Node_context.ro - - let events_section = [Protocol.name; "sc_rollup_node"] - - module Tag : TAG with type t = Configuration.purpose = struct - type t = Configuration.purpose - - let compare = Stdlib.compare - - let equal = Stdlib.( = ) - - let hash = Hashtbl.hash - - let string_of_tag = Configuration.string_of_purpose - - let pp ppf t = Format.pp_print_string ppf (string_of_tag t) - - let encoding : t Data_encoding.t = - let open Data_encoding in - string_enum - (List.map (fun t -> (string_of_tag t, t)) Configuration.purposes) - end - - module Operation = L1_operation - - (* TODO: https://gitlab.com/tezos/tezos/-/issues/3459 - Very coarse approximation for the number of operation we - expect for each block *) - let table_estimated_size : Tag.t -> int = function - | Publish -> 1 - | Add_messages -> 100 - | Cement -> 1 - | Timeout -> 1 - | Refute -> 1 - - let operation_tag : Operation.t -> Tag.t = function - | Add_messages _ -> Add_messages - | Cement _ -> Cement - | Publish _ -> Publish - | Timeout _ -> Timeout - | Refute _ -> Refute - - let fee_parameter node_ctxt operation = - Node_context.get_fee_parameter node_ctxt (operation_tag operation) - - (* TODO: https://gitlab.com/tezos/tezos/-/issues/3459 - Decide if some batches must have all the operations succeed. See - {!Injector_sigs.Parameter.batch_must_succeed}. *) - let batch_must_succeed _ = `At_least_one - - let retry_unsuccessful_operation _node_ctxt (_op : Operation.t) status = - let open Lwt_syntax in - match status with - | Backtracked | Skipped | Other_branch -> - (* Always retry backtracked or skipped operations, or operations that - are on another branch because of a reorg: - - - Commitments are always produced on finalized blocks. They don't - need to be recomputed, and as such are valid in another branch. - - - The cementation operations should be re-injected because the node - only keeps track of the last cemented level and the last published - commitment, without rollbacks. - - - Messages posted to an inbox should be re-emitted (i.e. re-queued) - in case of a fork. - - - Timeout should be re-submitted as the timeout may be reached as well - on the other branch. - - - Refutation should be re-submitted in case of fork. - TODO: https://gitlab.com/tezos/tezos/-/issues/3459 - maybe check if game exists on other branch as well. - *) - return Retry - | Failed error -> ( - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4071 - Think about which operations should be retried and when. *) - match classify_trace error with - | Permanent | Outdated -> return Forget - | Branch | Temporary -> return Retry) - | Never_included -> - (* Forget operations that are never included *) - return Forget -end +let injector_operation_to_manager : + L1_operation.t -> Protocol.Alpha_context.packed_manager_operation = function + | Add_messages {messages} -> Manager (Sc_rollup_add_messages {messages}) + | Cement {rollup; commitment = _} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + Manager (Sc_rollup_cement {rollup}) + | Publish {rollup; commitment} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let commitment = Sc_rollup_proto_types.Commitment.of_octez commitment in + Manager (Sc_rollup_publish {rollup; commitment}) + | Refute {rollup; opponent; refutation} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let refutation = + Sc_rollup_proto_types.Game.refutation_of_octez refutation + in + Manager (Sc_rollup_refute {rollup; opponent; refutation}) + | Timeout {rollup; stakers} -> + let rollup = Sc_rollup_proto_types.Address.of_octez rollup in + let stakers = Sc_rollup_proto_types.Game.index_of_octez stakers in + Manager (Sc_rollup_timeout {rollup; stakers}) + +let injector_operation_of_manager : + type kind. + kind Protocol.Alpha_context.manager_operation -> L1_operation.t option = + function + | Sc_rollup_add_messages {messages} -> Some (Add_messages {messages}) + | Sc_rollup_cement {rollup} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let commitment = Octez_smart_rollup.Commitment.Hash.zero in + (* Just for printing *) + Some (Cement {rollup; commitment}) + | Sc_rollup_publish {rollup; commitment} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let commitment = Sc_rollup_proto_types.Commitment.to_octez commitment in + Some (Publish {rollup; commitment}) + | Sc_rollup_refute {rollup; opponent; refutation} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let refutation = + Sc_rollup_proto_types.Game.refutation_to_octez refutation + in + Some (Refute {rollup; opponent; refutation}) + | Sc_rollup_timeout {rollup; stakers} -> + let rollup = Sc_rollup_proto_types.Address.to_octez rollup in + let stakers = Sc_rollup_proto_types.Game.index_to_octez stakers in + Some (Timeout {rollup; stakers}) + | _ -> None module Proto_client = struct open Protocol_client_context - type operation = Parameters.Operation.t + type operation = L1_operation.t - type state = Parameters.state + type state = Injector.state type unsigned_operation = Tezos_base.Operation.shell_header * packed_contents_list @@ -153,7 +109,7 @@ module Proto_client = struct (Contents contents) let operation_size op = - manager_operation_size (L1_operation.to_manager_operation op) + manager_operation_size (injector_operation_to_manager op) (* The operation size overhead is an upper bound (in practice) of the overhead that will be added to a manager operation. To compute it we can use any @@ -261,10 +217,9 @@ module Proto_client = struct operations) Lwt.return - let operation_status (node_ctxt : Node_context.ro) block_hash operation_hash - ~index = + let operation_status {Injector.cctxt; _} block_hash operation_hash ~index = let open Lwt_result_syntax in - let* operations = get_block_operations node_ctxt.cctxt block_hash in + let* operations = get_block_operations cctxt block_hash in match Operation_hash.Map.find_opt operation_hash operations with | None -> return_none | Some operation -> ( @@ -302,9 +257,7 @@ module Proto_client = struct let annotated_operations = List.map (fun operation -> - let (Manager operation) = - L1_operation.to_manager_operation operation - in + let (Manager operation) = injector_operation_to_manager operation in Annotated_manager_operation (Injection.prepare_manager_operation ~fee:Limit.unknown @@ -403,18 +356,17 @@ module Proto_client = struct Operation.encoding_with_legacy_attestation_name op - let time_until_next_block (node_ctxt : Node_context.ro) + let time_until_next_block + {Injector.minimal_block_delay; delay_increment_per_round; _} (header : Tezos_base.Block_header.shell_header option) = let open Result_syntax in - let Constants.Parametric.{minimal_block_delay; delay_increment_per_round; _} - = - node_ctxt.protocol_constants.Constants.parametric - in match header with - | None -> - minimal_block_delay |> Period.to_seconds |> Int64.to_int - |> Ptime.Span.of_int_s + | None -> minimal_block_delay |> Int64.to_int |> Ptime.Span.of_int_s | Some header -> + let minimal_block_delay = Period.of_seconds_exn minimal_block_delay in + let delay_increment_per_round = + Period.of_seconds_exn delay_increment_per_round + in let next_level_timestamp = let* durations = Round.Durations.create @@ -441,6 +393,4 @@ module Proto_client = struct (Time.System.now ()) end -include Injector_functor.Make (Parameters) - -let () = register_proto_client Protocol.hash (module Proto_client) +let () = Injector.register_proto_client Protocol.hash (module Proto_client) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/injector.mli b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.mli similarity index 85% rename from src/proto_016_PtMumbai/lib_sc_rollup_node/injector.mli rename to src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.mli index 0f3db24e434eeded77d995b2d9125bb5dfab40b5..ca4112313ef6449d4ec20d700049ae0d28263944 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/injector.mli +++ b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_injector.mli @@ -23,8 +23,10 @@ (* *) (*****************************************************************************) -include - Injector_sigs.S - with type state := Node_context.ro - and type tag := Configuration.purpose - and type operation := L1_operation.t +(** Manager operation for a given L1 operation. *) +val injector_operation_to_manager : + L1_operation.t -> Protocol.Alpha_context.packed_manager_operation + +(** L1 operation corresponding to a manager operation if any. *) +val injector_operation_of_manager : + 'a Protocol.Alpha_context.manager_operation -> L1_operation.t option