diff --git a/src/lib_smart_rollup_node/interpreter.ml b/src/lib_smart_rollup_node/interpreter.ml index 4b199972aec3e68900e81154331c9cd97252f340..2521be42f52b14aad4eb27c43de8c9feeb519e03 100644 --- a/src/lib_smart_rollup_node/interpreter.ml +++ b/src/lib_smart_rollup_node/interpreter.ml @@ -42,14 +42,29 @@ let get_boot_sector (module Plugin : Protocol_plugin_sig.PARTIAL) (** Apply potential unsafe patches to the PVM state. *) let apply_unsafe_patches (module Plugin : Protocol_plugin_sig.PARTIAL) - (node_ctxt : _ Node_context.t) state = + ~genesis_block_hash (node_ctxt : _ Node_context.t) state = let open Lwt_result_syntax in - List.fold_left_es - (fun state patch -> - let*! () = Interpreter_event.patching_genesis_state patch in - Plugin.Pvm.Unsafe.apply_patch node_ctxt.kind state patch) - state - (node_ctxt.unsafe_patches :> Pvm_patches.unsafe_patch list) + match (node_ctxt.unsafe_patches :> Pvm_patches.unsafe_patch list) with + | [] -> return state + | patches -> + let* whitelist = + Plugin.Layer1_helpers.find_whitelist + node_ctxt.cctxt + ~block:genesis_block_hash + node_ctxt.config.sc_rollup_address + in + let private_rollup = whitelist <> None in + let*? () = + error_unless + private_rollup + Rollup_node_errors.Cannot_patch_pvm_of_public_rollup + in + List.fold_left_es + (fun state patch -> + let*! () = Interpreter_event.patching_genesis_state patch in + Plugin.Pvm.Unsafe.apply_patch node_ctxt.kind state patch) + state + patches type original_genesis_state = Original of Context.pvmstate @@ -69,7 +84,11 @@ let genesis_state (module Plugin : Protocol_plugin_sig.PARTIAL) ?genesis_block Plugin.Pvm.install_boot_sector node_ctxt.kind initial_state boot_sector in let* genesis_state = - apply_unsafe_patches (module Plugin) node_ctxt unpatched_genesis_state + apply_unsafe_patches + (module Plugin) + node_ctxt + ~genesis_block_hash + unpatched_genesis_state in return (genesis_state, Original unpatched_genesis_state) diff --git a/src/lib_smart_rollup_node/protocol_plugin_sig.ml b/src/lib_smart_rollup_node/protocol_plugin_sig.ml index d786d491af3fa87e632840cc66ba5721f396b8ab..80d807b9125566067d688bc9b143b55ceb2fe602 100644 --- a/src/lib_smart_rollup_node/protocol_plugin_sig.ml +++ b/src/lib_smart_rollup_node/protocol_plugin_sig.ml @@ -156,11 +156,17 @@ module type LAYER1_HELPERS = sig Address.t -> Node_context.genesis_info tzresult Lwt.t + (** [get_boot_sector block_hash node_ctxt] retrieves the boot sector from the + rollup origination operation in block [block_hash]. Precondition: + [block_hash] has to be the block where the rollup was originated. *) val get_boot_sector : Block_hash.t -> _ Node_context.t -> string tzresult Lwt.t + (** Find and retrieve the whitelist the rollup at a given block (if provided) + or the head. *) val find_whitelist : #Client_context.full -> + ?block:Block_hash.t -> Address.t -> Signature.public_key_hash list option tzresult Lwt.t diff --git a/src/lib_smart_rollup_node/rollup_node_daemon.ml b/src/lib_smart_rollup_node/rollup_node_daemon.ml index ea6fb760ff6f9f5b05aa4ab28dd217a5176447d5..22193d358d1653d6ee083421365addb817a5d293 100644 --- a/src/lib_smart_rollup_node/rollup_node_daemon.ml +++ b/src/lib_smart_rollup_node/rollup_node_daemon.ml @@ -555,10 +555,10 @@ let rec process_daemon ({node_ctxt; _} as state) = in let loop () = daemonize state in protect loop ~on_error:(function - | Rollup_node_errors.( - ( Lost_game _ | Unparsable_boot_sector _ | Invalid_genesis_state _ - | Operator_not_in_whitelist | Purpose.Missing_operator _ - | Purpose.Too_many_operators _ )) + | ( Rollup_node_errors.( + ( Lost_game _ | Unparsable_boot_sector _ | Invalid_genesis_state _ + | Operator_not_in_whitelist | Cannot_patch_pvm_of_public_rollup )) + | Purpose.(Missing_operator _ | Too_many_operators _) ) :: _ as e -> fatal_error_exit e | Rollup_node_errors.Could_not_open_preimage_file _ :: _ as e -> diff --git a/src/lib_smart_rollup_node/rollup_node_errors.ml b/src/lib_smart_rollup_node/rollup_node_errors.ml index 65d0e27d86a7d561bcaa6feaca89201fa1bd9979..7bd71eeb28c65bdaeb7e5464cf3af3afe0edb5f2 100644 --- a/src/lib_smart_rollup_node/rollup_node_errors.ml +++ b/src/lib_smart_rollup_node/rollup_node_errors.ml @@ -77,6 +77,8 @@ type error += type error += Operator_not_in_whitelist +type error += Cannot_patch_pvm_of_public_rollup + type error += Operator_has_no_staked type error += Exit_bond_recovered_bailout_mode @@ -432,6 +434,20 @@ let () = (function Operator_not_in_whitelist -> Some () | _ -> None) (fun () -> Operator_not_in_whitelist) ; + register_error_kind + ~id:"sc_rollup.node.cannot_patch_pvm_of_public_rollup" + ~title:"Cannot patch PVM of public rollup" + ~description:"Unsafe PVM patches can only be applied in private rollups." + ~pp:(fun ppf () -> + Format.pp_print_string + ppf + "Unsafe PVM patches can only be applied in private rollups, i.e. in \ + non publicly refutable settings.") + `Permanent + Data_encoding.unit + (function Cannot_patch_pvm_of_public_rollup -> Some () | _ -> None) + (fun () -> Cannot_patch_pvm_of_public_rollup) ; + register_error_kind ~id:"sc_rollup.node.operator_has_no_staked" ~title:"The operator does not has any stake" 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 index fa347dda9529d3f987df12c34ba1d927477dd0b7..769e8f3d5b25a69540c4a78f15daac6ed2813e5c 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.ml @@ -237,7 +237,7 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | Found_boot_sector boot_sector -> return boot_sector | _ -> missing_boot_sector ()) -let find_whitelist _cctxt _rollup_address : +let find_whitelist _cctxt ?block:_ _rollup_address : Signature.public_key_hash trace option tzresult Lwt.t = return None 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 index 55bdef4ae9ee041c8b21b1480c26e8861645f861..8a665e9dc2ed2c53f0e73ea3d996292dbccd7564 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.mli +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/layer1_helpers.mli @@ -1,93 +1,17 @@ (*****************************************************************************) (* *) -(* 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. *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2023 Nomadic Labs *) +(* SPDX-FileCopyrightText: 2023-2024 Functori *) (* *) (*****************************************************************************) -open Octez_smart_rollup_node.Layer1 +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 : - t -> + Layer1.t -> Block_hash.t -> Protocol_client_context.Alpha_block_services.block_info tzresult Lwt.t - -(** [prefetch_tezos_blocks l1_ctxt blocks] prefetches the blocks - asynchronously. NOTE: the number of blocks to prefetch must not be greater - than the size of the blocks cache otherwise they will be lost. *) -val prefetch_tezos_blocks : t -> head list -> unit - -val get_last_cemented_commitment : - #Client_context.full -> Address.t -> Node_context.lcc tzresult Lwt.t - -val get_last_published_commitment : - ?allow_unstake:bool -> - #Client_context.full -> - Address.t -> - Signature.public_key_hash -> - Commitment.t option tzresult Lwt.t - -val get_kind : #Client_context.full -> Address.t -> Kind.t tzresult Lwt.t - -val genesis_inbox : - #Client_context.full -> - genesis_level:int32 -> - Octez_smart_rollup.Inbox.t tzresult Lwt.t - -(** Convert protocol constants to their protocol agnostic representation. *) -val constants_of_parametric : - Protocol.Alpha_context.Constants.Parametric.t -> - Rollup_constants.protocol_constants - -(** Retrieve protocol agnotic constants for the head of the chain. *) -val retrieve_constants : - ?block:Block_services.block -> - #Client_context.full -> - Rollup_constants.protocol_constants tzresult Lwt.t - -val retrieve_genesis_info : - #Client_context.full -> Address.t -> Node_context.genesis_info tzresult Lwt.t - -(** [get_boot_sector block_hash node_ctxt] retrieves the boot sector from the - rollup origination operation in block [block_hash]. Precondition: - [block_hash] has to be the block where the rollup was originated. *) -val get_boot_sector : Block_hash.t -> _ Node_context.t -> string tzresult Lwt.t - -(** Find and retrieve the whitelist the rollup. *) -val find_whitelist : - #Client_context.full -> - Address.t -> - Signature.public_key_hash list option tzresult Lwt.t - -(** Find and retrieve information about the last whitelist update. *) -val find_last_whitelist_update : - #Client_context.full -> Address.t -> (Z.t * Int32.t) option tzresult Lwt.t - -(** Retrieve a commitment published on L1. *) -val get_commitment : - #Client_context.full -> - Address.t -> - Commitment.Hash.t -> - Commitment.t tzresult Lwt.t diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.ml index 95d97652f5aa2a8481109ebd72a3d68654bcf375..d5e2e719d1e593b77e930f53ba507d7a4659f455 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.ml @@ -236,14 +236,11 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | Found_boot_sector boot_sector -> return boot_sector | _ -> missing_boot_sector ()) -let find_whitelist cctxt rollup_address = +let find_whitelist cctxt ?block rollup_address = + let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in Plugin.RPC.Sc_rollup.whitelist (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) - ( cctxt#chain, - `Head 0 - (* TODO: https://gitlab.com/tezos/tezos/-/issues/6152 - Rollup node: investigate use cctxt#block instead of `Head 0 in RPC calls*) - ) + (cctxt#chain, block) rollup_address let find_last_whitelist_update cctxt rollup_address = diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.mli b/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.mli index a75292119500a3da6f68fbe3b90a7ab579c0ea88..8a665e9dc2ed2c53f0e73ea3d996292dbccd7564 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.mli +++ b/src/proto_018_Proxford/lib_sc_rollup_node/layer1_helpers.mli @@ -1,93 +1,17 @@ (*****************************************************************************) (* *) -(* 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. *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2023 Nomadic Labs *) +(* SPDX-FileCopyrightText: 2023-2024 Functori *) (* *) (*****************************************************************************) -open Octez_smart_rollup_node.Layer1 +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 : - t -> + Layer1.t -> Block_hash.t -> Protocol_client_context.Alpha_block_services.block_info tzresult Lwt.t - -(** [prefetch_tezos_blocks l1_ctxt blocks] prefetches the blocks - asynchronously. NOTE: the number of blocks to prefetch must not be greater - than the size of the blocks cache otherwise they will be lost. *) -val prefetch_tezos_blocks : t -> head list -> unit - -val get_last_cemented_commitment : - #Client_context.full -> Address.t -> Node_context.lcc tzresult Lwt.t - -val get_last_published_commitment : - ?allow_unstake:bool -> - #Client_context.full -> - Address.t -> - Signature.public_key_hash -> - Commitment.t option tzresult Lwt.t - -val get_kind : #Client_context.full -> Address.t -> Kind.t tzresult Lwt.t - -val genesis_inbox : - #Client_context.full -> - genesis_level:int32 -> - Octez_smart_rollup.Inbox.t tzresult Lwt.t - -(** Convert protocol constants to their protocol agnostic representation. *) -val constants_of_parametric : - Protocol.Alpha_context.Constants.Parametric.t -> - Rollup_constants.protocol_constants - -(** Retrieve protocol agnotic constants for the head of the chain. *) -val retrieve_constants : - ?block:Block_services.block -> - #Client_context.full -> - Rollup_constants.protocol_constants tzresult Lwt.t - -val retrieve_genesis_info : - #Client_context.full -> Address.t -> Node_context.genesis_info tzresult Lwt.t - -(** [get_boot_sector block_hash node_ctxt] retrieves the boot sector from the - rollup origination operation in block [block_hash]. Precondition: - [block_hash] has to be the block where the rollup was originated. *) -val get_boot_sector : Block_hash.t -> _ Node_context.t -> string tzresult Lwt.t - -(** Find and retrieve the whitelist the rollup. *) -val find_whitelist : - #Client_context.full -> - Address.t -> - Protocol.Alpha_context.Sc_rollup.Whitelist.t option tzresult Lwt.t - -(** Find and retrieve information about the last whitelist update. *) -val find_last_whitelist_update : - #Client_context.full -> Address.t -> (Z.t * Int32.t) option tzresult Lwt.t - -(** Retrieve a commitment published on L1. *) -val get_commitment : - #Client_context.full -> - Address.t -> - Commitment.Hash.t -> - Commitment.t tzresult Lwt.t diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.ml index 95d97652f5aa2a8481109ebd72a3d68654bcf375..d5e2e719d1e593b77e930f53ba507d7a4659f455 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.ml @@ -236,14 +236,11 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | Found_boot_sector boot_sector -> return boot_sector | _ -> missing_boot_sector ()) -let find_whitelist cctxt rollup_address = +let find_whitelist cctxt ?block rollup_address = + let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in Plugin.RPC.Sc_rollup.whitelist (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) - ( cctxt#chain, - `Head 0 - (* TODO: https://gitlab.com/tezos/tezos/-/issues/6152 - Rollup node: investigate use cctxt#block instead of `Head 0 in RPC calls*) - ) + (cctxt#chain, block) rollup_address let find_last_whitelist_update cctxt rollup_address = diff --git a/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.mli b/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.mli index a75292119500a3da6f68fbe3b90a7ab579c0ea88..8a665e9dc2ed2c53f0e73ea3d996292dbccd7564 100644 --- a/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.mli +++ b/src/proto_019_PtParisB/lib_sc_rollup_node/layer1_helpers.mli @@ -1,93 +1,17 @@ (*****************************************************************************) (* *) -(* 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. *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2023 Nomadic Labs *) +(* SPDX-FileCopyrightText: 2023-2024 Functori *) (* *) (*****************************************************************************) -open Octez_smart_rollup_node.Layer1 +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 : - t -> + Layer1.t -> Block_hash.t -> Protocol_client_context.Alpha_block_services.block_info tzresult Lwt.t - -(** [prefetch_tezos_blocks l1_ctxt blocks] prefetches the blocks - asynchronously. NOTE: the number of blocks to prefetch must not be greater - than the size of the blocks cache otherwise they will be lost. *) -val prefetch_tezos_blocks : t -> head list -> unit - -val get_last_cemented_commitment : - #Client_context.full -> Address.t -> Node_context.lcc tzresult Lwt.t - -val get_last_published_commitment : - ?allow_unstake:bool -> - #Client_context.full -> - Address.t -> - Signature.public_key_hash -> - Commitment.t option tzresult Lwt.t - -val get_kind : #Client_context.full -> Address.t -> Kind.t tzresult Lwt.t - -val genesis_inbox : - #Client_context.full -> - genesis_level:int32 -> - Octez_smart_rollup.Inbox.t tzresult Lwt.t - -(** Convert protocol constants to their protocol agnostic representation. *) -val constants_of_parametric : - Protocol.Alpha_context.Constants.Parametric.t -> - Rollup_constants.protocol_constants - -(** Retrieve protocol agnotic constants for the head of the chain. *) -val retrieve_constants : - ?block:Block_services.block -> - #Client_context.full -> - Rollup_constants.protocol_constants tzresult Lwt.t - -val retrieve_genesis_info : - #Client_context.full -> Address.t -> Node_context.genesis_info tzresult Lwt.t - -(** [get_boot_sector block_hash node_ctxt] retrieves the boot sector from the - rollup origination operation in block [block_hash]. Precondition: - [block_hash] has to be the block where the rollup was originated. *) -val get_boot_sector : Block_hash.t -> _ Node_context.t -> string tzresult Lwt.t - -(** Find and retrieve the whitelist the rollup. *) -val find_whitelist : - #Client_context.full -> - Address.t -> - Protocol.Alpha_context.Sc_rollup.Whitelist.t option tzresult Lwt.t - -(** Find and retrieve information about the last whitelist update. *) -val find_last_whitelist_update : - #Client_context.full -> Address.t -> (Z.t * Int32.t) option tzresult Lwt.t - -(** Retrieve a commitment published on L1. *) -val get_commitment : - #Client_context.full -> - Address.t -> - Commitment.Hash.t -> - Commitment.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml index 95d97652f5aa2a8481109ebd72a3d68654bcf375..d5e2e719d1e593b77e930f53ba507d7a4659f455 100644 --- a/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml @@ -236,14 +236,11 @@ let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = | Found_boot_sector boot_sector -> return boot_sector | _ -> missing_boot_sector ()) -let find_whitelist cctxt rollup_address = +let find_whitelist cctxt ?block rollup_address = + let block = match block with Some b -> `Hash (b, 0) | None -> `Head 0 in Plugin.RPC.Sc_rollup.whitelist (new Protocol_client_context.wrap_full (cctxt :> Client_context.full)) - ( cctxt#chain, - `Head 0 - (* TODO: https://gitlab.com/tezos/tezos/-/issues/6152 - Rollup node: investigate use cctxt#block instead of `Head 0 in RPC calls*) - ) + (cctxt#chain, block) rollup_address let find_last_whitelist_update cctxt rollup_address = diff --git a/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.mli b/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.mli index a75292119500a3da6f68fbe3b90a7ab579c0ea88..8a665e9dc2ed2c53f0e73ea3d996292dbccd7564 100644 --- a/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.mli +++ b/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.mli @@ -1,93 +1,17 @@ (*****************************************************************************) (* *) -(* 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. *) +(* SPDX-License-Identifier: MIT *) +(* SPDX-FileCopyrightText: 2023 Nomadic Labs *) +(* SPDX-FileCopyrightText: 2023-2024 Functori *) (* *) (*****************************************************************************) -open Octez_smart_rollup_node.Layer1 +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 : - t -> + Layer1.t -> Block_hash.t -> Protocol_client_context.Alpha_block_services.block_info tzresult Lwt.t - -(** [prefetch_tezos_blocks l1_ctxt blocks] prefetches the blocks - asynchronously. NOTE: the number of blocks to prefetch must not be greater - than the size of the blocks cache otherwise they will be lost. *) -val prefetch_tezos_blocks : t -> head list -> unit - -val get_last_cemented_commitment : - #Client_context.full -> Address.t -> Node_context.lcc tzresult Lwt.t - -val get_last_published_commitment : - ?allow_unstake:bool -> - #Client_context.full -> - Address.t -> - Signature.public_key_hash -> - Commitment.t option tzresult Lwt.t - -val get_kind : #Client_context.full -> Address.t -> Kind.t tzresult Lwt.t - -val genesis_inbox : - #Client_context.full -> - genesis_level:int32 -> - Octez_smart_rollup.Inbox.t tzresult Lwt.t - -(** Convert protocol constants to their protocol agnostic representation. *) -val constants_of_parametric : - Protocol.Alpha_context.Constants.Parametric.t -> - Rollup_constants.protocol_constants - -(** Retrieve protocol agnotic constants for the head of the chain. *) -val retrieve_constants : - ?block:Block_services.block -> - #Client_context.full -> - Rollup_constants.protocol_constants tzresult Lwt.t - -val retrieve_genesis_info : - #Client_context.full -> Address.t -> Node_context.genesis_info tzresult Lwt.t - -(** [get_boot_sector block_hash node_ctxt] retrieves the boot sector from the - rollup origination operation in block [block_hash]. Precondition: - [block_hash] has to be the block where the rollup was originated. *) -val get_boot_sector : Block_hash.t -> _ Node_context.t -> string tzresult Lwt.t - -(** Find and retrieve the whitelist the rollup. *) -val find_whitelist : - #Client_context.full -> - Address.t -> - Protocol.Alpha_context.Sc_rollup.Whitelist.t option tzresult Lwt.t - -(** Find and retrieve information about the last whitelist update. *) -val find_last_whitelist_update : - #Client_context.full -> Address.t -> (Z.t * Int32.t) option tzresult Lwt.t - -(** Retrieve a commitment published on L1. *) -val get_commitment : - #Client_context.full -> - Address.t -> - Commitment.Hash.t -> - Commitment.t tzresult Lwt.t diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index 7630b5bb610ab0e46fbff6c3f1c34d5f9c346b26..ef4418a516fc0d0016f2257c1c0982ed6ade506a 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -4681,19 +4681,25 @@ let test_arg_boot_sector_file ~kind = let* _ = Sc_rollup_node.wait_sync ~timeout:10. rollup_node in unit -let test_unsafe_genesis_patch ~kind = +let test_unsafe_genesis_patch ~private_ ~kind = let commitment_period = 3 in let max_nb_tick = 50_000_000_000_000L in - let should_fail = match kind with "wasm_2_0_0" -> false | _ -> true in + let unsupported_pvm = match kind with "wasm_2_0_0" -> false | _ -> true in + let should_fail = unsupported_pvm || not private_ in + let operator = Constant.bootstrap1.public_key_hash in + let whitelist = if private_ then Some [operator] else None in test_full_scenario ~kind ~commitment_period + ~supports:(Protocol.From_protocol 018) + ?whitelist { variant = None; tags = ["node"; "unsafe_patch"]; description = sf - "Rollup can%s apply unsafe genesis PVM patches" + "Rollup (%s) can%s apply unsafe genesis PVM patches" + (if private_ then "private" else "public") (if should_fail then "not" else ""); } @@ fun _protocol rollup_node rollup _node client -> @@ -4710,10 +4716,13 @@ let test_unsafe_genesis_patch ~kind = () ; let* () = Sc_rollup_node.run ~wait_ready:false rollup_node rollup [] in if should_fail then - Sc_rollup_node.check_error - ~exit_code:1 - ~msg:(rex "Patch .* is not supported") - rollup_node + let msg = + if unsupported_pvm then rex "Patch .* is not supported" + else if not private_ then + rex "Unsafe PVM patches can only be applied in private rollups" + else assert false + in + Sc_rollup_node.check_error ~exit_code:1 ~msg rollup_node else let* () = bake_levels (commitment_period + 4) client in let* _ = Sc_rollup_node.wait_sync ~timeout:10. rollup_node in @@ -5749,7 +5758,8 @@ let register ~kind ~protocols = protocols ~kind ; test_outbox_message protocols ~kind ; - test_unsafe_genesis_patch protocols ~kind + test_unsafe_genesis_patch protocols ~private_:true ~kind ; + test_unsafe_genesis_patch protocols ~private_:false ~kind let register ~protocols = (* PVM-independent tests. We still need to specify a PVM kind