From ccd72af1cea92237ee6e5c6bfa1a09f64ea8e962 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Thu, 22 Jun 2023 16:25:22 +0200 Subject: [PATCH 1/2] SCORU/Node: remove protocol dependency from Simulation There is still a protocol dependency because the plugin is declared statically at this point. --- .../lib_sc_rollup_node/simulation.ml | 29 +++++++------------ .../lib_sc_rollup_node/simulation.mli | 5 +--- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/proto_alpha/lib_sc_rollup_node/simulation.ml b/src/proto_alpha/lib_sc_rollup_node/simulation.ml index dd39c830ed3d..01d7892a2e04 100644 --- a/src/proto_alpha/lib_sc_rollup_node/simulation.ml +++ b/src/proto_alpha/lib_sc_rollup_node/simulation.ml @@ -23,14 +23,13 @@ (* *) (*****************************************************************************) -open Protocol -open Alpha_context -module Fueled_pvm = Fueled_pvm.Free +module Pvm = Pvm_plugin +module Fueled_pvm = Pvm.Fueled.Free type level_position = Start | Middle | End type info_per_level = { - predecessor_timestamp : Timestamp.time; + predecessor_timestamp : Time.Protocol.t; predecessor : Block_hash.t; } @@ -91,15 +90,14 @@ let simulate_messages_no_checks (node_ctxt : Node_context.ro) info_per_level = _; } as sim) messages = let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! state_hash = PVM.state_hash state in - let*! tick = PVM.get_tick state in + let*! state_hash = Pvm.state_hash node_ctxt.kind state in + let*! tick = Pvm.get_tick node_ctxt.kind state in let eval_state = Pvm_plugin_sig. { state; - state_hash = Sc_rollup_proto_types.State_hash.to_octez state_hash; - tick = Sc_rollup.Tick.to_z tick; + state_hash; + tick; inbox_level; message_counter_offset = nb_messages_inbox; remaining_fuel = Fuel.Free.of_ticks 0L; @@ -113,7 +111,7 @@ let simulate_messages_no_checks (node_ctxt : Node_context.ro) let Pvm_plugin_sig.{state = {state; _}; num_ticks; num_messages; _} = Delayed_write_monad.ignore eval_result in - let*! ctxt = PVM.State.set ctxt state in + let*! ctxt = Context.PVMState.set ctxt state in let nb_messages_inbox = nb_messages_inbox + num_messages in return ({sim with ctxt; state; nb_messages_inbox}, num_ticks) @@ -128,10 +126,8 @@ let simulate_messages (node_ctxt : Node_context.ro) sim messages = let messages = if sim.level_position = Start then let {predecessor_timestamp; predecessor} = sim.info_per_level in - let open Sc_rollup_inbox_message_repr in - unsafe_to_string start_of_level_serialized - :: unsafe_to_string - (info_per_level_serialized ~predecessor ~predecessor_timestamp) + Pvm.start_of_level_serialized + :: Pvm.info_per_level_serialized ~predecessor ~predecessor_timestamp :: messages else messages in @@ -146,9 +142,6 @@ let end_simulation node_ctxt sim = (Exn (Failure "Level for simulation is ended")) in let+ sim, num_ticks = - simulate_messages_no_checks - node_ctxt - sim - [Sc_rollup_inbox_message_repr.(unsafe_to_string end_of_level_serialized)] + simulate_messages_no_checks node_ctxt sim [Pvm.end_of_level_serialized] in ({sim with level_position = End}, num_ticks) diff --git a/src/proto_alpha/lib_sc_rollup_node/simulation.mli b/src/proto_alpha/lib_sc_rollup_node/simulation.mli index 745ead3df562..c611851ba5ad 100644 --- a/src/proto_alpha/lib_sc_rollup_node/simulation.mli +++ b/src/proto_alpha/lib_sc_rollup_node/simulation.mli @@ -23,13 +23,10 @@ (* *) (*****************************************************************************) -open Protocol.Alpha_context -module Fueled_pvm = Fueled_pvm.Free - type level_position = Start | Middle | End type info_per_level = { - predecessor_timestamp : Timestamp.time; + predecessor_timestamp : Time.Protocol.t; predecessor : Block_hash.t; } -- GitLab From 9b985a961b29ebd06a2e510dd5d3c8f314e542cd Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Thu, 22 Jun 2023 17:13:20 +0200 Subject: [PATCH 2/2] SCORU/Node: move simulation outside of protocol directory --- .../simulation.ml | 23 ++- .../simulation.mli | 1 + .../lib_sc_rollup_node/simulation.ml | 159 ------------------ .../lib_sc_rollup_node/simulation.mli | 64 ------- .../lib_sc_rollup_node/simulation.ml | 154 ----------------- .../lib_sc_rollup_node/simulation.mli | 64 ------- 6 files changed, 15 insertions(+), 450 deletions(-) rename src/{proto_alpha/lib_sc_rollup_node => lib_smart_rollup_node}/simulation.ml (90%) rename src/{proto_alpha/lib_sc_rollup_node => lib_smart_rollup_node}/simulation.mli (98%) delete mode 100644 src/proto_016_PtMumbai/lib_sc_rollup_node/simulation.ml delete mode 100644 src/proto_016_PtMumbai/lib_sc_rollup_node/simulation.mli delete mode 100644 src/proto_017_PtNairob/lib_sc_rollup_node/simulation.ml delete mode 100644 src/proto_017_PtNairob/lib_sc_rollup_node/simulation.mli diff --git a/src/proto_alpha/lib_sc_rollup_node/simulation.ml b/src/lib_smart_rollup_node/simulation.ml similarity index 90% rename from src/proto_alpha/lib_sc_rollup_node/simulation.ml rename to src/lib_smart_rollup_node/simulation.ml index 01d7892a2e04..b611936cbd58 100644 --- a/src/proto_alpha/lib_sc_rollup_node/simulation.ml +++ b/src/lib_smart_rollup_node/simulation.ml @@ -23,9 +23,6 @@ (* *) (*****************************************************************************) -module Pvm = Pvm_plugin -module Fueled_pvm = Pvm.Fueled.Free - type level_position = Start | Middle | End type info_per_level = { @@ -41,18 +38,22 @@ type t = { nb_messages_inbox : int; level_position : level_position; info_per_level : info_per_level; + plugin : (module Protocol_plugin_sig.S); } let simulate_info_per_level (node_ctxt : [`Read] Node_context.t) predecessor = let open Lwt_result_syntax in - let* block_info = - Layer1_helpers.fetch_tezos_block node_ctxt.l1_ctxt predecessor + let* pred_header = + Layer1.fetch_tezos_shell_header node_ctxt.l1_ctxt predecessor in - let predecessor_timestamp = block_info.header.shell.timestamp in + let predecessor_timestamp = pred_header.timestamp in return {predecessor_timestamp; predecessor} let start_simulation node_ctxt ~reveal_map (Layer1.{hash; level} as head) = let open Lwt_result_syntax in + let inbox_level = Int32.succ level in + let* plugin = Protocol_plugins.proto_plugin_for_level node_ctxt inbox_level in + let module Plugin = (val plugin) in let*? () = error_unless (level >= node_ctxt.Node_context.genesis_info.level) @@ -66,9 +67,8 @@ let start_simulation node_ctxt ~reveal_map (Layer1.{hash; level} as head) = return (Context.empty node_ctxt.context) else Node_context.checkout_context node_ctxt hash in - let* ctxt, state = Interpreter.state_of_head node_ctxt ctxt head in + let* ctxt, state = Plugin.Interpreter.state_of_head node_ctxt ctxt head in let+ info_per_level = simulate_info_per_level node_ctxt hash in - let inbox_level = Int32.succ level in { ctxt; inbox_level; @@ -77,6 +77,7 @@ let start_simulation node_ctxt ~reveal_map (Layer1.{hash; level} as head) = nb_messages_inbox = 0; level_position = Start; info_per_level; + plugin; } let simulate_messages_no_checks (node_ctxt : Node_context.ro) @@ -86,10 +87,12 @@ let simulate_messages_no_checks (node_ctxt : Node_context.ro) inbox_level; reveal_map; nb_messages_inbox; + plugin; level_position = _; info_per_level = _; } as sim) messages = let open Lwt_result_syntax in + let open (val plugin) in let*! state_hash = Pvm.state_hash node_ctxt.kind state in let*! tick = Pvm.get_tick node_ctxt.kind state in let eval_state = @@ -106,7 +109,7 @@ let simulate_messages_no_checks (node_ctxt : Node_context.ro) in (* Build new state *) let* eval_result = - Fueled_pvm.eval_messages ?reveal_map node_ctxt eval_state + Pvm.Fueled.Free.eval_messages ?reveal_map node_ctxt eval_state in let Pvm_plugin_sig.{state = {state; _}; num_ticks; num_messages; _} = Delayed_write_monad.ignore eval_result @@ -117,6 +120,7 @@ let simulate_messages_no_checks (node_ctxt : Node_context.ro) let simulate_messages (node_ctxt : Node_context.ro) sim messages = let open Lwt_result_syntax in + let open (val sim.plugin) in (* Build new inbox *) let*? () = error_when @@ -136,6 +140,7 @@ let simulate_messages (node_ctxt : Node_context.ro) sim messages = let end_simulation node_ctxt sim = let open Lwt_result_syntax in + let open (val sim.plugin) in let*? () = error_when (sim.level_position = End) diff --git a/src/proto_alpha/lib_sc_rollup_node/simulation.mli b/src/lib_smart_rollup_node/simulation.mli similarity index 98% rename from src/proto_alpha/lib_sc_rollup_node/simulation.mli rename to src/lib_smart_rollup_node/simulation.mli index c611851ba5ad..5d5e2aba44b7 100644 --- a/src/proto_alpha/lib_sc_rollup_node/simulation.mli +++ b/src/lib_smart_rollup_node/simulation.mli @@ -39,6 +39,7 @@ type t = { nb_messages_inbox : int; level_position : level_position; info_per_level : info_per_level; + plugin : (module Protocol_plugin_sig.S); } (** [start_simulation node_ctxt reveal_source block] starts a new simulation {e diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/simulation.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/simulation.ml deleted file mode 100644 index 1b578613831f..000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/simulation.ml +++ /dev/null @@ -1,159 +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 -module Fueled_pvm = Fueled_pvm.Free - -type level_position = Start | Middle | End - -type info_per_level = { - predecessor_timestamp : Timestamp.time; - predecessor : Block_hash.t; -} - -type t = { - ctxt : Context.ro; - inbox_level : int32; - state : Context.tree; - reveal_map : string Utils.Reveal_hash_map.t option; - nb_messages_inbox : int; - level_position : level_position; - info_per_level : info_per_level; -} - -let simulate_info_per_level (node_ctxt : [`Read] Node_context.t) predecessor = - let open Lwt_result_syntax in - let* block_info = - Layer1_helpers.fetch_tezos_block node_ctxt.l1_ctxt predecessor - in - let predecessor_timestamp = block_info.header.shell.timestamp in - return {predecessor_timestamp; predecessor} - -let start_simulation node_ctxt ~reveal_map (Layer1.{hash; level} as head) = - let open Lwt_result_syntax in - let*? () = - error_unless - (level >= node_ctxt.Node_context.genesis_info.level) - (Exn (Failure "Cannot simulate before origination level")) - in - let first_inbox_level = Int32.succ node_ctxt.genesis_info.level in - let* ctxt = - if level < first_inbox_level then - (* This is before we have interpreted the boot sector, so we start - with an empty context in genesis *) - return (Context.empty node_ctxt.context) - else Node_context.checkout_context node_ctxt hash - in - let* ctxt, state = Interpreter.state_of_head node_ctxt ctxt head in - let+ info_per_level = simulate_info_per_level node_ctxt hash in - let inbox_level = Int32.succ level in - { - ctxt; - inbox_level; - state; - reveal_map; - nb_messages_inbox = 0; - level_position = Start; - info_per_level; - } - -let simulate_messages_no_checks (node_ctxt : Node_context.ro) - ({ - ctxt; - state; - inbox_level; - reveal_map; - nb_messages_inbox; - level_position = _; - info_per_level = _; - } as sim) messages = - let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! state_hash = PVM.state_hash state in - let*! tick = PVM.get_tick state in - let eval_state = - Pvm_plugin_sig. - { - state; - state_hash = Sc_rollup_proto_types.State_hash.to_octez state_hash; - tick = Sc_rollup.Tick.to_z tick; - inbox_level; - message_counter_offset = nb_messages_inbox; - remaining_fuel = Fuel.Free.of_ticks 0L; - remaining_messages = messages; - } - in - (* Build new state *) - let* eval_result = - Fueled_pvm.eval_messages ?reveal_map node_ctxt eval_state - in - let Pvm_plugin_sig.{state = {state; _}; num_ticks; num_messages; _} = - Delayed_write_monad.ignore eval_result - in - let*! ctxt = PVM.State.set ctxt state in - let nb_messages_inbox = nb_messages_inbox + num_messages in - return ({sim with ctxt; state; nb_messages_inbox}, num_ticks) - -let simulate_messages (node_ctxt : Node_context.ro) sim messages = - let open Lwt_result_syntax in - (* Build new inbox *) - let*? () = - error_when - (sim.level_position = End) - (Exn (Failure "Level for simulation is ended")) - in - let*? messages = - let open Result_syntax in - if sim.level_position = Start then - let {predecessor_timestamp; predecessor} = sim.info_per_level in - let open Sc_rollup_inbox_message_repr in - let+ info_per_level = - Environment.wrap_tzresult - @@ serialize - (Internal (Info_per_level {predecessor; predecessor_timestamp})) - in - unsafe_to_string start_of_level_serialized - :: unsafe_to_string info_per_level - :: messages - else return messages - in - let+ sim, num_ticks = simulate_messages_no_checks node_ctxt sim messages in - ({sim with level_position = Middle}, num_ticks) - -let end_simulation node_ctxt sim = - let open Lwt_result_syntax in - let*? () = - error_when - (sim.level_position = End) - (Exn (Failure "Level for simulation is ended")) - in - let+ sim, num_ticks = - simulate_messages_no_checks - node_ctxt - sim - [Sc_rollup_inbox_message_repr.(unsafe_to_string end_of_level_serialized)] - in - ({sim with level_position = End}, num_ticks) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/simulation.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/simulation.mli deleted file mode 100644 index 745ead3df562..000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/simulation.mli +++ /dev/null @@ -1,64 +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.Alpha_context -module Fueled_pvm = Fueled_pvm.Free - -type level_position = Start | Middle | End - -type info_per_level = { - predecessor_timestamp : Timestamp.time; - predecessor : Block_hash.t; -} - -(** Type of the state for a simulation. *) -type t = { - ctxt : Context.ro; - inbox_level : int32; - state : Context.tree; - reveal_map : string Utils.Reveal_hash_map.t option; - nb_messages_inbox : int; - level_position : level_position; - info_per_level : info_per_level; -} - -(** [start_simulation node_ctxt reveal_source block] starts a new simulation {e - on top} of [block], i.e. for an hypothetical new inbox (level). *) -val start_simulation : - Node_context.ro -> - reveal_map:string Utils.Reveal_hash_map.t option -> - Layer1.head -> - t tzresult Lwt.t - -(** [simulate_messages node_ctxt sim messages] runs a simulation of new - [messages] in the given simulation (state) [sim] and returns a new - simulation state, the remaining fuel (when [?fuel] is provided) and the - number of ticks that happened. *) -val simulate_messages : - Node_context.ro -> t -> string list -> (t * Z.t) tzresult Lwt.t - -(** [end_simulation node_ctxt sim] adds and [End_of_level] message and marks the - simulation as ended. *) -val end_simulation : Node_context.ro -> t -> (t * Z.t) tzresult Lwt.t diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/simulation.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/simulation.ml deleted file mode 100644 index dd39c830ed3d..000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/simulation.ml +++ /dev/null @@ -1,154 +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 -module Fueled_pvm = Fueled_pvm.Free - -type level_position = Start | Middle | End - -type info_per_level = { - predecessor_timestamp : Timestamp.time; - predecessor : Block_hash.t; -} - -type t = { - ctxt : Context.ro; - inbox_level : int32; - state : Context.tree; - reveal_map : string Utils.Reveal_hash_map.t option; - nb_messages_inbox : int; - level_position : level_position; - info_per_level : info_per_level; -} - -let simulate_info_per_level (node_ctxt : [`Read] Node_context.t) predecessor = - let open Lwt_result_syntax in - let* block_info = - Layer1_helpers.fetch_tezos_block node_ctxt.l1_ctxt predecessor - in - let predecessor_timestamp = block_info.header.shell.timestamp in - return {predecessor_timestamp; predecessor} - -let start_simulation node_ctxt ~reveal_map (Layer1.{hash; level} as head) = - let open Lwt_result_syntax in - let*? () = - error_unless - (level >= node_ctxt.Node_context.genesis_info.level) - (Exn (Failure "Cannot simulate before origination level")) - in - let first_inbox_level = Int32.succ node_ctxt.genesis_info.level in - let* ctxt = - if level < first_inbox_level then - (* This is before we have interpreted the boot sector, so we start - with an empty context in genesis *) - return (Context.empty node_ctxt.context) - else Node_context.checkout_context node_ctxt hash - in - let* ctxt, state = Interpreter.state_of_head node_ctxt ctxt head in - let+ info_per_level = simulate_info_per_level node_ctxt hash in - let inbox_level = Int32.succ level in - { - ctxt; - inbox_level; - state; - reveal_map; - nb_messages_inbox = 0; - level_position = Start; - info_per_level; - } - -let simulate_messages_no_checks (node_ctxt : Node_context.ro) - ({ - ctxt; - state; - inbox_level; - reveal_map; - nb_messages_inbox; - level_position = _; - info_per_level = _; - } as sim) messages = - let open Lwt_result_syntax in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! state_hash = PVM.state_hash state in - let*! tick = PVM.get_tick state in - let eval_state = - Pvm_plugin_sig. - { - state; - state_hash = Sc_rollup_proto_types.State_hash.to_octez state_hash; - tick = Sc_rollup.Tick.to_z tick; - inbox_level; - message_counter_offset = nb_messages_inbox; - remaining_fuel = Fuel.Free.of_ticks 0L; - remaining_messages = messages; - } - in - (* Build new state *) - let* eval_result = - Fueled_pvm.eval_messages ?reveal_map node_ctxt eval_state - in - let Pvm_plugin_sig.{state = {state; _}; num_ticks; num_messages; _} = - Delayed_write_monad.ignore eval_result - in - let*! ctxt = PVM.State.set ctxt state in - let nb_messages_inbox = nb_messages_inbox + num_messages in - return ({sim with ctxt; state; nb_messages_inbox}, num_ticks) - -let simulate_messages (node_ctxt : Node_context.ro) sim messages = - let open Lwt_result_syntax in - (* Build new inbox *) - let*? () = - error_when - (sim.level_position = End) - (Exn (Failure "Level for simulation is ended")) - in - let messages = - if sim.level_position = Start then - let {predecessor_timestamp; predecessor} = sim.info_per_level in - let open Sc_rollup_inbox_message_repr in - unsafe_to_string start_of_level_serialized - :: unsafe_to_string - (info_per_level_serialized ~predecessor ~predecessor_timestamp) - :: messages - else messages - in - let+ sim, num_ticks = simulate_messages_no_checks node_ctxt sim messages in - ({sim with level_position = Middle}, num_ticks) - -let end_simulation node_ctxt sim = - let open Lwt_result_syntax in - let*? () = - error_when - (sim.level_position = End) - (Exn (Failure "Level for simulation is ended")) - in - let+ sim, num_ticks = - simulate_messages_no_checks - node_ctxt - sim - [Sc_rollup_inbox_message_repr.(unsafe_to_string end_of_level_serialized)] - in - ({sim with level_position = End}, num_ticks) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/simulation.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/simulation.mli deleted file mode 100644 index 745ead3df562..000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/simulation.mli +++ /dev/null @@ -1,64 +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.Alpha_context -module Fueled_pvm = Fueled_pvm.Free - -type level_position = Start | Middle | End - -type info_per_level = { - predecessor_timestamp : Timestamp.time; - predecessor : Block_hash.t; -} - -(** Type of the state for a simulation. *) -type t = { - ctxt : Context.ro; - inbox_level : int32; - state : Context.tree; - reveal_map : string Utils.Reveal_hash_map.t option; - nb_messages_inbox : int; - level_position : level_position; - info_per_level : info_per_level; -} - -(** [start_simulation node_ctxt reveal_source block] starts a new simulation {e - on top} of [block], i.e. for an hypothetical new inbox (level). *) -val start_simulation : - Node_context.ro -> - reveal_map:string Utils.Reveal_hash_map.t option -> - Layer1.head -> - t tzresult Lwt.t - -(** [simulate_messages node_ctxt sim messages] runs a simulation of new - [messages] in the given simulation (state) [sim] and returns a new - simulation state, the remaining fuel (when [?fuel] is provided) and the - number of ticks that happened. *) -val simulate_messages : - Node_context.ro -> t -> string list -> (t * Z.t) tzresult Lwt.t - -(** [end_simulation node_ctxt sim] adds and [End_of_level] message and marks the - simulation as ended. *) -val end_simulation : Node_context.ro -> t -> (t * Z.t) tzresult Lwt.t -- GitLab