diff --git a/src/lib_scoru_sequencer/seq_batcher.ml b/src/lib_scoru_sequencer/seq_batcher.ml index 07f3d24a00f2382a897453f569d40c5d789263a7..54a98a3cc7f491222b58d8885fa99e79cc4d7e26 100644 --- a/src/lib_scoru_sequencer/seq_batcher.ml +++ b/src/lib_scoru_sequencer/seq_batcher.ml @@ -83,7 +83,16 @@ let get_previous_delayed_inbox_size node_ctxt (head : Layer1.head) = return (Context.empty node_ctxt.context) else Node_context.checkout_context node_ctxt previous_head.hash in - let* _ctxt, state = Interpreter.state_of_head node_ctxt ctxt previous_head in + let* _ctxt, state = + Interpreter.state_of_head + (module Rollup_node_plugin.Plugin) + (* TODO: https://gitlab.com/tezos/tezos/-/issues/5989 + We use the alpha rollup node plugin here but this should depend on the + current protocol. *) + node_ctxt + ctxt + previous_head + in let open Kernel_durable in let*! pointer_bytes = Durable_state.lookup state Delayed_inbox_pointer.path in match pointer_bytes with diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml b/src/lib_smart_rollup_node/interpreter.ml similarity index 66% rename from src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml rename to src/lib_smart_rollup_node/interpreter.ml index b9c436a37ca4e11d998b6869460167b92e4bf296..9ae9aae34228ec2ff7e9414fe1f04446451c683a 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.ml +++ b/src/lib_smart_rollup_node/interpreter.ml @@ -23,56 +23,56 @@ (* *) (*****************************************************************************) -open Protocol -open Alpha_context - -let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = +let get_boot_sector (module Plugin : Protocol_plugin_sig.PARTIAL) block_hash + (node_ctxt : _ Node_context.t) = let open Lwt_result_syntax in match node_ctxt.boot_sector_file with - | None -> Layer1_helpers.get_boot_sector block_hash node_ctxt + | None -> Plugin.Layer1_helpers.get_boot_sector block_hash node_ctxt | Some boot_sector_file -> - let module PVM = (val Pvm.of_kind node_ctxt.kind) in let*! boot_sector = Lwt_utils_unix.read_file boot_sector_file in let*? boot_sector = Option.value_e ~error: [ - Sc_rollup_node_errors.Unparsable_boot_sector - {path = boot_sector_file}; + Rollup_node_errors.Unparsable_boot_sector {path = boot_sector_file}; ] - (PVM.parse_boot_sector boot_sector) + (Plugin.Pvm.parse_boot_sector node_ctxt.kind boot_sector) in return boot_sector -let genesis_state block_hash node_ctxt ctxt = +let genesis_state (module Plugin : Protocol_plugin_sig.PARTIAL) block_hash + node_ctxt ctxt = let open Lwt_result_syntax in - let* boot_sector = get_boot_sector block_hash node_ctxt in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! initial_state = PVM.initial_state ~empty:(PVM.State.empty ()) in - let*! genesis_state = PVM.install_boot_sector initial_state boot_sector in - let*! ctxt = PVM.State.set ctxt genesis_state in + let* boot_sector = get_boot_sector (module Plugin) block_hash node_ctxt in + let*! initial_state = Plugin.Pvm.initial_state node_ctxt.kind in + let*! genesis_state = + Plugin.Pvm.install_boot_sector node_ctxt.kind initial_state boot_sector + in + let*! ctxt = Context.PVMState.set ctxt genesis_state in return (ctxt, genesis_state) -let state_of_head node_ctxt ctxt Layer1.{hash; level} = +let state_of_head plugin node_ctxt ctxt Layer1.{hash; level} = let open Lwt_result_syntax in let*! state = Context.PVMState.find ctxt in match state with | None -> let genesis_level = node_ctxt.Node_context.genesis_info.level in - if level = genesis_level then genesis_state hash node_ctxt ctxt - else tzfail (Sc_rollup_node_errors.Missing_PVM_state (hash, level)) + if level = genesis_level then genesis_state plugin hash node_ctxt ctxt + else tzfail (Rollup_node_errors.Missing_PVM_state (hash, level)) | Some state -> return (ctxt, state) -(** [transition_pvm node_ctxt predecessor head] runs a PVM at the - previous state from block [predecessor] by consuming as many messages - as possible from block [head]. *) -let transition_pvm node_ctxt ctxt predecessor Layer1.{hash = _; _} - inbox_messages = +(** [transition_pvm plugin node_ctxt ctxt predecessor head] runs a PVM at the + previous state from block [predecessor] by consuming as many messages as + possible from block [head]. *) +let transition_pvm (module Plugin : Protocol_plugin_sig.PARTIAL) node_ctxt ctxt + predecessor Layer1.{hash = _; _} inbox_messages = let open Lwt_result_syntax in (* Retrieve the previous PVM state from store. *) - let* ctxt, predecessor_state = state_of_head node_ctxt ctxt predecessor in + let* ctxt, predecessor_state = + state_of_head (module Plugin) node_ctxt ctxt predecessor + in let* eval_result = - Fueled_pvm.Free.eval_block_inbox + Plugin.Pvm.Fueled.Free.eval_block_inbox ~fuel:(Fuel.Free.of_ticks 0L) node_ctxt inbox_messages @@ -85,31 +85,30 @@ let transition_pvm node_ctxt ctxt predecessor Layer1.{hash = _; _} } = Delayed_write_monad.apply node_ctxt eval_result in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! ctxt = PVM.State.set ctxt state in - let*! initial_tick = PVM.get_tick predecessor_state in + let*! ctxt = Context.PVMState.set ctxt state in + let*! initial_tick = Plugin.Pvm.get_tick node_ctxt.kind predecessor_state in (* Produce events. *) let*! () = Interpreter_event.transitioned_pvm inbox_level state_hash tick num_messages in - return - (ctxt, num_messages, Z.to_int64 num_ticks, Sc_rollup.Tick.to_z initial_tick) + return (ctxt, num_messages, Z.to_int64 num_ticks, initial_tick) -(** [process_head node_ctxt ctxt ~predecessor head] runs the PVM for the given - head. *) -let process_head (node_ctxt : _ Node_context.t) ctxt +(** [process_head plugin node_ctxt ctxt ~predecessor head inbox_and_messages] runs the PVM for the given + head. *) +let process_head plugin (node_ctxt : _ Node_context.t) ctxt ~(predecessor : Layer1.header) (head : Layer1.header) inbox_and_messages = let open Lwt_result_syntax in let first_inbox_level = node_ctxt.genesis_info.level |> Int32.succ in if head.Layer1.level >= first_inbox_level then transition_pvm + plugin node_ctxt ctxt (Layer1.head_of_header predecessor) (Layer1.head_of_header head) inbox_and_messages else if head.Layer1.level = node_ctxt.genesis_info.level then - let* ctxt, state = genesis_state head.hash node_ctxt ctxt in + let* ctxt, state = genesis_state plugin head.hash node_ctxt ctxt in let*! ctxt = Context.PVMState.set ctxt state in return (ctxt, 0, 0L, Z.zero) else return (ctxt, 0, 0L, Z.zero) @@ -117,7 +116,7 @@ let process_head (node_ctxt : _ Node_context.t) ctxt (** Returns the starting evaluation before the evaluation of the block. It contains the PVM state at the end of the execution of the previous block and the messages the block ([remaining_messages]). *) -let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = +let start_state_of_block plugin node_ctxt (block : Sc_rollup_block.t) = let open Lwt_result_syntax in let pred_level = Int32.pred block.header.level in let* ctxt = @@ -125,6 +124,7 @@ let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = in let* _ctxt, state = state_of_head + plugin node_ctxt ctxt Layer1.{hash = block.header.predecessor; level = pred_level} @@ -134,48 +134,48 @@ let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = Node_context.get_messages node_ctxt block.header.inbox_witness in let inbox_level = Octez_smart_rollup.Inbox.inbox_level inbox in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! tick = PVM.get_tick state in - let*! state_hash = PVM.state_hash state in + let module Plugin = (val plugin) in + let*! tick = Plugin.Pvm.get_tick node_ctxt.kind state in + let*! state_hash = Plugin.Pvm.state_hash node_ctxt.kind state in let messages = - let open Sc_rollup_inbox_message_repr in - unsafe_to_string start_of_level_serialized + Plugin.Pvm.start_of_level_serialized :: (if is_first_block then - [unsafe_to_string Raw_context.protocol_migration_serialized_message] + Option.to_list Plugin.Pvm.protocol_migration_serialized else []) - @ unsafe_to_string - (info_per_level_serialized ~predecessor ~predecessor_timestamp) + @ Plugin.Pvm.info_per_level_serialized ~predecessor ~predecessor_timestamp :: messages - @ [unsafe_to_string end_of_level_serialized] + @ [Plugin.Pvm.end_of_level_serialized] in return Pvm_plugin_sig. { state; - state_hash = Sc_rollup_proto_types.State_hash.to_octez state_hash; + state_hash; inbox_level; - tick = Sc_rollup.Tick.to_z tick; + tick; message_counter_offset = 0; remaining_fuel = Fuel.Accounted.of_ticks 0L; remaining_messages = messages; } -(** [run_for_ticks node_ctxt start_state tick_distance] starts the evaluation of - messages in the [start_state] for at most [tick_distance]. *) -let run_to_tick node_ctxt start_state tick = +(** [run_for_ticks plugin node_ctxt start_state tick_distance] starts the + evaluation of messages in the [start_state] for at most [tick_distance]. *) +let run_to_tick (module Plugin : Protocol_plugin_sig.PARTIAL) node_ctxt + start_state tick = let open Delayed_write_monad.Lwt_result_syntax in let tick_distance = Z.sub tick start_state.Pvm_plugin_sig.tick |> Z.to_int64 in let>+ eval_result = - Fueled_pvm.Accounted.eval_messages + Plugin.Pvm.Fueled.Accounted.eval_messages node_ctxt {start_state with remaining_fuel = Fuel.Accounted.of_ticks tick_distance} in eval_result.state -let state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) tick = +let state_of_tick_aux plugin node_ctxt ~start_state (event : Sc_rollup_block.t) + tick = let open Lwt_result_syntax in let* start_state = match start_state with @@ -185,12 +185,12 @@ let state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) tick = | _ -> (* Recompute start state on level change or if we don't have a starting state on hand. *) - start_state_of_block node_ctxt event + start_state_of_block plugin node_ctxt event in (* TODO: #3384 We should test that we always have enough blocks to find the tick because [state_of_tick] is a critical function. *) - let* result_state = run_to_tick node_ctxt start_state tick in + let* result_state = run_to_tick plugin node_ctxt start_state tick in let result_state = Delayed_write_monad.ignore result_state in return result_state @@ -210,20 +210,20 @@ module Tick_state_cache = let tick_state_cache = Tick_state_cache.create 64 (* size of 2 dissections *) (* Memoized version of [state_of_tick_aux]. *) -let memo_state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) - tick = +let memo_state_of_tick_aux plugin node_ctxt ~start_state + (event : Sc_rollup_block.t) tick = Tick_state_cache.bind_or_put tick_state_cache (tick, event.header.block_hash) - (fun (tick, _hash) -> state_of_tick_aux node_ctxt ~start_state event tick) + (fun (tick, _hash) -> + state_of_tick_aux plugin node_ctxt ~start_state event tick) Lwt.return -(** [state_of_tick node_ctxt ?start_state tick level] returns [Some end_state] - for a given [tick] if this [tick] happened before [level]. Otherwise, - returns [None].*) -let state_of_tick node_ctxt ?start_state ~tick level = +(** [state_of_tick plugin node_ctxt ?start_state ~tick level] returns [Some + end_state] for [tick] if [tick] happened before + [level]. Otherwise, returns [None].*) +let state_of_tick plugin node_ctxt ?start_state ~tick level = let open Lwt_result_syntax in - let level = Raw_level.to_int32 level in let* event = Node_context.block_with_tick node_ctxt ~max_level:level tick in match event with | None -> return_none @@ -234,7 +234,7 @@ let state_of_tick node_ctxt ?start_state ~tick level = (* TODO: https://gitlab.com/tezos/tezos/-/issues/5253 The failures/loser mode does not work properly when restarting from intermediate states. *) - state_of_tick_aux node_ctxt ~start_state:None event tick - else memo_state_of_tick_aux node_ctxt ~start_state event tick + state_of_tick_aux plugin node_ctxt ~start_state:None event tick + else memo_state_of_tick_aux plugin node_ctxt ~start_state event tick in return_some result_state diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.mli b/src/lib_smart_rollup_node/interpreter.mli similarity index 67% rename from src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.mli rename to src/lib_smart_rollup_node/interpreter.mli index acf81542788bac8866fabe73d00f89ba47fd9585..c6355fc34c80762edbdc7e6332a6b53594bf25bb 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter.mli +++ b/src/lib_smart_rollup_node/interpreter.mli @@ -23,17 +23,16 @@ (* *) (*****************************************************************************) -open Protocol.Alpha_context - -(** [process_head node_ctxt ~predecessor head (inbox, messages)] interprets the - [messages] associated with a [head] (where [predecessor] is the predecessor - of [head] in the L1 chain). This requires the [inbox] to be updated - beforehand. It returns [(ctxt, num_messages, num_ticks, tick)] where [ctxt] - is the updated layer 2 context (with the new PVM state), [num_messages] is - the number of [messages], [num_ticks] is the number of ticks taken by the - PVM for the evaluation and [tick] is the tick reached by the PVM after the - evaluation. *) +(** [process_head plugin node_ctxt ctxt ~predecessor head (inbox, messages)] + interprets the [messages] associated with a [head] (where [predecessor] is + the predecessor of [head] in the L1 chain). This requires the [inbox] to be + updated beforehand. It returns [(ctxt, num_messages, num_ticks, tick)] where + [ctxt] is the updated layer 2 context (with the new PVM state), + [num_messages] is the number of [messages], [num_ticks] is the number of + ticks taken by the PVM for the evaluation and [tick] is the tick reached by + the PVM after the evaluation. *) val process_head : + (module Protocol_plugin_sig.PARTIAL) -> Node_context.rw -> 'a Context.t -> predecessor:Layer1.header -> @@ -41,21 +40,23 @@ val process_head : Octez_smart_rollup.Inbox.t * string list -> ('a Context.t * int * int64 * Z.t) tzresult Lwt.t -(** [state_of_tick node_ctxt ?start_state ~tick level] returns [Some (state, - hash)] for a given [tick] if this [tick] happened before [level]. Otherwise, - returns [None]. If provided, the evaluation is resumed from - [start_state]. *) +(** [state_of_tick plugin node_ctxt ?start_state ~tick level] returns [Some + (state, hash)] for a given [tick] if this [tick] happened before + [level]. Otherwise, returns [None]. If provided, the evaluation is resumed + from [start_state]. *) val state_of_tick : + (module Protocol_plugin_sig.PARTIAL) -> _ Node_context.t -> ?start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state -> tick:Z.t -> - Raw_level.t -> + int32 -> Fuel.Accounted.t Pvm_plugin_sig.eval_state option tzresult Lwt.t -(** [state_of_head node_ctxt ctxt head] returns the state corresponding to the - block [head], or the state at rollup genesis if the block is before the - rollup origination. *) +(** [state_of_head plugin node_ctxt ctxt head] returns the state corresponding + to the block [head], or the state at rollup genesis if the block is before + the rollup origination. *) val state_of_head : + (module Protocol_plugin_sig.PARTIAL) -> 'a Node_context.t -> 'a Context.t -> Layer1.head -> diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/interpreter_event.ml b/src/lib_smart_rollup_node/interpreter_event.ml similarity index 96% rename from src/proto_018_Proxford/lib_sc_rollup_node/interpreter_event.ml rename to src/lib_smart_rollup_node/interpreter_event.ml index 3eeb93d6b531a4f50ab2c38504c62602d5d863cc..31108746a9437077569a76a347ac01a7a7ad8907 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/interpreter_event.ml +++ b/src/lib_smart_rollup_node/interpreter_event.ml @@ -26,7 +26,7 @@ module Simple = struct include Internal_event.Simple - let section = [Protocol.name; "sc_rollup_node"; "interpreter"] + let section = ["sc_rollup_node"; "interpreter"] let transitioned_pvm = declare_4 @@ -37,7 +37,7 @@ module Simple = struct {ticks} with {num_messages} messages" ~level:Notice ("inbox_level", Data_encoding.int32) - ("state_hash", Octez_smart_rollup.State_hash.encoding) + ("state_hash", State_hash.encoding) ("ticks", Data_encoding.z) ("num_messages", Data_encoding.int31) diff --git a/src/lib_smart_rollup_node/protocol_plugin_sig.ml b/src/lib_smart_rollup_node/protocol_plugin_sig.ml index 48044883eac597263b5b22be41788bbb03cfe224..25faaf53ff8b4be2f319b5b9c9321aef0a5d379e 100644 --- a/src/lib_smart_rollup_node/protocol_plugin_sig.ml +++ b/src/lib_smart_rollup_node/protocol_plugin_sig.ml @@ -102,94 +102,6 @@ module type INBOX = sig end end -(** Protocol specific functions to interpret inbox and messages of L1 - blocks. *) -module type INTERPRETER = sig - (** [process_head node_ctxt ctxt ~predecessor head (inbox, messages)] interprets - the [messages] associated with a [head] (where [predecessor] is the - predecessor of [head] in the L1 chain). This requires the [inbox] to be - updated beforehand. It returns [(ctxt, num_messages, num_ticks, tick)] - where [ctxt] is the updated layer 2 context (with the new PVM state), - [num_messages] is the number of [messages], [num_ticks] is the number of - ticks taken by the PVM for the evaluation and [tick] is the tick reached - by the PVM after the evaluation. *) - val process_head : - Node_context.rw -> - 'a Context.t -> - predecessor:Layer1.header -> - Layer1.header -> - Octez_smart_rollup.Inbox.t * string trace -> - ('a Context.t * int * int64 * Z.t) tzresult Lwt.t - - (** [state_of_head node_ctxt ctxt head] returns the state corresponding to the - block [head], or the state at rollup genesis if the block is before the - rollup origination. *) - val state_of_head : - 'a Node_context.t -> - 'a Context.t -> - Layer1.head -> - ('a Context.t * Context.tree) tzresult Lwt.t -end - -(** Protocol specific refutation helper functions. *) -module type REFUTATION_GAME_HELPERS = sig - (** [generate_proof node_ctxt (game) start_state] generates a serialized proof - for the current [game] for the execution step starting with - [start_state]. *) - val generate_proof : - Node_context.rw -> Game.t -> Context.tree -> string tzresult Lwt.t - - (** [state_of_tick node_ctxt ?start_state ~tick level] returns [Some - (state, hash)] for a given [tick] if this [tick] happened before - [level]. Otherwise, returns [None]. If provided, the evaluation is resumed - from [start_state]. *) - val state_of_tick : - _ Node_context.t -> - ?start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state -> - tick:Z.t -> - int32 -> - Fuel.Accounted.t Pvm_plugin_sig.eval_state option tzresult Lwt.t - - (** [make_dissection node_ctxt ~start_state ~start_chunk ~our_stop_chunk - ~default_number_of_sections ~last_level] computes a dissection from between - [start_chunk] and [our_stop_chunk] at level [last_level]. This dissection - has [default_number_of_sections] if there are enough ticks. *) - val make_dissection : - _ Node_context.t -> - start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state option -> - start_chunk:Game.dissection_chunk -> - our_stop_chunk:Game.dissection_chunk -> - default_number_of_sections:int -> - last_level:int32 -> - Game.dissection_chunk trace tzresult Lwt.t - - (** [timeout_reached node_ctxt ~self ~opponent] returns [true] if the - timeout is reached against opponent in head of the L1 chain. *) - val timeout_reached : - _ Node_context.t -> - self:Signature.public_key_hash -> - opponent:Signature.public_key_hash -> - bool tzresult Lwt.t - - (** [get_conflicts cctxt rollup signer] returns the conflicts for commitments - staked on by [signer]. *) - val get_conflicts : - Client_context.full -> - Address.t -> - Signature.public_key_hash -> - Game.conflict list tzresult Lwt.t - - (** [get_ongoing_games cctxt rollup signer] returns the games that [signer] is - currently playing. *) - val get_ongoing_games : - Client_context.full -> - Address.t -> - Signature.public_key_hash -> - (Game.t * Signature.public_key_hash * Signature.public_key_hash) list - tzresult - Lwt.t -end - (** Protocol specific constants for the batcher. *) module type BATCHER_CONSTANTS = sig (** Maximum size of an L2 message allowed by the prototcol, which is @@ -279,6 +191,9 @@ module type LAYER1_HELPERS = sig #Client_context.full -> Address.t -> Node_context.genesis_info tzresult Lwt.t + + val get_boot_sector : + Block_hash.t -> _ Node_context.t -> string tzresult Lwt.t end (** Protocol specific functions for processing L1 blocks. *) @@ -292,11 +207,71 @@ module type L1_PROCESSING = sig Node_context.rw -> Layer1.header -> unit tzresult Lwt.t end +(** Partial protocol plugin with just the PVM and the function to access the + Layer1. This signature exists in order to build plugins for the interpreter + and the refutation games while avoiding circular dependencies. *) +module type PARTIAL = sig + (** The protocol for which this plugin is. *) + val protocol : Protocol_hash.t + + module Layer1_helpers : LAYER1_HELPERS + + module Pvm : Pvm_plugin_sig.S +end + +(** Protocol specific refutation helper functions. *) +module type REFUTATION_GAME_HELPERS = sig + (** [generate_proof node_ctxt (game) start_state] generates a serialized proof + for the current [game] for the execution step starting with + [start_state]. *) + val generate_proof : + Node_context.rw -> Game.t -> Context.tree -> string tzresult Lwt.t + + (** [make_dissection plugin node_ctxt ~start_state ~start_chunk ~our_stop_chunk + ~default_number_of_sections ~last_level] computes a dissection from between + [start_chunk] and [our_stop_chunk] at level [last_level]. This dissection + has [default_number_of_sections] if there are enough ticks. *) + val make_dissection : + (module PARTIAL) -> + _ Node_context.t -> + start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state option -> + start_chunk:Game.dissection_chunk -> + our_stop_chunk:Game.dissection_chunk -> + default_number_of_sections:int -> + last_level:int32 -> + Game.dissection_chunk trace tzresult Lwt.t + + (** [timeout_reached node_ctxt ~self ~opponent] returns [true] if the + timeout is reached against opponent in head of the L1 chain. *) + val timeout_reached : + _ Node_context.t -> + self:Signature.public_key_hash -> + opponent:Signature.public_key_hash -> + bool tzresult Lwt.t + + (** [get_conflicts cctxt rollup signer] returns the conflicts for commitments + staked on by [signer]. *) + val get_conflicts : + Client_context.full -> + Address.t -> + Signature.public_key_hash -> + Game.conflict list tzresult Lwt.t + + (** [get_ongoing_games cctxt rollup signer] returns the games that [signer] is + currently playing. *) + val get_ongoing_games : + Client_context.full -> + Address.t -> + Signature.public_key_hash -> + (Game.t * Signature.public_key_hash * Signature.public_key_hash) list + tzresult + Lwt.t +end + (** Signature of protocol plugins for the rollup node. NOTE: the plugins have to be registered to be made available to the rollup node. *) module type S = sig - (** The protocol for which this plugin is. *) - val protocol : Protocol_hash.t + include PARTIAL module RPC_directory : RPC_DIRECTORY @@ -304,15 +279,9 @@ module type S = sig 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 : L1_PROCESSING - module Pvm : Pvm_plugin_sig.S + module Refutation_game_helpers : REFUTATION_GAME_HELPERS end diff --git a/src/lib_smart_rollup_node/refutation_game.ml b/src/lib_smart_rollup_node/refutation_game.ml index 1725425e3840b51d88882bc18527b81a880f1d5a..5da2404cbd1c378b1405f26f78860b152973abbb 100644 --- a/src/lib_smart_rollup_node/refutation_game.ml +++ b/src/lib_smart_rollup_node/refutation_game.ml @@ -93,6 +93,7 @@ let new_dissection (module Plugin : Protocol_plugin_sig.S) ~opponent let our_stop_chunk = Game.{state_hash = our_state_hash; tick = our_tick} in let* dissection = Plugin.Refutation_game_helpers.make_dissection + (module Plugin) node_ctxt ~start_state ~start_chunk @@ -133,7 +134,8 @@ let generate_next_dissection (module Plugin : Protocol_plugin_sig.S) | Evaluated ok_state, _ -> Some ok_state in let* our = - Plugin.Refutation_game_helpers.state_of_tick + Interpreter.state_of_tick + (module Plugin) node_ctxt ?start_state ~tick @@ -181,7 +183,8 @@ let next_move (module Plugin : Protocol_plugin_sig.S) node_ctxt ~opponent let open Lwt_result_syntax in let final_move start_tick = let* start_state = - Plugin.Refutation_game_helpers.state_of_tick + Interpreter.state_of_tick + (module Plugin) node_ctxt ~tick:start_tick game.inbox_level diff --git a/src/lib_smart_rollup_node/rollup_node_daemon.ml b/src/lib_smart_rollup_node/rollup_node_daemon.ml index 9d9171661ad94d1015ef4ba376956146a53fe1ad..788f7fbc51261fc87cfffcd4e794d94f738c3f68 100644 --- a/src/lib_smart_rollup_node/rollup_node_daemon.ml +++ b/src/lib_smart_rollup_node/rollup_node_daemon.ml @@ -125,7 +125,8 @@ let process_new_head ({node_ctxt; _} as state) ~catching_up ~predecessor (* Avoid triggering the pvm execution if this has been done before for this head. *) let* ctxt, _num_messages, num_ticks, initial_tick = - Plugin.Interpreter.process_head + Interpreter.process_head + (module Plugin) node_ctxt rollup_ctxt ~predecessor @@ -435,7 +436,8 @@ module Internal_for_tests = struct messages in let* ctxt, _num_messages, num_ticks, initial_tick = - Plugin.Interpreter.process_head + Interpreter.process_head + (module Plugin) node_ctxt ctxt ~predecessor diff --git a/src/lib_smart_rollup_node/simulation.ml b/src/lib_smart_rollup_node/simulation.ml index b611936cbd584318824acaaaf41630e693d33d88..fa04d92f20dbbe34769e4d80a3a29e8f251b090b 100644 --- a/src/lib_smart_rollup_node/simulation.ml +++ b/src/lib_smart_rollup_node/simulation.ml @@ -53,7 +53,6 @@ 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) @@ -67,7 +66,9 @@ 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 = Plugin.Interpreter.state_of_head node_ctxt ctxt head in + let* ctxt, state = + Interpreter.state_of_head (module (val plugin)) node_ctxt ctxt head + in let+ info_per_level = simulate_info_per_level node_ctxt hash in { ctxt; diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml index 450299936f0078b33a9f28b9a4e03d4114df7816..2ff485e0fa9b3a5504be8bf514872f9d9cbb8f84 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml @@ -117,6 +117,7 @@ let rec process_head (daemon_components : (module Daemon_components.S)) this head. *) let* ctxt, _num_messages, num_ticks, initial_tick = Interpreter.process_head + (module Rollup_node_plugin.Plugin) node_ctxt ctxt ~predecessor @@ -428,7 +429,13 @@ module Internal_for_tests = struct messages in let* ctxt, _num_messages, num_ticks, initial_tick = - Interpreter.process_head node_ctxt ctxt ~predecessor head (inbox, messages) + Interpreter.process_head + (module Rollup_node_plugin.Plugin) + node_ctxt + ctxt + ~predecessor + head + (inbox, messages) in let*! context_hash = Context.commit ctxt in let* commitment_hash = diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml deleted file mode 100644 index 1a72e4792bf8c7fb5207a3753fe0715e4a669648..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.ml +++ /dev/null @@ -1,241 +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 - -let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = - let open Lwt_result_syntax in - match node_ctxt.boot_sector_file with - | None -> Layer1_helpers.get_boot_sector block_hash node_ctxt - | Some boot_sector_file -> - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! boot_sector = Lwt_utils_unix.read_file boot_sector_file in - let*? boot_sector = - Option.value_e - ~error: - [ - Sc_rollup_node_errors.Unparsable_boot_sector - {path = boot_sector_file}; - ] - (PVM.parse_boot_sector boot_sector) - in - return boot_sector - -let genesis_state block_hash node_ctxt ctxt = - let open Lwt_result_syntax in - let* boot_sector = get_boot_sector block_hash node_ctxt in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! initial_state = PVM.initial_state ~empty:(PVM.State.empty ()) in - let*! genesis_state = PVM.install_boot_sector initial_state boot_sector in - let*! ctxt = PVM.State.set ctxt genesis_state in - return (ctxt, genesis_state) - -let state_of_head node_ctxt ctxt Layer1.{hash; level} = - let open Lwt_result_syntax in - let*! state = Context.PVMState.find ctxt in - match state with - | None -> - let genesis_level = node_ctxt.Node_context.genesis_info.level in - if level = genesis_level then genesis_state hash node_ctxt ctxt - else tzfail (Sc_rollup_node_errors.Missing_PVM_state (hash, level)) - | Some state -> return (ctxt, state) - -(** [transition_pvm node_ctxt predecessor head] runs a PVM at the previous state - from block [predecessor] by consuming as many messages as possible from - block [head]. *) -let transition_pvm node_ctxt ctxt predecessor Layer1.{hash = _; _} - inbox_messages = - let open Lwt_result_syntax in - (* Retrieve the previous PVM state from store. *) - let* ctxt, predecessor_state = state_of_head node_ctxt ctxt predecessor in - let* eval_result = - Fueled_pvm.Free.eval_block_inbox - ~fuel:(Fuel.Free.of_ticks 0L) - node_ctxt - inbox_messages - predecessor_state - in - let* { - state = {state; state_hash; inbox_level; tick; _}; - num_messages; - num_ticks; - } = - Delayed_write_monad.apply node_ctxt eval_result - in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! ctxt = PVM.State.set ctxt state in - let*! initial_tick = PVM.get_tick predecessor_state in - (* Produce events. *) - let*! () = - Interpreter_event.transitioned_pvm inbox_level state_hash tick num_messages - in - return - (ctxt, num_messages, Z.to_int64 num_ticks, Sc_rollup.Tick.to_z initial_tick) - -(** [process_head node_ctxt ctxt ~predecessor head] runs the PVM for the given - head. *) -let process_head (node_ctxt : _ Node_context.t) ctxt - ~(predecessor : Layer1.header) (head : Layer1.header) inbox_and_messages = - let open Lwt_result_syntax in - let first_inbox_level = node_ctxt.genesis_info.level |> Int32.succ in - if head.Layer1.level >= first_inbox_level then - transition_pvm - node_ctxt - ctxt - (Layer1.head_of_header predecessor) - (Layer1.head_of_header head) - inbox_and_messages - else if head.Layer1.level = node_ctxt.genesis_info.level then - let* ctxt, state = genesis_state head.hash node_ctxt ctxt in - let*! ctxt = Context.PVMState.set ctxt state in - return (ctxt, 0, 0L, Z.zero) - else return (ctxt, 0, 0L, Z.zero) - -(** Returns the starting evaluation before the evaluation of the block. It - contains the PVM state at the end of the execution of the previous block and - the messages the block ([remaining_messages]). *) -let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - let pred_level = Int32.pred block.header.level in - let* ctxt = - Node_context.checkout_context node_ctxt block.header.predecessor - in - let* _ctxt, state = - state_of_head - node_ctxt - ctxt - Layer1.{hash = block.header.predecessor; level = pred_level} - in - let* inbox = Node_context.get_inbox node_ctxt block.header.inbox_hash in - let* {predecessor; predecessor_timestamp; messages; _} = - Node_context.get_messages node_ctxt block.header.inbox_witness - in - let inbox_level = Octez_smart_rollup.Inbox.inbox_level inbox in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! tick = PVM.get_tick state in - let*! state_hash = PVM.state_hash state in - let*? info_per_level = - Environment.wrap_tzresult - @@ Sc_rollup_inbox_message_repr.( - serialize - (Internal (Info_per_level {predecessor; predecessor_timestamp}))) - in - let messages = - let open Sc_rollup_inbox_message_repr in - unsafe_to_string start_of_level_serialized - :: unsafe_to_string info_per_level - :: messages - @ [unsafe_to_string end_of_level_serialized] - in - return - Pvm_plugin_sig. - { - state; - state_hash = Sc_rollup_proto_types.State_hash.to_octez state_hash; - inbox_level; - tick = Sc_rollup.Tick.to_z tick; - message_counter_offset = 0; - remaining_fuel = Fuel.Accounted.of_ticks 0L; - remaining_messages = messages; - } - -(** [run_for_ticks node_ctxt start_state tick_distance] starts the evaluation - of messages in the [start_state] for at most [tick_distance]. *) -let run_to_tick node_ctxt start_state tick = - let open Delayed_write_monad.Lwt_result_syntax in - let tick_distance = - Z.sub tick start_state.Pvm_plugin_sig.tick |> Z.to_int64 - in - let>+ eval_result = - Fueled_pvm.Accounted.eval_messages - node_ctxt - {start_state with remaining_fuel = Fuel.Accounted.of_ticks tick_distance} - in - eval_result.state - -let state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) tick = - let open Lwt_result_syntax in - let* start_state = - match start_state with - | Some start_state - when start_state.Pvm_plugin_sig.inbox_level = event.header.level -> - return start_state - | _ -> - (* Recompute start state on level change or if we don't have a - starting state on hand. *) - start_state_of_block node_ctxt event - in - (* TODO: #3384 - We should test that we always have enough blocks to find the tick - because [state_of_tick] is a critical function. *) - let* result_state = run_to_tick node_ctxt start_state tick in - let result_state = Delayed_write_monad.ignore result_state in - return result_state - -(* The cache allows cache intermediate states of the PVM in e.g. dissections. *) -module Tick_state_cache = - Aches_lwt.Lache.Make - (Aches.Rache.Transfer - (Aches.Rache.LRU) - (struct - type t = Z.t * Block_hash.t - - let equal (t1, b1) (t2, b2) = Z.equal t1 t2 && Block_hash.(b1 = b2) - - let hash (tick, block) = (Z.hash tick * 13) + Block_hash.hash block - end)) - -let tick_state_cache = Tick_state_cache.create 64 (* size of 2 dissections *) - -(* Memoized version of [state_of_tick_aux]. *) -let memo_state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) - tick = - Tick_state_cache.bind_or_put - tick_state_cache - (tick, event.header.block_hash) - (fun (tick, _hash) -> state_of_tick_aux node_ctxt ~start_state event tick) - Lwt.return - -(** [state_of_tick node_ctxt ?start_state tick level] returns [Some end_state] - for a given [tick] if this [tick] happened before [level]. Otherwise, - returns [None].*) -let state_of_tick node_ctxt ?start_state ~tick level = - let open Lwt_result_syntax in - let level = Raw_level.to_int32 level in - let* event = Node_context.block_with_tick node_ctxt ~max_level:level tick in - match event with - | None -> return_none - | Some event -> - assert (event.header.level <= level) ; - let* result_state = - if Node_context.is_loser node_ctxt then - (* TODO: https://gitlab.com/tezos/tezos/-/issues/5253 - The failures/loser mode does not work properly when restarting - from intermediate states. *) - state_of_tick_aux node_ctxt ~start_state:None event tick - else memo_state_of_tick_aux node_ctxt ~start_state event tick - in - return_some result_state diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.mli deleted file mode 100644 index acf81542788bac8866fabe73d00f89ba47fd9585..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter.mli +++ /dev/null @@ -1,62 +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.Alpha_context - -(** [process_head node_ctxt ~predecessor head (inbox, messages)] interprets the - [messages] associated with a [head] (where [predecessor] is the predecessor - of [head] in the L1 chain). This requires the [inbox] to be updated - beforehand. It returns [(ctxt, num_messages, num_ticks, tick)] where [ctxt] - is the updated layer 2 context (with the new PVM state), [num_messages] is - the number of [messages], [num_ticks] is the number of ticks taken by the - PVM for the evaluation and [tick] is the tick reached by the PVM after the - evaluation. *) -val process_head : - Node_context.rw -> - 'a Context.t -> - predecessor:Layer1.header -> - Layer1.header -> - Octez_smart_rollup.Inbox.t * string list -> - ('a Context.t * int * int64 * Z.t) tzresult Lwt.t - -(** [state_of_tick node_ctxt ?start_state ~tick level] returns [Some (state, - hash)] for a given [tick] if this [tick] happened before [level]. Otherwise, - returns [None]. If provided, the evaluation is resumed from - [start_state]. *) -val state_of_tick : - _ Node_context.t -> - ?start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state -> - tick:Z.t -> - Raw_level.t -> - Fuel.Accounted.t Pvm_plugin_sig.eval_state option tzresult Lwt.t - -(** [state_of_head node_ctxt ctxt head] returns the state corresponding to the - block [head], or the state at rollup genesis if the block is before the - rollup origination. *) -val state_of_head : - 'a Node_context.t -> - 'a Context.t -> - Layer1.head -> - ('a Context.t * Context.tree) tzresult Lwt.t diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter_event.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter_event.ml deleted file mode 100644 index 967bbe9094f25a4d5839b38009fe0cdc5ae3feae..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/interpreter_event.ml +++ /dev/null @@ -1,73 +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. *) -(* *) -(*****************************************************************************) - -module Simple = struct - include Internal_event.Simple - - let section = [Protocol.name; "sc_rollup_node"; "interpreter"] - - let transitioned_pvm = - declare_4 - ~section - ~name:"sc_rollup_node_interpreter_transitioned_pvm" - ~msg: - "Transitioned PVM at inbox level {inbox_level} to {state_hash} at tick \ - {ticks} with {num_messages} messages" - ~level:Notice - ("inbox_level", Data_encoding.int32) - ("state_hash", Octez_smart_rollup.State_hash.encoding) - ("ticks", Data_encoding.n) - ("num_messages", Data_encoding.int31) - - let intended_failure = - declare_4 - ~section - ~name:"sc_rollup_node_interpreter_intended_failure" - ~msg: - "Intended failure at level {level} for message indexed {message_index} \ - and at the tick {message_tick} of message processing (internal = \ - {internal})." - ~level:Notice - ("level", Data_encoding.int31) - ("message_index", Data_encoding.int31) - ("message_tick", Data_encoding.int64) - ("internal", Data_encoding.bool) -end - -(** [transition_pvm inbox_level hash tick n] emits the event that a PVM - transition is leading to the state of the given [hash] by - processing [n] messages at [tick]. *) -let transitioned_pvm inbox_level hash tick num_messages = - Simple.(emit transitioned_pvm (inbox_level, hash, tick, num_messages)) - -(** [intended_failure level message_index message_tick internal] emits - the event that an intended failure has been injected at some given - [level], during the processing of a given [message_index] and at - tick [message_tick] during this message processing. [internal] is - [true] if the failure is injected in a PVM internal - step. [internal] is [false] if the failure is injected in the input - to the PVM. *) -let intended_failure ~level ~message_index ~message_tick ~internal = - Simple.(emit intended_failure (level, message_index, message_tick, internal)) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game_helpers.ml index 0b9cc943bd163f61d88b75b77a2f9901e54a109d..79c861c89d08c10252eb87cc1a75021cfaf1c7a5 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game_helpers.ml @@ -277,19 +277,13 @@ let generate_proof (node_ctxt : _ Node_context.t) in return proof -let state_of_tick node_ctxt ?start_state ~tick level = - Interpreter.state_of_tick - node_ctxt - ?start_state - ~tick - (Raw_level.of_int32_exn level) - -let make_dissection (node_ctxt : _ Node_context.t) ~start_state ~start_chunk - ~our_stop_chunk ~default_number_of_sections ~last_level = +let make_dissection plugin (node_ctxt : _ Node_context.t) ~start_state + ~start_chunk ~our_stop_chunk ~default_number_of_sections ~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 = - state_of_tick + Interpreter.state_of_tick + plugin node_ctxt ?start_state ~tick:(Sc_rollup.Tick.to_z tick) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game_helpers.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game_helpers.mli index 8799f5deb3aa72166227ae37c12c9d2cc5226b42..f1cb92984580169289922b4e9e06d3e6de84ab0d 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game_helpers.mli +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/refutation_game_helpers.mli @@ -25,57 +25,4 @@ (* *) (*****************************************************************************) -(** [generate_proof node_ctxt (game) start_state] generates a serialized proof - for the current [game] for the execution step starting with - [start_state]. *) -val generate_proof : - Node_context.rw -> Game.t -> Context.tree -> string tzresult Lwt.t - -(** [state_of_tick node_ctxt ?start_state ~tick level] returns [Some - (state, hash)] for a given [tick] if this [tick] happened before - [level]. Otherwise, returns [None]. If provided, the evaluation is resumed - from [start_state]. *) -val state_of_tick : - _ Node_context.t -> - ?start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state -> - tick:Z.t -> - int32 -> - Fuel.Accounted.t Pvm_plugin_sig.eval_state option tzresult Lwt.t - -(** [make_dissection node_ctxt ~start_state ~start_chunk ~our_stop_chunk - ~default_number_of_sections ~last_level] computes a dissection from between - [start_chunk] and [our_stop_chunk] at level [last_level]. This dissection - has [default_number_of_sections] if there are enough ticks. *) -val make_dissection : - _ Node_context.t -> - start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state option -> - start_chunk:Game.dissection_chunk -> - our_stop_chunk:Game.dissection_chunk -> - default_number_of_sections:int -> - last_level:int32 -> - Game.dissection_chunk trace tzresult Lwt.t - -(** [timeout_reached node_ctxt ~self ~opponent] returns [true] if the - timeout is reached against opponent in head of the L1 chain. *) -val timeout_reached : - _ Node_context.t -> - self:Signature.public_key_hash -> - opponent:Signature.public_key_hash -> - bool tzresult Lwt.t - -(** [get_conflicts cctxt rollup signer] returns the conflicts for commitments - staked on by [signer]. *) -val get_conflicts : - Client_context.full -> - Address.t -> - Signature.public_key_hash -> - Game.conflict list tzresult Lwt.t - -(** [get_ongoing_games cctxt rollup signer] returns the games that [signer] is - currently playing. *) -val get_ongoing_games : - Client_context.full -> - Address.t -> - Signature.public_key_hash -> - (Game.t * Signature.public_key_hash * Signature.public_key_hash) list tzresult - Lwt.t +include Protocol_plugin_sig.REFUTATION_GAME_HELPERS diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml index 8d8f840a2f321e36874741eea360d5137d2da788..9796cf55d9ab5fa738144f7fa959d202a7c5197f 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml @@ -117,6 +117,7 @@ let rec process_head (daemon_components : (module Daemon_components.S)) this head. *) let* ctxt, _num_messages, num_ticks, initial_tick = Interpreter.process_head + (module Rollup_node_plugin.Plugin) node_ctxt ctxt ~predecessor @@ -423,7 +424,13 @@ module Internal_for_tests = struct messages in let* ctxt, _num_messages, num_ticks, initial_tick = - Interpreter.process_head node_ctxt ctxt ~predecessor head (inbox, messages) + Interpreter.process_head + (module Rollup_node_plugin.Plugin) + node_ctxt + ctxt + ~predecessor + head + (inbox, messages) in let*! context_hash = Context.commit ctxt in let* commitment_hash = diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter_event.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter_event.ml deleted file mode 100644 index 967bbe9094f25a4d5839b38009fe0cdc5ae3feae..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/interpreter_event.ml +++ /dev/null @@ -1,73 +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. *) -(* *) -(*****************************************************************************) - -module Simple = struct - include Internal_event.Simple - - let section = [Protocol.name; "sc_rollup_node"; "interpreter"] - - let transitioned_pvm = - declare_4 - ~section - ~name:"sc_rollup_node_interpreter_transitioned_pvm" - ~msg: - "Transitioned PVM at inbox level {inbox_level} to {state_hash} at tick \ - {ticks} with {num_messages} messages" - ~level:Notice - ("inbox_level", Data_encoding.int32) - ("state_hash", Octez_smart_rollup.State_hash.encoding) - ("ticks", Data_encoding.n) - ("num_messages", Data_encoding.int31) - - let intended_failure = - declare_4 - ~section - ~name:"sc_rollup_node_interpreter_intended_failure" - ~msg: - "Intended failure at level {level} for message indexed {message_index} \ - and at the tick {message_tick} of message processing (internal = \ - {internal})." - ~level:Notice - ("level", Data_encoding.int31) - ("message_index", Data_encoding.int31) - ("message_tick", Data_encoding.int64) - ("internal", Data_encoding.bool) -end - -(** [transition_pvm inbox_level hash tick n] emits the event that a PVM - transition is leading to the state of the given [hash] by - processing [n] messages at [tick]. *) -let transitioned_pvm inbox_level hash tick num_messages = - Simple.(emit transitioned_pvm (inbox_level, hash, tick, num_messages)) - -(** [intended_failure level message_index message_tick internal] emits - the event that an intended failure has been injected at some given - [level], during the processing of a given [message_index] and at - tick [message_tick] during this message processing. [internal] is - [true] if the failure is injected in a PVM internal - step. [internal] is [false] if the failure is injected in the input - to the PVM. *) -let intended_failure ~level ~message_index ~message_tick ~internal = - Simple.(emit intended_failure (level, message_index, message_tick, internal)) 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 index 2299dfa88d467f48ac3380ea44025d95dd75d0dd..a0367ac905ccf7319ea08e018521628cc939effc 100644 --- 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 @@ -277,19 +277,13 @@ let generate_proof (node_ctxt : _ Node_context.t) in return proof -let state_of_tick node_ctxt ?start_state ~tick level = - Interpreter.state_of_tick - node_ctxt - ?start_state - ~tick - (Raw_level.of_int32_exn level) - -let make_dissection (node_ctxt : _ Node_context.t) ~start_state ~start_chunk - ~our_stop_chunk ~default_number_of_sections ~last_level = +let make_dissection plugin (node_ctxt : _ Node_context.t) ~start_state + ~start_chunk ~our_stop_chunk ~default_number_of_sections ~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 = - state_of_tick + Interpreter.state_of_tick + plugin node_ctxt ?start_state ~tick:(Sc_rollup.Tick.to_z tick) 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 index 8799f5deb3aa72166227ae37c12c9d2cc5226b42..f1cb92984580169289922b4e9e06d3e6de84ab0d 100644 --- 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 @@ -25,57 +25,4 @@ (* *) (*****************************************************************************) -(** [generate_proof node_ctxt (game) start_state] generates a serialized proof - for the current [game] for the execution step starting with - [start_state]. *) -val generate_proof : - Node_context.rw -> Game.t -> Context.tree -> string tzresult Lwt.t - -(** [state_of_tick node_ctxt ?start_state ~tick level] returns [Some - (state, hash)] for a given [tick] if this [tick] happened before - [level]. Otherwise, returns [None]. If provided, the evaluation is resumed - from [start_state]. *) -val state_of_tick : - _ Node_context.t -> - ?start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state -> - tick:Z.t -> - int32 -> - Fuel.Accounted.t Pvm_plugin_sig.eval_state option tzresult Lwt.t - -(** [make_dissection node_ctxt ~start_state ~start_chunk ~our_stop_chunk - ~default_number_of_sections ~last_level] computes a dissection from between - [start_chunk] and [our_stop_chunk] at level [last_level]. This dissection - has [default_number_of_sections] if there are enough ticks. *) -val make_dissection : - _ Node_context.t -> - start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state option -> - start_chunk:Game.dissection_chunk -> - our_stop_chunk:Game.dissection_chunk -> - default_number_of_sections:int -> - last_level:int32 -> - Game.dissection_chunk trace tzresult Lwt.t - -(** [timeout_reached node_ctxt ~self ~opponent] returns [true] if the - timeout is reached against opponent in head of the L1 chain. *) -val timeout_reached : - _ Node_context.t -> - self:Signature.public_key_hash -> - opponent:Signature.public_key_hash -> - bool tzresult Lwt.t - -(** [get_conflicts cctxt rollup signer] returns the conflicts for commitments - staked on by [signer]. *) -val get_conflicts : - Client_context.full -> - Address.t -> - Signature.public_key_hash -> - Game.conflict list tzresult Lwt.t - -(** [get_ongoing_games cctxt rollup signer] returns the games that [signer] is - currently playing. *) -val get_ongoing_games : - Client_context.full -> - Address.t -> - Signature.public_key_hash -> - (Game.t * Signature.public_key_hash * Signature.public_key_hash) list tzresult - Lwt.t +include Protocol_plugin_sig.REFUTATION_GAME_HELPERS diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/daemon.ml b/src/proto_018_Proxford/lib_sc_rollup_node/daemon.ml index 9666e64b79806c35d5c3ec069e9fcbe6a83a1414..24253ce0756f8ee87913e3f367aef56756022cf6 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/daemon.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/daemon.ml @@ -122,6 +122,7 @@ let rec process_head (daemon_components : (module Daemon_components.S)) this head. *) let* ctxt, _num_messages, num_ticks, initial_tick = Interpreter.process_head + (module Rollup_node_plugin.Plugin) node_ctxt ctxt ~predecessor @@ -440,7 +441,13 @@ module Internal_for_tests = struct in let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in let* ctxt, _num_messages, num_ticks, initial_tick = - Interpreter.process_head node_ctxt ctxt ~predecessor head (inbox, messages) + Interpreter.process_head + (module Rollup_node_plugin.Plugin) + node_ctxt + ctxt + ~predecessor + head + (inbox, messages) in let*! context_hash = Context.commit ctxt in let* commitment_hash = diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/interpreter.ml b/src/proto_018_Proxford/lib_sc_rollup_node/interpreter.ml deleted file mode 100644 index c9c79e88f647613dc8fc8f1ac53a398588709deb..0000000000000000000000000000000000000000 --- a/src/proto_018_Proxford/lib_sc_rollup_node/interpreter.ml +++ /dev/null @@ -1,247 +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 - -let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = - let open Lwt_result_syntax in - match node_ctxt.boot_sector_file with - | None -> Layer1_helpers.get_boot_sector block_hash node_ctxt - | Some boot_sector_file -> - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! boot_sector = Lwt_utils_unix.read_file boot_sector_file in - let*? boot_sector = - Option.value_e - ~error: - [ - Sc_rollup_node_errors.Unparsable_boot_sector - {path = boot_sector_file}; - ] - (PVM.parse_boot_sector boot_sector) - in - return boot_sector - -let genesis_state block_hash node_ctxt ctxt = - let open Lwt_result_syntax in - let* boot_sector = get_boot_sector block_hash node_ctxt in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! initial_state = PVM.initial_state ~empty:(PVM.State.empty ()) in - let*! genesis_state = PVM.install_boot_sector initial_state boot_sector in - let*! ctxt = PVM.State.set ctxt genesis_state in - return (ctxt, genesis_state) - -let state_of_head node_ctxt ctxt Layer1.{hash; level} = - let open Lwt_result_syntax in - let*! state = Context.PVMState.find ctxt in - match state with - | None -> - let genesis_level = node_ctxt.Node_context.genesis_info.level in - if level = genesis_level then genesis_state hash node_ctxt ctxt - else tzfail (Sc_rollup_node_errors.Missing_PVM_state (hash, level)) - | Some state -> return (ctxt, state) - -(** [transition_pvm node_ctxt predecessor head] runs a PVM at the previous state - from block [predecessor] by consuming as many messages as possible from - block [head]. *) -let transition_pvm node_ctxt ctxt predecessor Layer1.{hash = _; _} - inbox_messages = - let open Lwt_result_syntax in - (* Retrieve the previous PVM state from store. *) - let* ctxt, predecessor_state = state_of_head node_ctxt ctxt predecessor in - let* eval_result = - Fueled_pvm.Free.eval_block_inbox - ~fuel:(Fuel.Free.of_ticks 0L) - node_ctxt - inbox_messages - predecessor_state - in - let* { - state = {state; state_hash; inbox_level; tick; _}; - num_messages; - num_ticks; - } = - Delayed_write_monad.apply node_ctxt eval_result - in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! ctxt = PVM.State.set ctxt state in - let*! initial_tick = PVM.get_tick predecessor_state in - (* Produce events. *) - let*! () = - Interpreter_event.transitioned_pvm inbox_level state_hash tick num_messages - in - return - (ctxt, num_messages, Z.to_int64 num_ticks, Sc_rollup.Tick.to_z initial_tick) - -(** [process_head node_ctxt ctxt ~predecessor head] runs the PVM for the given - head. *) -let process_head (node_ctxt : _ Node_context.t) ctxt - ~(predecessor : Layer1.header) (head : Layer1.header) inbox_and_messages = - let open Lwt_result_syntax in - let first_inbox_level = node_ctxt.genesis_info.level |> Int32.succ in - if head.Layer1.level >= first_inbox_level then - transition_pvm - node_ctxt - ctxt - (Layer1.head_of_header predecessor) - (Layer1.head_of_header head) - inbox_and_messages - else if head.Layer1.level = node_ctxt.genesis_info.level then - let* ctxt, state = genesis_state head.hash node_ctxt ctxt in - let*! ctxt = Context.PVMState.set ctxt state in - return (ctxt, 0, 0L, Z.zero) - else return (ctxt, 0, 0L, Z.zero) - -(** Returns the starting evaluation before the evaluation of the block. It - contains the PVM state at the end of the execution of the previous block and - the messages the block ([remaining_messages]). *) -let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - let pred_level = Int32.pred block.header.level in - let* ctxt = - Node_context.checkout_context node_ctxt block.header.predecessor - in - let* _ctxt, state = - state_of_head - node_ctxt - ctxt - Layer1.{hash = block.header.predecessor; level = pred_level} - in - let* inbox = - Node_context.get_inbox - node_ctxt - (Sc_rollup_proto_types.Inbox_hash.of_octez block.header.inbox_hash) - in - let* {is_first_block; predecessor; predecessor_timestamp; messages} = - Node_context.get_messages - node_ctxt - (Sc_rollup_proto_types.Merkelized_payload_hashes_hash.of_octez - block.header.inbox_witness) - in - let inbox_level = Octez_smart_rollup.Inbox.inbox_level inbox in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! tick = PVM.get_tick state in - let*! state_hash = PVM.state_hash state in - let messages = - let open Sc_rollup_inbox_message_repr in - unsafe_to_string start_of_level_serialized - :: - (if is_first_block then - [unsafe_to_string Raw_context.protocol_migration_serialized_message] - else []) - @ unsafe_to_string - (info_per_level_serialized ~predecessor ~predecessor_timestamp) - :: messages - @ [unsafe_to_string end_of_level_serialized] - in - return - Pvm_plugin_sig. - { - state; - state_hash; - inbox_level; - tick = Sc_rollup.Tick.to_z tick; - message_counter_offset = 0; - remaining_fuel = Fuel.Accounted.of_ticks 0L; - remaining_messages = messages; - } - -(** [run_for_ticks node_ctxt start_state tick_distance] starts the evaluation - of messages in the [start_state] for at most [tick_distance]. *) -let run_to_tick node_ctxt start_state tick = - let open Delayed_write_monad.Lwt_result_syntax in - let tick_distance = - Z.sub tick start_state.Pvm_plugin_sig.tick |> Z.to_int64 - in - let>+ eval_result = - Fueled_pvm.Accounted.eval_messages - node_ctxt - {start_state with remaining_fuel = Fuel.Accounted.of_ticks tick_distance} - in - eval_result.state - -let state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) tick = - let open Lwt_result_syntax in - let* start_state = - match start_state with - | Some start_state - when start_state.Pvm_plugin_sig.inbox_level = event.header.level -> - return start_state - | _ -> - (* Recompute start state on level change or if we don't have a - starting state on hand. *) - start_state_of_block node_ctxt event - in - (* TODO: #3384 - We should test that we always have enough blocks to find the tick - because [state_of_tick] is a critical function. *) - let* result_state = run_to_tick node_ctxt start_state tick in - let result_state = Delayed_write_monad.ignore result_state in - return result_state - -(* The cache allows cache intermediate states of the PVM in e.g. dissections. *) -module Tick_state_cache = - Aches_lwt.Lache.Make - (Aches.Rache.Transfer - (Aches.Rache.LRU) - (struct - type t = Z.t * Block_hash.t - - let equal (t1, b1) (t2, b2) = Z.equal t1 t2 && Block_hash.(b1 = b2) - - let hash (tick, block) = (Z.hash tick * 13) + Block_hash.hash block - end)) - -let tick_state_cache = Tick_state_cache.create 64 (* size of 2 dissections *) - -(* Memoized version of [state_of_tick_aux]. *) -let memo_state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) - tick = - Tick_state_cache.bind_or_put - tick_state_cache - (tick, event.header.block_hash) - (fun (tick, _hash) -> state_of_tick_aux node_ctxt ~start_state event tick) - Lwt.return - -(** [state_of_tick node_ctxt ?start_state tick level] returns [Some end_state] - for a given [tick] if this [tick] happened before [level]. Otherwise, - returns [None].*) -let state_of_tick node_ctxt ?start_state ~tick level = - let open Lwt_result_syntax in - let level = Raw_level.to_int32 level in - let* event = Node_context.block_with_tick node_ctxt ~max_level:level tick in - match event with - | None -> return_none - | Some event -> - assert (event.header.level <= level) ; - let* result_state = - if Node_context.is_loser node_ctxt then - (* TODO: https://gitlab.com/tezos/tezos/-/issues/5253 - The failures/loser mode does not work properly when restarting - from intermediate states. *) - state_of_tick_aux node_ctxt ~start_state:None event tick - else memo_state_of_tick_aux node_ctxt ~start_state event tick - in - return_some result_state diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/interpreter.mli b/src/proto_018_Proxford/lib_sc_rollup_node/interpreter.mli deleted file mode 100644 index acf81542788bac8866fabe73d00f89ba47fd9585..0000000000000000000000000000000000000000 --- a/src/proto_018_Proxford/lib_sc_rollup_node/interpreter.mli +++ /dev/null @@ -1,62 +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.Alpha_context - -(** [process_head node_ctxt ~predecessor head (inbox, messages)] interprets the - [messages] associated with a [head] (where [predecessor] is the predecessor - of [head] in the L1 chain). This requires the [inbox] to be updated - beforehand. It returns [(ctxt, num_messages, num_ticks, tick)] where [ctxt] - is the updated layer 2 context (with the new PVM state), [num_messages] is - the number of [messages], [num_ticks] is the number of ticks taken by the - PVM for the evaluation and [tick] is the tick reached by the PVM after the - evaluation. *) -val process_head : - Node_context.rw -> - 'a Context.t -> - predecessor:Layer1.header -> - Layer1.header -> - Octez_smart_rollup.Inbox.t * string list -> - ('a Context.t * int * int64 * Z.t) tzresult Lwt.t - -(** [state_of_tick node_ctxt ?start_state ~tick level] returns [Some (state, - hash)] for a given [tick] if this [tick] happened before [level]. Otherwise, - returns [None]. If provided, the evaluation is resumed from - [start_state]. *) -val state_of_tick : - _ Node_context.t -> - ?start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state -> - tick:Z.t -> - Raw_level.t -> - Fuel.Accounted.t Pvm_plugin_sig.eval_state option tzresult Lwt.t - -(** [state_of_head node_ctxt ctxt head] returns the state corresponding to the - block [head], or the state at rollup genesis if the block is before the - rollup origination. *) -val state_of_head : - 'a Node_context.t -> - 'a Context.t -> - Layer1.head -> - ('a Context.t * Context.tree) tzresult Lwt.t diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.ml index 850e54227fb888d5885e99ede49b502304295902..008a5c2505e3321a5b2e61cfdf7be8e5e04764bb 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.ml @@ -283,19 +283,13 @@ let generate_proof (node_ctxt : _ Node_context.t) in return proof -let state_of_tick node_ctxt ?start_state ~tick level = - Interpreter.state_of_tick - node_ctxt - ?start_state - ~tick - (Raw_level.of_int32_exn level) - -let make_dissection (node_ctxt : _ Node_context.t) ~start_state ~start_chunk - ~our_stop_chunk ~default_number_of_sections ~last_level = +let make_dissection plugin (node_ctxt : _ Node_context.t) ~start_state + ~start_chunk ~our_stop_chunk ~default_number_of_sections ~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 = - state_of_tick + Interpreter.state_of_tick + plugin node_ctxt ?start_state ~tick:(Sc_rollup.Tick.to_z tick) diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.mli b/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.mli index 8799f5deb3aa72166227ae37c12c9d2cc5226b42..f1cb92984580169289922b4e9e06d3e6de84ab0d 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.mli +++ b/src/proto_018_Proxford/lib_sc_rollup_node/refutation_game_helpers.mli @@ -25,57 +25,4 @@ (* *) (*****************************************************************************) -(** [generate_proof node_ctxt (game) start_state] generates a serialized proof - for the current [game] for the execution step starting with - [start_state]. *) -val generate_proof : - Node_context.rw -> Game.t -> Context.tree -> string tzresult Lwt.t - -(** [state_of_tick node_ctxt ?start_state ~tick level] returns [Some - (state, hash)] for a given [tick] if this [tick] happened before - [level]. Otherwise, returns [None]. If provided, the evaluation is resumed - from [start_state]. *) -val state_of_tick : - _ Node_context.t -> - ?start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state -> - tick:Z.t -> - int32 -> - Fuel.Accounted.t Pvm_plugin_sig.eval_state option tzresult Lwt.t - -(** [make_dissection node_ctxt ~start_state ~start_chunk ~our_stop_chunk - ~default_number_of_sections ~last_level] computes a dissection from between - [start_chunk] and [our_stop_chunk] at level [last_level]. This dissection - has [default_number_of_sections] if there are enough ticks. *) -val make_dissection : - _ Node_context.t -> - start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state option -> - start_chunk:Game.dissection_chunk -> - our_stop_chunk:Game.dissection_chunk -> - default_number_of_sections:int -> - last_level:int32 -> - Game.dissection_chunk trace tzresult Lwt.t - -(** [timeout_reached node_ctxt ~self ~opponent] returns [true] if the - timeout is reached against opponent in head of the L1 chain. *) -val timeout_reached : - _ Node_context.t -> - self:Signature.public_key_hash -> - opponent:Signature.public_key_hash -> - bool tzresult Lwt.t - -(** [get_conflicts cctxt rollup signer] returns the conflicts for commitments - staked on by [signer]. *) -val get_conflicts : - Client_context.full -> - Address.t -> - Signature.public_key_hash -> - Game.conflict list tzresult Lwt.t - -(** [get_ongoing_games cctxt rollup signer] returns the games that [signer] is - currently playing. *) -val get_ongoing_games : - Client_context.full -> - Address.t -> - Signature.public_key_hash -> - (Game.t * Signature.public_key_hash * Signature.public_key_hash) list tzresult - Lwt.t +include Protocol_plugin_sig.REFUTATION_GAME_HELPERS diff --git a/src/proto_018_Proxford/lib_sc_rollup_node/rollup_node_plugin.ml b/src/proto_018_Proxford/lib_sc_rollup_node/rollup_node_plugin.ml index 4c5dd5e5cfe44af177cd455e62b8dd74819996ad..07f675c950ad39f288ed8fad3625565b01b13d31 100644 --- a/src/proto_018_Proxford/lib_sc_rollup_node/rollup_node_plugin.ml +++ b/src/proto_018_Proxford/lib_sc_rollup_node/rollup_node_plugin.ml @@ -29,7 +29,6 @@ module Plugin : Protocol_plugin_sig.S = struct 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 diff --git a/src/proto_alpha/lib_sc_rollup_node/daemon.ml b/src/proto_alpha/lib_sc_rollup_node/daemon.ml index 9666e64b79806c35d5c3ec069e9fcbe6a83a1414..24253ce0756f8ee87913e3f367aef56756022cf6 100644 --- a/src/proto_alpha/lib_sc_rollup_node/daemon.ml +++ b/src/proto_alpha/lib_sc_rollup_node/daemon.ml @@ -122,6 +122,7 @@ let rec process_head (daemon_components : (module Daemon_components.S)) this head. *) let* ctxt, _num_messages, num_ticks, initial_tick = Interpreter.process_head + (module Rollup_node_plugin.Plugin) node_ctxt ctxt ~predecessor @@ -440,7 +441,13 @@ module Internal_for_tests = struct in let inbox_hash = Sc_rollup_proto_types.Inbox_hash.to_octez inbox_hash in let* ctxt, _num_messages, num_ticks, initial_tick = - Interpreter.process_head node_ctxt ctxt ~predecessor head (inbox, messages) + Interpreter.process_head + (module Rollup_node_plugin.Plugin) + node_ctxt + ctxt + ~predecessor + head + (inbox, messages) in let*! context_hash = Context.commit ctxt in let* commitment_hash = diff --git a/src/proto_alpha/lib_sc_rollup_node/interpreter.ml b/src/proto_alpha/lib_sc_rollup_node/interpreter.ml deleted file mode 100644 index c9c79e88f647613dc8fc8f1ac53a398588709deb..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_node/interpreter.ml +++ /dev/null @@ -1,247 +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 - -let get_boot_sector block_hash (node_ctxt : _ Node_context.t) = - let open Lwt_result_syntax in - match node_ctxt.boot_sector_file with - | None -> Layer1_helpers.get_boot_sector block_hash node_ctxt - | Some boot_sector_file -> - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! boot_sector = Lwt_utils_unix.read_file boot_sector_file in - let*? boot_sector = - Option.value_e - ~error: - [ - Sc_rollup_node_errors.Unparsable_boot_sector - {path = boot_sector_file}; - ] - (PVM.parse_boot_sector boot_sector) - in - return boot_sector - -let genesis_state block_hash node_ctxt ctxt = - let open Lwt_result_syntax in - let* boot_sector = get_boot_sector block_hash node_ctxt in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! initial_state = PVM.initial_state ~empty:(PVM.State.empty ()) in - let*! genesis_state = PVM.install_boot_sector initial_state boot_sector in - let*! ctxt = PVM.State.set ctxt genesis_state in - return (ctxt, genesis_state) - -let state_of_head node_ctxt ctxt Layer1.{hash; level} = - let open Lwt_result_syntax in - let*! state = Context.PVMState.find ctxt in - match state with - | None -> - let genesis_level = node_ctxt.Node_context.genesis_info.level in - if level = genesis_level then genesis_state hash node_ctxt ctxt - else tzfail (Sc_rollup_node_errors.Missing_PVM_state (hash, level)) - | Some state -> return (ctxt, state) - -(** [transition_pvm node_ctxt predecessor head] runs a PVM at the previous state - from block [predecessor] by consuming as many messages as possible from - block [head]. *) -let transition_pvm node_ctxt ctxt predecessor Layer1.{hash = _; _} - inbox_messages = - let open Lwt_result_syntax in - (* Retrieve the previous PVM state from store. *) - let* ctxt, predecessor_state = state_of_head node_ctxt ctxt predecessor in - let* eval_result = - Fueled_pvm.Free.eval_block_inbox - ~fuel:(Fuel.Free.of_ticks 0L) - node_ctxt - inbox_messages - predecessor_state - in - let* { - state = {state; state_hash; inbox_level; tick; _}; - num_messages; - num_ticks; - } = - Delayed_write_monad.apply node_ctxt eval_result - in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! ctxt = PVM.State.set ctxt state in - let*! initial_tick = PVM.get_tick predecessor_state in - (* Produce events. *) - let*! () = - Interpreter_event.transitioned_pvm inbox_level state_hash tick num_messages - in - return - (ctxt, num_messages, Z.to_int64 num_ticks, Sc_rollup.Tick.to_z initial_tick) - -(** [process_head node_ctxt ctxt ~predecessor head] runs the PVM for the given - head. *) -let process_head (node_ctxt : _ Node_context.t) ctxt - ~(predecessor : Layer1.header) (head : Layer1.header) inbox_and_messages = - let open Lwt_result_syntax in - let first_inbox_level = node_ctxt.genesis_info.level |> Int32.succ in - if head.Layer1.level >= first_inbox_level then - transition_pvm - node_ctxt - ctxt - (Layer1.head_of_header predecessor) - (Layer1.head_of_header head) - inbox_and_messages - else if head.Layer1.level = node_ctxt.genesis_info.level then - let* ctxt, state = genesis_state head.hash node_ctxt ctxt in - let*! ctxt = Context.PVMState.set ctxt state in - return (ctxt, 0, 0L, Z.zero) - else return (ctxt, 0, 0L, Z.zero) - -(** Returns the starting evaluation before the evaluation of the block. It - contains the PVM state at the end of the execution of the previous block and - the messages the block ([remaining_messages]). *) -let start_state_of_block node_ctxt (block : Sc_rollup_block.t) = - let open Lwt_result_syntax in - let pred_level = Int32.pred block.header.level in - let* ctxt = - Node_context.checkout_context node_ctxt block.header.predecessor - in - let* _ctxt, state = - state_of_head - node_ctxt - ctxt - Layer1.{hash = block.header.predecessor; level = pred_level} - in - let* inbox = - Node_context.get_inbox - node_ctxt - (Sc_rollup_proto_types.Inbox_hash.of_octez block.header.inbox_hash) - in - let* {is_first_block; predecessor; predecessor_timestamp; messages} = - Node_context.get_messages - node_ctxt - (Sc_rollup_proto_types.Merkelized_payload_hashes_hash.of_octez - block.header.inbox_witness) - in - let inbox_level = Octez_smart_rollup.Inbox.inbox_level inbox in - let module PVM = (val Pvm.of_kind node_ctxt.kind) in - let*! tick = PVM.get_tick state in - let*! state_hash = PVM.state_hash state in - let messages = - let open Sc_rollup_inbox_message_repr in - unsafe_to_string start_of_level_serialized - :: - (if is_first_block then - [unsafe_to_string Raw_context.protocol_migration_serialized_message] - else []) - @ unsafe_to_string - (info_per_level_serialized ~predecessor ~predecessor_timestamp) - :: messages - @ [unsafe_to_string end_of_level_serialized] - in - return - Pvm_plugin_sig. - { - state; - state_hash; - inbox_level; - tick = Sc_rollup.Tick.to_z tick; - message_counter_offset = 0; - remaining_fuel = Fuel.Accounted.of_ticks 0L; - remaining_messages = messages; - } - -(** [run_for_ticks node_ctxt start_state tick_distance] starts the evaluation - of messages in the [start_state] for at most [tick_distance]. *) -let run_to_tick node_ctxt start_state tick = - let open Delayed_write_monad.Lwt_result_syntax in - let tick_distance = - Z.sub tick start_state.Pvm_plugin_sig.tick |> Z.to_int64 - in - let>+ eval_result = - Fueled_pvm.Accounted.eval_messages - node_ctxt - {start_state with remaining_fuel = Fuel.Accounted.of_ticks tick_distance} - in - eval_result.state - -let state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) tick = - let open Lwt_result_syntax in - let* start_state = - match start_state with - | Some start_state - when start_state.Pvm_plugin_sig.inbox_level = event.header.level -> - return start_state - | _ -> - (* Recompute start state on level change or if we don't have a - starting state on hand. *) - start_state_of_block node_ctxt event - in - (* TODO: #3384 - We should test that we always have enough blocks to find the tick - because [state_of_tick] is a critical function. *) - let* result_state = run_to_tick node_ctxt start_state tick in - let result_state = Delayed_write_monad.ignore result_state in - return result_state - -(* The cache allows cache intermediate states of the PVM in e.g. dissections. *) -module Tick_state_cache = - Aches_lwt.Lache.Make - (Aches.Rache.Transfer - (Aches.Rache.LRU) - (struct - type t = Z.t * Block_hash.t - - let equal (t1, b1) (t2, b2) = Z.equal t1 t2 && Block_hash.(b1 = b2) - - let hash (tick, block) = (Z.hash tick * 13) + Block_hash.hash block - end)) - -let tick_state_cache = Tick_state_cache.create 64 (* size of 2 dissections *) - -(* Memoized version of [state_of_tick_aux]. *) -let memo_state_of_tick_aux node_ctxt ~start_state (event : Sc_rollup_block.t) - tick = - Tick_state_cache.bind_or_put - tick_state_cache - (tick, event.header.block_hash) - (fun (tick, _hash) -> state_of_tick_aux node_ctxt ~start_state event tick) - Lwt.return - -(** [state_of_tick node_ctxt ?start_state tick level] returns [Some end_state] - for a given [tick] if this [tick] happened before [level]. Otherwise, - returns [None].*) -let state_of_tick node_ctxt ?start_state ~tick level = - let open Lwt_result_syntax in - let level = Raw_level.to_int32 level in - let* event = Node_context.block_with_tick node_ctxt ~max_level:level tick in - match event with - | None -> return_none - | Some event -> - assert (event.header.level <= level) ; - let* result_state = - if Node_context.is_loser node_ctxt then - (* TODO: https://gitlab.com/tezos/tezos/-/issues/5253 - The failures/loser mode does not work properly when restarting - from intermediate states. *) - state_of_tick_aux node_ctxt ~start_state:None event tick - else memo_state_of_tick_aux node_ctxt ~start_state event tick - in - return_some result_state diff --git a/src/proto_alpha/lib_sc_rollup_node/interpreter.mli b/src/proto_alpha/lib_sc_rollup_node/interpreter.mli deleted file mode 100644 index acf81542788bac8866fabe73d00f89ba47fd9585..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_node/interpreter.mli +++ /dev/null @@ -1,62 +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.Alpha_context - -(** [process_head node_ctxt ~predecessor head (inbox, messages)] interprets the - [messages] associated with a [head] (where [predecessor] is the predecessor - of [head] in the L1 chain). This requires the [inbox] to be updated - beforehand. It returns [(ctxt, num_messages, num_ticks, tick)] where [ctxt] - is the updated layer 2 context (with the new PVM state), [num_messages] is - the number of [messages], [num_ticks] is the number of ticks taken by the - PVM for the evaluation and [tick] is the tick reached by the PVM after the - evaluation. *) -val process_head : - Node_context.rw -> - 'a Context.t -> - predecessor:Layer1.header -> - Layer1.header -> - Octez_smart_rollup.Inbox.t * string list -> - ('a Context.t * int * int64 * Z.t) tzresult Lwt.t - -(** [state_of_tick node_ctxt ?start_state ~tick level] returns [Some (state, - hash)] for a given [tick] if this [tick] happened before [level]. Otherwise, - returns [None]. If provided, the evaluation is resumed from - [start_state]. *) -val state_of_tick : - _ Node_context.t -> - ?start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state -> - tick:Z.t -> - Raw_level.t -> - Fuel.Accounted.t Pvm_plugin_sig.eval_state option tzresult Lwt.t - -(** [state_of_head node_ctxt ctxt head] returns the state corresponding to the - block [head], or the state at rollup genesis if the block is before the - rollup origination. *) -val state_of_head : - 'a Node_context.t -> - 'a Context.t -> - Layer1.head -> - ('a Context.t * Context.tree) tzresult Lwt.t diff --git a/src/proto_alpha/lib_sc_rollup_node/interpreter_event.ml b/src/proto_alpha/lib_sc_rollup_node/interpreter_event.ml deleted file mode 100644 index 3eeb93d6b531a4f50ab2c38504c62602d5d863cc..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_node/interpreter_event.ml +++ /dev/null @@ -1,73 +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. *) -(* *) -(*****************************************************************************) - -module Simple = struct - include Internal_event.Simple - - let section = [Protocol.name; "sc_rollup_node"; "interpreter"] - - let transitioned_pvm = - declare_4 - ~section - ~name:"sc_rollup_node_interpreter_transitioned_pvm" - ~msg: - "Transitioned PVM at inbox level {inbox_level} to {state_hash} at tick \ - {ticks} with {num_messages} messages" - ~level:Notice - ("inbox_level", Data_encoding.int32) - ("state_hash", Octez_smart_rollup.State_hash.encoding) - ("ticks", Data_encoding.z) - ("num_messages", Data_encoding.int31) - - let intended_failure = - declare_4 - ~section - ~name:"sc_rollup_node_interpreter_intended_failure" - ~msg: - "Intended failure at level {level} for message indexed {message_index} \ - and at the tick {message_tick} of message processing (internal = \ - {internal})." - ~level:Notice - ("level", Data_encoding.int31) - ("message_index", Data_encoding.int31) - ("message_tick", Data_encoding.int64) - ("internal", Data_encoding.bool) -end - -(** [transition_pvm inbox_level hash tick n] emits the event that a PVM - transition is leading to the state of the given [hash] by - processing [n] messages at [tick]. *) -let transitioned_pvm inbox_level hash tick num_messages = - Simple.(emit transitioned_pvm (inbox_level, hash, tick, num_messages)) - -(** [intended_failure level message_index message_tick internal] emits - the event that an intended failure has been injected at some given - [level], during the processing of a given [message_index] and at - tick [message_tick] during this message processing. [internal] is - [true] if the failure is injected in a PVM internal - step. [internal] is [false] if the failure is injected in the input - to the PVM. *) -let intended_failure ~level ~message_index ~message_tick ~internal = - Simple.(emit intended_failure (level, message_index, message_tick, internal)) diff --git a/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml b/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml index 850e54227fb888d5885e99ede49b502304295902..008a5c2505e3321a5b2e61cfdf7be8e5e04764bb 100644 --- a/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.ml @@ -283,19 +283,13 @@ let generate_proof (node_ctxt : _ Node_context.t) in return proof -let state_of_tick node_ctxt ?start_state ~tick level = - Interpreter.state_of_tick - node_ctxt - ?start_state - ~tick - (Raw_level.of_int32_exn level) - -let make_dissection (node_ctxt : _ Node_context.t) ~start_state ~start_chunk - ~our_stop_chunk ~default_number_of_sections ~last_level = +let make_dissection plugin (node_ctxt : _ Node_context.t) ~start_state + ~start_chunk ~our_stop_chunk ~default_number_of_sections ~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 = - state_of_tick + Interpreter.state_of_tick + plugin node_ctxt ?start_state ~tick:(Sc_rollup.Tick.to_z tick) diff --git a/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.mli b/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.mli index 8799f5deb3aa72166227ae37c12c9d2cc5226b42..f1cb92984580169289922b4e9e06d3e6de84ab0d 100644 --- a/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.mli +++ b/src/proto_alpha/lib_sc_rollup_node/refutation_game_helpers.mli @@ -25,57 +25,4 @@ (* *) (*****************************************************************************) -(** [generate_proof node_ctxt (game) start_state] generates a serialized proof - for the current [game] for the execution step starting with - [start_state]. *) -val generate_proof : - Node_context.rw -> Game.t -> Context.tree -> string tzresult Lwt.t - -(** [state_of_tick node_ctxt ?start_state ~tick level] returns [Some - (state, hash)] for a given [tick] if this [tick] happened before - [level]. Otherwise, returns [None]. If provided, the evaluation is resumed - from [start_state]. *) -val state_of_tick : - _ Node_context.t -> - ?start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state -> - tick:Z.t -> - int32 -> - Fuel.Accounted.t Pvm_plugin_sig.eval_state option tzresult Lwt.t - -(** [make_dissection node_ctxt ~start_state ~start_chunk ~our_stop_chunk - ~default_number_of_sections ~last_level] computes a dissection from between - [start_chunk] and [our_stop_chunk] at level [last_level]. This dissection - has [default_number_of_sections] if there are enough ticks. *) -val make_dissection : - _ Node_context.t -> - start_state:Fuel.Accounted.t Pvm_plugin_sig.eval_state option -> - start_chunk:Game.dissection_chunk -> - our_stop_chunk:Game.dissection_chunk -> - default_number_of_sections:int -> - last_level:int32 -> - Game.dissection_chunk trace tzresult Lwt.t - -(** [timeout_reached node_ctxt ~self ~opponent] returns [true] if the - timeout is reached against opponent in head of the L1 chain. *) -val timeout_reached : - _ Node_context.t -> - self:Signature.public_key_hash -> - opponent:Signature.public_key_hash -> - bool tzresult Lwt.t - -(** [get_conflicts cctxt rollup signer] returns the conflicts for commitments - staked on by [signer]. *) -val get_conflicts : - Client_context.full -> - Address.t -> - Signature.public_key_hash -> - Game.conflict list tzresult Lwt.t - -(** [get_ongoing_games cctxt rollup signer] returns the games that [signer] is - currently playing. *) -val get_ongoing_games : - Client_context.full -> - Address.t -> - Signature.public_key_hash -> - (Game.t * Signature.public_key_hash * Signature.public_key_hash) list tzresult - Lwt.t +include Protocol_plugin_sig.REFUTATION_GAME_HELPERS diff --git a/src/proto_alpha/lib_sc_rollup_node/rollup_node_plugin.ml b/src/proto_alpha/lib_sc_rollup_node/rollup_node_plugin.ml index 4c5dd5e5cfe44af177cd455e62b8dd74819996ad..07f675c950ad39f288ed8fad3625565b01b13d31 100644 --- a/src/proto_alpha/lib_sc_rollup_node/rollup_node_plugin.ml +++ b/src/proto_alpha/lib_sc_rollup_node/rollup_node_plugin.ml @@ -29,7 +29,6 @@ module Plugin : Protocol_plugin_sig.S = struct 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