diff --git a/.gitlab/ci/pipelines/opam.daily.yml b/.gitlab/ci/pipelines/opam.daily.yml index 8368eb9f0551b2676133dcfd9bfc870437cf0437..85d50c6e3e60e15152b24575ad4feff1da3c51aa 100644 --- a/.gitlab/ci/pipelines/opam.daily.yml +++ b/.gitlab/ci/pipelines/opam.daily.yml @@ -145,7 +145,6 @@ opam:all_6: - tezt-tezos - tezos-protocol-genesis - tezos-protocol-demo-noops - - tezos-protocol-demo-counter - tezos-openapi - tezos-dal-node-services - tezos-benchmark @@ -153,6 +152,7 @@ opam:all_6: - octez-riscv-pvm - octez-proto-libs - octez-performance-metrics + - octez-libs - octez-lib-upnp - octez-l2-libs - efunc_core @@ -275,7 +275,6 @@ opam:all_2: - package: - octez-smart-rollup-node-lib - octez-smart-rollup-node-PtParisB - - octez-smart-rollup-node-PtNairob - octez-smart-rollup-node-PsRiotum - octez-smart-rollup-node-PsQuebec - octez-smart-rollup-node-PsParisC @@ -287,6 +286,7 @@ opam:all_2: - octez-protocol-018-Proxford-libs - octez-protocol-017-PtNairob-libs - octez-protocol-016-PtMumbai-libs + - octez-protocol-001-PtCJ7pwo-libs - octez-protocol-000-Ps9mPmXa-libs - octez-injector - octez-baker-lib @@ -410,6 +410,7 @@ opam:all_3: parallel: matrix: - package: + - tezos-client-genesis - tezos-client-demo-counter - octez-rpc-process - octez-protocol-015-PtLimaPt-libs @@ -426,7 +427,6 @@ opam:all_3: - octez-protocol-004-Pt24m4xi-libs - octez-protocol-003-PsddFKi3-libs - octez-protocol-002-PsYLVpVv-libs - - octez-protocol-001-PtCJ7pwo-libs opam:exec_4: image: ${ci_image_name}/prebuild:${ci_image_tag} @@ -542,6 +542,7 @@ opam:all_4: parallel: matrix: - package: + - tezos-protocol-009-PsFLoren - tezos-protocol-008-PtEdoTez - tezos-protocol-008-PtEdo2Zk - tezos-protocol-007-PsDELPH1 @@ -554,7 +555,6 @@ opam:all_4: - tezos-protocol-001-PtCJ7pwo - tezos-protocol-000-Ps9mPmXa - tezos-dal-node-lib - - tezos-client-genesis - octez-node-config - octez-crawler - octez-baking-common-lib @@ -683,6 +683,7 @@ opam:all_5: parallel: matrix: - package: + - tezos-protocol-demo-counter - tezos-protocol-alpha - tezos-protocol-024-PtTALLiN - tezos-protocol-023-PtSeouLo @@ -699,7 +700,6 @@ opam:all_5: - tezos-protocol-012-Psithaca - tezos-protocol-011-PtHangz2 - tezos-protocol-010-PtGRANAD - - tezos-protocol-009-PsFLoren opam:all_7: image: ${ci_image_name}/prebuild:${ci_image_tag} @@ -763,7 +763,6 @@ opam:all_7: - octez-riscv-api - octez-protocol-compiler-compat - octez-lwt-domain - - octez-libs - octez-lib-upnp-args - octez-internal-libs - octez-igd-next diff --git a/CHANGES.rst b/CHANGES.rst index d7ebb6c7c37f0125ce04ecefca624b38d023c74d..7228e9d2e2982a7fa8ee080c3d94069d7e028342 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -69,6 +69,9 @@ Docker Images Smart Rollup node ----------------- +- Remove protocol plugin for Nairobi (17). This still allows to replay Etherlink + mainnet from genesis but not Etherlink testnet. (MR :gl:`!20301`) + Smart Rollup WASM Debugger -------------------------- diff --git a/dune-project b/dune-project index bed1b1899eb8b6c9fde3cc6a3d2b9841bee0561f..355ba8a05496350e258f5009f7f1166575d97f6c 100644 --- a/dune-project +++ b/dune-project @@ -99,7 +99,6 @@ (package (name octez-smart-rollup-node-PsParisC)(allow_empty)) (package (name octez-smart-rollup-node-PsQuebec)(allow_empty)) (package (name octez-smart-rollup-node-PsRiotum)(allow_empty)) -(package (name octez-smart-rollup-node-PtNairob)(allow_empty)) (package (name octez-smart-rollup-node-PtParisB)(allow_empty)) (package (name octez-smart-rollup-node-PtSeouLo)(allow_empty)) (package (name octez-smart-rollup-node-PtTALLiN)(allow_empty)) diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 3a97892fc78a014e0d654d897e606035fd3e31b6..05c8b3c8852fb811b4b13450d87e2235d0d3df4a 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -7813,9 +7813,9 @@ let hash = Protocol.hash ~linkall:true in let octez_sc_rollup_node = - (* For now, we want to keep this for Nairobi and above because Etherlink - Ghostnet requires it. *) - only_if N.(number >= 017) @@ fun () -> + (* For now, we want to keep this for Oxford and above to be able to + replay Etherlink Mainnet from genesis. *) + only_if N.(number >= 018) @@ fun () -> private_lib (sf "octez_smart_rollup_node_%s" short_hash) ~path:(path // "lib_sc_rollup_node") diff --git a/opam/octez-smart-rollup-node-PtNairob.opam b/opam/octez-smart-rollup-node-PtNairob.opam deleted file mode 100644 index 60cde2e51ce1c00ab1515cc82040ccb33a554e00..0000000000000000000000000000000000000000 --- a/opam/octez-smart-rollup-node-PtNairob.opam +++ /dev/null @@ -1,37 +0,0 @@ -# This file was automatically generated, do not edit. -# Edit file manifest/main.ml instead. -opam-version: "2.0" -maintainer: "contact@tezos.com" -authors: ["Tezos devteam"] -homepage: "https://www.tezos.com/" -bug-reports: "https://gitlab.com/tezos/tezos/issues" -dev-repo: "git+https://gitlab.com/tezos/tezos.git" -license: "MIT" -depends: [ - "dune" { >= "3.11.1" } - "ocaml" { >= "4.14" } - "octez-libs" { = version } - "octez-shell-libs" { = version } - "octez-protocol-017-PtNairob-libs" { = version } - "tezos-protocol-017-PtNairob" { = version } - "tezos-dal-node-services" { = version } - "tezos-dal-node-lib" { = version } - "octez-l2-libs" { = version } - "octez-crawler" { = version } - "octez-internal-libs" { = version } - "aches" { >= "1.1.0" } - "aches-lwt" { >= "1.1.0" } - "octez-injector" { = version } - "octez-smart-rollup-node-lib" { = version } - "octez-version" { = version } -] -conflicts: [ - "checkseum" { = "0.5.0" } -] -build: [ - ["rm" "-rf" "vendors" "contrib"] - ["dune" "build" "-p" name "-j" jobs] - ["dune" "runtest" "-p" name "-j" jobs] {with-test} -] -available: os-family != "windows" -synopsis: "Protocol specific (for 017-PtNairob) library for smart rollup node" diff --git a/opam/octez-smart-rollup-node.opam b/opam/octez-smart-rollup-node.opam index 63fd91fe3178fb20efd9c5c3bdd43e2b3c40de41..838f1311c85eccf0411d5a53ce13285d6dec7646 100644 --- a/opam/octez-smart-rollup-node.opam +++ b/opam/octez-smart-rollup-node.opam @@ -20,7 +20,6 @@ depends: [ "octez-smart-rollup-node-PtTALLiN" { = version } ] depopts: [ - "octez-smart-rollup-node-PtNairob" "octez-smart-rollup-node-Proxford" "octez-smart-rollup-node-PtParisB" "octez-smart-rollup-node-PsParisC" @@ -29,7 +28,6 @@ depopts: [ "octez-smart-rollup-node-alpha" ] conflicts: [ - "octez-smart-rollup-node-PtNairob" { != version } "octez-smart-rollup-node-Proxford" { != version } "octez-smart-rollup-node-PtParisB" { != version } "octez-smart-rollup-node-PsParisC" { != version } diff --git a/opam/tezos-smart-rollup-node-lib-test.opam b/opam/tezos-smart-rollup-node-lib-test.opam index 5c1205fa12efef689003a2d858825c3b51b22162..4c34644fcc71bd24baf516592671fa8439d4df6f 100644 --- a/opam/tezos-smart-rollup-node-lib-test.opam +++ b/opam/tezos-smart-rollup-node-lib-test.opam @@ -25,7 +25,6 @@ depends: [ "octez-smart-rollup-node-PtTALLiN" {with-test} ] depopts: [ - "octez-smart-rollup-node-PtNairob" {with-test} "octez-smart-rollup-node-Proxford" {with-test} "octez-smart-rollup-node-PtParisB" {with-test} "octez-smart-rollup-node-PsParisC" {with-test} diff --git a/script-inputs/ci-opam-package-tests b/script-inputs/ci-opam-package-tests index 8d2e125dac40c159b1e615f1fa2712b1440f4ed1..158ff09c1cb12015a6973c9a74907751d70aed5f 100644 --- a/script-inputs/ci-opam-package-tests +++ b/script-inputs/ci-opam-package-tests @@ -22,14 +22,14 @@ octez-internal-libs all 7 octez-l2-libs all 6 octez-lib-upnp all 6 octez-lib-upnp-args all 7 -octez-libs all 7 +octez-libs all 6 octez-lwt-domain all 7 octez-node exec 1 octez-node-config all 4 octez-performance-metrics all 6 octez-proto-libs all 6 octez-protocol-000-Ps9mPmXa-libs all 2 -octez-protocol-001-PtCJ7pwo-libs all 3 +octez-protocol-001-PtCJ7pwo-libs all 2 octez-protocol-002-PsYLVpVv-libs all 3 octez-protocol-003-PsddFKi3-libs all 3 octez-protocol-004-Pt24m4xi-libs all 3 @@ -69,7 +69,6 @@ octez-smart-rollup-node-Proxford all 2 octez-smart-rollup-node-PsParisC all 2 octez-smart-rollup-node-PsQuebec all 2 octez-smart-rollup-node-PsRiotum all 2 -octez-smart-rollup-node-PtNairob all 2 octez-smart-rollup-node-PtParisB all 2 octez-smart-rollup-node-PtSeouLo all 1 octez-smart-rollup-node-PtTALLiN all 1 @@ -78,7 +77,7 @@ octez-smart-rollup-node-lib all 2 octez-version exec 6 tezos-benchmark all 6 tezos-client-demo-counter all 3 -tezos-client-genesis all 4 +tezos-client-genesis all 3 tezos-dal-node-lib all 4 tezos-dal-node-services all 6 tezos-openapi all 6 @@ -93,7 +92,7 @@ tezos-protocol-006-PsCARTHA all 4 tezos-protocol-007-PsDELPH1 all 4 tezos-protocol-008-PtEdo2Zk all 4 tezos-protocol-008-PtEdoTez all 4 -tezos-protocol-009-PsFLoren all 5 +tezos-protocol-009-PsFLoren all 4 tezos-protocol-010-PtGRANAD all 5 tezos-protocol-011-PtHangz2 all 5 tezos-protocol-012-Psithaca all 5 @@ -110,7 +109,7 @@ tezos-protocol-022-PsRiotum all 5 tezos-protocol-023-PtSeouLo all 5 tezos-protocol-024-PtTALLiN all 5 tezos-protocol-alpha all 5 -tezos-protocol-demo-counter all 6 +tezos-protocol-demo-counter all 5 tezos-protocol-demo-noops all 6 tezos-protocol-genesis all 6 tezt-tezos all 6 diff --git a/src/bin_smart_rollup_node/dune b/src/bin_smart_rollup_node/dune index d8fa405c47bb88413c4c09077df5efe1dbe176ff..a74fe1d8e409b121cf62dac5aabfb4982919f759 100644 --- a/src/bin_smart_rollup_node/dune +++ b/src/bin_smart_rollup_node/dune @@ -17,9 +17,6 @@ octez-shell-libs.client-commands octez-l2-libs.smart-rollup octez-smart-rollup-node-lib - (select void_for_linking-octez_smart_rollup_node_PtNairob from - (octez_smart_rollup_node_PtNairob -> void_for_linking-octez_smart_rollup_node_PtNairob.empty) - (-> void_for_linking-octez_smart_rollup_node_PtNairob.empty)) (select void_for_linking-octez_smart_rollup_node_Proxford from (octez_smart_rollup_node_Proxford -> void_for_linking-octez_smart_rollup_node_Proxford.empty) (-> void_for_linking-octez_smart_rollup_node_Proxford.empty)) @@ -60,7 +57,6 @@ (rule (action (progn - (write-file void_for_linking-octez_smart_rollup_node_PtNairob.empty "") (write-file void_for_linking-octez_smart_rollup_node_Proxford.empty "") (write-file void_for_linking-octez_smart_rollup_node_PtParisB.empty "") (write-file void_for_linking-octez_smart_rollup_node_PsParisC.empty "") diff --git a/src/lib_smart_rollup_node/test/helpers/dune b/src/lib_smart_rollup_node/test/helpers/dune index 935c47387e77407ea6809c69616abb48a8e875f8..2d3a49aa105794189ffdbca3762f15f14236057e 100644 --- a/src/lib_smart_rollup_node/test/helpers/dune +++ b/src/lib_smart_rollup_node/test/helpers/dune @@ -16,9 +16,6 @@ octez-l2-libs.smart-rollup octez-smart-rollup-node-lib octez-l2-libs.layer2_store - (select void_for_linking-octez_smart_rollup_node_PtNairob from - (octez_smart_rollup_node_PtNairob -> void_for_linking-octez_smart_rollup_node_PtNairob.empty) - (-> void_for_linking-octez_smart_rollup_node_PtNairob.empty)) (select void_for_linking-octez_smart_rollup_node_Proxford from (octez_smart_rollup_node_Proxford -> void_for_linking-octez_smart_rollup_node_Proxford.empty) (-> void_for_linking-octez_smart_rollup_node_Proxford.empty)) @@ -53,7 +50,6 @@ (rule (action (progn - (write-file void_for_linking-octez_smart_rollup_node_PtNairob.empty "") (write-file void_for_linking-octez_smart_rollup_node_Proxford.empty "") (write-file void_for_linking-octez_smart_rollup_node_PtParisB.empty "") (write-file void_for_linking-octez_smart_rollup_node_PsParisC.empty "") diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/RPC_directory.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/RPC_directory.ml deleted file mode 100644 index 79633f4fb0b02ca979f208cb436101de6e0ec0fa..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/RPC_directory.ml +++ /dev/null @@ -1,201 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* Copyright (c) 2022-2023 TriliTech *) -(* 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 Rpc_directory_helpers -open Protocol -open Context_wrapper.Irmin - -module Slot_pages_map = struct - open Protocol - open Alpha_context - include Map.Make (Dal.Slot_index) -end - -module Block_directory = Make_sub_directory (struct - include Sc_rollup_services.Block - - type context = Node_context.rw - - type subcontext = Node_context.ro * Block_hash.t - - let context_of_prefix node_ctxt (((), block) : prefix) = - let open Lwt_result_syntax in - let+ block = Block_directory_helpers.block_of_prefix node_ctxt block in - (Node_context.readonly node_ctxt, block) -end) - -module Block_helpers_directory = Make_sub_directory (struct - include Sc_rollup_services.Block.Helpers - - (* The context needs to be accessed with write permissions because we need to - commit on disk to generate the proofs. *) - type context = Node_context.rw - - (* The context needs to be accessed with write permissions because we need to - commit on disk to generate the proofs. *) - type subcontext = Node_context.rw * Block_hash.t - - let context_of_prefix node_ctxt (((), block) : prefix) = - let open Lwt_result_syntax in - let+ block = Block_directory_helpers.block_of_prefix node_ctxt block in - (node_ctxt, block) -end) - -let get_state (node_ctxt : _ Node_context.t) block_hash = - let open Lwt_result_syntax in - let* ctxt = Node_context.checkout_context node_ctxt block_hash in - let*! state = Context.PVMState.find ctxt in - match state with - | None -> failwith "No state" - | Some state -> return (state, of_node_pvmstate state) - -let simulate_messages (node_ctxt : Node_context.ro) block ~reveal_pages - ~insight_requests ~log_kernel_debug_file messages = - let open Lwt_result_syntax in - let open Alpha_context in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let reveal_map = - match reveal_pages with - | Some pages -> - let map = - List.fold_left - (fun map page -> - let hash = - Protocol.Sc_rollup_reveal_hash.hash_string - ~scheme:Blake2B - [page] - |> Data_encoding.Binary.to_bytes_exn - Protocol.Sc_rollup_reveal_hash.encoding - in - Utils.Reveal_hash_map.add hash page map) - Utils.Reveal_hash_map.empty - pages - in - Some map - | None -> None - in - let* level = Node_context.level_of_hash node_ctxt block in - let* sim = - Simulation.start_simulation - node_ctxt - ~reveal_map - ?log_kernel_debug_file - Layer1.{hash = block; level} - in - let* sim, num_ticks_0 = Simulation.simulate_messages sim messages in - let* {state; inbox_level; _}, num_ticks_end = Simulation.end_simulation sim in - let*! insights = - List.map_p - (function - | Sc_rollup_services.Pvm_state_key key -> - PVM.State.lookup (of_node_pvmstate state) key - | Durable_storage_key key -> - PVM.Inspect_durable_state.lookup (of_node_pvmstate state) key) - insight_requests - in - let num_ticks = Z.(num_ticks_0 + num_ticks_end) in - let level = Raw_level.of_int32_exn inbox_level in - let*! outbox = PVM.get_outbox level (of_node_pvmstate state) in - let output = - List.filter (fun Sc_rollup.{outbox_level; _} -> outbox_level = level) outbox - in - let*! state_hash = PVM.state_hash (of_node_pvmstate state) in - let*! status = PVM.get_status (of_node_pvmstate state) in - let status = PVM.string_of_status status in - return - Sc_rollup_services. - {state_hash; status; output; inbox_level; num_ticks; insights} - -let () = - Block_directory.register0 Sc_rollup_services.Block.status - @@ fun (node_ctxt, block) () () -> - let open Lwt_result_syntax in - let* _, state = get_state node_ctxt block in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! status = PVM.get_status state in - return (PVM.string_of_status status) - -let () = - Block_directory.register0 Sc_rollup_services.Block.outbox - @@ fun (node_ctxt, block) outbox_level () -> - let open Lwt_result_syntax in - let* _, state = get_state node_ctxt block in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! outbox = PVM.get_outbox outbox_level state in - return outbox - -let () = - Block_directory.register1 Sc_rollup_services.Block.outbox_messages - @@ fun (node_ctxt, block) outbox_level () () -> - let open Lwt_result_syntax in - let* _, state = get_state node_ctxt block in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! outbox = PVM.get_outbox outbox_level state in - return outbox - -let () = - Block_helpers_directory.register1 - Sc_rollup_services.Block.Helpers.outbox_proof_simple - @@ fun (node_ctxt, _block_hash) outbox_level message_index () -> - let open Lwt_result_syntax in - let+ commitment, proof = - Outbox.proof_of_output_simple node_ctxt ~outbox_level ~message_index - in - (Sc_rollup_proto_types.Commitment_hash.of_octez commitment, proof) - -let () = - Block_directory.register0 Sc_rollup_services.Block.simulate - @@ - fun (node_ctxt, block) - () - {messages; reveal_pages; insight_requests; log_kernel_debug_file} - -> - simulate_messages - node_ctxt - block - ~reveal_pages - ~insight_requests - ~log_kernel_debug_file - messages - -let block_directory (node_ctxt : _ Node_context.t) = - let module PVM = (val Pvm_rpc.of_kind node_ctxt.kind) in - List.fold_left - (fun dir f -> Tezos_rpc.Directory.merge dir (f node_ctxt)) - Tezos_rpc.Directory.empty - [ - Block_directory.build_sub_directory; - Block_helpers_directory.build_sub_directory; - PVM.build_sub_directory; - ] - -let directory (node_ctxt : _ Node_context.t) = - Tezos_rpc.Directory.merge - (Octez_smart_rollup_node.Rpc_directory.top_directory node_ctxt) - (Tezos_rpc.Directory.prefix - Sc_rollup_services.Block.prefix - (block_directory node_ctxt)) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/RPC_directory.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/RPC_directory.mli deleted file mode 100644 index 1cac46c2ded4ff6d534f64eb1db05f8599832038..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/RPC_directory.mli +++ /dev/null @@ -1,33 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** The RPC directory, specific to blocks, for this rollup node. *) -val block_directory : - Node_context.rw -> - (unit * Rollup_node_services.Arg.block_id) Tezos_rpc.Directory.t - -(** The full RPC directory for this rollup node, merging the top level directory - and the block directory. *) -val directory : Node_context.rw -> unit Tezos_rpc.Directory.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/arith_pvm.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/arith_pvm.ml deleted file mode 100644 index 66d0e3ec4a153daac1c034d05b13e9af864a6b31..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/arith_pvm.ml +++ /dev/null @@ -1,103 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022-2023 TriliTech *) -(* *) -(* 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 -open Alpha_context - -(** This module manifests the proof format used by the Arith PVM as defined by - the Layer 1 implementation for it. - - It is imperative that this is aligned with the protocol's implementation. -*) -module Arith_proof_format = - Irmin_context.Proof - (struct - include Sc_rollup.State_hash - - let of_context_hash = Sc_rollup.State_hash.context_hash_to_state_hash - end) - (struct - let proof_encoding = - Tezos_context_merkle_proof_encoding.Merkle_proof_encoding.V2.Tree2 - .tree_proof_encoding - end) - -module Impl : Pvm_sig.S = struct - module PVM = Sc_rollup.ArithPVM.Make (Arith_proof_format) - include PVM - - let kind = Sc_rollup.Kind.Example_arith - - module State = Irmin_context.PVMState - - module Inspect_durable_state = struct - let lookup _state _keys = - raise (Invalid_argument "No durable storage for arith PVM") - end - - module Unsafe_patches = struct - (** No unsafe patches for the arith PVM. *) - type t = | - - let of_patch (p : Pvm_patches.unsafe_patch) = - match p with - | Increase_max_nb_ticks _ -> assert false - | Patch_durable_storage _ -> assert false - - let apply _state (x : t) = match x with _ -> . - end - - let new_dissection = Game_helpers.default_new_dissection - - let string_of_status status = - match status with - | Halted -> "Halted" - | Waiting_for_input_message -> "Waiting for input message" - | Waiting_for_reveal -> "Waiting for reveal" - | Waiting_for_metadata -> "Waiting for metadata" - | Parsing -> "Parsing" - | Evaluating -> "Evaluating" - - let eval_many ~reveal_builtins:_ ~write_debug:_ ?stop_at_snapshot ~max_steps - initial_state = - ignore stop_at_snapshot ; - let rec go state step = - let open Lwt.Syntax in - let* is_input_required = is_input_state state in - - if is_input_required = No_input_required && step < max_steps then - let open Lwt.Syntax in - (* Note: This is not an efficient implementation because the state is - decoded/encoded to/from the tree at each step but for Arith PVM - it doesn't matter - *) - let* next_state = eval state in - go next_state (Int64.succ step) - else Lwt.return (state, step) - in - go initial_state 0L -end - -include Impl diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/batcher_constants.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/batcher_constants.ml deleted file mode 100644 index edfa3ea32f006f8995fb2ca4999e28d87e98df71..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/batcher_constants.ml +++ /dev/null @@ -1,56 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -let message_size_limit = Protocol.Constants_repr.sc_rollup_message_size_limit - -let protocol_max_batch_size = - let open Protocol in - let open Alpha_context in - let empty_message_op : _ Operation.t = - let open Operation in - { - shell = {branch = Block_hash.zero}; - protocol_data = - { - signature = Some Signature.zero; - contents = - Single - (Manager_operation - { - source = Signature.Public_key_hash.zero; - fee = Tez.of_mutez_exn Int64.max_int; - counter = Manager_counter.Internal_for_tests.of_int max_int; - gas_limit = - Gas.Arith.integral_of_int_exn ((max_int - 1) / 1000); - storage_limit = Z.of_int max_int; - operation = Sc_rollup_add_messages {messages = [""]}; - }); - }; - } - in - Protocol.Constants_repr.max_operation_data_length - - Data_encoding.Binary.length - Operation.encoding - (Operation.pack empty_message_op) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/batcher_constants.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/batcher_constants.mli deleted file mode 100644 index dda41ddc6be1ad185be0997f1f289daae059f0c2..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/batcher_constants.mli +++ /dev/null @@ -1,32 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** Maximum size of an L2 message allowed by the prototcol. Is - {!val:Protocol.Constants_repr.sc_rollup_message_size_limit}. *) -val message_size_limit : int - -(** Maximum size in bytes of an batch of L2 messages that can fit in an - operation on L1. It is protocol dependent. *) -val protocol_max_batch_size : int diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/context_wrapper.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/context_wrapper.ml deleted file mode 100644 index f8ce92b5ab0638146d7ff6d674b5500e0a796e37..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/context_wrapper.ml +++ /dev/null @@ -1,30 +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. *) -(* *) -(*****************************************************************************) - -module Irmin = Context.Wrapper.Make (struct - include Irmin_context - - let load ~cache_size path = load ~cache_size path -end) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/context_wrapper.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/context_wrapper.mli deleted file mode 100644 index 7132f1c89a48ea5d206cb93c42ced9ef9b6cd781..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/context_wrapper.mli +++ /dev/null @@ -1,32 +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. *) -(* *) -(*****************************************************************************) - -(** Specialized module to handle translation to/from Irmin_context. - Directly used in Arith, Wasm_2_0_0 and RISC-V PVM *) -module Irmin : - Context.Wrapper.S - with type repo = Irmin_context.repo - and type tree = Irmin_context.tree - and type mut_state = Irmin_context.mut_state diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_helpers.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_helpers.ml deleted file mode 100644 index 978dca06cba759ca28eb140146468a2caff5c541..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_helpers.ml +++ /dev/null @@ -1,353 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Nomadic Labs, *) -(* Copyright (c) 2023 TriliTech *) -(* 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 Protocol -open Alpha_context -open Apply_results - -let check_pvm_initial_state_hash {Node_context.cctxt; config; kind; _} = - let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind kind) in - let* l1_reference_initial_state_hash = - RPC.Sc_rollup.initial_pvm_state_hash - (new Protocol_client_context.wrap_full cctxt) - (cctxt#chain, cctxt#block) - (Sc_rollup_proto_types.Address.of_octez config.sc_rollup_address) - in - let*! s = PVM.initial_state ~empty:(PVM.State.empty ()) in - let*! l2_initial_state_hash = PVM.state_hash s in - let l1_reference_initial_state_hash = - Sc_rollup_proto_types.State_hash.to_octez l1_reference_initial_state_hash - in - let l2_initial_state_hash = - Sc_rollup_proto_types.State_hash.to_octez l2_initial_state_hash - in - fail_unless - Octez_smart_rollup.State_hash.( - l1_reference_initial_state_hash = l2_initial_state_hash) - (Sc_rollup_node_errors.Wrong_initial_pvm_state - { - initial_state_hash = l2_initial_state_hash; - expected_state_hash = l1_reference_initial_state_hash; - }) - -(** Returns [Some c] if [their_commitment] is refutable where [c] is our - commitment for the same inbox level. *) -let is_refutable_commitment node_ctxt - (their_commitment : Octez_smart_rollup.Commitment.t) their_commitment_hash = - let open Lwt_result_syntax in - let* l2_block = - Node_context.get_l2_block_by_level node_ctxt their_commitment.inbox_level - in - let* our_commitment_and_hash = - Option.filter_map_es - (fun hash -> - let+ commitment = Node_context.find_commitment node_ctxt hash in - Option.map (fun c -> (c, hash)) commitment) - l2_block.header.commitment_hash - in - match our_commitment_and_hash with - | Some (our_commitment, our_commitment_hash) - when Octez_smart_rollup.Commitment.Hash.( - their_commitment_hash <> our_commitment_hash - && their_commitment.predecessor = our_commitment.predecessor) -> - return our_commitment_and_hash - | _ -> return_none - -(** Publish a commitment when an accuser node sees a refutable commitment. *) -let accuser_publish_commitment_when_refutable node_ctxt ~other rollup - their_commitment their_commitment_hash = - let open Lwt_result_syntax in - when_ (Node_context.is_accuser node_ctxt) @@ fun () -> - (* We are seeing a commitment from someone else. We check if we agree - with it, otherwise the accuser publishes our commitment in order to - play the refutation game. *) - let* refutable = - is_refutable_commitment node_ctxt their_commitment their_commitment_hash - in - match refutable with - | None -> return_unit - | Some (our_commitment, our_commitment_hash) -> - let*! () = - Refutation_game_event.potential_conflict_detected - ~our_commitment_hash - ~their_commitment_hash - ~level:their_commitment.inbox_level - ~other - in - assert ( - Octez_smart_rollup.Address.(node_ctxt.config.sc_rollup_address = rollup)) ; - Publisher.publish_single_commitment node_ctxt our_commitment - -(** If in bailout mode and when the operator is not staked on any - commitment, the bond is recovered. *) -let maybe_recover_bond node_ctxt = - let open Lwt_result_syntax in - if Node_context.is_bailout node_ctxt then - let operating_pkh = Node_context.get_operator node_ctxt Operating in - match operating_pkh with - | None -> return_unit - | Some (Single operating_pkh) -> ( - let*? operating_pkh = - Signature.Of_V_latest.get_public_key_hash operating_pkh - in - let* staked_on_commitment = - RPC.Sc_rollup.staked_on_commitment - (new Protocol_client_context.wrap_full node_ctxt.cctxt) - (node_ctxt.cctxt#chain, `Head 0) - (Sc_rollup_proto_types.Address.of_octez - node_ctxt.config.sc_rollup_address) - operating_pkh - in - match staked_on_commitment with - | None -> Publisher.recover_bond node_ctxt - | Some _ (* operator still staked on something *) -> return_unit) - else return_unit - -(** Process an L1 SCORU operation (for the node's rollup) which is included - for the first time. {b Note}: this function does not process inboxes for - the rollup, which is done instead by {!Inbox.process_head}. *) -let process_included_l1_operation (type kind) (node_ctxt : Node_context.rw) - (head : Layer1.header) ~source (operation : kind manager_operation) - (result : kind successful_manager_operation_result) = - let open Lwt_result_syntax in - match (operation, result) with - | ( Sc_rollup_publish {commitment; _}, - Sc_rollup_publish_result {published_at_level; _} ) - when Node_context.is_operator node_ctxt source -> - (* Published commitment --------------------------------------------- *) - let commitment = Sc_rollup_proto_types.Commitment.to_octez commitment in - let commitment_hash = Octez_smart_rollup.Commitment.hash commitment in - let* () = - Node_context.register_published_commitment - node_ctxt - commitment - ~first_published_at_level:(Raw_level.to_int32 published_at_level) - ~level:head.Layer1.level - ~published_by_us:true - in - let*! () = - Commitment_event.last_published_commitment_updated - commitment_hash - head.Layer1.level - in - return_unit - | ( Sc_rollup_publish {commitment = their_commitment; rollup}, - Sc_rollup_publish_result - {published_at_level; staked_hash = their_commitment_hash; _} ) -> - (* Commitment published by someone else *) - (* We first register the publication information *) - let their_commitment_hash = - Sc_rollup_proto_types.Commitment_hash.to_octez their_commitment_hash - in - let* () = - Node_context.register_published_commitment - node_ctxt - (Sc_rollup_proto_types.Commitment.to_octez their_commitment) - ~first_published_at_level:(Raw_level.to_int32 published_at_level) - ~level:head.Layer1.level - ~published_by_us:false - in - (* An accuser node will publish its commitment if the other one is - refutable. *) - let rollup = Sc_rollup_proto_types.Address.to_octez rollup in - let their_commitment = - Sc_rollup_proto_types.Commitment.to_octez their_commitment - in - accuser_publish_commitment_when_refutable - node_ctxt - ~other:source - rollup - their_commitment - their_commitment_hash - | ( Sc_rollup_cement _, - Sc_rollup_cement_result {inbox_level; commitment_hash; _} ) -> - (* Cemented commitment ---------------------------------------------- *) - let inbox_level = Raw_level.to_int32 inbox_level in - let commitment_hash = - Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash - in - let* inbox_block = - Node_context.get_l2_block_by_level node_ctxt inbox_level - in - let*? () = - (* We stop the node if we disagree with a cemented commitment *) - let our_commitment_hash = inbox_block.header.commitment_hash in - error_unless - (Option.equal - Octez_smart_rollup.Commitment.Hash.( = ) - our_commitment_hash - (Some commitment_hash)) - (Sc_rollup_node_errors.Disagree_with_cemented - {inbox_level; ours = our_commitment_hash; on_l1 = commitment_hash}) - in - let* () = - Node_context.set_lcc - node_ctxt - {commitment = commitment_hash; level = inbox_level} - in - let* () = maybe_recover_bond node_ctxt in - return_unit - | ( Sc_rollup_refute _, - Sc_rollup_refute_result {game_status = Ended end_status; _} ) - | ( Sc_rollup_timeout _, - Sc_rollup_timeout_result {game_status = Ended end_status; _} ) -> ( - match end_status with - | Loser {loser; reason} - when Node_context.is_operator - node_ctxt - (Tezos_crypto.Signature.Of_V1.public_key_hash loser) -> - let result = - match reason with - | Conflict_resolved -> Sc_rollup_node_errors.Conflict_resolved - | Timeout -> Timeout - in - tzfail (Sc_rollup_node_errors.Lost_game result) - | Loser _ -> - (* Other player lost *) - return_unit - | Draw -> - let stakers = - match operation with - | Sc_rollup_refute {opponent; _} -> - [source; Tezos_crypto.Signature.Of_V1.public_key_hash opponent] - | Sc_rollup_timeout {stakers = {alice; bob}; _} -> - [ - Tezos_crypto.Signature.Of_V1.public_key_hash alice; - Tezos_crypto.Signature.Of_V1.public_key_hash bob; - ] - | _ -> assert false - in - fail_when - (List.exists (Node_context.is_operator node_ctxt) stakers) - (Sc_rollup_node_errors.Lost_game Draw)) - | Dal_publish_slot_header _, Dal_publish_slot_header_result {slot_header; _} - when Node_context.dal_supported node_ctxt -> - let* () = - Node_context.save_slot_header - node_ctxt - ~published_in_block_hash:head.Layer1.hash - (Sc_rollup_proto_types.Dal.Slot_header.to_octez slot_header) - in - return_unit - (* If the node is in bailout mode and the bond of the operator has - been recovered then initiate an exit from bailout mode and - gracefully shut down the process. Otherwise, no action is - taken. *) - | Sc_rollup_recover_bond {staker; _}, Sc_rollup_recover_bond_result _ - when Node_context.is_bailout node_ctxt -> ( - match Node_context.get_operator node_ctxt Operating with - | Some (Single operating_pkh) -> - fail_when - Tezos_crypto.Signature.Public_key_hash.( - operating_pkh - = Tezos_crypto.Signature.Of_V1.public_key_hash staker) - Sc_rollup_node_errors.Exit_bond_recovered_bailout_mode - | _ -> return_unit) - | _, _ -> - (* Other manager operations *) - return_unit - -let process_l1_operation (type kind) node_ctxt (head : Layer1.header) ~source - (operation : kind manager_operation) - (result : kind Apply_results.manager_operation_result) = - let open Lwt_result_syntax in - let is_for_my_rollup : type kind. kind manager_operation -> bool = function - | Sc_rollup_add_messages _ -> true - | Sc_rollup_cement {rollup; _} - | Sc_rollup_publish {rollup; _} - | Sc_rollup_refute {rollup; _} - | Sc_rollup_timeout {rollup; _} - | Sc_rollup_execute_outbox_message {rollup; _} - | Sc_rollup_recover_bond {sc_rollup = rollup; staker = _} -> - Octez_smart_rollup.Address.( - Sc_rollup_proto_types.Address.to_octez rollup - = node_ctxt.Node_context.config.sc_rollup_address) - | Dal_publish_slot_header _ -> true - | Reveal _ | Transaction _ | Origination _ | Delegation _ - | Update_consensus_key _ | Register_global_constant _ | Set_deposits_limit _ - | Increase_paid_storage _ | Transfer_ticket _ | Sc_rollup_originate _ - | Zk_rollup_origination _ | Zk_rollup_publish _ | Zk_rollup_update _ -> - false - in - (* Only look at operations that are for the node's rollup *) - if not (is_for_my_rollup operation) then return_unit - else - let*! () = - (* Only event for rollup node's own operations *) - if not (Node_context.is_operator node_ctxt source) then Lwt.return_unit - else - match Sc_rollup_injector.injector_operation_of_manager operation with - | None -> Lwt.return_unit - | Some op -> - let status, errors = - match result with - | Applied _ -> (`Applied, None) - | Backtracked (_, e) -> - (`Backtracked, Option.map Environment.wrap_tztrace e) - | Failed (_, e) -> (`Failed, Some (Environment.wrap_tztrace e)) - | Skipped _ -> (`Skipped, None) - in - Daemon_event.included_operation ?errors status op - in - match result with - | Applied success_result -> - process_included_l1_operation - node_ctxt - head - ~source - operation - success_result - | _ -> - (* No action for non successful operations *) - return_unit - -let process_l1_block_operations ~catching_up:_ node_ctxt (head : Layer1.header) - = - let open Lwt_result_syntax in - let* block = - Layer1_helpers.fetch_tezos_block node_ctxt.Node_context.l1_ctxt head.hash - in - let apply (type kind) accu ~source (operation : kind manager_operation) result - = - let open Lwt_result_syntax in - let* () = accu in - let source = Tezos_crypto.Signature.Of_V1.public_key_hash source in - process_l1_operation node_ctxt head ~source operation result - in - let apply_internal (type kind) accu ~source:_ - (_operation : kind Apply_internal_results.internal_operation) - (_result : kind Apply_internal_results.internal_operation_result) = - accu - in - let* () = - Layer1_services.process_manager_operations - return_unit - block.operations - {apply; apply_internal} - in - return_unit diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_helpers.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_helpers.mli deleted file mode 100644 index 24dc1b74acf6173b0966ad2d82be1d373045bc47..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon_helpers.mli +++ /dev/null @@ -1,32 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Nomadic Labs, *) -(* Copyright (c) 2023 TriliTech *) -(* 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. *) -(* *) -(*****************************************************************************) - -include Protocol_plugin_sig.L1_PROCESSING - -(** Ensure that the initial state hash of the PVM as defined by the rollup node - matches the one of the PVM on the L1 node. *) -val check_pvm_initial_state_hash : _ Node_context.t -> unit tzresult Lwt.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_pages_request.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/dal_pages_request.ml deleted file mode 100644 index 7424e66d0261dbc67ab8cd341120a4e99d607894..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_pages_request.ml +++ /dev/null @@ -1,153 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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 -open Alpha_context - -(** If a slot, published at some level L, is expected to be confirmed at level - L+D then, once the confirmation level is over, the rollup node is supposed to: - - Download and save the content of the slot's pages in the store, if the slot - is confirmed; - - Add entries [None] for the slot's pages in the store, if the slot - is not confirmed. *) - -type error += - | Dal_slot_not_found_in_store of Dal.Slot.Header.id - | Dal_invalid_page_for_slot of Dal.Page.t - -let () = - Sc_rollup_node_errors.register_error_kind - `Permanent - ~id:"dal_pages_request.dal_slot_not_found_in_store" - ~title:"Dal slot not found in store" - ~description:"The Dal slot whose ID is given is not found in the store" - ~pp:(fun ppf -> - Format.fprintf ppf "Dal slot not found in store %a" Dal.Slot.Header.pp_id) - Data_encoding.(obj1 (req "slot_id" Dal.Slot.Header.id_encoding)) - (function Dal_slot_not_found_in_store slot_id -> Some slot_id | _ -> None) - (fun slot_id -> Dal_slot_not_found_in_store slot_id) ; - Sc_rollup_node_errors.register_error_kind - `Permanent - ~id:"dal_pages_request.dal_invalid_page_for_slot" - ~title:"Invalid Dal page requested for slot" - ~description:"The requested Dal page for a given slot is invalid" - ~pp:(fun ppf -> - Format.fprintf ppf "Invalid Dal page requested %a" Dal.Page.pp) - Data_encoding.(obj1 (req "page_id" Dal.Page.encoding)) - (function Dal_invalid_page_for_slot page_id -> Some page_id | _ -> None) - (fun page_id -> Dal_invalid_page_for_slot page_id) - -let store_entry_from_published_level ~dal_attestation_lag ~published_level - node_ctxt = - Node_context.hash_of_level node_ctxt - @@ Int32.( - add (of_int dal_attestation_lag) (Raw_level.to_int32 published_level)) - -module Slot_id = struct - include Tezos_dal_node_services.Types.Slot_id - - let equal id1 id2 = Comparable.compare id1 id2 = 0 - - let hash id = Hashtbl.hash id -end - -(* The cache allows to not fetch pages on the DAL node more than necessary. *) -module Pages_cache = - Aches_lwt.Lache.Make (Aches.Rache.Transfer (Aches.Rache.LRU) (Slot_id)) - -let get_slot_pages = - let pages_cache = - Pages_cache.create 16 - (* 130MB *) - in - fun dal_cctxt commitment -> - Pages_cache.bind_or_put - pages_cache - commitment - (Dal_node_client.get_slot_pages dal_cctxt) - Lwt.return - -let download_confirmed_slot_pages {Node_context.dal_cctxt; _} ~published_level - ~index = - let dal_cctxt = WithExceptions.Option.get ~loc:__LOC__ dal_cctxt in - (* DAL must be configured for this point to be reached *) - get_slot_pages - dal_cctxt - {slot_level = Raw_level.to_int32 published_level; slot_index = index} - -let storage_invariant_broken published_level index = - failwith - "Internal error: [Node_context.find_slot_status] is supposed to have \ - registered the status of the slot %d published at level %a in the store" - index - Raw_level.pp - published_level - -let slot_pages ~dal_attestation_lag node_ctxt - Dal.Slot.Header.{published_level; index} = - let open Lwt_result_syntax in - let* confirmed_in_block_hash = - store_entry_from_published_level - ~dal_attestation_lag - ~published_level - node_ctxt - in - let index = Dal.Slot_index.to_int index in - let* processed = - Node_context.find_slot_status node_ctxt ~confirmed_in_block_hash index - in - match processed with - | Some `Confirmed -> - let* pages = - download_confirmed_slot_pages node_ctxt ~published_level ~index - in - return (Some pages) - | Some `Unconfirmed -> return None - | None -> storage_invariant_broken published_level index - -let page_content ~dal_attestation_lag node_ctxt page_id = - let open Lwt_result_syntax in - let Dal.Page.{slot_id; page_index} = page_id in - let Dal.Slot.Header.{published_level; index} = slot_id in - let* confirmed_in_block_hash = - store_entry_from_published_level - ~dal_attestation_lag - ~published_level - node_ctxt - in - let index = Dal.Slot_index.to_int index in - let* processed = - Node_context.find_slot_status node_ctxt ~confirmed_in_block_hash index - in - match processed with - | Some `Confirmed -> ( - let* pages = - download_confirmed_slot_pages node_ctxt ~published_level ~index - in - match List.nth_opt pages page_index with - | Some page -> return @@ Some page - | None -> tzfail @@ Dal_invalid_page_for_slot page_id) - | Some `Unconfirmed -> return None - | None -> storage_invariant_broken published_level index diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_pages_request.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/dal_pages_request.mli deleted file mode 100644 index f27d737fbc29eb109f1e6799425491e8c9256231..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_pages_request.mli +++ /dev/null @@ -1,76 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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 -open Alpha_context - -(** Access DAL slots and pages content. - - This module is a wrapper on top of {!Store.Dal_slot_pages} module to - access DAL slots and pages' data that have been previously fetched by - the rollup node. -*) - -(** This error is returned when a slot, identified by its ID, is not found in - the store. *) -type error += Dal_slot_not_found_in_store of Dal.Slot.Header.id - -(** Retrieve the pages' content of the given slot ID's from the store. - - The function returns [Dal_slot_not_found_in_store] if no entry is found in - the store for the given ID (i.e. no page is registered with or without content). - - If the returned value is [Some pages], the slot whose ID is given is - supposed to be confirmed and [pages] correspond to the pages of the slot. - Otherwise [None] is returned. - - The function relies on {!Store.Dal_slot_pages}'s invariants to guarantee that: - - the pages are returned in increasing order w.r.t. their indexes in the slot; - - the size of the list, in case it is not empty, is equal to the expected - number of pages in a slot. - - [dal_attestation_lag] is used to retrieve the correct entry in [store]. -*) -val slot_pages : - dal_attestation_lag:int -> - _ Node_context.t -> - Dal.slot_id -> - Dal.Page.content list option tzresult Lwt.t - -(** Retrieve the content of the page identified by the given ID from the store. - - The function returns [Dal_slot_not_found_in_store] if no entry is found in - the store for the given ID. It - returns [None] in case the entry is found, but the slot is not confirmed. Said - otherwise, some content is only returned for confirmed pages (slots) for - which the content has already been downloaded and saved to the store. - - [dal_attestation_lag] is used to retrieve the correct entry in [store]. -*) -val page_content : - dal_attestation_lag:int -> - _ Node_context.t -> - Dal.Page.t -> - Dal.Page.content option tzresult Lwt.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_slots_tracker.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/dal_slots_tracker.ml deleted file mode 100644 index f9f03db9a6c0151ff4ea8da58020b39aea7efed0..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_slots_tracker.ml +++ /dev/null @@ -1,189 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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 -open Alpha_context - -let ancestor_hash ~number_of_levels - ({Node_context.genesis_info; _} as node_ctxt) head = - let genesis_level = genesis_info.level in - let rec go number_of_levels (Layer1.{hash; level} as head) = - let open Lwt_result_syntax in - if level < genesis_level then return_none - else if number_of_levels = 0 then return_some hash - else - let* pred_head = Node_context.get_predecessor_opt node_ctxt head in - match pred_head with - | None -> return_none - | Some pred_head -> go (number_of_levels - 1) pred_head - in - go number_of_levels head - -(* Values of type `confirmations_info` are used to catalog the status of slots - published in a given block hash. These values record whether - the slot has been confirmed after the attestation_lag has passed. *) -type confirmations_info = { - (* The hash of the block in which the slots have been published. *) - published_block_hash : Block_hash.t; - (* The indexes of slots that have beenp published in block - with hash `published_block_hash`, and have later been confirmed. *) - confirmed_slots_indexes : Bitset.t; -} - -(** [slots_info constants node_ctxt head] gathers information about the slot confirmations - of slot indexes. It reads the slot indexes that have been declared available - from [head]'s block receipt. It then returns the hash of - the block where the slot headers have been published and the list of - slot indexes that have been confirmed for that block. *) -let slots_info constants node_ctxt (Layer1.{hash; _} as head) = - (* DAL/FIXME: https://gitlab.com/tezos/tezos/-/issues/3722 - The case for protocol migrations when the lag constant has - been changed is tricky, especially if the lag is reduced. - Suppose that a slot header is published at the second last level of a - cycle, and the lag is 2. The block is expected to be confirmed at the - first level of the new cycle. However, if during the protocol migration - we reduce the lag to 1, then the slots header will never be confirmed. - *) - let open Lwt_result_syntax in - let lag = constants.Rollup_constants.dal.attestation_lag in - (* we are downloading endorsemented for slots at level [level], so - we need to download the data at level [level - lag]. - *) - let* published_slots_block_hash = - ancestor_hash ~number_of_levels:lag node_ctxt head - in - match published_slots_block_hash with - | None -> - (* Less then lag levels have passed from the rollup origination, and - confirmed slots should not be applied *) - return None - | Some published_block_hash -> - let* {metadata; _} = - Layer1_helpers.fetch_tezos_block node_ctxt.Node_context.l1_ctxt hash - in - let*? metadata = - Option.to_result - ~none:(TzTrace.make @@ Layer1_services.Cannot_read_block_metadata hash) - metadata - in - (* `metadata.protocol_data.dal_attestation` is `None` if we are behind - the `Dal feature flag`: in this case we return an empty slot endorsement. - *) - let confirmed_slots = - Option.value - ~default:Dal.Attestation.empty - metadata.protocol_data.dal_attestation - in - let* published_slots_indexes = - Node_context.get_slot_indexes - node_ctxt - ~published_in_block_hash:published_block_hash - in - let confirmed_slots_indexes_list = - List.filter - (Dal.Attestation.is_attested confirmed_slots) - (List.filter_map Dal.Slot_index.of_int_opt published_slots_indexes) - in - let*? confirmed_slots_indexes = - Environment.wrap_tzresult - (confirmed_slots_indexes_list - |> List.map Dal.Slot_index.to_int - |> Bitset.from_list) - in - return @@ Some {published_block_hash; confirmed_slots_indexes} - -(* DAL/FIXME: https://gitlab.com/tezos/tezos/-/issues/3884 - avoid going back and forth between bitsets and lists of slot indexes. *) -let to_slot_index_list (constants : Rollup_constants.protocol_constants) bitset - = - let all_slots = Misc.(0 --> (constants.dal.number_of_slots - 1)) in - List.filter_e (Bitset.mem bitset) all_slots - -(* DAL/FIXME: https://gitlab.com/tezos/tezos/-/issues/4139. - Use a shared storage between dal and rollup node to store slots data. -*) - -let download_and_save_slots constants (node_context : _ Node_context.t) - ~current_block_hash {published_block_hash; confirmed_slots_indexes} = - let open Lwt_result_syntax in - let*? all_slots = - Bitset.fill ~length:constants.Rollup_constants.dal.number_of_slots - |> Environment.wrap_tzresult - in - let*? not_confirmed = - Environment.wrap_tzresult - @@ to_slot_index_list constants - @@ Bitset.diff all_slots confirmed_slots_indexes - in - let*? confirmed = - Environment.wrap_tzresult - @@ to_slot_index_list constants confirmed_slots_indexes - in - (* The contents of each slot index are written to a different location on - disk, therefore calls to store contents for different slot indexes can - be parallelized. *) - let* () = - List.iter_ep - (fun s_slot -> - Node_context.save_slot_status - node_context - current_block_hash - s_slot - `Unconfirmed) - not_confirmed - in - List.iter_ep - (fun s_slot -> - let* () = - Node_context.save_slot_status - node_context - current_block_hash - s_slot - `Confirmed - in - let*? s_slot = - Environment.wrap_tzresult @@ Dal.Slot_index.of_int s_slot - in - let*! () = - Dal_slots_tracker_event.slot_has_been_confirmed - s_slot - published_block_hash - current_block_hash - in - return_unit) - confirmed - -let process_head node_ctxt (Layer1.{hash = head_hash; level} as head) = - let open Lwt_result_syntax in - let* constants = Protocol_plugins.get_constants_of_level node_ctxt level in - let* confirmation_info = slots_info constants node_ctxt head in - match confirmation_info with - | None -> return_unit - | Some confirmation_info -> - download_and_save_slots - ~current_block_hash:head_hash - constants - node_ctxt - confirmation_info diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_slots_tracker.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/dal_slots_tracker.mli deleted file mode 100644 index cec412233c110624236ef9005afb8b67e2d96c18..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_slots_tracker.mli +++ /dev/null @@ -1,34 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -(** The rollup node keeps the list of dal slots for each block it needs to - process. This is to determine whether the inbox for a given block will need - to be retrieved from the block operations, or from the data availability - layer after lag levels have passed and the slot for the block has been - declared available. - - The state of slots per block is persistent. *) - -include Protocol_plugin_sig.DAL_SLOTS_TRACKER diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_slots_tracker_event.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/dal_slots_tracker_event.ml deleted file mode 100644 index 05620638edb998237635252ebe5799f9fb3e1013..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_slots_tracker_event.ml +++ /dev/null @@ -1,49 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 TriliTech *) -(* *) -(* 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 -open Alpha_context - -module Simple = struct - include Internal_event.Simple - - let section = [Protocol.name; "sc_rollup_node"; "dal_slots_tracker"] - - let slot_has_been_confirmed = - declare_3 - ~section - ~name:"dal_confirmed_slot" - ~msg: - "Slot header for index {slot_index} was published at block \ - {published_hash}. The slot header has been confirmed at \ - {confirmed_hash}. The slot contents will be downloaded." - ~level:Notice - ("slot_index", Dal.Slot_index.encoding) - ("published_hash", Block_hash.encoding) - ("confirmed_hash", Block_hash.encoding) -end - -let slot_has_been_confirmed slot published_hash confirmed_hash = - Simple.(emit slot_has_been_confirmed (slot, published_hash, confirmed_hash)) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/dune b/src/proto_017_PtNairob/lib_sc_rollup_node/dune deleted file mode 100644 index f12335716415da88eef2705bb3fa2b752bdd7bb4..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/dune +++ /dev/null @@ -1,80 +0,0 @@ -; This file was automatically generated, do not edit. -; Edit file manifest/main.ml instead. - -(library - (name octez_smart_rollup_node_PtNairob) - (package octez-smart-rollup-node-PtNairob) - (instrumentation (backend bisect_ppx)) - (libraries - octez-libs.base - octez-libs.stdlib-unix - octez-shell-libs.client-base - octez-shell-libs.client-base-unix - octez-protocol-017-PtNairob-libs.client - octez-libs.tezos-context.encoding - octez-libs.tezos-context.helpers - tezos-protocol-017-PtNairob.protocol - octez-protocol-017-PtNairob-libs.plugin - tezos-protocol-017-PtNairob.parameters - octez-libs.rpc - octez-libs.rpc-http - octez-libs.rpc-http-server - octez-libs.tezos-workers - tezos-dal-node-services - tezos-dal-node-lib - octez-shell-libs.shell-services - octez-l2-libs.smart-rollup - octez-protocol-017-PtNairob-libs.smart-rollup - octez-protocol-017-PtNairob-libs.smart-rollup-layer2 - octez-protocol-017-PtNairob-libs.layer2-utils - octez-l2-libs.layer2_store - octez-l2-libs.riscv_context - octez-l2-libs.irmin_context - octez-crawler - octez-libs.tree-encoding - octez-libs.data-encoding - octez-internal-libs.irmin_pack - octez-internal-libs.irmin_pack.unix - octez-internal-libs.irmin - aches - aches-lwt - octez-injector - octez-smart-rollup-node-lib - octez-libs.scoru-wasm - octez-l2-libs.scoru-wasm-fast - octez-libs.crypto-dal - octez-version.value) - (library_flags (:standard -linkall)) - (flags - (:standard) - -open Tezos_base - -open Tezos_base.TzPervasives - -open Tezos_base.TzPervasives.Error_monad_legacy - -open Tezos_stdlib_unix - -open Tezos_client_base - -open Tezos_client_base_unix - -open Tezos_client_017_PtNairob - -open Tezos_protocol_017_PtNairob - -open Tezos_protocol_plugin_017_PtNairob - -open Tezos_protocol_017_PtNairob_parameters - -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 - -open Tezos_layer2_store - -open Tezos_layer2_riscv_context - -open Tezos_layer2_irmin_context - -open Octez_crawler - -open Octez_injector - -open Octez_smart_rollup_node - -open Tezos_crypto_dal)) - -(rule - (targets signature.ml) - (action - (write-file - %{targets} - " module Bls = Tezos_crypto.Signature.Bls\n module Ed25519 = Tezos_crypto.Signature.Ed25519\n module P256 = Tezos_crypto.Signature.P256\n module Secp256k1 = Tezos_crypto.Signature.Secp256k1\n include Tezos_crypto.Signature.V1"))) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/fueled_pvm.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/fueled_pvm.ml deleted file mode 100644 index aa832b38272db223ed57c9d7a546edf73bae8ec0..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/fueled_pvm.ml +++ /dev/null @@ -1,468 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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 -open Alpha_context -open Context_wrapper.Irmin -module Inbox = Sc_rollup.Inbox -open Pvm_plugin_sig - -module Make_fueled (F : Fuel.S) : FUELED_PVM with type fuel = F.t = struct - type fuel = F.t - - type pvm_state = Irmin_context.tree - - let get_reveal ~pre_images_endpoint ~data_dir ~pvm_kind reveal_map hash = - let found_in_map = - match reveal_map with - | None -> None - | Some map -> - Utils.Reveal_hash_map.find_opt (Reveals.proto_hash_to_bytes hash) map - in - match found_in_map with - | Some data -> return data - | None -> Reveals.get ~pre_images_endpoint ~data_dir ~pvm_kind ~hash - - type eval_completion = - | Aborted of {state : pvm_state; fuel : fuel; current_tick : int64} - | Completed of { - state : pvm_state; - fuel : fuel; - current_tick : int64; - failing_ticks : int64 list; - } - - exception Error_wrapper of tztrace - - let metadata (node_ctxt : _ Node_context.t) = - let address = - Sc_rollup_proto_types.Address.of_octez node_ctxt.config.sc_rollup_address - in - let origination_level = - Raw_level.of_int32_exn node_ctxt.genesis_info.level - in - Sc_rollup.Metadata.{address; origination_level} - - (** [eval_until_input node_ctxt reveal_map level message_index ~fuel - start_tick failing_ticks state] advances a PVM [state] until it wants - more inputs or there are no more [fuel] (if [Some fuel] is - specified). The evaluation is running under the processing of some - [message_index] at a given [level] and this is the [start_tick] of this - message processing. If some [failing_ticks] are planned by the loser - mode, they will be made. *) - let eval_until_input (node_ctxt : _ Node_context.t) reveal_map level - message_index ~fuel start_tick failing_ticks state = - let open Lwt_result_syntax in - let* constants = - Protocol_plugins.get_constants_of_level node_ctxt (Int32.of_int level) - in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let metadata = metadata node_ctxt in - let dal_attestation_lag = constants.dal.attestation_lag in - let decode_reveal (Tezos_scoru_wasm.Wasm_pvm_state.Reveal_raw payload) = - match - Data_encoding.Binary.of_string_opt - Sc_rollup_PVM_sig.reveal_encoding - payload - with - | Some reveal -> reveal - | None -> - (* If the kernel has tried to submit an incorrect reveal request, - we don’t stuck the rollup. Instead, we fallback to the - requesting the [well_known_reveal_hash] preimage *) - Reveal_raw_data Sc_rollup.Wasm_2_0_0PVM.well_known_reveal_hash - in - let reveal_builtins request = - match decode_reveal request with - | Reveal_raw_data hash -> ( - let*! data = - get_reveal - ~pre_images_endpoint:node_ctxt.config.pre_images_endpoint - ~data_dir:node_ctxt.data_dir - ~pvm_kind:node_ctxt.kind - reveal_map - hash - in - match data with - | Error error -> - (* The [Error_wrapper] must be caught upstream and converted into - a tzresult. *) - Lwt.fail (Error_wrapper error) - | Ok data -> Lwt.return data) - | Reveal_metadata -> - Lwt.return - (Data_encoding.Binary.to_string_exn - Sc_rollup.Metadata.encoding - metadata) - | Request_dal_page _ -> - (* DAL in the Fast Execution WASM PVM is not supported for Mumbai. *) - assert false - in - let eval_tick fuel failing_ticks state = - let max_steps = F.max_ticks fuel in - let normal_eval ?(max_steps = max_steps) state = - Lwt.catch - (fun () -> - let*! state, executed_ticks = - PVM.eval_many - ~reveal_builtins - ~write_debug:(Printer node_ctxt.kernel_debug_logger) - ~max_steps - state - in - return (state, executed_ticks, failing_ticks)) - (function - | Error_wrapper error -> Lwt.return (Error error) - | exn -> Lwt.reraise exn) - in - let failure_insertion_eval state tick failing_ticks' = - let*! () = - Interpreter_event.intended_failure - ~level - ~message_index - ~message_tick:tick - ~internal:true - in - let*! state = PVM.Internal_for_tests.insert_failure state in - return (state, 1L, failing_ticks') - in - match failing_ticks with - | xtick :: failing_ticks' -> - let jump = Int64.(max 0L (pred xtick)) in - if Compare.Int64.(jump = 0L) then - (* Insert the failure in the first tick. *) - failure_insertion_eval state xtick failing_ticks' - else - (* Jump just before the tick where we'll insert a failure. - Nevertheless, we don't execute more than [max_steps]. *) - let max_steps = Int64.max 0L max_steps |> Int64.min max_steps in - let* state, executed_ticks, _failing_ticks = - normal_eval ~max_steps state - in - (* Insert the failure. *) - let* state, executed_ticks', failing_ticks' = - failure_insertion_eval state xtick failing_ticks' - in - let executed_ticks = Int64.add executed_ticks executed_ticks' in - return (state, executed_ticks, failing_ticks') - | _ -> normal_eval state - in - let abort state fuel current_tick = - return (Aborted {state; fuel; current_tick}) - in - let complete state fuel current_tick failing_ticks = - return (Completed {state; fuel; current_tick; failing_ticks}) - in - let rec go (fuel : fuel) current_tick failing_ticks state = - let*! input_request = PVM.is_input_state state in - match input_request with - | No_input_required when F.is_empty fuel -> abort state fuel current_tick - | No_input_required -> ( - let* next_state, executed_ticks, failing_ticks = - eval_tick fuel failing_ticks state - in - let fuel_executed = F.of_ticks executed_ticks in - match F.consume fuel_executed fuel with - | None -> abort state fuel current_tick - | Some fuel -> - go - fuel - (Int64.add current_tick executed_ticks) - failing_ticks - next_state) - | Needs_reveal (Reveal_raw_data hash) -> ( - let* data = - get_reveal - ~pre_images_endpoint:node_ctxt.config.pre_images_endpoint - ~data_dir:node_ctxt.data_dir - ~pvm_kind:node_ctxt.kind - reveal_map - hash - in - let*! next_state = PVM.set_input (Reveal (Raw_data data)) state in - match F.consume F.one_tick_consumption fuel with - | None -> abort state fuel current_tick - | Some fuel -> - go fuel (Int64.succ current_tick) failing_ticks next_state) - | Needs_reveal Reveal_metadata -> ( - let*! next_state = PVM.set_input (Reveal (Metadata metadata)) state in - match F.consume F.one_tick_consumption fuel with - | None -> abort state fuel current_tick - | Some fuel -> - go fuel (Int64.succ current_tick) failing_ticks next_state) - | Needs_reveal (Request_dal_page page_id) -> ( - let* content_opt = - Dal_pages_request.page_content - ~dal_attestation_lag - node_ctxt - page_id - in - let*! next_state = - PVM.set_input (Reveal (Dal_page content_opt)) state - in - match F.consume F.one_tick_consumption fuel with - | None -> abort state fuel current_tick - | Some fuel -> - go fuel (Int64.succ current_tick) failing_ticks next_state) - | Initial | First_after _ -> - complete state fuel current_tick failing_ticks - in - go fuel start_tick failing_ticks state - - (** [mutate input] corrupts the payload of [input] for testing purposes. *) - let mutate input = - let payload = - Sc_rollup.Inbox_message.unsafe_of_string - "\001to the cheater we promise pain and misery" - in - {input with Sc_rollup.payload} - - type feed_input_completion = - | Feed_input_aborted of {state : pvm_state; fuel : fuel; fed_input : bool} - | Feed_input_completed of {state : pvm_state; fuel : fuel} - - (** [feed_input node_ctxt reveal_map level message_index ~fuel - ~failing_ticks state input] feeds [input] (that has a given - [message_index] in inbox of [level]) to the PVM in order to advance - [state] to the next step that requires an input. This function is - controlled by some [fuel] and may introduce intended failures at some - given [failing_ticks]. *) - let feed_input (node_ctxt : _ Node_context.t) reveal_map level message_index - ~fuel ~failing_ticks state input = - let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let* res = - eval_until_input - node_ctxt - reveal_map - level - message_index - ~fuel - 0L - failing_ticks - state - in - match res with - | Aborted {state; fuel; _} -> - return (Feed_input_aborted {state; fuel; fed_input = false}) - | Completed {state; fuel; current_tick = tick; failing_ticks} -> ( - match F.consume F.one_tick_consumption fuel with - | None -> return (Feed_input_aborted {state; fuel; fed_input = false}) - | Some fuel -> ( - let* input, failing_ticks = - match failing_ticks with - | xtick :: failing_ticks' -> - if xtick = tick then - let*! () = - Interpreter_event.intended_failure - ~level - ~message_index - ~message_tick:tick - ~internal:false - in - return (mutate input, failing_ticks') - else return (input, failing_ticks) - | [] -> return (input, failing_ticks) - in - let*! state = PVM.set_input (Inbox_message input) state in - let* res = - eval_until_input - node_ctxt - reveal_map - level - message_index - ~fuel - tick - failing_ticks - state - in - match res with - | Aborted {state; fuel; _} -> - return (Feed_input_aborted {state; fuel; fed_input = true}) - | Completed {state; fuel; _} -> - return (Feed_input_completed {state; fuel}))) - - let eval_messages ~reveal_map ~fuel node_ctxt ~message_counter_offset state - inbox_level messages = - let open Lwt_result_syntax in - let level = Int32.to_int inbox_level in - (* Iterate the PVM state with all the messages. *) - let rec feed_messages (state, fuel) message_index = function - | [] -> - (* Fed all messages *) - return (state, fuel, message_index - message_counter_offset, []) - | messages when F.is_empty fuel -> - (* Consumed all fuel *) - return (state, fuel, message_index - message_counter_offset, messages) - | message :: messages -> ( - let payload = Sc_rollup.Inbox_message.unsafe_of_string message in - let message_counter = Z.of_int message_index in - let input = - Sc_rollup. - { - inbox_level = Raw_level.of_int32_exn inbox_level; - message_counter; - payload; - } - in - let failing_ticks = - Loser_mode.is_failure - node_ctxt.Node_context.config.loser_mode - ~level - ~message_index - in - let* res = - feed_input - node_ctxt - reveal_map - level - message_index - ~fuel - ~failing_ticks - state - input - in - match res with - | Feed_input_completed {state; fuel} -> - feed_messages (state, fuel) (message_index + 1) messages - | Feed_input_aborted {state; fuel; fed_input = false} -> - return - ( state, - fuel, - message_index - message_counter_offset, - message :: messages ) - | Feed_input_aborted {state; fuel; fed_input = true} -> - return - ( state, - fuel, - message_index + 1 - message_counter_offset, - messages )) - in - (feed_messages [@tailcall]) (state, fuel) message_counter_offset messages - - let eval_block_inbox ~fuel (node_ctxt : _ Node_context.t) (inbox, messages) - (state : Context.pvmstate) : fuel eval_result tzresult Lwt.t = - let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - (* Obtain inbox and its messages for this block. *) - let inbox_level = Octez_smart_rollup.Inbox.inbox_level inbox in - let*! initial_tick = PVM.get_tick (of_node_pvmstate state) in - (* Evaluate all the messages for this level. *) - let* state, remaining_fuel, num_messages, remaining_messages = - eval_messages - ~reveal_map:None - ~fuel - node_ctxt - ~message_counter_offset:0 - (of_node_pvmstate state) - inbox_level - messages - in - let*! final_tick = PVM.get_tick state in - let*! state_hash = PVM.state_hash state in - let num_ticks = Sc_rollup.Tick.distance initial_tick final_tick in - let eval_state = - { - state = to_node_pvmstate state; - state_hash = Sc_rollup_proto_types.State_hash.to_octez state_hash; - tick = Sc_rollup.Tick.to_z final_tick; - inbox_level; - message_counter_offset = num_messages; - remaining_fuel; - remaining_messages; - } - in - return {state = eval_state; num_ticks; num_messages} - - let eval_messages ?reveal_map (node_ctxt : _ Node_context.t) - { - state; - tick = initial_tick; - inbox_level; - message_counter_offset; - remaining_fuel = fuel; - remaining_messages = messages; - _; - } = - let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let* state, remaining_fuel, num_messages, remaining_messages = - match messages with - | [] -> - let level = Int32.to_int inbox_level in - let message_index = message_counter_offset - 1 in - let failing_ticks = - Loser_mode.is_failure - node_ctxt.Node_context.config.loser_mode - ~level - ~message_index - in - let* res = - eval_until_input - node_ctxt - reveal_map - level - message_index - ~fuel - 0L - failing_ticks - (of_node_pvmstate state) - in - let state, remaining_fuel = - match res with - | Aborted {state; fuel; _} | Completed {state; fuel; _} -> - (state, fuel) - in - return (state, remaining_fuel, 0, []) - | _ -> - eval_messages - ~reveal_map - ~fuel - node_ctxt - ~message_counter_offset - (of_node_pvmstate state) - inbox_level - messages - in - let*! final_tick = PVM.get_tick state in - let final_tick = Sc_rollup.Tick.to_z final_tick in - let*! state_hash = PVM.state_hash state in - let num_ticks = Z.sub final_tick initial_tick in - let eval_state = - { - state = to_node_pvmstate state; - state_hash = Sc_rollup_proto_types.State_hash.to_octez state_hash; - tick = final_tick; - inbox_level; - message_counter_offset = message_counter_offset + num_messages; - remaining_fuel; - remaining_messages; - } - in - return {state = eval_state; num_ticks; num_messages} -end - -module Free = Make_fueled (Fuel.Free) -module Accounted = Make_fueled (Fuel.Accounted) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/inbox.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/inbox.ml deleted file mode 100644 index e72f812f32f3b1327529ac6f7676f18c32befbdb..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/inbox.ml +++ /dev/null @@ -1,290 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -(* module Constants will be shadowed by Alpha_context.Constansts - once we open Alpha_context, hence we we alias it to Rollup_node_constants -*) -open Protocol -open Alpha_context - -let lift promise = Lwt.map Environment.wrap_tzresult promise - -let get_messages Node_context.{l1_ctxt; _} head = - let open Lwt_result_syntax in - let* block = Layer1_helpers.fetch_tezos_block l1_ctxt head in - let apply (type kind) accu ~source:_ (operation : kind manager_operation) - _result = - let open Result_syntax in - let+ accu in - match operation with - | Sc_rollup_add_messages {messages} -> - let messages = - List.map - (fun message -> Sc_rollup.Inbox_message.External message) - messages - in - List.rev_append messages accu - | _ -> accu - in - let apply_internal (type kind) accu ~source - (operation : kind Apply_internal_results.internal_operation) - (result : - kind Apply_internal_results.successful_internal_operation_result) = - let open Result_syntax in - let* accu in - match (operation, result) with - | ( { - operation = Transaction {destination = Sc_rollup rollup; parameters; _}; - source = Contract (Originated sender); - _; - }, - ITransaction_result (Transaction_to_sc_rollup_result _) ) -> - let+ payload = - Environment.wrap_tzresult @@ Script_repr.force_decode parameters - in - let message = - Sc_rollup.Inbox_message.Transfer - {destination = rollup; payload; sender; source} - in - Sc_rollup.Inbox_message.Internal message :: accu - | _ -> return accu - in - let*? rev_messages = - Layer1_services.( - process_applied_manager_operations - (Ok []) - block.operations - {apply; apply_internal}) - in - let*? messages = - Environment.wrap_tzresult - @@ List.rev_map_e - (fun msg -> - let open Result_syntax in - let+ msg = Sc_rollup.Inbox_message.serialize msg in - Sc_rollup.Inbox_message.unsafe_to_string msg) - rev_messages - in - return messages - -let same_as_layer_1 node_ctxt level inbox = - let open Lwt_result_syntax in - let Node_context.{cctxt; _} = node_ctxt in - let cctxt = new Protocol_client_context.wrap_full cctxt in - let* layer1_inbox = - Plugin.RPC.Sc_rollup.inbox cctxt (cctxt#chain, `Level level) - in - let layer1_inbox = Sc_rollup_proto_types.Inbox.to_octez layer1_inbox in - fail_unless - (Octez_smart_rollup.Inbox.equal layer1_inbox inbox) - (Sc_rollup_node_errors.Inconsistent_inbox {layer1_inbox; inbox}) - -let add_messages ~is_first_block ~predecessor_timestamp ~predecessor inbox - messages = - let open Lwt_result_syntax in - let no_history = Sc_rollup.Inbox.History.empty ~capacity:0L in - lift - @@ let*? ( messages_history, - _no_history, - inbox, - witness, - messages_with_protocol_internal_messages ) = - Sc_rollup.Inbox.add_all_messages - ~first_block:is_first_block - ~predecessor_timestamp - ~predecessor - no_history - inbox - messages - in - let witness_hash = - Sc_rollup.Inbox_merkelized_payload_hashes.hash witness - in - return - ( messages_history, - witness_hash, - inbox, - messages_with_protocol_internal_messages ) - -let process_messages (node_ctxt : _ Node_context.t) ~is_first_block - ~(predecessor : Layer1.header) messages = - let open Lwt_result_syntax in - let* inbox = - Node_context.inbox_of_head node_ctxt (Layer1.head_of_header predecessor) - in - let predecessor_timestamp = predecessor.header.timestamp in - let inbox = Sc_rollup_proto_types.Inbox.of_octez inbox in - let*? messages = - Environment.wrap_tzresult - @@ List.map_e - (fun msg -> - Sc_rollup.Inbox_message.(deserialize @@ unsafe_of_string msg)) - messages - in - let* ( _messages_history, - witness_hash, - inbox, - messages_with_protocol_internal_messages ) = - add_messages - ~is_first_block - ~predecessor_timestamp - ~predecessor:predecessor.hash - inbox - messages - in - let inbox = Sc_rollup_proto_types.Inbox.to_octez inbox in - let* inbox_hash = Node_context.save_inbox node_ctxt inbox in - let witness_hash = - Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez witness_hash - in - let*? messages_with_protocol_internal_messages = - Environment.wrap_tzresult - @@ List.map_e - (fun msg -> - let open Result_syntax in - let+ msg = Sc_rollup.Inbox_message.serialize msg in - Sc_rollup.Inbox_message.unsafe_to_string msg) - messages_with_protocol_internal_messages - in - let* () = - Node_context.save_messages - node_ctxt - witness_hash - ~level:(Int32.succ predecessor.level) - messages_with_protocol_internal_messages - in - return - (inbox_hash, inbox, witness_hash, messages_with_protocol_internal_messages) - -let process_head (node_ctxt : _ Node_context.t) ~(predecessor : Layer1.header) - (head : Layer1.header) = - let open Lwt_result_syntax in - let first_inbox_level = node_ctxt.genesis_info.level |> Int32.succ in - if head.level >= first_inbox_level then - (* We compute the inbox of this block using the inbox of its - predecessor. That way, the computation of inboxes is robust to chain - reorganization. *) - let* collected_messages = get_messages node_ctxt head.hash in - let*! () = - Inbox_event.get_messages - head.hash - head.level - (List.length collected_messages) - in - let* head_proto = Node_context.protocol_of_level node_ctxt head.level in - let is_first_block = head_proto.first_level_of_protocol in - process_messages node_ctxt ~is_first_block ~predecessor collected_messages - else - let* inbox = - Layer1_helpers.genesis_inbox - node_ctxt.cctxt - ~genesis_level:node_ctxt.genesis_info.level - in - let Octez_smart_rollup.Inbox.{hash = witness; _} = - Octez_smart_rollup.Inbox.Skip_list.content inbox.old_levels_messages - in - let* () = - Node_context.save_messages node_ctxt witness ~level:head.level [] - in - let* inbox_hash = Node_context.save_inbox node_ctxt inbox in - return (inbox_hash, inbox, witness, []) - -let payloads_history_of_messages ~is_first_block ~predecessor - ~predecessor_timestamp messages = - let open Result_syntax in - let dummy_inbox = - (* The inbox is not necessary to compute the payloads *) - Sc_rollup.Inbox.genesis ~predecessor_timestamp ~predecessor Raw_level.root - in - let* messages = - Environment.wrap_tzresult - @@ List.map_e - (fun msg -> - Sc_rollup.Inbox_message.(deserialize @@ unsafe_of_string msg)) - messages - in - let+ ( payloads_history, - _history, - _inbox, - _witness, - _messages_with_protocol_internal_messages ) = - (* TODO: https://gitlab.com/tezos/tezos/-/issues/4918 Inject - [Protocol_migration (Proto_017)] when migrating to proto_alpha - (N after next snapshot). *) - Environment.wrap_tzresult - @@ Sc_rollup.Inbox.add_all_messages - ~first_block:is_first_block - ~predecessor_timestamp - ~predecessor - (Sc_rollup.Inbox.History.empty ~capacity:0L) - dummy_inbox - messages - in - payloads_history - -let payloads_history_of_all_messages messages = - let open Result_syntax in - let payloads_history = - let capacity = List.length messages |> Int64.of_int in - Sc_rollup.Inbox_merkelized_payload_hashes.History.empty ~capacity - in - match List.map Sc_rollup.Inbox_message.unsafe_of_string messages with - | [] -> assert false - | first :: messages -> - Environment.wrap_tzresult - @@ let* payloads_history, witness = - Sc_rollup.Inbox_merkelized_payload_hashes.genesis - payloads_history - first - in - let* payloads_history, _witness = - List.fold_left_e - (fun (payloads_history, witness) -> - Sc_rollup.Inbox_merkelized_payload_hashes.add_payload - payloads_history - witness) - (payloads_history, witness) - messages - in - return payloads_history - -let serialize_external_message msg = - Environment.wrap_tzresult - @@ - let open Result_syntax in - let open Sc_rollup.Inbox_message in - let+ msg = serialize @@ External msg in - unsafe_to_string msg - -let init ~predecessor_timestamp ~predecessor ~level = - Sc_rollup.Inbox.genesis - ~predecessor_timestamp - ~predecessor - (Raw_level.of_int32_exn level) - |> Sc_rollup_proto_types.Inbox.to_octez - -module Internal_for_tests = struct - let process_messages = process_messages -end diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/inbox.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/inbox.mli deleted file mode 100644 index 367ff3a25f9e13d604711e556d6e2b8db8983716..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/inbox.mli +++ /dev/null @@ -1,72 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -(** The rollup node maintains an inbox of incoming messages. - - The incoming messages for a rollup are published on the layer 1. To - maintain the state of its inbox, a rollup node retrieves these - messages each time the tezos blockchain is updated. - - The inbox state is persistent. - -*) - -open Protocol.Alpha_context -open Sc_rollup - -include Protocol_plugin_sig.INBOX - -(** [add_messages ~is_first_block ~predecessor_timestamp - ~predecessor inbox messages] adds [messages] to the [inbox] using - {!Sc_rollup.Inbox.add_all_messages}. *) -val add_messages : - is_first_block:bool -> - predecessor_timestamp:Timestamp.time -> - predecessor:Block_hash.t -> - Inbox.t -> - Inbox_message.t list -> - (Inbox_merkelized_payload_hashes.History.t - * Inbox_merkelized_payload_hashes.Hash.t - * Inbox.t - * Inbox_message.t list) - tzresult - Lwt.t - -(** [payloads_history_of_messages ~is_first_block ~predecessor - ~predecessor_timestamp messages] builds the payloads history for - the list of [messages]. This allows to not store payloads - histories (which contain merkelized skip lists) but simply - messages. *) -val payloads_history_of_messages : - is_first_block:bool -> - predecessor:Block_hash.t -> - predecessor_timestamp:Timestamp.time -> - string list -> - Sc_rollup.Inbox_merkelized_payload_hashes.History.t tzresult - -(** [payloads_history_of_all_messages messages] builds the merkelized payloads - history for the list of serialzied messages [messages]. *) -val payloads_history_of_all_messages : - string list -> Sc_rollup.Inbox_merkelized_payload_hashes.History.t tzresult diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/inbox_event.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/inbox_event.ml deleted file mode 100644 index 346a494bcd560dffdc75ad3fe8b919add1368e97..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/inbox_event.ml +++ /dev/null @@ -1,45 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -module Simple = struct - include Internal_event.Simple - - let section = [Protocol.name; "smart_rollup_node"; "inbox"] - - let get_messages = - declare_3 - ~section - ~name:"smart_rollup_node_layer_1_get_messages" - ~msg: - "Fetching {number_of_messages} messages from block {hash} at level \ - {level}" - ~level:Notice - ("hash", Block_hash.encoding) - ("level", Data_encoding.int32) - ("number_of_messages", Data_encoding.int32) -end - -let get_messages hash level number_of_messages = - Simple.(emit get_messages (hash, level, Int32.of_int number_of_messages)) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/inbox_event.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/inbox_event.mli deleted file mode 100644 index 4e313d39797bf1bc088713e5a48857178add590b..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/inbox_event.mli +++ /dev/null @@ -1,28 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -(** [get_messages hash level n] emits the event that [n] messages are being - fetched from the block of the given [hash] at the given [level]. *) -val get_messages : Block_hash.t -> int32 -> int -> unit Lwt.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_event.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_event.ml deleted file mode 100644 index 6a0987632b05f33897697fb843de8c909db21eb6..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_event.ml +++ /dev/null @@ -1,61 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -module Simple = struct - include Internal_event.Simple - - let section = [Protocol.name; "sc_rollup_node"; "layer_1"] - - let starting = - declare_0 - ~section - ~name:"sc_rollup_node_layer_1_starting" - ~msg:"Starting layer 1 tracker of the smart rollup node" - ~level:Notice - () - - let stopping = - declare_0 - ~section - ~name:"sc_rollup_node_layer_1_stopping" - ~msg:"Stopping layer 1 tracker of the smart rollup node" - ~level:Notice - () - - let switched_new_head = - declare_2 - ~section - ~name:"sc_rollup_node_layer_1_new_head" - ~msg:"Layer 1 node has switched to head {hash} at level {level}" - ~level:Notice - ("hash", Block_hash.encoding) - ("level", Data_encoding.int32) -end - -let starting = Simple.(emit starting) - -let stopping = Simple.(emit stopping) - -let switched_new_head hash level = Simple.(emit switched_new_head (hash, level)) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_event.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_event.mli deleted file mode 100644 index 5b8ff83a660c8f47c23e8596b35c9ee19b2aba44..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_event.mli +++ /dev/null @@ -1,35 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -(** This module defines functions that emit the events used by the layer 1 chain - (see {!Layer}). *) - -val starting : unit -> unit Lwt.t - -val stopping : unit -> unit Lwt.t - -(** [switched_new_head hash level] emits the event that the layer 1 has notified - a new head with [hash] at some given [level]. *) -val switched_new_head : Block_hash.t -> int32 -> unit Lwt.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.ml deleted file mode 100644 index fc7cdd3563089d40d6f8d564d4f527056c8b4f4e..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.ml +++ /dev/null @@ -1,270 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Protocol_client_context - -type Layer1.block += Block of Alpha_block_services.block_info - -let fetch cctxt ?metadata ?chain ?block () = - let open Lwt_result_syntax in - let+ block = Alpha_block_services.info cctxt ?metadata ?chain ?block () in - Block block - -let extract_header = function - | Block block -> block.header.shell - | _ -> - invalid_arg ("Internal error: Block is not of protocol " ^ Protocol.name) - -let fetch_tezos_block l1_ctxt hash = - let open Lwt_result_syntax in - let+ block = Layer1.fetch_tezos_block fetch extract_header l1_ctxt hash in - match block with - | Block block -> block - | _ -> - Format.kasprintf - invalid_arg - "Internal error: Block %a is not of protocol %s" - Block_hash.pp - hash - Protocol.name - -let prefetch_tezos_blocks = Layer1.prefetch_tezos_blocks fetch extract_header - -let get_last_cemented_commitment (cctxt : #Client_context.full) rollup_address : - Node_context.lcc tzresult Lwt.t = - let open Lwt_result_syntax in - let cctxt = - new Protocol_client_context.wrap_full (cctxt :> Client_context.full) - in - let rollup_address = Sc_rollup_proto_types.Address.of_octez rollup_address in - let+ commitment, level = - Plugin.RPC.Sc_rollup.last_cemented_commitment_hash_with_level - cctxt - (cctxt#chain, `Head 0) - rollup_address - in - { - Node_context.commitment = - Sc_rollup_proto_types.Commitment_hash.to_octez commitment; - level = Protocol.Alpha_context.Raw_level.to_int32 level; - } - -let get_last_published_commitment ?(allow_unstake = true) - (cctxt : #Client_context.full) rollup_address operator = - let open Lwt_result_syntax in - let cctxt = - new Protocol_client_context.wrap_full (cctxt :> Client_context.full) - in - let*? operator = Signature.Of_V_latest.get_public_key_hash operator in - let rollup_address = Sc_rollup_proto_types.Address.of_octez rollup_address in - let*! res = - Plugin.RPC.Sc_rollup.staked_on_commitment - cctxt - (cctxt#chain, `Head 0) - rollup_address - operator - in - match res with - | Error trace - when allow_unstake - && TzTrace.fold - (fun exists -> function - | Environment.Ecoproto_error - Protocol.Sc_rollup_errors.Sc_rollup_not_staked -> - true - | _ -> exists) - false - trace -> - return_none - | Error trace -> fail trace - | Ok None -> return_none - | Ok (Some (_staked_hash, staked_commitment)) -> - return_some (Sc_rollup_proto_types.Commitment.to_octez staked_commitment) - -let get_kind cctxt rollup_address = - let open Lwt_result_syntax in - let cctxt = - new Protocol_client_context.wrap_full (cctxt :> Client_context.full) - in - let rollup_address = Sc_rollup_proto_types.Address.of_octez rollup_address in - let+ kind = - RPC.Sc_rollup.kind cctxt (cctxt#chain, cctxt#block) rollup_address () - in - Sc_rollup_proto_types.Kind.to_octez kind - -let genesis_inbox cctxt ~genesis_level = - let open Lwt_result_syntax in - let cctxt = - new Protocol_client_context.wrap_full (cctxt :> Client_context.full) - in - let+ inbox = - Plugin.RPC.Sc_rollup.inbox cctxt (cctxt#chain, `Level genesis_level) - in - Sc_rollup_proto_types.Inbox.to_octez inbox - -let constants_of_parametric - Protocol.Alpha_context.Constants.Parametric. - { - minimal_block_delay; - delay_increment_per_round; - sc_rollup = - { - challenge_window_in_blocks; - commitment_period_in_blocks; - max_number_of_stored_cemented_commitments; - max_active_outbox_levels; - _; - }; - dal = - { - feature_enable; - attestation_lag; - number_of_slots; - cryptobox_parameters; - _; - }; - _; - } = - let open Protocol.Alpha_context in - Rollup_constants. - { - minimal_block_delay = Period.to_seconds minimal_block_delay; - delay_increment_per_round = Period.to_seconds delay_increment_per_round; - sc_rollup = - { - challenge_window_in_blocks; - commitment_period_in_blocks; - reveal_activation_level = None; - max_number_of_stored_cemented_commitments; - max_active_outbox_levels = Int32.to_int max_active_outbox_levels; - }; - dal = - {feature_enable; attestation_lag; number_of_slots; cryptobox_parameters}; - } - -(* TODO: https://gitlab.com/tezos/tezos/-/issues/2901 - The constants are retrieved from the latest tezos block. These constants can - be different from the ones used at the creation at the rollup because of a - protocol amendment that modifies some of them. This need to be fixed when the - rollup nodes will be able to handle the migration of protocol. -*) -let retrieve_constants ?(block = `Head 0) cctxt = - let open Lwt_result_syntax in - let cctxt = - new Protocol_client_context.wrap_full (cctxt :> Client_context.full) - in - let+ {parametric; _} = - Protocol.Constants_services.all cctxt (cctxt#chain, block) - in - constants_of_parametric parametric - -let retrieve_genesis_info cctxt rollup_address = - let open Lwt_result_syntax in - let open Protocol.Alpha_context in - let cctxt = - new Protocol_client_context.wrap_full (cctxt :> Client_context.full) - in - let+ {level; commitment_hash} = - RPC.Sc_rollup.genesis_info - cctxt - (cctxt#chain, `Head 0) - (Sc_rollup_proto_types.Address.of_octez rollup_address) - in - Node_context. - { - level = Raw_level.to_int32 level; - commitment_hash = - Sc_rollup_proto_types.Commitment_hash.to_octez commitment_hash; - } - -let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = - let open Protocol in - let open Alpha_context in - let open Lwt_result_syntax in - let exception Found_boot_sector of string in - let* block = fetch_tezos_block node_ctxt.l1_ctxt block_hash in - let missing_boot_sector () = - failwith "Boot sector not found in Tezos block %a" Block_hash.pp block_hash - in - Lwt.catch - (fun () -> - let apply (type kind) accu ~source:_ (operation : kind manager_operation) - (result : kind Apply_results.successful_manager_operation_result) = - match (operation, result) with - | ( Sc_rollup_originate {boot_sector; _}, - Sc_rollup_originate_result {address; _} ) - when Octez_smart_rollup.Address.( - node_ctxt.config.sc_rollup_address - = Sc_rollup_proto_types.Address.to_octez address) -> - raise (Found_boot_sector boot_sector) - | _ -> accu - in - let apply_internal (type kind) accu ~source:_ - (_operation : kind Apply_internal_results.internal_operation) - (_result : - kind Apply_internal_results.successful_internal_operation_result) = - accu - in - let*? () = - Layer1_services.( - process_applied_manager_operations - (Ok ()) - block.operations - {apply; apply_internal}) - in - missing_boot_sector ()) - (function - | Found_boot_sector boot_sector -> return boot_sector - | _ -> missing_boot_sector ()) - -let find_whitelist _cctxt ?block:_ _rollup_address : - Tezos_crypto.Signature.public_key_hash trace option tzresult Lwt.t = - return None - -let find_last_whitelist_update _cctxt _rollup_address = return_none - -let get_commitment cctxt rollup_address commitment_hash = - let open Lwt_result_syntax in - let+ commitment = - Plugin.RPC.Sc_rollup.commitment - (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) - (cctxt#chain, `Head 0) - (Sc_rollup_proto_types.Address.of_octez rollup_address) - (Sc_rollup_proto_types.Commitment_hash.of_octez commitment_hash) - in - Sc_rollup_proto_types.Commitment.to_octez commitment - -let get_balance_mutez cctxt ?block pkh = - let open Lwt_result_syntax in - let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in - let cctxt = - new Protocol_client_context.wrap_full (cctxt :> Client_context.full) - in - let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in - let+ balance = - Protocol.Contract_services.balance cctxt (cctxt#chain, block) (Implicit pkh) - in - Protocol.Alpha_context.Tez.to_mutez balance diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.mli deleted file mode 100644 index 8a665e9dc2ed2c53f0e73ea3d996292dbccd7564..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.mli +++ /dev/null @@ -1,17 +0,0 @@ -(*****************************************************************************) -(* *) -(* SPDX-License-Identifier: MIT *) -(* SPDX-FileCopyrightText: 2023 Nomadic Labs *) -(* SPDX-FileCopyrightText: 2023-2024 Functori *) -(* *) -(*****************************************************************************) - -include Protocol_plugin_sig.LAYER1_HELPERS - -(** [fetch_tezos_block cctxt hash] returns a block info given a block hash. - Looks for the block in the blocks cache first, and fetches it from the L1 - node otherwise. *) -val fetch_tezos_block : - Layer1.t -> - Block_hash.t -> - Protocol_client_context.Alpha_block_services.block_info tzresult Lwt.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/outbox.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/outbox.ml deleted file mode 100644 index f9cd98ac850fd0b5864a643606fa5ccd80a7d874..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/outbox.ml +++ /dev/null @@ -1,89 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* Copyright (c) 2023 TriliTech, *) -(* *) -(* 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 Node_context -open Context_wrapper.Irmin - -let get_state_of_lcc node_ctxt = - let open Lwt_result_syntax in - let lcc = Reference.get node_ctxt.lcc in - let* block_hash = Node_context.hash_of_level node_ctxt lcc.level in - let* ctxt = Node_context.checkout_context node_ctxt block_hash in - let*! state = Context.PVMState.find ctxt in - return state - -let proof_of_output node_ctxt output = - let open Lwt_result_syntax in - let* state = get_state_of_lcc node_ctxt in - let lcc = Reference.get node_ctxt.lcc in - match state with - | None -> - (* - This case should never happen as origination creates an LCC which - must have been considered by the rollup node at startup time. - *) - failwith "Error producing outbox proof (no cemented state in the node)" - | Some state -> ( - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! proof = - PVM.produce_output_proof - (of_node_context node_ctxt.context) - (of_node_pvmstate state) - output - in - match proof with - | Ok proof -> - let serialized_proof = - Data_encoding.Binary.to_string_exn PVM.output_proof_encoding proof - in - return @@ (lcc.commitment, serialized_proof) - | Error err -> - failwith - "Error producing outbox proof (%a)" - Environment.Error_monad.pp - err) - -let proof_of_output_simple node_ctxt ~outbox_level ~message_index = - let open Lwt_result_syntax in - let outbox_level = Protocol.Alpha_context.Raw_level.to_int32 outbox_level in - let* state = get_state_of_lcc node_ctxt in - let lcc = Reference.get node_ctxt.lcc in - match state with - | None -> - (* - This case should never happen as origination creates an LCC which - must have been considered by the rollup node at startup time. - *) - failwith "Error producing outbox proof (no cemented state in the node)" - | Some state -> - let+ proof = - Pvm_plugin.produce_serialized_output_proof - node_ctxt - state - ~outbox_level - ~message_index - in - (lcc.commitment, proof) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/outbox.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/outbox.mli deleted file mode 100644 index a1fe87d186a2778ffa3fc563741ea3dba26d98e0..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/outbox.mli +++ /dev/null @@ -1,44 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* Copyright (c) 2023 TriliTech, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** This module provides helper to interact with PVM outboxes. *) - -open Protocol.Alpha_context - -(** [proof_of_output node_ctxt output] returns the last cemented commitment hash - and the proof of the output in the LCC. *) -val proof_of_output : - Node_context.rw -> - Sc_rollup.output -> - (Octez_smart_rollup.Commitment.Hash.t * string) tzresult Lwt.t - -(** [proof_of_output_at node_ctxt ~level ~message_index] returns the last cemented - commitment hash and the proof of the output in the LCC. *) -val proof_of_output_simple : - Node_context.rw -> - outbox_level:Raw_level.t -> - message_index:int -> - (Octez_smart_rollup.Commitment.Hash.t * string) tzresult Lwt.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/pvm.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/pvm.ml deleted file mode 100644 index 284d7d2a2c48b6fed11453bfa3427ca64e7ba368..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/pvm.ml +++ /dev/null @@ -1,40 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022-2023 TriliTech *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -module type S = Pvm_sig.S - -let of_kind : Kind.t -> (module S) = function - | Example_arith -> (module Arith_pvm) - | Wasm_2_0_0 -> (module Wasm_2_0_0_pvm) - | Riscv -> invalid_arg "Riscv rollup is inactive in this protocol" - -let context : Kind.t -> (module Context_sigs.S) = function - | _ -> - (module struct - include Irmin_context - - let load ~cache_size path = load ~cache_size path - end) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_plugin.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_plugin.ml deleted file mode 100644 index 87fd3ee4e398e3e53545f63edca2aeddc90a3e4d..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_plugin.ml +++ /dev/null @@ -1,205 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) -open Protocol -open Alpha_context -open Context_wrapper.Irmin - -let context = Pvm.context - -module Context = Irmin_context - -let get_tick kind state = - let open Lwt_syntax in - let module PVM = (val Pvm.of_kind kind) in - let+ tick = PVM.get_tick (of_node_pvmstate state) in - Sc_rollup.Tick.to_z tick - -let state_hash kind state = - let open Lwt_syntax in - let module PVM = (val Pvm.of_kind kind) in - let+ hash = PVM.state_hash (of_node_pvmstate state) in - Sc_rollup_proto_types.State_hash.to_octez hash - -let initial_state kind = - let open Lwt_syntax in - let module PVM = (val Pvm.of_kind kind) in - let+ state = PVM.initial_state ~empty:(PVM.State.empty ()) in - to_node_pvmstate state - -let parse_boot_sector kind = - let module PVM = (val Pvm.of_kind kind) in - PVM.parse_boot_sector - -let install_boot_sector kind state boot_sector = - let open Lwt_syntax in - let module PVM = (val Pvm.of_kind kind) in - let+ state = PVM.install_boot_sector (of_node_pvmstate state) boot_sector in - to_node_pvmstate state - -let get_status node_ctxt state = - let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind node_ctxt.Node_context.kind) in - let*! status = PVM.get_status (of_node_pvmstate state) in - return (PVM.string_of_status status) - -let get_current_level kind state = - let open Lwt_option_syntax in - let module PVM = (val Pvm.of_kind kind) in - let+ current_level = PVM.get_current_level (of_node_pvmstate state) in - Raw_level.to_int32 current_level - -module Fueled = Fueled_pvm - -let start_of_level_serialized = - let open Sc_rollup_inbox_message_repr in - unsafe_to_string start_of_level_serialized - -let end_of_level_serialized = - let open Sc_rollup_inbox_message_repr in - unsafe_to_string end_of_level_serialized - -let protocol_migration_serialized = - let open Sc_rollup_inbox_message_repr in - Some (unsafe_to_string Raw_context.protocol_migration_serialized_message) - -let info_per_level_serialized ~predecessor ~predecessor_timestamp = - let open Sc_rollup_inbox_message_repr in - unsafe_to_string - (info_per_level_serialized ~predecessor ~predecessor_timestamp) - -let find_whitelist_update_output_index _node_ctxt _state ~outbox_level:_ = - Lwt.return_none - -let outbox_transaction_summary - (transaction : Sc_rollup.Outbox.Message.transaction) = - Outbox_message. - { - destination = Contract_hash.to_b58check transaction.destination; - entrypoint = Entrypoint.to_string transaction.entrypoint; - parameters = - (Michelson_v1_printer.unparse_expression - transaction.unparsed_parameters) - .unexpanded; - parameters_ty = None; - } - -let outbox_typed_transaction_summary - (transaction : Sc_rollup.Outbox.Message.typed_transaction) = - Outbox_message. - { - destination = Contract_hash.to_b58check transaction.destination; - entrypoint = Entrypoint.to_string transaction.entrypoint; - parameters = - (Michelson_v1_printer.unparse_expression - transaction.unparsed_parameters) - .unexpanded; - parameters_ty = - Some - (Michelson_v1_printer.unparse_expression transaction.unparsed_ty) - .unexpanded; - } - -let outbox_message_summary (output : Sc_rollup.output) = - let summary = - match output with - | {message = Atomic_transaction_batch {transactions}; _} -> - let transactions = List.map outbox_transaction_summary transactions in - Outbox_message.Transaction_batch transactions - | {message = Atomic_transaction_batch_typed {transactions}; _} -> - let transactions = - List.map outbox_typed_transaction_summary transactions - in - Transaction_batch transactions - in - (Z.to_int output.message_index, summary) - -let get_outbox_messages node_ctxt state ~outbox_level = - let open Lwt_syntax in - let outbox_level = Raw_level.of_int32_exn outbox_level in - let open (val Pvm.of_kind node_ctxt.Node_context.kind) in - let* outbox = get_outbox outbox_level (of_node_pvmstate state) in - List.rev_map outbox_message_summary outbox |> List.rev |> return - -let produce_serialized_output_proof node_ctxt state ~outbox_level ~message_index - = - let open Lwt_result_syntax in - let state = of_node_pvmstate state in - let module PVM = (val Pvm.of_kind node_ctxt.Node_context.kind) in - let outbox_level = Raw_level.of_int32_exn outbox_level in - let*! outbox = PVM.get_outbox outbox_level state in - let output = List.nth outbox message_index in - match output with - | None -> invalid_arg "invalid index" - | Some output -> ( - let*! proof = - PVM.produce_output_proof - (of_node_context node_ctxt.context) - state - output - in - match proof with - | Ok proof -> - let serialized_proof = - Data_encoding.Binary.to_string_exn PVM.output_proof_encoding proof - in - return serialized_proof - | Error err -> - failwith - "Error producing outbox proof (%a)" - Environment.Error_monad.pp - err) - -module Wasm_2_0_0 = struct - let decode_durable_state enc tree = - Wasm_2_0_0_pvm.Durable_state.Tree_encoding_runner.decode - enc - (of_node_pvmstate tree) - - let proof_mem_tree tree = - Wasm_2_0_0_pvm.Wasm_2_0_0_proof_format.Tree.mem_tree (of_node_pvmstate tree) - - let proof_fold_tree ?depth tree key ~order ~init ~f = - Wasm_2_0_0_pvm.Wasm_2_0_0_proof_format.Tree.fold - ?depth - (of_node_pvmstate tree) - key - ~order - ~init - ~f:(fun a b c -> f a (to_node_pvmstate b) c) -end - -module Unsafe = struct - let apply_patch (kind : Octez_smart_rollup.Kind.t) state - (patch : Pvm_patches.unsafe_patch) = - let open Lwt_result_syntax in - let open (val Pvm.of_kind kind) in - let*? patch = Unsafe_patches.of_patch patch in - let* state = - protect @@ fun () -> - Unsafe_patches.apply (of_node_pvmstate state) patch |> Lwt_result.ok - in - return (to_node_pvmstate state) -end diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_plugin.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_plugin.mli deleted file mode 100644 index e0183f81e6368cf6a620b4ec9d3c185465b832bc..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_plugin.mli +++ /dev/null @@ -1,27 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -include Pvm_plugin_sig.S diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_rpc.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_rpc.ml deleted file mode 100644 index f1180236418279b0b73f78090a3bc84941525dbc..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_rpc.ml +++ /dev/null @@ -1,45 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -module type S = sig - (** Build RPC directory of the PVM *) - val build_sub_directory : - Node_context.rw -> - (unit * Rollup_node_services.Arg.block_id) Tezos_rpc.Directory.t -end - -module No_rpc = struct - let build_sub_directory _node_ctxt = Tezos_rpc.Directory.empty -end - -let no_rpc = (module No_rpc : S) - -let of_kind = function - | Kind.Example_arith -> no_rpc - | Wasm_2_0_0 -> - (module Wasm_2_0_0_rpc.Make_RPC (Wasm_2_0_0_pvm.Durable_state) : S) - | Riscv -> - (* Riscv rollup is inactive in this protocol *) - no_rpc diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_sig.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_sig.ml deleted file mode 100644 index 3b0cc19d9e57c8fe73c77bafc266e27818067ae8..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/pvm_sig.ml +++ /dev/null @@ -1,114 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022-2023 TriliTech *) -(* Copyright (c) 2022 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 -open Alpha_context - -(** Desired module type of a PVM from the L2 node's perspective *) -module type S = sig - include - Sc_rollup.PVM.S - with type context = Irmin_context.rw_index - and type state = Irmin_context.tree - and type hash = Sc_rollup.State_hash.t - - (** Kind of the PVM. *) - val kind : Sc_rollup.Kind.t - - (** [get_tick state] gets the total tick counter for the given PVM state. *) - val get_tick : state -> Sc_rollup.Tick.t Lwt.t - - (** PVM status *) - type status - - (** [get_status state] gives you the current execution status for the PVM. *) - val get_status : state -> status Lwt.t - - (** [string_of_status status] returns a string representation of [status]. *) - val string_of_status : status -> string - - (** [get_outbox outbox_level state] returns a list of outputs - available in the outbox of [state] at a given [outbox_level]. *) - val get_outbox : Raw_level.t -> state -> Sc_rollup.output list Lwt.t - - (** [eval_many ~max_steps s0] returns a state [s1] resulting from the - execution of up to [~max_steps] steps of the rollup at state [s0]. *) - val eval_many : - reveal_builtins:Tezos_scoru_wasm.Builtins.reveals -> - write_debug:Tezos_scoru_wasm.Builtins.write_debug -> - ?stop_at_snapshot:bool -> - max_steps:int64 -> - state -> - (state * int64) Lwt.t - - val new_dissection : - default_number_of_sections:int -> - start_chunk:Sc_rollup.Dissection_chunk.t -> - our_stop_chunk:Sc_rollup.Dissection_chunk.t -> - Sc_rollup.Tick.t list - - (** State storage for this PVM. *) - module State : sig - (** [empty ()] is the empty state. *) - val empty : unit -> state - - (** [find context] returns the PVM state stored in the [context], if any. *) - val find : _ Irmin_context.t -> state option Lwt.t - - (** [lookup state path] returns the data stored for the path [path] in the - PVM state [state]. *) - val lookup : state -> string list -> bytes option Lwt.t - - (** [set context state] saves the PVM state [state] in the context and - returns the updated context. Note: [set] does not perform any write on - disk, this information must be committed using {!val:Irmin_context.commit}. *) - val set : 'a Irmin_context.t -> state -> 'a Irmin_context.t Lwt.t - end - - (** Inspect durable state using a more specialised way of reading the - PVM state. - For example in WASM, it decodes the durable storage in the state - before reading values. - *) - module Inspect_durable_state : sig - (** [lookup state path] returns the data stored for the path [path] in the - PVM state [state]. *) - val lookup : state -> string list -> bytes option Lwt.t - end - - (** Expose unsafe state patching functions for manual intervention. - At the moment this feature is only used to increase the maximum number of - ticks of the WASM PVM in a non refutable setting. *) - module Unsafe_patches : sig - type t - - (** [of_patch p] returns the PVM patch if it has a corresponding one. *) - val of_patch : Pvm_patches.unsafe_patch -> t tzresult - - (** [apply state patch] applies the unsafe patch [patch] on the state. *) - val apply : state -> t -> state Lwt.t - end -end diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game_helpers.ml deleted file mode 100644 index 65a809f5bde3a1b4302e55fd252656cf1a578a57..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game_helpers.ml +++ /dev/null @@ -1,367 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Nomadic Labs, *) -(* Copyright (c) 2023 TriliTech *) -(* 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 Protocol -open Alpha_context -open Context_wrapper.Irmin - -(** This function computes the inclusion/membership proof of the page - identified by [page_id] in the slot whose data are provided in - [slot_data]. *) -let page_membership_proof params page_index slot_data = - (* FIXME/DAL: https://gitlab.com/tezos/tezos/-/issues/4048 - Rely on DAL node to compute page membership proof and drop - the dal-crypto dependency from the rollup node. *) - let proof = - let open Result_syntax in - (* The computation of the page's proof below can be a bit costly. In fact, - it involves initialising a cryptobox environment and some non-trivial - crypto processing. *) - let* dal = Cryptobox.make params in - let* polynomial = Cryptobox.polynomial_from_slot dal slot_data in - Cryptobox.prove_page dal polynomial page_index - in - let open Lwt_result_syntax in - match proof with - | Ok proof -> return proof - | Error e -> - failwith - "%s" - (match e with - | `Fail s -> "Fail " ^ s - | `Page_index_out_of_range -> "Page_index_out_of_range" - | `Slot_wrong_size s -> "Slot_wrong_size: " ^ s - | ( `Invalid_degree_strictly_less_than_expected _ - | `Prover_SRS_not_loaded ) as commit_error -> - Cryptobox.string_of_commit_error commit_error) - -(** When the PVM is waiting for a Dal page input, this function attempts to - retrieve the page's content from the store, the data of its slot. Then it - computes the proof that the page is part of the slot and returns the - content along with the proof. - - If the PVM is not waiting for a Dal page input, or if the slot is known to - be unconfirmed on L1, this function returns [None]. If the data of the - slot are not saved to the store, the function returns a failure - in the error monad. *) -let page_info_from_pvm_state (node_ctxt : _ Node_context.t) ~dal_attestation_lag - (dal_params : Dal.parameters) start_state = - let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! input_request = PVM.is_input_state start_state in - match input_request with - | Sc_rollup.(Needs_reveal (Request_dal_page page_id)) -> ( - let Dal.Page.{slot_id; page_index} = page_id in - let* pages = - Dal_pages_request.slot_pages ~dal_attestation_lag node_ctxt slot_id - in - match pages with - | None -> return_none (* The slot is not confirmed. *) - | Some pages -> ( - let pages_per_slot = dal_params.slot_size / dal_params.page_size in - (* check invariant that pages' length is correct. *) - (* FIXME/DAL: https://gitlab.com/tezos/tezos/-/issues/4031 - It's better to do the check when the slots are saved into disk. *) - (* FIXME/DAL: https://gitlab.com/tezos/tezos/-/issues/3997 - This check is not resilient to dal parameters change. *) - match List.nth_opt pages page_index with - | Some content -> - let* page_proof = - page_membership_proof dal_params page_index - @@ Bytes.concat Bytes.empty pages - in - return_some (content, page_proof) - | None -> - failwith - "Page index %d too big or negative.\n\ - Number of pages in a slot is %d." - page_index - pages_per_slot)) - | _ -> return_none - -let metadata (node_ctxt : _ Node_context.t) = - let address = - Sc_rollup_proto_types.Address.of_octez node_ctxt.config.sc_rollup_address - in - let origination_level = Raw_level.of_int32_exn node_ctxt.genesis_info.level in - Sc_rollup.Metadata.{address; origination_level} - -let generate_proof (node_ctxt : _ Node_context.t) - (game : Octez_smart_rollup.Game.t) (start_state : Context.pvmstate) = - let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let snapshot = - Sc_rollup_proto_types.Inbox.history_proof_of_octez game.inbox_snapshot - in - (* NOTE: [snapshot_level_int32] below refers to the level of the snapshotted - inbox (from the skip list) which also matches [game.start_level - 1]. *) - let snapshot_level_int32 = - (Octez_smart_rollup.Inbox.Skip_list.content game.inbox_snapshot).level - in - let* context = - let* start_hash = Node_context.hash_of_level node_ctxt game.inbox_level in - let+ context = Node_context.checkout_context node_ctxt start_hash in - Context.index context - in - let* dal_slots_history = - (* DAL is not activated in Nairobi *) - return Dal.Slots_history.genesis - in - let* dal_slots_history_cache = - (* DAL is not activated in Nairobi *) - return (Dal.Slots_history.History_cache.empty ~capacity:0L) - in - (* We fetch the value of protocol constants at block snapshot level - where the game started. *) - let* constants = - Protocol_plugins.get_constants_of_level node_ctxt snapshot_level_int32 - in - let dal_l1_parameters = constants.dal in - let dal_parameters = dal_l1_parameters.cryptobox_parameters in - let dal_attestation_lag = dal_l1_parameters.attestation_lag in - - let* page_info = - page_info_from_pvm_state - ~dal_attestation_lag - node_ctxt - dal_parameters - (of_node_pvmstate start_state) - in - let module P = struct - include PVM - - let context : context = of_node_context context - - let state = of_node_pvmstate start_state - - let reveal hash = - let open Lwt_syntax in - let* res = - Reveals.get - ~pre_images_endpoint:node_ctxt.config.pre_images_endpoint - ~data_dir:node_ctxt.data_dir - ~pvm_kind:(Sc_rollup_proto_types.Kind.to_octez PVM.kind) - ~hash - in - match res with Ok data -> return @@ Some data | Error _ -> return None - - module Inbox_with_history = struct - let inbox = snapshot - - let get_history inbox_hash = - let open Lwt_syntax in - let+ inbox = - Node_context.find_inbox - node_ctxt - (Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash) - in - match inbox with - | Error err -> - Format.kasprintf - Stdlib.failwith - "Refutation game: Cannot get inbox history for %a, %a" - Sc_rollup.Inbox.Hash.pp - inbox_hash - pp_print_trace - err - | Ok inbox -> - Option.map - (fun i -> - Sc_rollup.Inbox.take_snapshot - (Sc_rollup_proto_types.Inbox.of_octez i)) - inbox - - let get_payloads_history witness = - Lwt.map - (WithExceptions.Result.to_exn_f - ~error:(Format.kasprintf Stdlib.failwith "%a" pp_print_trace)) - @@ - let open Lwt_result_syntax in - let* messages = - Node_context.get_messages - node_ctxt - (Sc_rollup_proto_types.Merkelized_payload_hashes_hash.to_octez - witness) - in - let*? hist = Inbox.payloads_history_of_all_messages messages in - return hist - end - - module Dal_with_history = struct - let confirmed_slots_history = dal_slots_history - - let get_history ptr = - Dal.Slots_history.History_cache.find ptr dal_slots_history_cache - |> Lwt.return - - let dal_attestation_lag = dal_attestation_lag - - let dal_parameters = dal_parameters - - let page_info = page_info - end - end in - let metadata = metadata node_ctxt in - let*! start_tick = PVM.get_tick (of_node_pvmstate start_state) in - let* proof = - trace - (Sc_rollup_node_errors.Cannot_produce_proof - { - inbox_level = game.inbox_level; - start_tick = Sc_rollup.Tick.to_z start_tick; - }) - @@ (Sc_rollup.Proof.produce - ~metadata - (module P) - (Raw_level.of_int32_exn game.inbox_level) - >|= Environment.wrap_tzresult) - in - let*? pvm_step = - Sc_rollup.Proof.unserialize_pvm_step ~pvm:(module PVM) proof.pvm_step - |> Environment.wrap_tzresult - in - let unserialized_proof = {proof with pvm_step} in - let*! res = - Sc_rollup.Proof.valid - ~metadata - snapshot - (Raw_level.of_int32_exn game.inbox_level) - dal_slots_history - dal_parameters - ~dal_attestation_lag - ~pvm:(module PVM) - unserialized_proof - >|= Environment.wrap_tzresult - in - assert (Result.is_ok res) ; - let proof = - Data_encoding.Binary.to_string_exn Sc_rollup.Proof.encoding proof - in - return proof - -let make_dissection plugin (node_ctxt : _ Node_context.t) state_cache - ~start_state ~start_chunk ~our_stop_chunk ~default_number_of_sections - ~commitment_period_tick_offset ~last_level = - let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let state_of_tick ?start_state tick = - Interpreter.state_of_tick - plugin - node_ctxt - state_cache - ?start_state - ~tick:(Z.add (Sc_rollup.Tick.to_z tick) commitment_period_tick_offset) - last_level - in - let state_hash_of_eval_state Pvm_plugin_sig.{state_hash; _} = - Sc_rollup_proto_types.State_hash.of_octez state_hash - in - let start_chunk = - Sc_rollup_proto_types.Game.dissection_chunk_of_octez start_chunk - in - let our_stop_chunk = - Sc_rollup_proto_types.Game.dissection_chunk_of_octez our_stop_chunk - in - let+ dissection = - Game_helpers.make_dissection - ~state_of_tick - ~state_hash_of_eval_state - ?start_state - ~start_chunk - ~our_stop_chunk - @@ PVM.new_dissection - ~start_chunk - ~our_stop_chunk - ~default_number_of_sections - in - List.map Sc_rollup_proto_types.Game.dissection_chunk_to_octez dissection - -let timeout_reached node_ctxt ~self ~opponent = - let open Lwt_result_syntax in - let Node_context.{config; cctxt; _} = node_ctxt in - let*? self = Signature.Of_V_latest.get_public_key_hash self in - let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in - let+ game_result = - Plugin.RPC.Sc_rollup.timeout_reached - (new Protocol_client_context.wrap_full cctxt) - (cctxt#chain, `Head 0) - (Sc_rollup_proto_types.Address.of_octez config.sc_rollup_address) - self - opponent - in - let open Sc_rollup.Game in - match game_result with - | Some (Loser {loser; _}) -> - let is_it_me = Environment.Signature.Public_key_hash.(self = loser) in - not is_it_me - | _ -> false - -let timeout node_ctxt ~self ~opponent = - let open Lwt_result_syntax in - let Node_context.{config; cctxt; _} = node_ctxt in - let*? self = Signature.Of_V_latest.get_public_key_hash self in - let*? opponent = Signature.Of_V_latest.get_public_key_hash opponent in - let+ timeout = - Plugin.RPC.Sc_rollup.timeout - (new Protocol_client_context.wrap_full cctxt) - (cctxt#chain, `Head 0) - (Sc_rollup_proto_types.Address.of_octez config.sc_rollup_address) - self - opponent - in - Option.map Sc_rollup_proto_types.Game.timeout_to_octez timeout - -let get_conflicts cctxt rollup staker = - let open Lwt_result_syntax in - let cctxt = new Protocol_client_context.wrap_full cctxt in - let*? staker = Signature.Of_V_latest.get_public_key_hash staker in - let+ conflicts = - Plugin.RPC.Sc_rollup.conflicts - cctxt - (cctxt#chain, `Head 0) - (Sc_rollup_proto_types.Address.of_octez rollup) - staker - in - List.map Sc_rollup_proto_types.Game.conflict_to_octez conflicts - -let get_ongoing_games cctxt rollup staker = - let open Lwt_result_syntax in - let cctxt = new Protocol_client_context.wrap_full cctxt in - let*? staker = Signature.Of_V_latest.get_public_key_hash staker in - let+ games = - Plugin.RPC.Sc_rollup.ongoing_refutation_games - cctxt - (cctxt#chain, `Head 0) - (Sc_rollup_proto_types.Address.of_octez rollup) - staker - in - List.map - (fun (game, staker1, staker2) -> - ( Sc_rollup_proto_types.Game.to_octez game, - Tezos_crypto.Signature.Of_V1.public_key_hash staker1, - Tezos_crypto.Signature.Of_V1.public_key_hash staker2 )) - games diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game_helpers.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game_helpers.mli deleted file mode 100644 index f1cb92984580169289922b4e9e06d3e6de84ab0d..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/refutation_game_helpers.mli +++ /dev/null @@ -1,28 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Nomadic Labs, *) -(* Copyright (c) 2023 TriliTech *) -(* 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. *) -(* *) -(*****************************************************************************) - -include Protocol_plugin_sig.REFUTATION_GAME_HELPERS diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/reveals.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/reveals.ml deleted file mode 100644 index 04afa4fac7dc320a2e23614b1bfe361acaa10210..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/reveals.ml +++ /dev/null @@ -1,181 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -open Protocol.Alpha_context -module Reveal_hash = Protocol.Sc_rollup_reveal_hash - -type error += Wrong_hash of {found : Reveal_hash.t; expected : Reveal_hash.t} - -let () = - Sc_rollup_node_errors.register_error_kind - ~id:"sc_rollup.node.wrong_hash_of_reveal_preimage" - ~title:"Hash of reveal preimage is not correct" - ~description:"Hash of reveal preimage is not correct." - ~pp:(fun ppf (found, expected) -> - Format.fprintf - ppf - "The hash of reveal preimage is %a while a value of %a is expected" - Reveal_hash.pp - found - Reveal_hash.pp - expected) - `Permanent - Data_encoding.( - obj2 - (req "found" Reveal_hash.encoding) - (req "expected" Reveal_hash.encoding)) - (function - | Wrong_hash {found; expected} -> Some (found, expected) | _ -> None) - (fun (found, expected) -> Wrong_hash {found; expected}) - -type source = String of string | File of string - -let file_contents filename = - let open Lwt_result_syntax in - Lwt.catch - (fun () -> - let*! contents = Lwt_utils_unix.read_file filename in - return_some contents) - (fun _ -> return_none) - -let path data_dir pvm_name hash = - let hash = Protocol.Sc_rollup_reveal_hash.to_hex hash in - Filename.(concat (concat data_dir pvm_name) hash) - -let to_reveal_hash = - Data_encoding.Binary.of_bytes_exn Protocol.Sc_rollup_reveal_hash.encoding - -let of_reveal_hash = - Data_encoding.Binary.to_bytes_exn Protocol.Sc_rollup_reveal_hash.encoding - -let of_hex hex = - Protocol.Sc_rollup_reveal_hash.of_hex hex |> Option.map of_reveal_hash - -let to_hex hash = to_reveal_hash hash |> Protocol.Sc_rollup_reveal_hash.to_hex - -let hex_encoding = - let binary = - Data_encoding.conv - to_reveal_hash - of_reveal_hash - Protocol.Sc_rollup_reveal_hash.encoding - in - Data_encoding.( - (* Hexifies the hash when encoding in json. *) - splitted - ~binary - ~json: - (conv_with_guard - to_hex - (fun str -> Result.of_option ~error:"Not a valid hash" (of_hex str)) - (string' Plain))) - -let proto_hash_to_bytes proto_reveal_hash = - proto_reveal_hash - |> Data_encoding.Binary.to_bytes_exn Protocol.Sc_rollup_reveal_hash.encoding - |> Data_encoding.Binary.of_bytes_exn hex_encoding - -let get_from_preimages_service ~pre_images_endpoint ~local_filename hash = - let open Lwt_result_syntax in - let hash_hex = Protocol.Sc_rollup_reveal_hash.to_hex hash in - let*! () = Interpreter_event.missing_pre_image ~hash:hash_hex in - let url = - Uri.with_path - pre_images_endpoint - String.(concat "/" [Uri.path pre_images_endpoint; hash_hex]) - in - let*! resp, body = Cohttp_lwt_unix.Client.get url in - let*! body_str = Cohttp_lwt.Body.to_string body in - match resp.status with - | `OK -> - let contents_hash = - Reveal_hash.hash_string ~scheme:Reveal_hash.Blake2B [body_str] - in - if Reveal_hash.equal contents_hash hash then - let*! () = - Lwt_utils_unix.create_dir (Filename.dirname local_filename) - in - let*! () = Lwt_utils_unix.create_file local_filename body_str in - return_some body_str - else - let*! () = - Interpreter_event.fetched_incorrect_pre_image - ~expected_hash:hash_hex - ~content_hash:(Protocol.Sc_rollup_reveal_hash.to_hex contents_hash) - in - return_none - | #Cohttp.Code.status_code -> - tzfail (Layer_1.Http_connection_error (resp.status, body_str)) - -let get ~pre_images_endpoint ~data_dir ~pvm_kind ~hash = - let open Lwt_result_syntax in - let filename = - path data_dir (Octez_smart_rollup.Kind.to_string pvm_kind) hash - in - (* TODO: https://gitlab.com/tezos/tezos/-/issues/5296 - Use DAC observer client when [filename] doesn't exist. *) - let* contents = - let* file_contents = file_contents filename in - match file_contents with - | Some contents -> return contents - | None -> ( - match pre_images_endpoint with - | None -> - tzfail (Sc_rollup_node_errors.Could_not_open_preimage_file filename) - | Some pre_images_endpoint -> ( - let* contents = - get_from_preimages_service - ~pre_images_endpoint - ~local_filename:filename - hash - in - match contents with - | Some contents -> return contents - | None -> - tzfail - (Sc_rollup_node_errors.Could_not_open_preimage_file filename)) - ) - in - let*? () = - let contents_hash = - Reveal_hash.hash_string ~scheme:Reveal_hash.Blake2B [contents] - in - error_unless - (Reveal_hash.equal contents_hash hash) - (Wrong_hash {found = contents_hash; expected = hash}) - in - let* _encoded = - (* Check that the reveal input can be encoded within the bounds enforced by - the protocol. *) - trace Sc_rollup_node_errors.Could_not_encode_raw_data - @@ protect - @@ fun () -> - Data_encoding.Binary.to_bytes_exn - Sc_rollup.input_encoding - (Reveal (Raw_data contents)) - |> return - in - return contents diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/reveals.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/reveals.mli deleted file mode 100644 index be4076cd7fe8916859353073037f96ce1541741f..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/reveals.mli +++ /dev/null @@ -1,79 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -(** This module provides basic support for reveals. - - The rollup can ask for data being the reveal of some hash. This - allows transferring data directly to the rollup without going - through the L1 inbox. - - Data length must be under 4KB to be refutable in a single L1 - operation. - - Data must be made available by off-chain mechanisms: it is the - responsibility of the rollup kernel to make sure that the reveal - data is available: otherwise, there is a potential safety issue. - - For the moment, the support is basic and mostly manual as the operator - needs to explicitly import a file in the rollup node data directoy to - enable the rollup node to answer reveal requests. - -*) - -(* FIXME:https://gitlab.com/tezos/tezos/-/issues/3854 - - We should probably have a mechanism to let the kernel declare - sources of reveal data so that the rollup node can automatically - download data in advance. *) - -(** Source of data *) -type source = - | String of string (** A string containing the whole data *) - | File of string - (** A file name whose associated file contains the whole data *) - -(** [get ~pre_images_endpoint ~data_dir ~pvm_name ~hash] retrieves - the data associated with the reveal hash [hash] from disk. If the data is - not already on disk, it will be retrieved from an - HTTP service at [pre_images_endpoint]. May fail with: - {ul - {li [Wrong_hash {found; expected}] where [expected = hash], and - [found <> hash], if the data is retrieved and hashes to the wrong - hash [found],} - {li [Could_not_open_preimage_file filename] if the function tries to - retrieve the data from [filename], but it cannot read the contents - of the file.} - {li [Could_not_encode_raw_data] if the data is too large (more than - 4kB) to be revealed.} - } *) -val get : - pre_images_endpoint:Uri.t option -> - data_dir:string -> - pvm_kind:Kind.t -> - hash:Protocol.Sc_rollup_reveal_hash.t -> - string tzresult Lwt.t - -(** Conversion from protocol reveal hash to protocol agnostic hash. *) -val proto_hash_to_bytes : Protocol.Sc_rollup_reveal_hash.t -> bytes diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/rollup_node_plugin.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/rollup_node_plugin.ml deleted file mode 100644 index 4c5dd5e5cfe44af177cd455e62b8dd74819996ad..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/rollup_node_plugin.ml +++ /dev/null @@ -1,40 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -module Plugin : Protocol_plugin_sig.S = struct - let protocol = Protocol.hash - - module RPC_directory = RPC_directory - module Dal_slots_tracker = Dal_slots_tracker - module Inbox = Inbox - module Interpreter = Interpreter - module Refutation_game_helpers = Refutation_game_helpers - module Batcher_constants = Batcher_constants - module Layer1_helpers = Layer1_helpers - module L1_processing = Daemon_helpers - module Pvm = Pvm_plugin -end - -let () = Protocol_plugins.register (module Plugin) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml deleted file mode 100644 index 71d21e9131945513754220dad3c54ee7e329fafa..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.ml +++ /dev/null @@ -1,497 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context -open Injector_common -open Injector_sigs -module Block_cache = - Aches_lwt.Lache.Make_result - (Aches.Rache.Transfer (Aches.Rache.LRU) (Block_hash)) - -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 - let opponent = Signature.Of_V_latest.get_public_key_hash_exn opponent 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}) - | Recover_bond {rollup; staker} -> - let rollup = Sc_rollup_proto_types.Address.of_octez rollup in - let staker = Signature.Of_V_latest.get_public_key_hash_exn staker in - Manager (Sc_rollup_recover_bond {sc_rollup = rollup; staker}) - | Execute_outbox_message {rollup; cemented_commitment; output_proof} -> - let rollup = Sc_rollup_proto_types.Address.of_octez rollup in - let cemented_commitment = - Sc_rollup_proto_types.Commitment_hash.of_octez cemented_commitment - in - Manager - (Sc_rollup_execute_outbox_message - {rollup; cemented_commitment; output_proof}) - | Publish_dal_commitment _ -> - Stdlib.failwith "Publish_dal_commitment not supported in Nairobi" - -let injector_operation_of_manager : type kind. - 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 - let opponent = Tezos_crypto.Signature.Of_V1.public_key_hash opponent 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}) - | Sc_rollup_execute_outbox_message {rollup; cemented_commitment; output_proof} - -> - let rollup = Sc_rollup_proto_types.Address.to_octez rollup in - let cemented_commitment = - Sc_rollup_proto_types.Commitment_hash.to_octez cemented_commitment - in - Some (Execute_outbox_message {rollup; cemented_commitment; output_proof}) - | _ -> None - -module Proto_client = struct - open Protocol_client_context - - type operation = L1_operation.t - - type state = Injector.state - - type unsigned_operation = - Tezos_base.Operation.shell_header * packed_contents_list - - let max_operation_data_length = Constants.max_operation_data_length - - let manager_pass = Operation_repr.manager_pass - - let manager_operation_size (Manager operation) = - let contents = - Manager_operation - { - source = Signature.Public_key_hash.zero; - operation; - fee = Tez.zero; - counter = Manager_counter.Internal_for_tests.of_int 0; - gas_limit = Gas.Arith.zero; - storage_limit = Z.zero; - } - in - Data_encoding.Binary.length Operation.contents_encoding (Contents contents) - - let operation_size 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 - manager operation (here a revelation), add an overhead with upper bounds as - values (for the fees, limits, counters, etc.) and compare the encoded - operations with respect to their size. - NOTE: This information is only used to pre-select operations from the - injector queue as a candidate batch. *) - let operation_size_overhead = - let dummy_operation = - Reveal - (Signature.Public_key.of_b58check_exn - "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav") - in - let dummy_contents = - Manager_operation - { - source = Signature.Public_key_hash.zero; - operation = dummy_operation; - fee = Tez.of_mutez_exn 3_000_000L; - counter = Manager_counter.Internal_for_tests.of_int 500_000; - gas_limit = Gas.Arith.integral_of_int_exn 500_000; - storage_limit = Z.of_int 500_000; - } - in - let dummy_size = - Data_encoding.Binary.length - Operation.contents_encoding - (Contents dummy_contents) - in - dummy_size - manager_operation_size (Manager dummy_operation) - - let manager_operation_result_status (type kind) - (op_result : kind Apply_results.manager_operation_result) : - operation_status = - match op_result with - | Applied _ -> Successful - | Backtracked (_, None) -> Unsuccessful Backtracked - | Skipped _ -> Unsuccessful Skipped - | Backtracked (_, Some err) - (* Backtracked because internal operation failed *) - | Failed (_, err) -> - Unsuccessful (Failed (Environment.wrap_tztrace err)) - - let operation_result_status (type kind) - (op_result : kind Apply_results.contents_result) : operation_status = - match op_result with - | Preendorsement_result _ -> Successful - | Endorsement_result _ -> Successful - | Dal_attestation_result _ -> Successful - | Seed_nonce_revelation_result _ -> Successful - | Vdf_revelation_result _ -> Successful - | Double_endorsement_evidence_result _ -> Successful - | Double_preendorsement_evidence_result _ -> Successful - | Double_baking_evidence_result _ -> Successful - | Activate_account_result _ -> Successful - | Proposals_result -> Successful - | Ballot_result -> Successful - | Drain_delegate_result _ -> Successful - | Manager_operation_result {operation_result; _} -> - manager_operation_result_status operation_result - - let operation_contents_status (type kind) - (contents : kind Apply_results.contents_result_list) ~index : - operation_status tzresult = - let rec rec_status : type kind. - int -> kind Apply_results.contents_result_list -> _ = - fun n -> function - | Apply_results.Single_result _ when n <> 0 -> - error_with "No operation with index %d" index - | Single_result result -> Ok (operation_result_status result) - | Cons_result (result, _rest) when n = 0 -> - Ok (operation_result_status result) - | Cons_result (_result, rest) -> rec_status (n - 1) rest - in - rec_status index contents - - let operation_status_of_receipt (operation : Protocol.operation_receipt) - ~index : operation_status tzresult = - match (operation : _) with - | No_operation_metadata -> - error_with "Cannot find operation status because metadata is missing" - | Operation_metadata {contents} -> operation_contents_status contents ~index - - let get_block_operations = - let ops_cache = Block_cache.create 32 in - fun cctxt block_hash -> - Block_cache.bind_or_put - ops_cache - block_hash - (fun block_hash -> - let open Lwt_result_syntax in - let+ operations = - Alpha_block_services.Operations.operations_in_pass - cctxt - ~chain:cctxt#chain - ~block:(`Hash (block_hash, 0)) - ~metadata:`Always - manager_pass - in - List.fold_left - (fun acc (op : Alpha_block_services.operation) -> - Operation_hash.Map.add op.hash op acc) - Operation_hash.Map.empty - operations) - Lwt.return - - let operation_status {Injector.cctxt; _} block_hash operation_hash ~index = - let open Lwt_result_syntax 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 -> ( - match operation.receipt with - | Empty -> - failwith "Cannot find operation status because metadata is empty" - | Too_large -> - failwith - "Cannot find operation status because metadata is too large" - | Receipt receipt -> - let*? status = operation_status_of_receipt receipt ~index in - return_some status) - - let dummy_sk_uri = - WithExceptions.Result.get_ok ~loc:__LOC__ - @@ Tezos_signer_backends.Unencrypted.make_sk - @@ Tezos_crypto.Signature.Secret_key.of_b58check_exn - "edsk3UqeiQWXX7NFEY1wUs6J1t2ez5aQ3hEWdqX5Jr5edZiGLW8nZr" - - let simulate_operations cctxt ~force ~source ~src_pk ~successor_level - ~fee_parameter ?safety_guard operations = - let open Lwt_result_syntax in - let fee_parameter : Injection.fee_parameter = - { - minimal_fees = Tez.of_mutez_exn fee_parameter.minimal_fees.mutez; - minimal_nanotez_per_byte = fee_parameter.minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit = - fee_parameter.minimal_nanotez_per_gas_unit; - force_low_fee = fee_parameter.force_low_fee; - fee_cap = Tez.of_mutez_exn fee_parameter.fee_cap.mutez; - burn_cap = Tez.of_mutez_exn fee_parameter.burn_cap.mutez; - } - in - let open Annotated_manager_operation in - let annotated_operations = - List.map - (fun operation -> - let (Manager operation) = injector_operation_to_manager operation in - Annotated_manager_operation - (Injection.prepare_manager_operation - ~fee:Limit.unknown - ~gas_limit:Limit.unknown - ~storage_limit:Limit.unknown - operation)) - operations - in - let (Manager_list annot_op) = - Annotated_manager_operation.manager_of_list annotated_operations - in - let cctxt = - new Protocol_client_context.wrap_full (cctxt :> Client_context.full) - in - let safety_guard = Option.map Gas.Arith.integral_of_int_exn safety_guard in - let*! simulation_result = - let*? source = Signature.Of_V_latest.get_public_key_hash source in - let*? src_pk = Signature.Of_V_latest.get_public_key src_pk in - Injection.inject_manager_operation - cctxt - ~simulation:true (* Only simulation here *) - ~force - ~chain:cctxt#chain - ~block:(`Head 0) - ~source - ~src_pk - ~src_sk:dummy_sk_uri - (* Use dummy secret key as it is not used by simulation *) - ~successor_level - ~fee:Limit.unknown - ~gas_limit:Limit.unknown - ~storage_limit:Limit.unknown - ?safety_guard - ~fee_parameter - annot_op - in - match simulation_result with - | Error trace -> - let exceeds_quota = - TzTrace.fold - (fun exceeds -> function - | Environment.Ecoproto_error - (Gas.Block_quota_exceeded | Gas.Operation_quota_exceeded) -> - true - | _ -> exceeds) - false - trace - in - fail (if exceeds_quota then `Exceeds_quotas trace else `TzError trace) - | Ok (_oph, packed_op, _contents, results) -> - let nb_ops = List.length operations in - let results = Apply_results.to_list (Contents_result_list results) in - (* packed_op can have reveal operations added automatically. *) - let start_index = List.length results - nb_ops in - (* remove extra reveal operations *) - let operations_statuses = - List.fold_left_i - (fun index_in_batch acc (Apply_results.Contents_result result) -> - if index_in_batch < start_index then acc - else - {index_in_batch; status = operation_result_status result} :: acc) - [] - results - |> List.rev - in - let unsigned_operation = - let {shell; protocol_data = Operation_data {contents; signature = _}} - = - packed_op - in - (shell, Contents_list contents) - in - return {operations_statuses; unsigned_operation} - - let sign_operation cctxt src_sk - ((shell, Contents_list contents) as unsigned_op) = - let open Lwt_result_syntax in - let unsigned_bytes = - Data_encoding.Binary.to_bytes_exn Operation.unsigned_encoding unsigned_op - in - let cctxt = - new Protocol_client_context.wrap_full (cctxt :> Client_context.full) - in - let+ signature = - Client_keys.sign - cctxt - ~watermark:Signature.Generic_operation - src_sk - unsigned_bytes - in - let op : packed_operation = - { - shell; - protocol_data = Operation_data {contents; signature = Some signature}; - } - in - Data_encoding.Binary.to_bytes_exn Operation.encoding op - - 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 - match header with - | 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 - ~first_round_duration:minimal_block_delay - ~delay_increment_per_round - in - let* predecessor_round = Fitness.round_from_raw header.fitness in - Round.timestamp_of_round - durations - ~predecessor_timestamp:header.timestamp - ~predecessor_round - ~round:Round.zero - in - let next_level_timestamp = - Result.value - next_level_timestamp - ~default: - (WithExceptions.Result.get_ok - ~loc:__LOC__ - Timestamp.(header.timestamp +? minimal_block_delay)) - in - Ptime.diff - (Time.System.of_protocol_exn next_level_timestamp) - (Time.System.now ()) - - let check_fee_parameters Injector.{fee_parameters; _} = - (* copied from removed Nairobi’s mempool module *) - let default_minimal_fees = - match Tez.of_mutez 100L with None -> assert false | Some t -> t - in - (* copied from removed Nairobi’s mempool module *) - let default_minimal_nanotez_per_gas_unit = Q.of_int 100 in - (* copied from removed Nairobi’s mempool module *) - let default_minimal_nanotez_per_byte = Q.of_int 1000 in - let check_value operation_kind name compare to_string mempool_default value - = - if compare mempool_default value > 0 then - error_with - "Bad configuration fee_parameter.%s for %s. It must be at least %s \ - for operations of the injector to be propagated." - name - (Operation_kind.to_string operation_kind) - (to_string mempool_default) - else Ok () - in - let check purpose - { - minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee = _; - fee_cap = _; - burn_cap = _; - } = - let open Result_syntax in - let+ () = - check_value - purpose - "minimal_fees" - Int64.compare - Int64.to_string - (Protocol.Alpha_context.Tez.to_mutez default_minimal_fees) - minimal_fees.mutez - and+ () = - check_value - purpose - "minimal_nanotez_per_byte" - Q.compare - Q.to_string - default_minimal_nanotez_per_byte - minimal_nanotez_per_byte - and+ () = - check_value - purpose - "minimal_nanotez_per_gas_unit" - Q.compare - Q.to_string - default_minimal_nanotez_per_gas_unit - minimal_nanotez_per_gas_unit - in - () - in - Operation_kind.Map.iter_e check fee_parameters - - let checks state = check_fee_parameters state - - let get_balance_mutez cctxt ?block pkh = - let open Lwt_result_syntax in - let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in - let cctxt = - new Protocol_client_context.wrap_full (cctxt :> Client_context.full) - in - let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in - let+ balance = - Protocol.Alpha_services.Contract.balance - cctxt - (cctxt#chain, block) - (Implicit pkh) - in - Protocol.Alpha_context.Tez.to_mutez balance -end - -let () = Injector.register_proto_client Protocol.hash (module Proto_client) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.mli deleted file mode 100644 index ca4112313ef6449d4ec20d700049ae0d28263944..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_injector.mli +++ /dev/null @@ -1,32 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 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. *) -(* *) -(*****************************************************************************) - -(** 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_node/sc_rollup_node_errors.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_node_errors.ml deleted file mode 100644 index bf57c29eda9b498b56c5e7775eb30e5caaaf9e3e..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_node_errors.ml +++ /dev/null @@ -1,33 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -include Rollup_node_errors - -(** Registering protocol specific errors *) - -let make_id id = String.concat "." [Protocol.name; id] - -let register_error_kind ~id = register_error_kind ~id:(make_id id) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/wasm_2_0_0_pvm.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/wasm_2_0_0_pvm.ml deleted file mode 100644 index 19ce223d107617b5171ef60f951823361eb22ef0..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/wasm_2_0_0_pvm.ml +++ /dev/null @@ -1,237 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022-2023 TriliTech *) -(* *) -(* 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 -open Alpha_context - -(** This module manifests the proof format used by the Wasm PVM as defined by - the Layer 1 implementation for it. - - It is imperative that this is aligned with the protocol's implementation. -*) -module Wasm_2_0_0_proof_format = - Irmin_context.Proof - (struct - include Sc_rollup.State_hash - - let of_context_hash = Sc_rollup.State_hash.context_hash_to_state_hash - end) - (struct - let proof_encoding = - Tezos_context_merkle_proof_encoding.Merkle_proof_encoding.V2.Tree2 - .tree_proof_encoding - end) - -module type TreeS = - Tezos_context_sigs.Context.TREE - with type key = string list - and type value = bytes - -module Make_wrapped_tree (Tree : TreeS) : - Tezos_tree_encoding.TREE with type tree = Tree.tree = struct - type Tezos_tree_encoding.tree_instance += PVM_tree of Tree.tree - - include Tree - - let select = function - | PVM_tree t -> t - | _ -> raise Tezos_tree_encoding.Incorrect_tree_type - - let wrap t = PVM_tree t -end - -module Make_backend (Tree : TreeS) = struct - include Tezos_scoru_wasm_fast.Pvm.Make (Make_wrapped_tree (Tree)) - - let compute_step = - compute_step ~wasm_entrypoint:Tezos_scoru_wasm.Constants.wasm_entrypoint - - let reveal_exn reveal = - match - Tezos_scoru_wasm.Wasm_pvm_state.Compatibility.of_current_opt reveal - with - | Some r -> r - | None -> - (* The WASM PVM before environment V11 will not request a value - outside of the [Compatibility.reveal] domain. *) - Stdlib.failwith - "The rollup node tried to interact with an inconsistent state." - - let input_request_exn = function - | Tezos_scoru_wasm.Wasm_pvm_state.No_input_required -> - Environment.Wasm_2_0_0.No_input_required - | Input_required -> Input_required - | Reveal_required req -> Reveal_required (reveal_exn req) - - let info_exn - Tezos_scoru_wasm.Wasm_pvm_state. - {current_tick; last_input_read; input_request} = - Environment.Wasm_2_0_0. - { - current_tick; - last_input_read; - input_request = input_request_exn input_request; - } - - let get_info tree = - let open Lwt_syntax in - let+ info = get_info tree in - info_exn info -end - -(** Durable part of the storage of this PVM. *) -module type Durable_state = sig - type state - - (** [value_length state key] returns the length of data stored - for the [key] in the durable storage of the PVM state [state], if any. *) - val value_length : state -> string -> int64 option Lwt.t - - (** [lookup state key] returns the data stored - for the [key] in the durable storage of the PVM state [state], if any. *) - val lookup : state -> string -> bytes option Lwt.t - - (** [subtrees state key] returns subtrees - for the [key] in the durable storage of the PVM state [state]. - Empty list in case if path doesn't exist. *) - val list : state -> string -> string list Lwt.t - - module Tree_encoding_runner : - Tezos_tree_encoding.Runner.S with type tree = state -end - -module Make_durable_state - (T : Tezos_tree_encoding.TREE with type tree = Irmin_context.tree) : - Durable_state with type state = T.tree = struct - module Tree_encoding_runner = Tezos_tree_encoding.Runner.Make (T) - - type state = T.tree - - let decode_durable tree = - Tree_encoding_runner.decode - Tezos_scoru_wasm.Wasm_pvm.durable_storage_encoding - tree - - let value_length tree key_str = - let open Lwt_syntax in - let key = Tezos_scoru_wasm.Durable.key_of_string_exn key_str in - let* durable = decode_durable tree in - let+ res_opt = Tezos_scoru_wasm.Durable.find_value durable key in - Option.map Tezos_lazy_containers.Chunked_byte_vector.length res_opt - - let lookup tree key_str = - let open Lwt_syntax in - let key = Tezos_scoru_wasm.Durable.key_of_string_exn key_str in - let* durable = decode_durable tree in - let* res_opt = Tezos_scoru_wasm.Durable.find_value durable key in - match res_opt with - | None -> return_none - | Some v -> - let+ bts = Tezos_lazy_containers.Chunked_byte_vector.to_bytes v in - Some bts - - let list tree key_str = - let open Lwt_syntax in - let key = Tezos_scoru_wasm.Durable.key_of_string_exn key_str in - let* durable = decode_durable tree in - Tezos_scoru_wasm.Durable.list durable key -end - -module Durable_state = - Make_durable_state (Make_wrapped_tree (Wasm_2_0_0_proof_format.Tree)) - -type unsafe_patch = - | Increase_max_nb_ticks of int64 - | Patch_durable_storage of {key : string; value : string} - -module Impl : Pvm_sig.S with type Unsafe_patches.t = unsafe_patch = struct - module PVM = - Sc_rollup.Wasm_2_0_0PVM.Make (Make_backend) (Wasm_2_0_0_proof_format) - include PVM - - let kind = Sc_rollup.Kind.Wasm_2_0_0 - - let new_dissection = Game_helpers.Wasm.new_dissection - - module State = Irmin_context.PVMState - - module Inspect_durable_state = struct - let lookup state keys = - let key = "/" ^ String.concat "/" keys in - Durable_state.lookup state key - end - - module Backend = Make_backend (Wasm_2_0_0_proof_format.Tree) - - module Unsafe_patches = struct - type t = unsafe_patch - - let of_patch (p : Pvm_patches.unsafe_patch) = - match p with - | Increase_max_nb_ticks max_nb_ticks -> - Ok (Increase_max_nb_ticks max_nb_ticks) - | Patch_durable_storage {key; value} -> - Ok (Patch_durable_storage {key; value}) - - let apply state unsafe_patch = - let open Lwt_syntax in - match unsafe_patch with - | Increase_max_nb_ticks max_nb_ticks -> - let* registered_max_nb_ticks = - Backend.Unsafe.get_max_nb_ticks state - in - let max_nb_ticks = Z.of_int64 max_nb_ticks in - if Z.Compare.(max_nb_ticks < registered_max_nb_ticks) then - Format.ksprintf - invalid_arg - "Decreasing tick limit of WASM PVM from %s to %s is not allowed" - (Z.to_string registered_max_nb_ticks) - (Z.to_string max_nb_ticks) ; - Backend.Unsafe.set_max_nb_ticks max_nb_ticks state - | Patch_durable_storage {key; value} -> - Backend.Unsafe.durable_set ~key ~value state - end - - let string_of_status : status -> string = function - | Waiting_for_input_message -> "Waiting for input message" - | Waiting_for_reveal (Sc_rollup.Reveal_raw_data hash) -> - Format.asprintf - "Waiting for preimage reveal %a" - Sc_rollup_reveal_hash.pp - hash - | Waiting_for_reveal Sc_rollup.Reveal_metadata -> "Waiting for metadata" - | Waiting_for_reveal (Sc_rollup.Request_dal_page page_id) -> - Format.asprintf "Waiting for page data %a" Dal.Page.pp page_id - | Computing -> "Computing" - - let eval_many ~reveal_builtins ~write_debug = - Backend.compute_step_many - ~wasm_entrypoint:Tezos_scoru_wasm.Constants.wasm_entrypoint - ~reveal_builtins - ~write_debug - ?hooks:None -end - -include Impl diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/wasm_2_0_0_rpc.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/wasm_2_0_0_rpc.ml deleted file mode 100644 index 8a7062719c36746292f65f15381232d5e7f03371..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/wasm_2_0_0_rpc.ml +++ /dev/null @@ -1,82 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Nomadic Labs, *) -(* Copyright (c) 2023 Trili Tech *) -(* *) -(* 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 Rpc_directory_helpers -open Context_wrapper.Irmin - -module Make_RPC - (Durable_state : - Wasm_2_0_0_pvm.Durable_state with type state = Irmin_context.tree) = -struct - module Block_directory = Make_sub_directory (struct - include Sc_rollup_services.Block - - type context = Node_context.rw - - type subcontext = Node_context.ro * Block_hash.t - - let context_of_prefix node_ctxt (((), block) : prefix) = - let open Lwt_result_syntax in - let+ block = Block_directory_helpers.block_of_prefix node_ctxt block in - (Node_context.readonly node_ctxt, block) - end) - - let get_state (node_ctxt : _ Node_context.t) block_hash = - let open Lwt_result_syntax in - let* ctxt = Node_context.checkout_context node_ctxt block_hash in - let*! state = Context.PVMState.find ctxt in - match state with None -> failwith "No state" | Some state -> return state - - let register () = - let open Protocol.Alpha_context.Sc_rollup in - ( Block_directory.register0 - (Sc_rollup_services.Block.durable_state_value Kind.Wasm_2_0_0) - @@ fun (node_ctxt, block) {key} () -> - let open Lwt_result_syntax in - let* state = get_state node_ctxt block in - let*! value = Durable_state.lookup (of_node_pvmstate state) key in - return value ) ; - - ( Block_directory.register0 - (Sc_rollup_services.Block.durable_state_length Kind.Wasm_2_0_0) - @@ fun (node_ctxt, block) {key} () -> - let open Lwt_result_syntax in - let* state = get_state node_ctxt block in - let*! leng = Durable_state.value_length (of_node_pvmstate state) key in - return leng ) ; - - Block_directory.register0 - (Sc_rollup_services.Block.durable_state_subkeys Kind.Wasm_2_0_0) - @@ fun (node_ctxt, block) {key} () -> - let open Lwt_result_syntax in - let* state = get_state node_ctxt block in - let*! subkeys = Durable_state.list (of_node_pvmstate state) key in - return subkeys - - let build_sub_directory node_ctxt = - register () ; - Block_directory.build_sub_directory node_ctxt -end diff --git a/tobi/config b/tobi/config index e0cf354cf52fb794204813592f2ad5e3981b349e..956d8354dbb8af415d349b258df2ae2dc9d3e13e 100644 --- a/tobi/config +++ b/tobi/config @@ -130,7 +130,6 @@ octez-smart-rollup-node-Proxford: src/proto_018_Proxford/lib_sc_rollup_node octez-smart-rollup-node-PsParisC: src/proto_020_PsParisC/lib_sc_rollup_node octez-smart-rollup-node-PsQuebec: src/proto_021_PsQuebec/lib_sc_rollup_node octez-smart-rollup-node-PsRiotum: src/proto_022_PsRiotum/lib_sc_rollup_node -octez-smart-rollup-node-PtNairob: src/proto_017_PtNairob/lib_sc_rollup_node octez-smart-rollup-node-PtParisB: src/proto_019_PtParisB/lib_sc_rollup_node octez-smart-rollup-node-PtSeouLo: src/proto_023_PtSeouLo/lib_sc_rollup_node octez-smart-rollup-node-PtTALLiN: src/proto_024_PtTALLiN/lib_sc_rollup_node