From 8eb0afaf5b3135821141ca9c5294c75a3bea869c Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Thu, 22 Sep 2022 18:12:06 +0200 Subject: [PATCH] WASM/PVM: expose [compute_step_many] for future usage in the L2 node --- src/lib_scoru_wasm/gather_floppies.ml | 2 ++ .../test/test_hash_consistency.ml | 6 ++--- src/lib_scoru_wasm/test/wasm_utils.ml | 4 +-- src/lib_scoru_wasm/wasm_pvm.ml | 4 +-- src/lib_scoru_wasm/wasm_pvm_sig.ml | 26 ++++++++++++------- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/lib_scoru_wasm/gather_floppies.ml b/src/lib_scoru_wasm/gather_floppies.ml index 56f94b729d7b..0459d8538d42 100644 --- a/src/lib_scoru_wasm/gather_floppies.ml +++ b/src/lib_scoru_wasm/gather_floppies.ml @@ -418,6 +418,8 @@ module Make inner_info.last_input_read; }) + let compute_step_many = Wasm.compute_step_many + module Internal_for_tests = struct include Wasm.Internal_for_tests diff --git a/src/lib_scoru_wasm/test/test_hash_consistency.ml b/src/lib_scoru_wasm/test/test_hash_consistency.ml index b1517c150c29..80c63d6b87e0 100644 --- a/src/lib_scoru_wasm/test/test_hash_consistency.ml +++ b/src/lib_scoru_wasm/test/test_hash_consistency.ml @@ -40,12 +40,10 @@ let test_execution_correspondance skip count () = let* tree = initial_tree ~from_binary:true ~max_tick:40_000L kernel in let* tree = if skip = 0L then Lwt.return tree - else Wasm.Internal_for_tests.compute_step_many ~max_steps:skip tree + else Wasm.compute_step_many ~max_steps:skip tree in let rec explore tree' n = - let* tree_ref = - Wasm.Internal_for_tests.compute_step_many ~max_steps:n tree - in + let* tree_ref = Wasm.compute_step_many ~max_steps:n tree in let* tree' = Wasm.compute_step tree' in assert ( Context_hash.(Context.Tree.hash tree_ref = Context.Tree.hash tree')) ; diff --git a/src/lib_scoru_wasm/test/wasm_utils.ml b/src/lib_scoru_wasm/test/wasm_utils.ml index ea25626ce55a..eda9c920cb2e 100644 --- a/src/lib_scoru_wasm/test/wasm_utils.ml +++ b/src/lib_scoru_wasm/test/wasm_utils.ml @@ -58,7 +58,7 @@ let initial_tree ?(max_tick = 100000L) ?(from_binary = false) code = let eval_until_stuck ?(max_steps = 20000L) tree = let open Lwt.Syntax in let rec go counter tree = - let* tree = Wasm.Internal_for_tests.compute_step_many ~max_steps tree in + let* tree = Wasm.compute_step_many ~max_steps tree in let* stuck = Wasm.Internal_for_tests.is_stuck tree in match stuck with | Some stuck -> Lwt_result.return (stuck, tree) @@ -73,7 +73,7 @@ let rec eval_until_input_requested ?(max_steps = Int64.max_int) tree = let* info = Wasm.get_info tree in match info.input_request with | No_input_required -> - let* tree = Wasm.Internal_for_tests.compute_step_many ~max_steps tree in + let* tree = Wasm.compute_step_many ~max_steps tree in eval_until_input_requested tree | Input_required -> return tree diff --git a/src/lib_scoru_wasm/wasm_pvm.ml b/src/lib_scoru_wasm/wasm_pvm.ml index c0e379e9380f..7623e0602991 100644 --- a/src/lib_scoru_wasm/wasm_pvm.ml +++ b/src/lib_scoru_wasm/wasm_pvm.ml @@ -409,7 +409,7 @@ struct in return pvm_state - let compute_step_many ?(max_steps = 1L) tree = + let compute_step_many ~max_steps tree = let open Lwt.Syntax in assert (max_steps > 0L) ; @@ -549,8 +549,6 @@ struct | Stuck error -> Lwt.return_some error | _ -> Lwt.return_none - let compute_step_many = compute_step_many - let set_max_nb_ticks n tree = let open Lwt_syntax in let* pvm_state = Tree_encoding_runner.decode pvm_state_encoding tree in diff --git a/src/lib_scoru_wasm/wasm_pvm_sig.ml b/src/lib_scoru_wasm/wasm_pvm_sig.ml index bfb17853e2d1..2a054ed041bc 100644 --- a/src/lib_scoru_wasm/wasm_pvm_sig.ml +++ b/src/lib_scoru_wasm/wasm_pvm_sig.ml @@ -61,8 +61,6 @@ module type Internal_for_tests = sig val is_stuck : tree -> Wasm_pvm_errors.t option Lwt.t - val compute_step_many : ?max_steps:int64 -> tree -> tree Lwt.t - val set_max_nb_ticks : Z.t -> tree -> tree Lwt.t end @@ -72,16 +70,24 @@ module type S = sig type tick_state - (** [compute_step] forwards the VM by one compute tick. If the VM is expecting - input, it gets stuck. If the VM is already stuck, this function may - raise an exception. *) + (** [compute_step_many ~max_steps tree] forwards the VM by at most [max_step] + compute tick, yielding if it reaches the maximum number of ticks for a + toplevel kernel call. If the VM is expecting input, it gets stuck. If the + VM is already stuck, this function may raise an exception. It is more + efficient than [compute_step] if it has to be called for more than one + tick, but its resulting tree will be stricly equivalent. *) + val compute_step_many : max_steps:int64 -> tree -> tree Lwt.t + + (** [compute_step tree] forwards the VM by one compute tick. If the VM is expecting + input, it gets stuck. If the VM is already stuck, this function may raise + an exception. It is strictly equivalent to [compute_step_many ~max_step=1 + tree]. *) val compute_step : tree -> tree Lwt.t - (** [set_input_step] forwards the VM by one input tick. If the VM is not - expecting input, it gets stuck. If the VM is already stuck, this function - may raise an exception. Note at this point the function raises an - exception if the VM is not expecting input. WHen we implement astuck - state this needs to be slightly changed.*) + (** [set_input_step input_info message tree] forwards the VM by one input + tick. If the VM is not expecting input, it gets stuck. If the VM is + already stuck, this function may raise an exception. Note at this point + the function raises an exception if the VM is not expecting input. *) val set_input_step : input_info -> string -> tree -> tree Lwt.t (** [get_output output state] returns the payload associated with the given -- GitLab