diff --git a/src/lib_smart_rollup_node/interpreter.ml b/src/lib_smart_rollup_node/interpreter.ml index 5fe2c3463565c19d5efdfdfd4382c398f2e152b1..12b85a2fd70a80457a9625a334de5329e5dd36d7 100644 --- a/src/lib_smart_rollup_node/interpreter.ml +++ b/src/lib_smart_rollup_node/interpreter.ml @@ -44,13 +44,23 @@ let get_boot_sector (module Plugin : Protocol_plugin_sig.PARTIAL) let apply_unsafe_patches (module Plugin : Protocol_plugin_sig.PARTIAL) ~genesis_block_hash (node_ctxt : _ Node_context.t) state = let open Lwt_result_syntax in - match (node_ctxt.unsafe_patches :> Pvm_patches.unsafe_patch list) with + match + (node_ctxt.unsafe_patches + :> (Pvm_patches.unsafe_patch * Pvm_patches.kind) list) + with | [] -> return state | patches -> + let has_user_provided_patches = + List.exists + (function + | _, Pvm_patches.User_provided -> true | _, Hardcoded -> false) + patches + in let*? () = - error_unless - node_ctxt.config.apply_unsafe_patches - (Rollup_node_errors.Needs_apply_unsafe_flag patches) + error_when + (has_user_provided_patches + && not node_ctxt.config.apply_unsafe_patches) + (Rollup_node_errors.Needs_apply_unsafe_flag (List.map fst patches)) in let* whitelist = Plugin.Layer1_helpers.find_whitelist @@ -65,7 +75,7 @@ let apply_unsafe_patches (module Plugin : Protocol_plugin_sig.PARTIAL) Rollup_node_errors.Cannot_patch_pvm_of_public_rollup in List.fold_left_es - (fun state patch -> + (fun state (patch, _kind) -> let*! () = Interpreter_event.patching_genesis_state patch in Plugin.Pvm.Unsafe.apply_patch node_ctxt.kind state patch) state diff --git a/src/lib_smart_rollup_node/publisher.ml b/src/lib_smart_rollup_node/publisher.ml index 95f9874120998b77590c13c5e3e7b28c87a3b5ab..36d016413427358f4905cf1ec7e8279880f759a7 100644 --- a/src/lib_smart_rollup_node/publisher.ml +++ b/src/lib_smart_rollup_node/publisher.ml @@ -131,7 +131,10 @@ let build_commitment (module Plugin : Protocol_plugin_sig.S) let genesis_pvm_state (module Plugin : Protocol_plugin_sig.S) (node_ctxt : _ Node_context.t) ctxt = let open Lwt_result_syntax in - match (node_ctxt.unsafe_patches :> Pvm_patches.unsafe_patch list) with + match + (node_ctxt.unsafe_patches + :> (Pvm_patches.unsafe_patch * Pvm_patches.kind) list) + with | [] -> ( let*! pvm_state = Context.PVMState.find ctxt in match pvm_state with diff --git a/src/lib_smart_rollup_node/pvm_patches.ml b/src/lib_smart_rollup_node/pvm_patches.ml index d6a334f6c68f1637a49215d065867fc183c96e70..1140785443c232727ab00a5fc3e7bde6ba75d5a0 100644 --- a/src/lib_smart_rollup_node/pvm_patches.ml +++ b/src/lib_smart_rollup_node/pvm_patches.ml @@ -7,12 +7,14 @@ type unsafe_patch = Increase_max_nb_ticks of int64 -type t = unsafe_patch list +type kind = Hardcoded | User_provided + +type t = (unsafe_patch * kind) list let patch_kinds = function Increase_max_nb_ticks _ -> [Kind.Wasm_2_0_0] (* Patches for Etherlink PVM. *) -let etherlink_patches = [Increase_max_nb_ticks 50_000_000_000_000L] +let etherlink_patches = [(Increase_max_nb_ticks 50_000_000_000_000L, Hardcoded)] (* Add hardcoded etherlink addresses on various networks. *) let etherlink_addresses = @@ -39,16 +41,19 @@ let pp_unsafe_patch fmt = function | Increase_max_nb_ticks nb -> Format.fprintf fmt "Increase maximum number of ticks to %#Ld" nb -let make kind rollup_address patches = +let make kind rollup_address user_provided_patches = let open Result_syntax in let hardcoded_patches = List.assoc ~equal:Address.equal rollup_address hardcoded_patches_list |> Option.value ~default:[] in - let patches = hardcoded_patches @ patches in + let patches = + hardcoded_patches + @ List.map (fun p -> (p, User_provided)) user_provided_patches + in let+ () = List.iter_e - (fun patch -> + (fun (patch, _kind) -> if not @@ List.mem ~equal:Kind.equal kind (patch_kinds patch) then error_with "Patch \"%a\" is not supported for rollup kind %a" diff --git a/src/lib_smart_rollup_node/pvm_patches.mli b/src/lib_smart_rollup_node/pvm_patches.mli index 149289620449cb1086abe73ead3e17bfa315c823..424a4a8d4b71d654cc9f76522367e94f7fe24e2c 100644 --- a/src/lib_smart_rollup_node/pvm_patches.mli +++ b/src/lib_smart_rollup_node/pvm_patches.mli @@ -10,8 +10,13 @@ type unsafe_patch = | Increase_max_nb_ticks of int64 (** Increase the maximum number of ticks. *) +(** Where the patch comes from *) +type kind = + | Hardcoded (** Hardcoded by the rollup node *) + | User_provided (** Provided by the user in the configuration file *) + (** The type of registered patches for the PVM. *) -type t = private unsafe_patch list +type t = private (unsafe_patch * kind) list (** Encoding for unsafe patches. *) val unsafe_patch_encoding : unsafe_patch Data_encoding.t @@ -19,6 +24,6 @@ val unsafe_patch_encoding : unsafe_patch Data_encoding.t (** Pretty printer for unsafe patches. *) val pp_unsafe_patch : Format.formatter -> unsafe_patch -> unit -(** [make kind address patches] builds the patches from the provided list +(** [make kind address patches] builds the patches from the user provided list [patches] and adds the hardcoded PVM patches for the rollup [address]. *) val make : Kind.t -> Address.t -> unsafe_patch list -> t tzresult